These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Azine\SocialBarBundle\Tests\Templating; |
||
4 | |||
5 | use Azine\SocialBarBundle\Templating\SocialBarTwigExtension; |
||
6 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
7 | |||
8 | class SocialBarTwigExtensionTest extends \PHPUnit\Framework\TestCase |
||
9 | { |
||
10 | public function testGetName() |
||
11 | { |
||
12 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
13 | |||
14 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
15 | $this->assertSame('azine_social_bar', $socialBarExt->getName()); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
16 | } |
||
17 | |||
18 | public function testGetFunctions() |
||
19 | { |
||
20 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
21 | |||
22 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
23 | $functions = $socialBarExt->getFunctions(); |
||
24 | $this->assertSame(6, sizeof($functions)); |
||
25 | |||
26 | $this->assertArrayHasKey('socialButtons', $functions); |
||
27 | $this->assertArrayHasKey('facebookButton', $functions); |
||
28 | $this->assertArrayHasKey('twitterButton', $functions); |
||
29 | $this->assertArrayHasKey('googlePlusButton', $functions); |
||
30 | $this->assertArrayHasKey('xingButton', $functions); |
||
31 | $this->assertArrayHasKey('linkedInButton', $functions); |
||
32 | } |
||
33 | |||
34 | public function testGetSocialButtons_all_plugins_share() |
||
35 | { |
||
36 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
37 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
38 | |||
39 | $action = 'share'; |
||
40 | $inputRenderingParams = array(); |
||
41 | $expectedRenderingParams = array('facebook' => array(), |
||
42 | 'twitter' => array(), |
||
43 | 'googleplus' => array(), |
||
44 | 'xing' => array(), |
||
45 | 'linkedin' => array(), |
||
46 | 'action' => 'share', |
||
47 | 'width' => 130, |
||
48 | 'height' => 20, |
||
49 | ); |
||
50 | |||
51 | $helperMock->expects($this->once())->method('socialButtons')->with($expectedRenderingParams); |
||
52 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
53 | |||
54 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
55 | $socialBarExt->getSocialButtons($inputRenderingParams, $action); |
||
56 | } |
||
57 | |||
58 | public function testGetSocialButtons_no_plugins() |
||
59 | { |
||
60 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
61 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
62 | |||
63 | $action = 'follow'; |
||
64 | $inputRenderingParams = array('facebook' => false, |
||
65 | 'twitter' => false, |
||
66 | 'googleplus' => false, |
||
67 | 'xing' => false, |
||
68 | 'linkedin' => false, |
||
69 | ); |
||
70 | $expectedRenderingParams = array('facebook' => false, |
||
71 | 'twitter' => false, |
||
72 | 'googleplus' => false, |
||
73 | 'xing' => false, |
||
74 | 'linkedin' => false, |
||
75 | 'action' => 'follow', |
||
76 | 'width' => 130, |
||
77 | 'height' => 20, |
||
78 | ); |
||
79 | |||
80 | $helperMock->expects($this->once())->method('socialButtons')->with($expectedRenderingParams); |
||
81 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
82 | |||
83 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
84 | $socialBarExt->getSocialButtons($inputRenderingParams, $action); |
||
85 | } |
||
86 | |||
87 | public function testGetSocialButtons_plugins_with_custom_params() |
||
88 | { |
||
89 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
90 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
91 | |||
92 | $action = 'follow'; |
||
93 | $inputRenderingParams = array('facebook' => array('someParam' => 123), |
||
94 | 'twitter' => array('someParam' => 456), |
||
95 | 'googleplus' => array('someParam' => 789), |
||
96 | 'xing' => array('someParam' => 98), |
||
97 | 'linkedin' => array('someParam' => 765), |
||
98 | ); |
||
99 | $expectedRenderingParams = array('facebook' => array('someParam' => 123), |
||
100 | 'twitter' => array('someParam' => 456), |
||
101 | 'googleplus' => array('someParam' => 789), |
||
102 | 'xing' => array('someParam' => 98), |
||
103 | 'linkedin' => array('someParam' => 765), |
||
104 | 'action' => 'follow', |
||
105 | 'width' => 130, |
||
106 | 'height' => 20, |
||
107 | ); |
||
108 | |||
109 | $helperMock->expects($this->once())->method('socialButtons')->with($expectedRenderingParams); |
||
110 | $containerMock->expects($this->once())->method('get', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->with('azine.socialBarHelper')->will($this->returnValue($helperMock)); |
||
111 | |||
112 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
113 | $socialBarExt->getSocialButtons($inputRenderingParams, $action); |
||
114 | } |
||
115 | |||
116 | public function testGetFacebookButton_follow() |
||
117 | { |
||
118 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
119 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
120 | |||
121 | $action = 'follow'; |
||
122 | $inputRenderingParams = array(); |
||
123 | $fbProfileUrl = 'http://some.fb.url'; |
||
124 | $expectedRenderingParams = array('locale' => 'en_US', |
||
125 | 'send' => false, |
||
126 | 'width' => 130, |
||
127 | 'showFaces' => false, |
||
128 | 'layout' => 'button_count', |
||
129 | 'url' => $fbProfileUrl, |
||
130 | 'action' => 'fb-follow', |
||
131 | ); |
||
132 | |||
133 | $helperMock->expects($this->once())->method('facebookButton')->with($expectedRenderingParams); |
||
134 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
135 | $containerMock->expects($this->once())->method('getParameter')->with('azine_social_bar_fb_profile_url')->will($this->returnValue($fbProfileUrl)); |
||
136 | |||
137 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
138 | $socialBarExt->getFacebookButton($inputRenderingParams, $action); |
||
139 | } |
||
140 | |||
141 | public function testGetFacebookButton_share() |
||
142 | { |
||
143 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
144 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
145 | |||
146 | $action = 'share'; |
||
147 | $someUrl = 'http://some.fb.url'; |
||
148 | $inputRenderingParams = array('url' => $someUrl); |
||
149 | $expectedRenderingParams = array('locale' => 'en_US', |
||
150 | 'send' => false, |
||
151 | 'width' => 130, |
||
152 | 'showFaces' => false, |
||
153 | 'layout' => 'button_count', |
||
154 | 'url' => $someUrl, |
||
155 | 'action' => 'fb-like', |
||
156 | ); |
||
157 | |||
158 | $helperMock->expects($this->once())->method('facebookButton')->with($expectedRenderingParams); |
||
159 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
160 | $containerMock->expects($this->never())->method('getParameter'); |
||
161 | |||
162 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
163 | $socialBarExt->getFacebookButton($inputRenderingParams, $action); |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * @expectedException \Exception |
||
168 | */ |
||
169 | public function testGetFacebookButton_invalidAction() |
||
170 | { |
||
171 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
172 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
173 | $socialBarExt->getFacebookButton(array(), 'invalid'); |
||
174 | } |
||
175 | |||
176 | public function testGetTwitterButton_follow() |
||
177 | { |
||
178 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
179 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
180 | |||
181 | $action = 'follow'; |
||
182 | $inputRenderingParams = array(); |
||
183 | $twitterUserName = 'azine'; |
||
184 | $expectedRenderingParams = array('locale' => 'en', |
||
185 | 'url' => null, |
||
186 | 'action' => $twitterUserName, |
||
187 | 'actionClass' => 'twitter-follow-button', |
||
188 | 'message' => 'I want to share that page with you', |
||
189 | 'text' => 'Tweet', |
||
190 | 'via' => $twitterUserName, |
||
191 | 'tag' => $twitterUserName, |
||
192 | ); |
||
193 | |||
194 | $helperMock->expects($this->once())->method('twitterButton')->with($expectedRenderingParams); |
||
195 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
196 | $containerMock->expects($this->exactly(3))->method('getParameter')->with('azine_social_bar_twitter_username')->will($this->returnValue($twitterUserName)); |
||
197 | |||
198 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
199 | $socialBarExt->getTwitterButton($inputRenderingParams, $action); |
||
200 | } |
||
201 | |||
202 | public function testGetTwitterButton_tweet() |
||
203 | { |
||
204 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
205 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
206 | |||
207 | $action = 'share'; |
||
208 | $someUrl = 'http://some.fb.url'; |
||
209 | $inputRenderingParams = array('url' => $someUrl, 'tag' => 'someTag'); |
||
210 | $expectedRenderingParams = array('locale' => 'en', |
||
211 | 'url' => $someUrl, |
||
212 | 'action' => 'share', |
||
213 | 'actionClass' => 'twitter-share-button', |
||
214 | 'message' => 'I want to share that page with you', |
||
215 | 'text' => 'Tweet', |
||
216 | 'via' => 'azine team', |
||
217 | 'tag' => 'someTag', |
||
218 | ); |
||
219 | |||
220 | $helperMock->expects($this->once())->method('twitterButton')->with($expectedRenderingParams); |
||
221 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
222 | $containerMock->expects($this->once())->method('getParameter')->with('azine_social_bar_twitter_username')->will($this->returnValue('azine team')); |
||
223 | |||
224 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
225 | $socialBarExt->getTwitterButton($inputRenderingParams, $action); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @expectedException \Exception |
||
230 | */ |
||
231 | public function testGetTwitterButton_invalidAction() |
||
232 | { |
||
233 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
234 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
235 | $socialBarExt->getTwitterButton(array(), 'invalid'); |
||
236 | } |
||
237 | |||
238 | public function testGetGooglePlusButton_follow() |
||
239 | { |
||
240 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
241 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
242 | |||
243 | $action = 'follow'; |
||
244 | $inputRenderingParams = array(); |
||
245 | $googleProfile = 'http://plus.google.com/some/profile/url/76543234567'; |
||
246 | $expectedRenderingParams = array('locale' => 'en', |
||
247 | 'url' => $googleProfile, |
||
248 | 'action' => 'g-follow', |
||
249 | 'size' => 'medium', |
||
250 | 'annotation' => 'bubble', |
||
251 | 'width' => 130, |
||
252 | 'height' => 20, |
||
253 | 'rel' => 'publisher', |
||
254 | ); |
||
255 | |||
256 | $helperMock->expects($this->once())->method('googlePlusButton')->with($expectedRenderingParams); |
||
257 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
258 | $containerMock->expects($this->once())->method('getParameter')->with('azine_social_bar_google_plus_profile_url')->will($this->returnValue($googleProfile)); |
||
259 | |||
260 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
261 | $socialBarExt->getGooglePlusButton($inputRenderingParams, $action); |
||
262 | } |
||
263 | |||
264 | public function testGetGooglePlusButton_plus() |
||
265 | { |
||
266 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
267 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
268 | |||
269 | $action = 'share'; |
||
270 | $someUrl = 'http://some.url.com/76543234567'; |
||
271 | $inputRenderingParams = array('url' => $someUrl); |
||
272 | $expectedRenderingParams = array('locale' => 'en', |
||
273 | 'url' => $someUrl, |
||
274 | 'action' => 'g-plusone', |
||
275 | 'size' => 'medium', |
||
276 | 'annotation' => 'bubble', |
||
277 | 'width' => 130, |
||
278 | 'height' => 20, |
||
279 | 'rel' => 'author', |
||
280 | ); |
||
281 | |||
282 | $helperMock->expects($this->once())->method('googlePlusButton')->with($expectedRenderingParams); |
||
283 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
284 | $containerMock->expects($this->never())->method('getParameter'); |
||
285 | |||
286 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
287 | $socialBarExt->getGooglePlusButton($inputRenderingParams, $action); |
||
288 | } |
||
289 | |||
290 | /** |
||
291 | * @expectedException \Exception |
||
292 | */ |
||
293 | public function testGetGooglePlusButton_invalidAction() |
||
294 | { |
||
295 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
296 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
297 | $socialBarExt->getGooglePlusButton(array(), 'invalid'); |
||
298 | } |
||
299 | |||
300 | View Code Duplication | public function testGetLinkedInButton_follow() |
|
301 | { |
||
302 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
303 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
304 | |||
305 | $action = 'follow'; |
||
306 | $inputRenderingParams = array(); |
||
307 | $companyId = '6543234567'; |
||
308 | $expectedRenderingParams = array('locale' => 'en', |
||
309 | 'companyId' => $companyId, |
||
310 | 'action' => 'IN/FollowCompany', |
||
311 | 'counterLocation' => 'right', |
||
312 | ); |
||
313 | |||
314 | $helperMock->expects($this->once())->method('linkedInButton')->with($expectedRenderingParams); |
||
315 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
316 | $containerMock->expects($this->once())->method('getParameter')->with('azine_social_bar_linked_in_company_id')->will($this->returnValue($companyId)); |
||
317 | |||
318 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
319 | $socialBarExt->getLinkedInButton($inputRenderingParams, $action); |
||
320 | } |
||
321 | |||
322 | View Code Duplication | public function testGetLinkedInButton_share() |
|
323 | { |
||
324 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
325 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
326 | |||
327 | $action = 'share'; |
||
328 | $someUrl = 'http://some.url.com/76543234567'; |
||
329 | $inputRenderingParams = array('url' => $someUrl); |
||
330 | $expectedRenderingParams = array('locale' => 'en', |
||
331 | 'url' => $someUrl, |
||
332 | 'action' => 'IN/Share', |
||
333 | 'counterLocation' => 'right', |
||
334 | ); |
||
335 | |||
336 | $helperMock->expects($this->once())->method('linkedInButton')->with($expectedRenderingParams); |
||
337 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
338 | $containerMock->expects($this->never())->method('getParameter'); |
||
339 | |||
340 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
341 | $socialBarExt->getLinkedInButton($inputRenderingParams, $action); |
||
342 | } |
||
343 | |||
344 | /** |
||
345 | * @expectedException \Exception |
||
346 | */ |
||
347 | public function testGetLinkedInButton_invalidAction() |
||
348 | { |
||
349 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
350 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
351 | $socialBarExt->getLinkedInButton(array(), 'invalid'); |
||
352 | } |
||
353 | |||
354 | View Code Duplication | public function testGetXingButton_follow() |
|
355 | { |
||
356 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
357 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
358 | |||
359 | $action = 'follow'; |
||
360 | $inputRenderingParams = array(); |
||
361 | $profileUrl = 'http://xing.com/some/profile/url/76543234567'; |
||
362 | $expectedRenderingParams = array('locale' => 'en', |
||
363 | 'url' => $profileUrl, |
||
364 | 'action' => 'XING/Share', |
||
365 | 'counterLocation' => 'right', |
||
366 | ); |
||
367 | |||
368 | $helperMock->expects($this->once())->method('xingButton')->with($expectedRenderingParams); |
||
369 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
370 | $containerMock->expects($this->once())->method('getParameter')->with('azine_social_bar_xing_profile_url')->will($this->returnValue($profileUrl)); |
||
371 | |||
372 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
373 | $socialBarExt->getXingButton($inputRenderingParams, $action); |
||
374 | } |
||
375 | |||
376 | View Code Duplication | public function testGetXingButton_share() |
|
377 | { |
||
378 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
379 | $helperMock = $this->getMockBuilder("Azine\SocialBarBundle\Templating\SocialBarHelper")->disableOriginalConstructor()->getMock(); |
||
380 | |||
381 | $action = 'share'; |
||
382 | $someUrl = 'http://some.url.com/76543234567'; |
||
383 | $inputRenderingParams = array('url' => $someUrl); |
||
384 | $expectedRenderingParams = array('locale' => 'en', |
||
385 | 'url' => $someUrl, |
||
386 | 'action' => 'XING/Share', |
||
387 | 'counterLocation' => 'right', |
||
388 | ); |
||
389 | |||
390 | $helperMock->expects($this->once())->method('xingButton')->with($expectedRenderingParams); |
||
391 | $containerMock->expects($this->once())->method('get')->with('azine.socialBarHelper', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)->will($this->returnValue($helperMock)); |
||
392 | $containerMock->expects($this->never())->method('getParameter'); |
||
393 | |||
394 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
395 | $socialBarExt->getXingButton($inputRenderingParams, $action); |
||
396 | } |
||
397 | |||
398 | /** |
||
399 | * @expectedException \Exception |
||
400 | */ |
||
401 | public function testGetXingButton_invalidAction() |
||
402 | { |
||
403 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->getMock(); |
||
404 | $socialBarExt = new SocialBarTwigExtension($containerMock); |
||
405 | $socialBarExt->getXingButton(array(), 'invalid'); |
||
406 | } |
||
407 | } |
||
408 |