@@ -68,7 +68,7 @@ public function shouldDoNothingForHaveNullMethod()
68
68
->method ('getUrl ' );
69
69
70
70
$ listener = new AuthListener (null , array ('password ' => 'pass ' , 'tokenOrLogin ' => 'test ' ));
71
- $ this -> assertNull ( $ listener ->preSend ($ request) );
71
+ $ listener ->preSend ($ request );
72
72
}
73
73
74
74
/**
@@ -99,35 +99,51 @@ public function shouldDoNothingForPostSend()
99
99
->method ('getHeader ' );
100
100
101
101
$ listener = new AuthListener (Client::AUTH_HTTP_PASSWORD , array ('tokenOrLogin ' => 'login ' , 'password ' => 'mypasswd ' ));
102
- $ this -> assertNull ( $ listener ->postSend ($ request , $ response) );
102
+ $ listener ->postSend ($ request , $ response );
103
103
}
104
104
105
105
/**
106
106
* @test
107
107
*/
108
108
public function shouldSetAuthBasicHeaderForAuthPassMethod ()
109
109
{
110
+ $ expected = 'Basic ' .base64_encode ('login:mypasswd ' );
111
+
110
112
$ request = $ this ->getMock ('Buzz\Message\RequestInterface ' );
111
113
$ request ->expects ($ this ->once ())
112
114
->method ('addHeader ' )
113
- ->with ('Authorization: Basic ' .base64_encode ('login:mypasswd ' ));
115
+ ->with ('Authorization: ' .$ expected );
116
+ $ request ->expects ($ this ->once ())
117
+ ->method ('getHeader ' )
118
+ ->with ('Authorization ' )
119
+ ->will ($ this ->returnValue ($ expected ));
114
120
115
121
$ listener = new AuthListener (Client::AUTH_HTTP_PASSWORD , array ('tokenOrLogin ' => 'login ' , 'password ' => 'mypasswd ' ));
116
122
$ listener ->preSend ($ request );
123
+
124
+ $ this ->assertEquals ($ expected , $ request ->getHeader ('Authorization ' ));
117
125
}
118
126
119
127
/**
120
128
* @test
121
129
*/
122
130
public function shouldSetAuthTokenHeaderForAuthPassMethod ()
123
131
{
132
+ $ expected = 'token test ' ;
133
+
124
134
$ request = $ this ->getMock ('Buzz\Message\RequestInterface ' );
125
135
$ request ->expects ($ this ->once ())
126
136
->method ('addHeader ' )
127
- ->with ('Authorization: token test ' );
137
+ ->with ('Authorization: ' .$ expected );
138
+ $ request ->expects ($ this ->once ())
139
+ ->method ('getHeader ' )
140
+ ->with ('Authorization ' )
141
+ ->will ($ this ->returnValue ($ expected ));
128
142
129
143
$ listener = new AuthListener (Client::AUTH_HTTP_TOKEN , array ('tokenOrLogin ' => 'test ' ));
130
144
$ listener ->preSend ($ request );
145
+
146
+ $ this ->assertEquals ($ expected , $ request ->getHeader ('Authorization ' ));
131
147
}
132
148
133
149
/**
@@ -142,4 +158,17 @@ public function shouldSetTokenInUrlForAuthUrlMethod()
142
158
143
159
$ this ->assertEquals ('/res?access_token=test ' , $ request ->getUrl ());
144
160
}
161
+
162
+ /**
163
+ * @test
164
+ */
165
+ public function shouldSetClientDetailsInUrlForAuthUrlMethod ()
166
+ {
167
+ $ request = new Request (Request::METHOD_GET , '/res ' );
168
+
169
+ $ listener = new AuthListener (Client::AUTH_URL_CLIENT_ID , array ('tokenOrLogin ' => 'clientId ' , 'password ' => 'clientSsecret ' ));
170
+ $ listener ->preSend ($ request );
171
+
172
+ $ this ->assertEquals ('/res?client_id=clientId&client_secret=clientSsecret ' , $ request ->getUrl ());
173
+ }
145
174
}
0 commit comments