forked from aimeos/ai-typo3
/
Typo3Test.php
276 lines (229 loc) · 11.9 KB
/
Typo3Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Metaways Infosystems GmbH, 2011
* @copyright Aimeos (aimeos.org), 2014
*/
/**
* Test class for MShop_Customer_Manager_Typo3
*/
class MShop_Customer_Manager_Typo3Test extends MW_Unittest_Testcase
{
private $_context;
private $_object;
private $_editor;
private $_item;
/**
* Sets up the fixture. This method is called before a test is executed.
*/
protected function setUp()
{
$this->_context = TestHelper::getContext();
$this->_editor = $this->_context->getEditor();
$this->_context->getConfig()->set( 'mshop/customer/manager/typo3/pid-default', 999999 );
$this->_object = new MShop_Customer_Manager_Typo3( $this->_context );
}
/**
* Tears down the fixture. This method is called after a test is executed.
*/
protected function tearDown()
{
unset($this->_object, $this->_item);
MShop_Factory::clear();
}
public function testGetSearchAttributes()
{
foreach( $this->_object->getSearchAttributes() as $attribute )
{
$this->assertInstanceOf( 'MW_Common_Criteria_Attribute_Interface', $attribute );
}
}
public function testCreateItem()
{
$item = $this->_object->createItem();
$this->assertInstanceOf( 'MShop_Customer_Item_Interface', $item );
}
public function testGetItem()
{
$search = $this->_object->createSearch();
$search->setConditions( $search->compare( '==', 'customer.code', 'unitCustomer1@example.com' ) );
$items = $this->_object->searchItems( $search );
if( ( $expected = reset( $items ) ) === false ) {
throw new Exception( 'No customer found.' );
}
$actual = $this->_object->getItem( $expected->getId() );
$billing = $actual->getPaymentAddress();
$this->assertEquals( $expected, $actual );
$this->assertEquals( 'Max Mustermann', $actual->getLabel() );
$this->assertEquals( 'unitCustomer1@example.com', $actual->getCode() );
$this->assertEquals( 'mr', $billing->getSalutation() );
$this->assertEquals( 'Example company LLC', $billing->getCompany() );
$this->assertEquals( 'Dr.', $billing->getTitle() );
$this->assertEquals( 'Max', $billing->getFirstname() );
$this->assertEquals( 'Mustermann', $billing->getLastname() );
$this->assertEquals( 'Musterstraße 1a', $billing->getAddress1() );
$this->assertEquals( '', $billing->getAddress2() );
$this->assertEquals( '', $billing->getAddress3() );
$this->assertEquals( '20001', $billing->getPostal() );
$this->assertEquals( 'Musterstadt', $billing->getCity() );
$this->assertEquals( 'Hamburg', $billing->getState() );
$this->assertEquals( 'de', $billing->getLanguageId() );
$this->assertEquals( 'DE', $billing->getCountryId() );
$this->assertEquals( '01234567890', $billing->getTelephone() );
$this->assertEquals( 'unitCustomer1@example.com', $billing->getEMail() );
$this->assertEquals( '01234567890', $billing->getTelefax() );
$this->assertEquals( 'www.example.com', $billing->getWebsite() );
$this->assertEquals( 1, $actual->getStatus() );
$this->assertEquals( '5f4dcc3b5aa765d61d8327deb882cf99', $actual->getPassword() );
$this->assertEquals( '2011-01-13 11:03:36', $actual->getTimeCreated() );
$this->assertEquals( '2011-01-13 11:03:46', $actual->getTimeModified() );
$this->assertEquals( '', $actual->getEditor() );
}
public function testSaveUpdateDeleteItem()
{
$search = $this->_object->createSearch();
$search->setConditions( $search->compare( '==', 'customer.code', 'unitCustomer1@example.com' ) );
$results = $this->_object->searchItems( $search );
if( ( $item = reset( $results ) ) === false ) {
throw new Exception( 'No customer found.' );
}
$item->setId( null );
$item->setCode( 'unitTest' );
$item->setLabel( 'unitTest' );
$this->_object->saveItem( $item );
$itemSaved = $this->_object->getItem( $item->getId() );
$itemExp = clone $itemSaved;
$itemExp->setCode( 'unitTest2' );
$itemExp->setLabel( 'unitTest2' );
$this->_object->saveItem( $itemExp );
$itemUpd = $this->_object->getItem( $itemExp->getId() );
$this->_object->deleteItem( $item->getId() );
$this->assertTrue( $item->getId() !== null );
$this->assertEquals( $item->getId(), $itemSaved->getId() );
$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
$this->assertEquals( $item->getStatus(), $itemSaved->getStatus() );
$this->assertEquals( $item->getCode(), $itemSaved->getCode() );
$this->assertEquals( $item->getLabel(), $itemSaved->getLabel() );
$this->assertEquals( $item->getPaymentAddress(), $itemSaved->getPaymentAddress() );
$this->assertEquals( $item->getBirthday(), $itemSaved->getBirthday() );
$this->assertEquals( $item->getPassword(), $itemSaved->getPassword() );
$this->assertEquals( '', $itemSaved->getEditor() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
$this->assertEquals( $itemExp->getStatus(), $itemUpd->getStatus() );
$this->assertEquals( $itemExp->getCode(), $itemUpd->getCode() );
$this->assertEquals( $itemExp->getLabel(), $itemUpd->getLabel() );
$this->assertEquals( $itemExp->getPaymentAddress(), $itemUpd->getPaymentAddress() );
$this->assertEquals( $itemExp->getBirthday(), $itemUpd->getBirthday() );
$this->assertEquals( $itemExp->getPassword(), $itemUpd->getPassword() );
$this->assertEquals( '', $itemUpd->getEditor() );
$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
$this->setExpectedException( 'MShop_Exception' );
$this->_object->getItem( $item->getId() );
}
public function testCreateSearch()
{
$this->assertInstanceOf( 'MW_Common_Criteria_Interface', $this->_object->createSearch() );
}
public function testSearchItems()
{
$total = 0;
$search = $this->_object->createSearch();
$expr = array();
$expr[] = $search->compare( '!=', 'customer.id', null );
$expr[] = $search->compare( '==', 'customer.label', 'Franz-Xaver Gabler' );
$expr[] = $search->compare( '==', 'customer.code', 'unitCustomer3@example.com' );
$expr[] = $search->compare( '==', 'customer.salutation', 'mr' );
$expr[] = $search->compare( '==', 'customer.company', 'Example company LLC' );
$expr[] = $search->compare( '==', 'customer.title', '' );
$expr[] = $search->compare( '==', 'customer.firstname', 'Franz-Xaver' );
$expr[] = $search->compare( '==', 'customer.lastname', 'Gabler' );
$expr[] = $search->compare( '==', 'customer.address1', 'Phantasiestraße 2' );
$expr[] = $search->compare( '==', 'customer.postal', '23643' );
$expr[] = $search->compare( '==', 'customer.city', 'Berlin' );
$expr[] = $search->compare( '==', 'customer.state', 'Berlin' );
$expr[] = $search->compare( '==', 'customer.telephone', '01234509876' );
$expr[] = $search->compare( '==', 'customer.email', 'unitCustomer3@example.com' );
$expr[] = $search->compare( '==', 'customer.telefax', '055544333212' );
$expr[] = $search->compare( '==', 'customer.website', 'www.example.com' );
$expr[] = $search->compare( '==', 'customer.status', 1 );
$expr[] = $search->compare( '!=', 'customer.password', '' );
$expr[] = $search->compare( '>', 'customer.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>', 'customer.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '!=', 'customer.address.id', null );
$expr[] = $search->compare( '!=', 'customer.address.siteid', null );
$expr[] = $search->compare( '!=', 'customer.address.refid', null );
$expr[] = $search->compare( '==', 'customer.address.salutation', 'company' );
$expr[] = $search->compare( '==', 'customer.address.company', 'unitcompany' );
$expr[] = $search->compare( '==', 'customer.address.title', 'unittitle' );
$expr[] = $search->compare( '==', 'customer.address.firstname', 'unitfirstname' );
$expr[] = $search->compare( '==', 'customer.address.lastname', 'unitlastname' );
$expr[] = $search->compare( '==', 'customer.address.address1', 'unitaddress1' );
$expr[] = $search->compare( '==', 'customer.address.address2', 'unitaddress2' );
$expr[] = $search->compare( '==', 'customer.address.address3', 'unitaddress3' );
$expr[] = $search->compare( '==', 'customer.address.postal', 'unitpostal' );
$expr[] = $search->compare( '==', 'customer.address.city', 'unitcity' );
$expr[] = $search->compare( '==', 'customer.address.state', 'unitstate' );
$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
$expr[] = $search->compare( '==', 'customer.address.telephone', '1234567890' );
$expr[] = $search->compare( '==', 'customer.address.email', 'unitCustomer3@example.com' );
$expr[] = $search->compare( '==', 'customer.address.telefax', '1234567891' );
$expr[] = $search->compare( '==', 'customer.address.website', 'unit.web.site' );
$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
$expr[] = $search->compare( '==', 'customer.address.position', 2 );
$expr[] = $search->compare( '==', 'customer.address.editor', $this->_editor );
$expr[] = $search->compare( '>', 'customer.address.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>', 'customer.address.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '!=', 'customer.list.id', null );
$expr[] = $search->compare( '!=', 'customer.list.siteid', null );
$expr[] = $search->compare( '!=', 'customer.list.parentid', null );
$expr[] = $search->compare( '==', 'customer.list.domain', 'text' );
$expr[] = $search->compare( '>', 'customer.list.typeid', 0 );
$expr[] = $search->compare( '>', 'customer.list.refid', 0 );
$expr[] = $search->compare( '==', 'customer.list.datestart', '2010-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.list.dateend', '2022-01-01 00:00:00' );
$expr[] = $search->compare( '>', 'customer.list.position', 0 );
$expr[] = $search->compare( '>=', 'customer.list.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>=', 'customer.list.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.list.editor', $this->_editor );
$expr[] = $search->compare( '!=', 'customer.list.type.id', null );
$expr[] = $search->compare( '!=', 'customer.list.type.siteid', null );
$expr[] = $search->compare( '==', 'customer.list.type.code', 'default' );
$expr[] = $search->compare( '==', 'customer.list.type.domain', 'text' );
$expr[] = $search->compare( '==', 'customer.list.type.label', 'Default' );
$expr[] = $search->compare( '==', 'customer.list.type.status', 1 );
$expr[] = $search->compare( '>=', 'customer.list.type.mtime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '>=', 'customer.list.type.ctime', '1970-01-01 00:00:00' );
$expr[] = $search->compare( '==', 'customer.list.type.editor', $this->_editor );
$search->setConditions( $search->combine( '&&', $expr ) );
$result = $this->_object->searchItems( $search, array(), $total );
$this->assertEquals( 1, count( $result ) );
$this->assertEquals( 1, $total );
$this->assertEquals( array( 1, 2, 3 ), reset( $result )->getGroups() );
// search without base criteria
$search = $this->_object->createSearch();
$results = $this->_object->searchItems( $search );
$this->assertEquals( 3, count( $results ) );
// search with base criteria
$search = $this->_object->createSearch(true);
$results = $this->_object->searchItems( $search );
$this->assertEquals( 2, count( $results ) );
foreach( $results as $itemId => $item ) {
$this->assertEquals( $itemId, $item->getId() );
}
}
public function testGetSubManager()
{
$this->setExpectedException( 'MShop_Exception' );
$this->_object->getSubManager( 'unknown' );
}
public function testGetSubManagerInvalidName()
{
$this->setExpectedException( 'MShop_Exception' );
$this->_object->getSubManager( 'address', 'unknown' );
}
}