1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2020 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Product\Decorator; |
10
|
|
|
|
11
|
|
|
|
12
|
|
|
class BaseTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
private $context; |
15
|
|
|
private $object; |
16
|
|
|
private $stub; |
17
|
|
|
|
18
|
|
|
|
19
|
|
|
protected function setUp() : void |
20
|
|
|
{ |
21
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
22
|
|
|
|
23
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class ) |
28
|
|
|
->setConstructorArgs( [$this->stub, $this->context] ) |
29
|
|
|
->getMockForAbstractClass(); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
protected function tearDown() : void |
34
|
|
|
{ |
35
|
|
|
unset( $this->context, $this->object, $this->stub ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testConstructException() |
40
|
|
|
{ |
41
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock(); |
42
|
|
|
|
43
|
|
|
$this->expectException( \Aimeos\MW\Common\Exception::class ); |
44
|
|
|
|
45
|
|
|
$this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class ) |
46
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
47
|
|
|
->getMockForAbstractClass(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
|
public function testCall() |
52
|
|
|
{ |
53
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class ) |
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods( ['invalid'] ) |
56
|
|
|
->getMock(); |
57
|
|
|
|
58
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class ) |
59
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
60
|
|
|
->getMockForAbstractClass(); |
61
|
|
|
|
62
|
|
|
$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) ); |
63
|
|
|
|
64
|
|
|
$this->assertTrue( $object->invalid() ); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
|
68
|
|
|
public function testAggregate() |
69
|
|
|
{ |
70
|
|
|
$this->stub->expects( $this->once() )->method( 'aggregate' ) |
71
|
|
|
->will( $this->returnValue( map() ) ); |
72
|
|
|
|
73
|
|
|
$this->assertEquals( [], $this->object->aggregate( 'test' )->toArray() ); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
|
77
|
|
|
public function testAllOf() |
78
|
|
|
{ |
79
|
|
|
$this->assertSame( $this->object, $this->object->allOf( [1, 2] ) ); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
public function testCategory() |
84
|
|
|
{ |
85
|
|
|
$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE; |
86
|
|
|
$this->assertSame( $this->object, $this->object->category( 1, 'default', $level ) ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testCompare() |
91
|
|
|
{ |
92
|
|
|
$this->assertSame( $this->object, $this->object->compare( '==', 'product.code', 'test' ) ); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
public function testFind() |
97
|
|
|
{ |
98
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem(); |
99
|
|
|
$expected = \Aimeos\MShop\Product\Item\Iface::class; |
100
|
|
|
|
101
|
|
|
$this->stub->expects( $this->once() )->method( 'find' ) |
102
|
|
|
->will( $this->returnValue( $item ) ); |
103
|
|
|
|
104
|
|
|
$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testFunction() |
109
|
|
|
{ |
110
|
|
|
$this->stub->expects( $this->once() )->method( 'function' ) |
111
|
|
|
->will( $this->returnValue( 'product:has("domain","type","refid")' ) ); |
112
|
|
|
|
113
|
|
|
$str = $this->object->function( 'product:has', ['domain', 'type', 'refid'] ); |
114
|
|
|
$this->assertEquals( 'product:has("domain","type","refid")', $str ); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
|
118
|
|
|
public function testGet() |
119
|
|
|
{ |
120
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem(); |
121
|
|
|
$expected = \Aimeos\MShop\Product\Item\Iface::class; |
122
|
|
|
|
123
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
124
|
|
|
->will( $this->returnValue( $item ) ); |
125
|
|
|
|
126
|
|
|
$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) ); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
|
130
|
|
|
public function testHas() |
131
|
|
|
{ |
132
|
|
|
$this->assertSame( $this->object, $this->object->has( 'attribute', 'default', -1 ) ); |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
|
136
|
|
|
public function testOneOf() |
137
|
|
|
{ |
138
|
|
|
$this->assertSame( $this->object, $this->object->oneOf( [1, 2] ) ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testParse() |
143
|
|
|
{ |
144
|
|
|
$this->assertSame( $this->object, $this->object->parse( [] ) ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
|
148
|
|
|
public function testPrice() |
149
|
|
|
{ |
150
|
|
|
$this->assertSame( $this->object, $this->object->price( 0 ) ); |
151
|
|
|
} |
152
|
|
|
|
153
|
|
|
|
154
|
|
|
public function testProduct() |
155
|
|
|
{ |
156
|
|
|
$this->assertSame( $this->object, $this->object->product( [1, 3] ) ); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
|
160
|
|
|
public function testProperty() |
161
|
|
|
{ |
162
|
|
|
$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) ); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
|
166
|
|
|
public function testResolve() |
167
|
|
|
{ |
168
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem(); |
169
|
|
|
|
170
|
|
|
$this->stub->expects( $this->once() )->method( 'resolve' ) |
171
|
|
|
->will( $this->returnValue( $item ) ); |
172
|
|
|
|
173
|
|
|
$this->assertEquals( $item, $this->object->resolve( 'test' ) ); |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
|
177
|
|
|
public function testSearch() |
178
|
|
|
{ |
179
|
|
|
$total = 0; |
180
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem(); |
181
|
|
|
|
182
|
|
|
$this->stub->expects( $this->once() )->method( 'search' ) |
183
|
|
|
->will( $this->returnValue( map( [$item] ) ) ); |
184
|
|
|
|
185
|
|
|
$this->assertEquals( [$item], $this->object->search( $total )->toArray() ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
|
189
|
|
|
public function testSlice() |
190
|
|
|
{ |
191
|
|
|
$this->assertSame( $this->object, $this->object->slice( 0, 100 ) ); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
|
195
|
|
|
public function testSort() |
196
|
|
|
{ |
197
|
|
|
$this->assertSame( $this->object, $this->object->sort( 'code' ) ); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
|
201
|
|
|
public function testSupplier() |
202
|
|
|
{ |
203
|
|
|
$this->assertSame( $this->object, $this->object->supplier( [1], 'default' ) ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testText() |
208
|
|
|
{ |
209
|
|
|
$this->assertSame( $this->object, $this->object->text( 'test' ) ); |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
|
213
|
|
|
public function testUses() |
214
|
|
|
{ |
215
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
public function testGetController() |
220
|
|
|
{ |
221
|
|
|
$result = $this->access( 'getController' )->invokeArgs( $this->object, [] ); |
222
|
|
|
|
223
|
|
|
$this->assertSame( $this->stub, $result ); |
224
|
|
|
} |
225
|
|
|
|
226
|
|
|
|
227
|
|
|
protected function access( $name ) |
228
|
|
|
{ |
229
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Product\Decorator\Base::class ); |
230
|
|
|
$method = $class->getMethod( $name ); |
231
|
|
|
$method->setAccessible( true ); |
232
|
|
|
|
233
|
|
|
return $method; |
234
|
|
|
} |
235
|
|
|
} |
236
|
|
|
|