|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by Andreas Penz. |
|
4
|
|
|
* Date: 24.06.14 |
|
5
|
|
|
* Time: 21:53 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
class LimeSoda_LiveGuard_Test_Model_ObserverTests |
|
|
|
|
|
|
9
|
|
|
extends EcomDev_PHPUnit_Test_Case_Config |
|
|
|
|
|
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @return Mage_Core_Model_Abstract |
|
15
|
|
|
*/ |
|
16
|
|
|
protected function _getObserverInstance() |
|
17
|
|
|
{ |
|
18
|
|
|
return Mage::getModel('limesoda_liveguard/observer'); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @return Varien_Event_Observer |
|
23
|
|
|
*/ |
|
24
|
|
|
protected function _getVarienEventObserverMock() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->getMock('Varien_Event_Observer'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @test |
|
31
|
|
|
*/ |
|
32
|
|
|
public function testControllerFrontInitBeforeNoConfigExists() |
|
33
|
|
|
{ |
|
34
|
|
|
$observer = $this->_getObserverInstance()->controllerFrontInitBefore($this->_getVarienEventObserverMock()); |
|
35
|
|
|
$this->assertInstanceOf('LimeSoda_LiveGuard_Model_Observer', $observer); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @test |
|
40
|
|
|
*/ |
|
41
|
|
|
public function testControllerFrontInitBefore() |
|
42
|
|
|
{ |
|
43
|
|
|
$mock = $this->getModelMock('limesoda_liveguard/config', array('configExists', 'getGuards')); |
|
44
|
|
|
|
|
45
|
|
|
$mock->expects($this->once()) |
|
46
|
|
|
->method('configExists') |
|
47
|
|
|
->will($this->returnValue(true)); |
|
48
|
|
|
|
|
49
|
|
|
$fourthGuardMock = $this->getMock('Fourth_Guard_Class', array('process')); |
|
50
|
|
|
|
|
51
|
|
|
$fourthGuardMock->expects($this->once()) |
|
52
|
|
|
->method('process'); |
|
53
|
|
|
|
|
54
|
|
|
$this->replaceByMock('model', 'fourth_guard/class', $fourthGuardMock); |
|
55
|
|
|
|
|
56
|
|
|
$fifthGuardMock = $this->getMock('Second_Guard_Class'); |
|
57
|
|
|
|
|
58
|
|
|
$fifthGuardMock->expects($this->once()) |
|
59
|
|
|
->method('process'); |
|
60
|
|
|
|
|
61
|
|
|
$this->replaceByMock('model', 'second_guard/class', $fifthGuardMock); |
|
62
|
|
|
|
|
63
|
|
|
$mock->expects($this->once()) |
|
64
|
|
|
->method('getGuards') |
|
65
|
|
|
->will($this->returnValue(array( $fourthGuardMock, $fifthGuardMock))); |
|
66
|
|
|
|
|
67
|
|
|
$this->replaceByMock('model', 'limesoda_liveguard/config', $mock); |
|
68
|
|
|
|
|
69
|
|
|
$observer = $this->_getObserverInstance()->controllerFrontInitBefore($this->_getVarienEventObserverMock()); |
|
70
|
|
|
|
|
71
|
|
|
$this->assertInstanceOf('LimeSoda_LiveGuard_Model_Observer', $observer); |
|
72
|
|
|
} |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
class Fourth_Guard_Class |
|
|
|
|
|
|
76
|
|
|
implements LimeSoda_LiveGuard_Model_GuardInterface |
|
|
|
|
|
|
77
|
|
|
{ |
|
78
|
|
|
public function process() |
|
79
|
|
|
{ |
|
80
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
class Fifth_Guard_Class |
|
|
|
|
|
|
85
|
|
|
implements LimeSoda_LiveGuard_Model_GuardInterface |
|
|
|
|
|
|
86
|
|
|
{ |
|
87
|
|
|
public function process() |
|
88
|
|
|
{ |
|
89
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
} |
|
92
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.