1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ni-ju-san CMS. |
5
|
|
|
* |
6
|
|
|
* (c) Christian Gripp <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Core23\PiwikBundle\Tests\Block\Service; |
13
|
|
|
|
14
|
|
|
use Core23\PiwikBundle\Block\Service\PiwikStatisticBlockService; |
15
|
|
|
use Core23\PiwikBundle\Client\ClientFactory; |
16
|
|
|
use Core23\PiwikBundle\Exception\PiwikException; |
17
|
|
|
use Psr\Log\LoggerInterface; |
18
|
|
|
use Sonata\BlockBundle\Block\BlockContext; |
19
|
|
|
use Sonata\BlockBundle\Model\Block; |
20
|
|
|
use Sonata\BlockBundle\Tests\Block\AbstractBlockServiceTest; |
21
|
|
|
use Sonata\BlockBundle\Tests\Block\Service\FakeTemplating; |
22
|
|
|
|
23
|
|
|
class PiwikStatisticBlockServiceTest extends AbstractBlockServiceTest |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|LoggerInterface |
27
|
|
|
*/ |
28
|
|
|
protected $logger; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var \PHPUnit_Framework_MockObject_MockObject|ClientFactory |
32
|
|
|
*/ |
33
|
|
|
protected $factory; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var FakeTemplating |
37
|
|
|
*/ |
38
|
|
|
protected $templating; |
39
|
|
|
|
40
|
|
|
protected function setUp() |
41
|
|
|
{ |
42
|
|
|
parent::setUp(); |
43
|
|
|
|
44
|
|
|
$this->logger = $this->getMock('Psr\Log\LoggerInterface'); |
45
|
|
|
$this->factory = $this->getMock('Core23\PiwikBundle\Client\ClientFactory'); |
46
|
|
|
$this->templating = new FakeTemplating(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testExecute() |
50
|
|
|
{ |
51
|
|
|
$client = $this->getMockBuilder('Core23\PiwikBundle\Client\Client')->disableOriginalConstructor()->getMock(); |
52
|
|
|
$client->expects($this->once())->method('call')->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo(array( |
53
|
|
|
'idSite' => 'foo', |
54
|
|
|
'period' => 'day', |
55
|
|
|
'date' => 'last30', |
56
|
|
|
)))->will($this->returnValue('bar')); |
57
|
|
|
|
58
|
|
|
$this->factory->expects($this->once())->method('createPiwikClient')->will($this->returnValue($client)); |
59
|
|
|
|
60
|
|
|
$block = new Block(); |
61
|
|
|
|
62
|
|
|
$blockContext = new BlockContext($block, array( |
63
|
|
|
'title' => 'Piwik Statistic', |
64
|
|
|
'site' => 'foo', |
65
|
|
|
'method' => 'VisitsSummary.getVisits', |
66
|
|
|
'host' => null, |
67
|
|
|
'token' => null, |
68
|
|
|
'period' => 'day', |
69
|
|
|
'date' => 'last30', |
70
|
|
|
'template' => 'Core23PiwikBundle:Block:block_piwik_statistic.html.twig', |
71
|
|
|
)); |
72
|
|
|
|
73
|
|
|
$blockService = new PiwikStatisticBlockService('block.service', $this->templating, $this->factory, $this->logger); |
74
|
|
|
$blockService->execute($blockContext); |
75
|
|
|
|
76
|
|
|
$this->assertSame('Core23PiwikBundle:Block:block_piwik_statistic.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('Sonata\BlockBundle\Model\BlockInterface', $this->templating->parameters['block']); |
81
|
|
|
$this->assertSame('bar', $this->templating->parameters['data']); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public function testExecuteOffline() |
85
|
|
|
{ |
86
|
|
|
$client = $this->getMockBuilder('Core23\PiwikBundle\Client\Client')->disableOriginalConstructor()->getMock(); |
87
|
|
|
$client->expects($this->once())->method('call')->with($this->equalTo('VisitsSummary.getVisits'), $this->equalTo(array( |
88
|
|
|
'idSite' => 'foo', |
89
|
|
|
'period' => 'day', |
90
|
|
|
'date' => 'last30', |
91
|
|
|
)))->willThrowException(new PiwikException('Offline')); |
92
|
|
|
|
93
|
|
|
$this->factory->expects($this->once())->method('createPiwikClient')->will($this->returnValue($client)); |
94
|
|
|
|
95
|
|
|
$this->logger->expects($this->once())->method('warning'); |
|
|
|
|
96
|
|
|
|
97
|
|
|
$block = new Block(); |
98
|
|
|
|
99
|
|
|
$blockContext = new BlockContext($block, array( |
100
|
|
|
'title' => 'Piwik Statistic', |
101
|
|
|
'site' => 'foo', |
102
|
|
|
'method' => 'VisitsSummary.getVisits', |
103
|
|
|
'host' => null, |
104
|
|
|
'token' => null, |
105
|
|
|
'period' => 'day', |
106
|
|
|
'date' => 'last30', |
107
|
|
|
'template' => 'Core23PiwikBundle:Block:block_piwik_statistic.html.twig', |
108
|
|
|
)); |
109
|
|
|
|
110
|
|
|
$blockService = new PiwikStatisticBlockService('block.service', $this->templating, $this->factory, $this->logger); |
111
|
|
|
$blockService->execute($blockContext); |
112
|
|
|
|
113
|
|
|
$this->assertSame('Core23PiwikBundle:Block:block_piwik_statistic.html.twig', $this->templating->view); |
114
|
|
|
|
115
|
|
|
$this->assertSame($blockContext, $this->templating->parameters['context']); |
116
|
|
|
$this->assertInternalType('array', $this->templating->parameters['settings']); |
117
|
|
|
$this->assertInstanceOf('Sonata\BlockBundle\Model\BlockInterface', $this->templating->parameters['block']); |
118
|
|
|
$this->assertSame(null, $this->templating->parameters['data']); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testDefaultSettings() |
122
|
|
|
{ |
123
|
|
|
$blockService = new PiwikStatisticBlockService('block.service', $this->templating, $this->factory, $this->logger); |
124
|
|
|
$blockContext = $this->getBlockContext($blockService); |
125
|
|
|
|
126
|
|
|
$this->assertSettings(array( |
127
|
|
|
'title' => 'Piwik Statistic', |
128
|
|
|
'site' => false, |
129
|
|
|
'method' => 'VisitsSummary.getVisits', |
130
|
|
|
'host' => null, |
131
|
|
|
'token' => null, |
132
|
|
|
'period' => 'day', |
133
|
|
|
'date' => 'last30', |
134
|
|
|
'template' => 'Core23PiwikBundle:Block:block_piwik_statistic.html.twig', |
135
|
|
|
), $blockContext); |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.