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