1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017-2023 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Customer\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 = \TestHelper::context(); |
22
|
|
|
|
23
|
|
|
$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
24
|
|
|
->disableOriginalConstructor() |
25
|
|
|
->getMock(); |
26
|
|
|
|
27
|
|
|
$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\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 testCall() |
40
|
|
|
{ |
41
|
|
|
$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Standard::class ) |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->onlyMethods( ['__call'] ) |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Customer\Decorator\Base::class ) |
47
|
|
|
->setConstructorArgs( [$stub, $this->context] ) |
48
|
|
|
->getMockForAbstractClass(); |
49
|
|
|
|
50
|
|
|
$stub->expects( $this->once() )->method( '__call' )->will( $this->returnValue( true ) ); |
51
|
|
|
|
52
|
|
|
$this->assertTrue( $object->invalid() ); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
public function testAdd() |
57
|
|
|
{ |
58
|
|
|
$this->stub->expects( $this->once() )->method( 'add' ); |
59
|
|
|
$this->assertSame( $this->object, $this->object->add( [] ) ); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
|
63
|
|
|
public function testAddAddressItem() |
64
|
|
|
{ |
65
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/address' )->create(); |
66
|
|
|
|
67
|
|
|
$this->stub->expects( $this->once() )->method( 'addAddressItem' ); |
68
|
|
|
$this->assertSame( $this->object, $this->object->addAddressItem( $item ) ); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
|
public function testAddListItem() |
73
|
|
|
{ |
74
|
|
|
$listItem = \Aimeos\MShop::create( $this->context, 'customer/lists' )->create(); |
75
|
|
|
|
76
|
|
|
$this->stub->expects( $this->once() )->method( 'addListItem' ); |
77
|
|
|
$this->assertSame( $this->object, $this->object->addListItem( 'customer', $listItem ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testAddPropertyItem() |
82
|
|
|
{ |
83
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/property' )->create(); |
84
|
|
|
|
85
|
|
|
$this->stub->expects( $this->once() )->method( 'addPropertyItem' ); |
86
|
|
|
$this->assertSame( $this->object, $this->object->addPropertyItem( $item ) ); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
|
90
|
|
|
public function testCreateAddressItem() |
91
|
|
|
{ |
92
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/address' )->create(); |
93
|
|
|
|
94
|
|
|
$this->stub->expects( $this->once() )->method( 'createAddressItem' )->will( $this->returnValue( $item ) ); |
95
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Address\Iface::class, $this->object->createAddressItem() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
|
99
|
|
|
public function testCreateListItem() |
100
|
|
|
{ |
101
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/lists' )->create(); |
102
|
|
|
|
103
|
|
|
$this->stub->expects( $this->once() )->method( 'createListItem' )->will( $this->returnValue( $item ) ); |
104
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Lists\Iface::class, $this->object->createListItem() ); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
|
108
|
|
|
public function testCreatePropertyItem() |
109
|
|
|
{ |
110
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/property' )->create(); |
111
|
|
|
|
112
|
|
|
$this->stub->expects( $this->once() )->method( 'createPropertyItem' )->will( $this->returnValue( $item ) ); |
113
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $this->object->createPropertyItem() ); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
|
117
|
|
|
public function testDeleteItem() |
118
|
|
|
{ |
119
|
|
|
$this->stub->expects( $this->once() )->method( 'delete' ); |
120
|
|
|
$this->assertSame( $this->object, $this->object->delete() ); |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
|
124
|
|
|
public function testDeleteAddressItem() |
125
|
|
|
{ |
126
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/address' )->create(); |
127
|
|
|
|
128
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteAddressItem' ); |
129
|
|
|
$this->assertSame( $this->object, $this->object->deleteAddressItem( $item ) ); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
|
133
|
|
|
public function testDeleteListItem() |
134
|
|
|
{ |
135
|
|
|
$listItem = \Aimeos\MShop::create( $this->context, 'customer/lists' )->create(); |
136
|
|
|
|
137
|
|
|
$this->stub->expects( $this->once() )->method( 'deleteListItem' ); |
138
|
|
|
$this->assertSame( $this->object, $this->object->deleteListItem( 'customer', $listItem ) ); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
|
142
|
|
|
public function testDeletePropertyItem() |
143
|
|
|
{ |
144
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer/property' )->create(); |
145
|
|
|
|
146
|
|
|
$this->stub->expects( $this->once() )->method( 'deletePropertyItem' ); |
147
|
|
|
$this->assertSame( $this->object, $this->object->deletePropertyItem( $item ) ); |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
public function testFind() |
152
|
|
|
{ |
153
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer' )->create(); |
154
|
|
|
|
155
|
|
|
$this->stub->expects( $this->once() )->method( 'find' ) |
156
|
|
|
->will( $this->returnValue( $item ) ); |
157
|
|
|
|
158
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Iface::class, $this->object->find( 'test' ) ); |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
|
162
|
|
|
public function testGet() |
163
|
|
|
{ |
164
|
|
|
$item = \Aimeos\MShop::create( $this->context, 'customer' )->create(); |
165
|
|
|
|
166
|
|
|
$this->stub->expects( $this->once() )->method( 'get' ) |
167
|
|
|
->will( $this->returnValue( $item ) ); |
168
|
|
|
|
169
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Customer\Item\Iface::class, $this->object->get() ); |
170
|
|
|
} |
171
|
|
|
|
172
|
|
|
|
173
|
|
|
public function testStore() |
174
|
|
|
{ |
175
|
|
|
$this->stub->expects( $this->once() )->method( 'store' ); |
176
|
|
|
$this->assertSame( $this->object, $this->object->store() ); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
|
180
|
|
|
public function testUses() |
181
|
|
|
{ |
182
|
|
|
$this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
|
186
|
|
|
public function testGetController() |
187
|
|
|
{ |
188
|
|
|
$this->assertSame( $this->stub, $this->access( 'getController' )->invokeArgs( $this->object, [] ) ); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
|
192
|
|
|
protected function access( $name ) |
193
|
|
|
{ |
194
|
|
|
$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Customer\Decorator\Base::class ); |
195
|
|
|
$method = $class->getMethod( $name ); |
196
|
|
|
$method->setAccessible( true ); |
197
|
|
|
|
198
|
|
|
return $method; |
199
|
|
|
} |
200
|
|
|
} |
201
|
|
|
|