|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
|
5
|
|
|
* @copyright Aimeos (aimeos.org), 2017 |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
|
|
9
|
|
|
namespace Aimeos\Controller\Frontend\Customer; |
|
10
|
|
|
|
|
11
|
|
|
|
|
12
|
|
|
class StandardTest extends \PHPUnit\Framework\TestCase |
|
13
|
|
|
{ |
|
14
|
|
|
private $context; |
|
15
|
|
|
private $object; |
|
16
|
|
|
|
|
17
|
|
|
|
|
18
|
|
|
protected function setUp() |
|
19
|
|
|
{ |
|
20
|
|
|
$this->context = \TestHelperFrontend::getContext(); |
|
21
|
|
|
$this->object = new \Aimeos\Controller\Frontend\Customer\Standard( $this->context ); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
protected function tearDown() |
|
26
|
|
|
{ |
|
27
|
|
|
unset( $this->context, $this->object ); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
public function testAddEditSaveDeleteItem() |
|
32
|
|
|
{ |
|
33
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' ); |
|
34
|
|
|
$id = $manager->findItem( 'UTC001' )->getId(); |
|
35
|
|
|
|
|
36
|
|
|
$this->context->setUserId( $id ); |
|
37
|
|
|
$item = $this->object->addItem( ['customer.code' => 'unittest-ctnl', 'customer.status' => 1] ); |
|
38
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item ); |
|
39
|
|
|
|
|
40
|
|
|
$this->context->setUserId( $item->getId() ); |
|
41
|
|
|
$item = $this->object->editItem( $item->getId(), ['customer.code' => 'unittest-ctnl2'] ); |
|
42
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $item ); |
|
43
|
|
|
|
|
44
|
|
|
$item->setStatus( 0 ); |
|
45
|
|
|
$this->object->saveItem( $item ); |
|
46
|
|
|
$this->assertEquals( 0, $item->getStatus() ); |
|
47
|
|
|
|
|
48
|
|
|
$this->object->deleteItem( $item->getId() ); |
|
49
|
|
|
|
|
50
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
|
51
|
|
|
$manager->findItem( 'unittest-ctnl' ); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
public function testCreateItem() |
|
56
|
|
|
{ |
|
57
|
|
|
$result = $this->object->createItem(); |
|
58
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result ); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
|
|
62
|
|
|
public function testGetItem() |
|
63
|
|
|
{ |
|
64
|
|
|
$id = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' )->getId(); |
|
65
|
|
|
$this->context->setUserId( $id ); |
|
66
|
|
|
|
|
67
|
|
|
$result = $this->object->getItem( $id, ['customer/address', 'text'] ); |
|
68
|
|
|
|
|
69
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result ); |
|
70
|
|
|
$this->assertEquals( 1, count( $result->getRefItems( 'text' ) ) ); |
|
71
|
|
|
$this->assertEquals( 1, count( $result->getAddressItems() ) ); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
|
75
|
|
|
public function testFindItem() |
|
76
|
|
|
{ |
|
77
|
|
|
$result = $this->object->findItem( 'UTC001' ); |
|
78
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Iface', $result ); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
|
|
82
|
|
|
public function testAddEditSaveDeleteAddressItem() |
|
83
|
|
|
{ |
|
84
|
|
|
$customer = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' ); |
|
85
|
|
|
$this->context->setUserId( $customer->getId() ); |
|
86
|
|
|
|
|
87
|
|
|
$item = $this->object->addAddressItem( ['customer.address.lastname' => 'unittest-ctnl'] ); |
|
88
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item ); |
|
89
|
|
|
|
|
90
|
|
|
$item = $this->object->editAddressItem( $item->getId(), ['customer.address.lastname' => 'unittest-ctnl2'] ); |
|
91
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $item ); |
|
92
|
|
|
|
|
93
|
|
|
$item->setLastName( 'test' ); |
|
94
|
|
|
$this->object->saveAddressItem( $item ); |
|
95
|
|
|
$this->assertEquals( 'test', $item->getLastName() ); |
|
96
|
|
|
|
|
97
|
|
|
$this->object->deleteAddressItem( $item->getId() ); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
|
|
101
|
|
|
public function testCreateAddressItem() |
|
102
|
|
|
{ |
|
103
|
|
|
$result = $this->object->createAddressItem(); |
|
104
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result ); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
public function testGetAddressItem() |
|
109
|
|
|
{ |
|
110
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/address' ); |
|
111
|
|
|
$search = $manager->createSearch(); |
|
112
|
|
|
$search->setSlice( 0, 1 ); |
|
113
|
|
|
$result = $manager->searchItems( $search ); |
|
114
|
|
|
|
|
115
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
|
116
|
|
|
throw new \RuntimeException( 'No customer address available' ); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
$this->context->setUserId( $item->getParentId() ); |
|
120
|
|
|
$result = $this->object->getAddressItem( $item->getId() ); |
|
121
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Customer\Item\Address\Iface', $result ); |
|
122
|
|
|
} |
|
123
|
|
|
|
|
124
|
|
|
|
|
125
|
|
|
public function testAddEditDeleteListsItem() |
|
126
|
|
|
{ |
|
127
|
|
|
$customer = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' )->findItem( 'UTC001' ); |
|
128
|
|
|
$this->context->setUserId( $customer->getId() ); |
|
129
|
|
|
|
|
130
|
|
|
$values = [ |
|
131
|
|
|
'customer.lists.type' => 'favorite', |
|
132
|
|
|
'customer.lists.domain' => 'product', |
|
133
|
|
|
'customer.lists.refid' => '-1' |
|
134
|
|
|
]; |
|
135
|
|
|
|
|
136
|
|
|
$item = $this->object->addListsItem( $values ); |
|
137
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item ); |
|
138
|
|
|
|
|
139
|
|
|
$values = [ |
|
140
|
|
|
'customer.lists.type' => 'favorite', |
|
141
|
|
|
'customer.lists.domain' => 'product', |
|
142
|
|
|
'customer.lists.refid' => '-2' |
|
143
|
|
|
]; |
|
144
|
|
|
|
|
145
|
|
|
$item = $this->object->editListsItem( $item->getId(), $values ); |
|
146
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item ); |
|
147
|
|
|
|
|
148
|
|
|
$this->object->deleteListsItem( $item->getId() ); |
|
149
|
|
|
|
|
150
|
|
|
$this->setExpectedException( '\Aimeos\MShop\Exception' ); |
|
151
|
|
|
$this->object->getListsItem( $item->getId() ); |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
|
|
155
|
|
|
public function testGetListsItem() |
|
156
|
|
|
{ |
|
157
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer/lists' ); |
|
158
|
|
|
$search = $manager->createSearch(); |
|
159
|
|
|
$search->setSlice( 0, 1 ); |
|
160
|
|
|
$result = $manager->searchItems( $search ); |
|
161
|
|
|
|
|
162
|
|
|
if( ( $item = reset( $result ) ) === false ) { |
|
163
|
|
|
throw new \RuntimeException( 'No customer lists item available' ); |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
$this->context->setUserId( $item->getParentId() ); |
|
167
|
|
|
$result = $this->object->getListsItem( $item->getId() ); |
|
168
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $result ); |
|
169
|
|
|
} |
|
170
|
|
|
|
|
171
|
|
|
|
|
172
|
|
|
public function testSearchListsItem() |
|
173
|
|
|
{ |
|
174
|
|
|
$manager = \Aimeos\MShop\Factory::createManager( $this->context, 'customer' ); |
|
175
|
|
|
$customer = $manager->findItem( 'UTC001' ); |
|
176
|
|
|
$this->context->setUserId( $customer->getId() ); |
|
177
|
|
|
|
|
178
|
|
|
$filter = $this->object->createListsFilter(); |
|
179
|
|
|
$result = $this->object->searchListsItems( $filter ); |
|
180
|
|
|
|
|
181
|
|
|
foreach( $result as $item ) |
|
182
|
|
|
{ |
|
183
|
|
|
$this->assertEquals( $customer->getId(), $item->getParentId() ); |
|
184
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Lists\Iface', $item ); |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
} |
|
188
|
|
|
|