1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Meup TagCommander Bundle. |
5
|
|
|
* |
6
|
|
|
* (c) 1001pharmacies <http://github.com/1001pharmacies/tagcommander-bundle> |
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 Meup\Bundle\TagcommanderBundle\EventDispatcher\Subscriber; |
13
|
|
|
|
14
|
|
|
use Meup\Bundle\TagcommanderBundle\DataCollector\DataLayerCollector; |
15
|
|
|
use Meup\Bundle\TagcommanderBundle\EventDispatcher\Subscriber\CollectorSubscriber; |
16
|
|
|
use Meup\Bundle\TagcommanderBundle\EventDispatcher\Event\DeployContainer; |
17
|
|
|
use Meup\Bundle\TagcommanderBundle\EventDispatcher\Event\Track; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* |
21
|
|
|
*/ |
22
|
|
|
class CollectorSubscriberTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @param DeployContainer $deployContainer |
26
|
|
|
* @param Track $track |
27
|
|
|
* @return DataLayerCollector |
28
|
|
|
*/ |
29
|
|
|
private function buildCollector(DeployContainer $deployContainer, Track $track) |
30
|
|
|
{ |
31
|
|
|
$collector = $this |
32
|
|
|
->getMockBuilder('Meup\Bundle\TagcommanderBundle\DataCollector\DataLayerCollector') |
33
|
|
|
->disableOriginalConstructor() |
34
|
|
|
->setMethods(array('collectContainer', 'collectEvent')) |
35
|
|
|
->getMock() |
36
|
|
|
; |
37
|
|
|
|
38
|
|
|
$this->withDeployContainerEvent($collector, $deployContainer); |
39
|
|
|
$this->withTrackEvent($collector, $track); |
40
|
|
|
|
41
|
|
|
return $collector; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
private function withDeployContainerEvent($collector, DeployContainer $deployContainer) |
45
|
|
|
{ |
46
|
|
|
$collector |
47
|
|
|
->expects($this->once()) |
48
|
|
|
->method('collectContainer') |
49
|
|
|
->with( |
50
|
|
|
$this->equalTo($deployContainer->getContainerName()), |
51
|
|
|
$this->equalTo($deployContainer->getContainerScript()), |
52
|
|
|
$this->equalTo($deployContainer->getContainerVersion()), |
53
|
|
|
$this->equalTo($deployContainer->getContainerAlternative()) |
54
|
|
|
) |
55
|
|
|
; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
private function withTrackEvent($collector, Track $track) |
59
|
|
|
{ |
60
|
|
|
$collector |
61
|
|
|
->expects($this->once()) |
62
|
|
|
->method('collectEvent') |
63
|
|
|
->with( |
64
|
|
|
$this->equalTo($track->getTrackerName()), |
65
|
|
|
$this->equalTo($track->getEventName()), |
66
|
|
|
$this->equalTo($track->getValues()) |
67
|
|
|
) |
68
|
|
|
; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* |
73
|
|
|
*/ |
74
|
|
|
public function testConstruct() |
75
|
|
|
{ |
76
|
|
|
$deployContainer = new DeployContainer('name', 'http://'); |
77
|
|
|
$track = new Track('tracker', 'event', array('foo' => 'bar')); |
78
|
|
|
|
79
|
|
|
$collectorSubscriber = new CollectorSubscriber($this->buildCollector($deployContainer, $track)); |
80
|
|
|
$collectorSubscriber->onTcContainer($deployContainer); |
81
|
|
|
$collectorSubscriber->onTcEvent($track); |
82
|
|
|
|
83
|
|
|
$this->assertEquals( |
84
|
|
|
array('tc_container', 'tc_event'), |
85
|
|
|
array_keys($collectorSubscriber->getSubscribedEvents()) |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|