1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Andreas Penz. |
4
|
|
|
* Date: 24.06.14 |
5
|
|
|
* Time: 18:07 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
class LimeSoda_LiveGuard_Test_Model_ConfigTests |
|
|
|
|
9
|
|
|
extends EcomDev_PHPUnit_Test_Case_Config |
|
|
|
|
10
|
|
|
{ |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @return false|Mage_Core_Model_Abstract |
14
|
|
|
*/ |
15
|
|
|
protected function _getConfigInstance() |
16
|
|
|
{ |
17
|
|
|
return Mage::getModel('limesoda_liveguard/config'); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @test |
22
|
|
|
*/ |
23
|
|
|
public function testConfigExists() |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
$mock = $this->getModelMock('limesoda_liveguard/config', array('getConfig')); |
27
|
|
|
|
28
|
|
|
$mock->expects($this->once()) |
29
|
|
|
->method('getConfig') |
30
|
|
|
->will($this->returnValue(array())); |
31
|
|
|
|
32
|
|
|
$this->replaceByMock('model', 'limesoda_liveguard/config', $mock); |
33
|
|
|
|
34
|
|
|
$configExists = $this->_getConfigInstance()->configExists(); |
35
|
|
|
|
36
|
|
|
$this->assertTrue($configExists); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @test |
42
|
|
|
* @loadFixture |
43
|
|
|
* @loadExpectation |
44
|
|
|
*/ |
45
|
|
|
public function testGetConfig() |
46
|
|
|
{ |
47
|
|
|
$config = $this->_getConfigInstance()->getConfig(); |
48
|
|
|
|
49
|
|
|
$this->assertNotNull($config); |
50
|
|
|
|
51
|
|
|
$this->assertInstanceOf('Mage_Core_Model_Config_Element', $config); |
52
|
|
|
|
53
|
|
|
$this->assertSame( |
54
|
|
|
$config->asArray(), |
55
|
|
|
$this->expected()->getData() |
56
|
|
|
); |
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @param $name |
62
|
|
|
*/ |
63
|
|
|
protected function _mockGetEnvironmentName( $name ) |
64
|
|
|
{ |
65
|
|
|
|
66
|
|
|
$mock = $this->getHelperMock('limesoda_environmentconfiguration/current', array('getEnvironmentName')); |
67
|
|
|
|
68
|
|
|
$mock->expects($this->any()) |
69
|
|
|
->method('getConfig') |
70
|
|
|
->will($this->returnValue($name)); |
71
|
|
|
|
72
|
|
|
$this->replaceByMock('helper', 'limesoda_environmentconfiguration/current', $mock); |
73
|
|
|
|
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @test |
78
|
|
|
* @loadFixture |
79
|
|
|
* @expectedException InvalidArgumentException |
80
|
|
|
*/ |
81
|
|
|
public function testGetGuardsMissesArguments() |
82
|
|
|
{ |
83
|
|
|
$this->_mockGetEnvironmentName('dev'); |
84
|
|
|
$this->_getConfigInstance()->getGuards(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @test |
89
|
|
|
* @loadFixture |
90
|
|
|
*/ |
91
|
|
|
public function testGetGuardsSkipGuards() |
92
|
|
|
{ |
93
|
|
|
$this->_mockGetEnvironmentName('dev'); |
94
|
|
|
$guards = $this->_getConfigInstance()->getGuards(); |
95
|
|
|
$this->assertEmpty($guards); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @test |
100
|
|
|
* @loadFixture |
101
|
|
|
* @expectedException InvalidArgumentException |
102
|
|
|
*/ |
103
|
|
|
public function testGetGuardsGuardModelDoesNotImplementInterface() |
104
|
|
|
{ |
105
|
|
|
$mock = $this->getMock('First_Guard_Class'); |
106
|
|
|
$this->replaceByMock('model', 'first_guard/class', $mock); |
107
|
|
|
|
108
|
|
|
$this->_mockGetEnvironmentName('dev'); |
109
|
|
|
$this->_getConfigInstance()->getGuards(); |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @loadFixture |
115
|
|
|
*/ |
116
|
|
|
public function testGetGuards() |
117
|
|
|
{ |
118
|
|
|
$secondGuardMock = $this->getMock('Second_Guard_Class'); |
119
|
|
|
$this->replaceByMock('model', 'second_guard/class', $secondGuardMock); |
120
|
|
|
|
121
|
|
|
$thirdGuardMock = $this->getMock('Third_Guard_Class'); |
122
|
|
|
$this->replaceByMock('model', 'third_guard/class', $thirdGuardMock); |
123
|
|
|
|
124
|
|
|
$this->_mockGetEnvironmentName('staging'); |
125
|
|
|
$guards = $this->_getConfigInstance()->getGuards(); |
126
|
|
|
|
127
|
|
|
$this->assertEquals(2, count($guards)); |
128
|
|
|
|
129
|
|
|
$this->assertInstanceOf(get_class($secondGuardMock), $guards[0]); |
130
|
|
|
|
131
|
|
|
$this->assertInstanceOf(get_class($thirdGuardMock), $guards[1]); |
132
|
|
|
|
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
class First_Guard_Class |
|
|
|
|
138
|
|
|
{ |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
class Second_Guard_Class |
|
|
|
|
142
|
|
|
implements LimeSoda_LiveGuard_Model_GuardInterface |
|
|
|
|
143
|
|
|
{ |
144
|
|
|
public function process() |
145
|
|
|
{ |
146
|
|
|
|
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
class Third_Guard_Class |
|
|
|
|
151
|
|
|
implements LimeSoda_LiveGuard_Model_GuardInterface |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
public function process() |
154
|
|
|
{ |
155
|
|
|
|
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|
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.