1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* (c) Christian Gripp <[email protected]> |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Core23\FacebookBundle\Tests\Block\Service; |
11
|
|
|
|
12
|
|
|
use Core23\FacebookBundle\Block\Service\PageFeedBlockService; |
13
|
|
|
use Facebook\Authentication\AccessToken; |
14
|
|
|
use Facebook\Facebook; |
15
|
|
|
use Facebook\FacebookApp; |
16
|
|
|
use Facebook\FacebookResponse; |
17
|
|
|
use Facebook\GraphNodes\GraphEdge; |
18
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
19
|
|
|
use Sonata\BlockBundle\Model\Block; |
20
|
|
|
use Sonata\BlockBundle\Model\BlockInterface; |
21
|
|
|
use Sonata\BlockBundle\Test\AbstractBlockServiceTestCase; |
22
|
|
|
|
23
|
|
|
class PageFeedBlockServiceTest extends AbstractBlockServiceTestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|Facebook |
27
|
|
|
*/ |
28
|
|
|
private $facebook; |
29
|
|
|
|
30
|
|
|
protected function setUp() |
31
|
|
|
{ |
32
|
|
|
parent::setUp(); |
33
|
|
|
|
34
|
|
|
$this->facebook = $this->createMock(Facebook::class); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function testExecute() |
38
|
|
|
{ |
39
|
|
|
$token = $this->createMock(AccessToken::class); |
40
|
|
|
|
41
|
|
|
$app = $this->createMock(FacebookApp::class); |
42
|
|
|
$app->expects($this->once())->method('getAccessToken') |
43
|
|
|
->will($this->returnValue($token)); |
44
|
|
|
|
45
|
|
|
$this->facebook->expects($this->once())->method('getApp') |
46
|
|
|
->will($this->returnValue($app)); |
47
|
|
|
|
48
|
|
|
$feedResponse = array( |
49
|
|
|
array('foo' => 'bar'), |
50
|
|
|
); |
51
|
|
|
|
52
|
|
|
$edge = $this->createMock(GraphEdge::class); |
53
|
|
|
$edge->expects($this->once())->method('asArray') |
54
|
|
|
->will($this->returnValue($feedResponse)); |
55
|
|
|
|
56
|
|
|
$response = $this->createMock(FacebookResponse::class); |
57
|
|
|
$response->expects($this->once())->method('getGraphEdge') |
58
|
|
|
->will($this->returnValue($edge)); |
59
|
|
|
|
60
|
|
|
$this->facebook->method('get') |
61
|
|
|
->with($this->equalTo('/0815/feed?fields=type,message,description,permalink_url,picture,created_time'), $this->equalTo($token)) |
62
|
|
|
->will($this->returnValue($response)); |
63
|
|
|
|
64
|
|
|
$block = new Block(); |
65
|
|
|
|
66
|
|
|
$blockContext = new BlockContext($block, array( |
67
|
|
|
'title' => 'Facebook Timeline', |
68
|
|
|
'template' => 'Core23FacebookBundle:Block:block_page_feed.html.twig', |
69
|
|
|
'id' => '0815', |
70
|
|
|
'fields' => 'type,message,description,permalink_url,picture,created_time', |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
74
|
|
|
$blockService->execute($blockContext); |
75
|
|
|
|
76
|
|
|
$this->assertSame('Core23FacebookBundle:Block:block_page_feed.html.twig', $this->templating->view); |
77
|
|
|
|
78
|
|
|
$this->assertSame($blockContext, $this->templating->parameters['context']); |
79
|
|
|
$this->assertInternalType('array', $this->templating->parameters['settings']); |
80
|
|
|
$this->assertInstanceOf(BlockInterface::class, $this->templating->parameters['block']); |
81
|
|
|
|
82
|
|
|
$this->assertSame($feedResponse, $this->templating->parameters['feed']); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testDefaultSettings() |
86
|
|
|
{ |
87
|
|
|
$blockService = new PageFeedBlockService('block.service', $this->templating, $this->facebook); |
88
|
|
|
$blockContext = $this->getBlockContext($blockService); |
89
|
|
|
|
90
|
|
|
$this->assertSettings(array( |
91
|
|
|
'title' => 'Facebook Timeline', |
92
|
|
|
'id' => null, |
93
|
|
|
'limit' => 10, |
94
|
|
|
'class' => '', |
95
|
|
|
'fields' => 'type,message,description,permalink_url,picture,created_time', |
96
|
|
|
'template' => 'Core23FacebookBundle:Block:block_page_feed.html.twig', |
97
|
|
|
), $blockContext); |
98
|
|
|
} |
99
|
|
|
} |
100
|
|
|
|