Completed
Push — master ( 3c8aea...1bc6df )
by Dominik
21:07
created

Tests/Templating/SocialBarTwigExtensionTest.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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