1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Aimeos\MShop\Customer\Manager\Address; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
8
|
|
|
* @copyright Aimeos (aimeos.org), 2015 |
9
|
|
|
*/ |
10
|
|
|
class FosUserTest extends \PHPUnit_Framework_TestCase |
11
|
|
|
{ |
12
|
|
|
private $fixture = null; |
13
|
|
|
private $object = null; |
14
|
|
|
private $editor = ''; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Sets up the fixture. This method is called before a test is executed. |
19
|
|
|
*/ |
20
|
|
|
protected function setUp() |
21
|
|
|
{ |
22
|
|
|
$context = \TestHelper::getContext(); |
23
|
|
|
$this->editor = $context->getEditor(); |
24
|
|
|
$customer = new \Aimeos\MShop\Customer\Manager\FosUser( $context ); |
25
|
|
|
|
26
|
|
|
$search = $customer->createSearch(); |
27
|
|
|
$conditions = array( |
28
|
|
|
$search->compare( '==', 'customer.code', 'UTC001' ), |
29
|
|
|
$search->compare( '==', 'customer.editor', $this->editor ) |
30
|
|
|
); |
31
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
32
|
|
|
$result = $customer->searchItems( $search ); |
33
|
|
|
|
34
|
|
|
if( ( $customerItem = reset( $result ) ) === false ) { |
35
|
|
|
throw new \Exception( sprintf( 'No customer item found for code "%1$s"', 'UTC001' ) ); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$this->fixture = array( |
39
|
|
|
'customer.address.parentid' => $customerItem->getId(), |
40
|
|
|
'customer.address.company' => 'ABC GmbH', |
41
|
|
|
'customer.address.vatid' => 'DE999999999', |
42
|
|
|
'customer.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR, |
43
|
|
|
'customer.address.title' => 'Herr', |
44
|
|
|
'customer.address.firstname' => 'firstunit', |
45
|
|
|
'customer.address.lastname' => 'lastunit', |
46
|
|
|
'customer.address.address1' => 'unit str.', |
47
|
|
|
'customer.address.address2' => ' 166', |
48
|
|
|
'customer.address.address3' => '4.OG', |
49
|
|
|
'customer.address.postal' => '22769', |
50
|
|
|
'customer.address.city' => 'Hamburg', |
51
|
|
|
'customer.address.state' => 'Hamburg', |
52
|
|
|
'customer.address.countryid' => 'de', |
53
|
|
|
'customer.address.languageid' => 'de', |
54
|
|
|
'customer.address.telephone' => '05554433221', |
55
|
|
|
'customer.address.email' => '[email protected]', |
56
|
|
|
'customer.address.telefax' => '05554433222', |
57
|
|
|
'customer.address.website' => 'unittest.aimeos.org', |
58
|
|
|
'customer.address.position' => 1, |
59
|
|
|
'customer.address.siteid' => $context->getLocale()->getSiteId(), |
60
|
|
|
); |
61
|
|
|
|
62
|
|
|
$this->object = $customer->getSubManager( 'address', 'FosUser' ); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Tears down the fixture. This method is called after a test is executed. |
68
|
|
|
*/ |
69
|
|
|
protected function tearDown() |
70
|
|
|
{ |
71
|
|
|
unset( $this->object, $this->fixture ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
|
75
|
|
|
public function testCleanup() |
76
|
|
|
{ |
77
|
|
|
$this->object->cleanup( array( -1 ) ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetSearchAttributes() |
81
|
|
|
{ |
82
|
|
|
foreach( $this->object->getSearchAttributes() as $attribute ) { |
83
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute ); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testGetSubManager() |
88
|
|
|
{ |
89
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
90
|
|
|
$this->object->getSubManager( 'unknown' ); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
public function testCreateItem() |
94
|
|
|
{ |
95
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Address\\Iface', $this->object->createItem() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
public function testGetItem() |
99
|
|
|
{ |
100
|
|
|
$search = $this->object->createSearch(); |
101
|
|
|
$search->setConditions( $search->compare( '~=', 'customer.address.company', 'ABC GmbH' ) ); |
102
|
|
|
|
103
|
|
|
$items = $this->object->searchItems( $search ); |
104
|
|
|
|
105
|
|
|
if( ( $item = reset( $items ) ) === false ) { |
106
|
|
|
throw new \Exception( 'No address item with company "ABC" found' ); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
$this->assertEquals( $item, $this->object->getItem( $item->getId() ) ); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
public function testSaveUpdateDeleteItem() |
113
|
|
|
{ |
114
|
|
|
$item = new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.', $this->fixture ); |
115
|
|
|
$item->setId( null ); |
116
|
|
|
$this->object->saveItem( $item ); |
117
|
|
|
$itemSaved = $this->object->getItem( $item->getId() ); |
118
|
|
|
|
119
|
|
|
$itemExp = clone $itemSaved; |
120
|
|
|
$itemExp->setPosition( 1 ); |
121
|
|
|
$itemExp->setCity( 'Berlin' ); |
122
|
|
|
$itemExp->setState( 'Berlin' ); |
123
|
|
|
$this->object->saveItem( $itemExp ); |
124
|
|
|
$itemUpd = $this->object->getItem( $itemExp->getId() ); |
125
|
|
|
|
126
|
|
|
$this->object->deleteItem( $itemSaved->getId() ); |
127
|
|
|
|
128
|
|
|
|
129
|
|
|
$this->assertTrue( $item->getId() !== null ); |
130
|
|
|
$this->assertEquals( $item->getId(), $itemSaved->getId() ); |
131
|
|
|
$this->assertEquals( $item->getParentId(), $itemSaved->getParentId()); |
132
|
|
|
$this->assertEquals( $item->getPosition(), $itemSaved->getPosition()); |
133
|
|
|
$this->assertEquals( $item->getCompany(), $itemSaved->getCompany()); |
134
|
|
|
$this->assertEquals( $item->getVatID(), $itemSaved->getVatID()); |
135
|
|
|
$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation()); |
136
|
|
|
$this->assertEquals( $item->getTitle(), $itemSaved->getTitle()); |
137
|
|
|
$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname()); |
138
|
|
|
$this->assertEquals( $item->getLastname(), $itemSaved->getLastname()); |
139
|
|
|
$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1()); |
140
|
|
|
$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2()); |
141
|
|
|
$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3()); |
142
|
|
|
$this->assertEquals( $item->getPostal(), $itemSaved->getPostal()); |
143
|
|
|
$this->assertEquals( $item->getCity(), $itemSaved->getCity()); |
144
|
|
|
$this->assertEquals( $item->getState(), $itemSaved->getState()); |
145
|
|
|
$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId()); |
146
|
|
|
$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId()); |
147
|
|
|
$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone()); |
148
|
|
|
$this->assertEquals( $item->getEmail(), $itemSaved->getEmail()); |
149
|
|
|
$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax()); |
150
|
|
|
$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite()); |
151
|
|
|
$this->assertEquals( $item->getFlag(), $itemSaved->getFlag()); |
152
|
|
|
|
153
|
|
|
$this->assertEquals( $this->editor, $itemSaved->getEditor() ); |
154
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() ); |
155
|
|
|
$this->assertRegExp('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified()); |
156
|
|
|
|
157
|
|
|
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() ); |
158
|
|
|
$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId()); |
159
|
|
|
$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition()); |
160
|
|
|
$this->assertEquals( $itemExp->getCompany(), $itemUpd->getCompany()); |
161
|
|
|
$this->assertEquals( $itemExp->getVatID(), $itemUpd->getVatID()); |
162
|
|
|
$this->assertEquals( $itemExp->getSalutation(), $itemUpd->getSalutation()); |
163
|
|
|
$this->assertEquals( $itemExp->getTitle(), $itemUpd->getTitle()); |
164
|
|
|
$this->assertEquals( $itemExp->getFirstname(), $itemUpd->getFirstname()); |
165
|
|
|
$this->assertEquals( $itemExp->getLastname(), $itemUpd->getLastname()); |
166
|
|
|
$this->assertEquals( $itemExp->getAddress1(), $itemUpd->getAddress1()); |
167
|
|
|
$this->assertEquals( $itemExp->getAddress2(), $itemUpd->getAddress2()); |
168
|
|
|
$this->assertEquals( $itemExp->getAddress3(), $itemUpd->getAddress3()); |
169
|
|
|
$this->assertEquals( $itemExp->getPostal(), $itemUpd->getPostal()); |
170
|
|
|
$this->assertEquals( $itemExp->getCity(), $itemUpd->getCity()); |
171
|
|
|
$this->assertEquals( $itemExp->getState(), $itemUpd->getState()); |
172
|
|
|
$this->assertEquals( $itemExp->getCountryId(), $itemUpd->getCountryId()); |
173
|
|
|
$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId()); |
174
|
|
|
$this->assertEquals( $itemExp->getTelephone(), $itemUpd->getTelephone()); |
175
|
|
|
$this->assertEquals( $itemExp->getEmail(), $itemUpd->getEmail()); |
176
|
|
|
$this->assertEquals( $itemExp->getTelefax(), $itemUpd->getTelefax()); |
177
|
|
|
$this->assertEquals( $itemExp->getWebsite(), $itemUpd->getWebsite()); |
178
|
|
|
$this->assertEquals( $itemExp->getFlag(), $itemUpd->getFlag()); |
179
|
|
|
|
180
|
|
|
$this->assertEquals( $this->editor, $itemUpd->getEditor() ); |
181
|
|
|
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() ); |
182
|
|
|
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() ); |
183
|
|
|
|
184
|
|
|
$this->setExpectedException('\\Aimeos\\MShop\\Exception'); |
185
|
|
|
$this->object->getItem( $itemSaved->getId() ); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
public function testCreateSearch() |
189
|
|
|
{ |
190
|
|
|
$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() ); |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
|
194
|
|
|
public function testSearchItem() |
195
|
|
|
{ |
196
|
|
|
$search = $this->object->createSearch(); |
197
|
|
|
|
198
|
|
|
$conditions = array( |
199
|
|
|
$search->compare( '==', 'customer.address.company', 'ABC' ), |
200
|
|
|
$search->compare( '==', 'customer.address.editor', $this->editor ) |
201
|
|
|
); |
202
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
203
|
|
|
$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) ); |
204
|
|
|
} |
205
|
|
|
|
206
|
|
|
|
207
|
|
|
public function testSearchItemTotal() |
208
|
|
|
{ |
209
|
|
|
$total = 0; |
210
|
|
|
$search = $this->object->createSearch(); |
211
|
|
|
|
212
|
|
|
$conditions = array( |
213
|
|
|
$search->compare( '~=', 'customer.address.company', 'ABC GmbH' ), |
214
|
|
|
$search->compare( '==', 'customer.address.editor', $this->editor ) |
215
|
|
|
); |
216
|
|
|
|
217
|
|
|
$search->setConditions( $search->combine( '&&', $conditions ) ); |
218
|
|
|
$search->setSlice( 0, 1 ); |
219
|
|
|
|
220
|
|
|
$results = $this->object->searchItems( $search, array(), $total ); |
221
|
|
|
|
222
|
|
|
$this->assertEquals( 1, count( $results ) ); |
223
|
|
|
$this->assertEquals( 2, $total ); |
224
|
|
|
|
225
|
|
|
foreach( $results as $id => $item ) { |
226
|
|
|
$this->assertEquals( $id, $item->getId() ); |
227
|
|
|
} |
228
|
|
|
} |
229
|
|
|
} |
230
|
|
|
|