Completed
Push — 2016.04 ( 690368...e61816 )
by Aimeos
04:37
created

Typo3Test   A

Complexity

Total Complexity 14

Size/Duplication

Total Lines 241
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 14
c 3
b 0
f 0
lcom 1
cbo 1
dl 0
loc 241
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testCreateSearch() 0 4 1
A setUp() 0 6 1
A tearDown() 0 5 1
A testGetSearchAttributes() 0 7 2
A testCreateItem() 0 5 1
B testGetItem() 0 36 2
B testSaveUpdateDeleteItem() 0 82 2
A testSearchItems() 0 55 2
A testGetSubManager() 0 5 1
A testGetSubManagerInvalidName() 0 5 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2014
7
 */
8
9
namespace Aimeos\MShop\Customer\Manager\Address;
10
11
12
/**
13
 * Test class for \Aimeos\MShop\Customer\Manager\Address\Typo3
14
 */
15
class Typo3Test extends \PHPUnit_Framework_TestCase
16
{
17
	private $object;
18
	private $editor = '';
19
20
21
	/**
22
	 * Sets up the fixture. This method is called before a test is executed.
23
	 */
24
	protected function setUp()
25
	{
26
		$this->editor = \TestHelper::getContext()->getEditor();
27
		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( \TestHelper::getContext(), 'Typo3' );
28
		$this->object = $manager->getSubManager( 'address', 'Typo3' );
29
	}
30
31
32
	/**
33
	 * Tears down the fixture. This method is called after a test is executed.
34
	 */
35
	protected function tearDown()
36
	{
37
		unset( $this->object );
38
		\Aimeos\MShop\Factory::clear();
39
	}
40
41
42
	public function testGetSearchAttributes()
43
	{
44
		foreach( $this->object->getSearchAttributes() as $attribute )
45
		{
46
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
47
		}
48
	}
49
50
51
	public function testCreateItem()
52
	{
53
		$item = $this->object->createItem();
54
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Address\\Iface', $item );
55
	}
56
57
58
	public function testGetItem()
59
	{
60
		$search = $this->object->createSearch();
61
		$search->setConditions( $search->compare( '==', 'customer.address.email', '[email protected]' ) );
62
		$items = $this->object->searchItems( $search );
63
64
		if( ( $expected = reset( $items ) ) === false ) {
65
			throw new \Exception( 'No customer address found' );
66
		}
67
68
		$actual = $this->object->getItem( $expected->getId() );
69
70
		$this->assertEquals( $expected, $actual );
71
72
		$this->assertEquals( 'mr', $actual->getSalutation() );
73
		$this->assertEquals( 'Example Company', $actual->getCompany() );
74
		$this->assertEquals( 'DE999999999', $actual->getVatID() );
75
		$this->assertEquals( 'Dr', $actual->getTitle() );
76
		$this->assertEquals( 'Our', $actual->getFirstname() );
77
		$this->assertEquals( 'Unittest', $actual->getLastname() );
78
		$this->assertEquals( 'Pickhuben', $actual->getAddress1() );
79
		$this->assertEquals( '2-4', $actual->getAddress2() );
80
		$this->assertEquals( '', $actual->getAddress3() );
81
		$this->assertEquals( '20457', $actual->getPostal() );
82
		$this->assertEquals( 'Hamburg', $actual->getCity() );
83
		$this->assertEquals( 'Hamburg', $actual->getState() );
84
		$this->assertEquals( 'de', $actual->getLanguageId() );
85
		$this->assertEquals( 'DE', $actual->getCountryId() );
86
		$this->assertEquals( '055544332211', $actual->getTelephone() );
87
		$this->assertEquals( '[email protected]', $actual->getEMail() );
88
		$this->assertEquals( '055544332212', $actual->getTelefax() );
89
		$this->assertEquals( 'www.example.com', $actual->getWebsite() );
90
		$this->assertEquals( 0, $actual->getFlag() );
91
		$this->assertEquals( 0, $actual->getPosition() );
92
		$this->assertEquals( $this->editor, $actual->getEditor() );
93
	}
94
95
96
	public function testSaveUpdateDeleteItem()
97
	{
98
		$search = $this->object->createSearch();
99
		$search->setConditions( $search->compare( '==', 'customer.address.email', '[email protected]' ) );
100
		$results = $this->object->searchItems( $search );
101
102
		if( ( $item = reset( $results ) ) === false ) {
103
			throw new \Exception( 'No customer address found' );
104
		}
105
106
		$item->setId( null );
107
		$this->object->saveItem( $item );
108
		$itemSaved = $this->object->getItem( $item->getId() );
109
110
		$itemExp = clone $itemSaved;
111
		$itemExp->setCompany( 'unitTest' );
112
		$this->object->saveItem( $itemExp );
113
		$itemUpd = $this->object->getItem( $itemExp->getId() );
114
115
		$this->object->deleteItem( $item->getId() );
116
117
118
		$this->assertTrue( $item->getId() !== null );
119
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
120
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
121
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
122
		$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation() );
123
		$this->assertEquals( $item->getCompany(), $itemSaved->getCompany() );
124
		$this->assertEquals( $item->getVatID(), $itemSaved->getVatID() );
125
		$this->assertEquals( $item->getTitle(), $itemSaved->getTitle() );
126
		$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname() );
127
		$this->assertEquals( $item->getLastname(), $itemSaved->getLastname() );
128
		$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1() );
129
		$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2() );
130
		$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3() );
131
		$this->assertEquals( $item->getPostal(), $itemSaved->getPostal() );
132
		$this->assertEquals( $item->getCity(), $itemSaved->getCity() );
133
		$this->assertEquals( $item->getState(), $itemSaved->getState() );
134
		$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() );
135
		$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId() );
136
		$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone() );
137
		$this->assertEquals( $item->getEMail(), $itemSaved->getEMail() );
138
		$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax() );
139
		$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite() );
140
		$this->assertEquals( $item->getFlag(), $itemSaved->getFlag() );
141
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
142
		$this->assertEquals( $item->getEditor(), $itemSaved->getEditor() );
143
144
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
145
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
146
147
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
148
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
149
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
150
		$this->assertEquals( $itemExp->getSalutation(), $itemUpd->getSalutation() );
151
		$this->assertEquals( $itemExp->getCompany(), $itemUpd->getCompany() );
152
		$this->assertEquals( $itemExp->getVatID(), $itemUpd->getVatID() );
153
		$this->assertEquals( $itemExp->getTitle(), $itemUpd->getTitle() );
154
		$this->assertEquals( $itemExp->getFirstname(), $itemUpd->getFirstname() );
155
		$this->assertEquals( $itemExp->getLastname(), $itemUpd->getLastname() );
156
		$this->assertEquals( $itemExp->getAddress1(), $itemUpd->getAddress1() );
157
		$this->assertEquals( $itemExp->getAddress2(), $itemUpd->getAddress2() );
158
		$this->assertEquals( $itemExp->getAddress3(), $itemUpd->getAddress3() );
159
		$this->assertEquals( $itemExp->getPostal(), $itemUpd->getPostal() );
160
		$this->assertEquals( $itemExp->getCity(), $itemUpd->getCity() );
161
		$this->assertEquals( $itemExp->getState(), $itemUpd->getState() );
162
		$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() );
163
		$this->assertEquals( $itemExp->getCountryId(), $itemUpd->getCountryId() );
164
		$this->assertEquals( $itemExp->getTelephone(), $itemUpd->getTelephone() );
165
		$this->assertEquals( $itemExp->getEMail(), $itemUpd->getEMail() );
166
		$this->assertEquals( $itemExp->getTelefax(), $itemUpd->getTelefax() );
167
		$this->assertEquals( $itemExp->getWebsite(), $itemUpd->getWebsite() );
168
		$this->assertEquals( $itemExp->getFlag(), $itemUpd->getFlag() );
169
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
170
		$this->assertEquals( $itemExp->getEditor(), $itemUpd->getEditor() );
171
172
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
173
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
174
175
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
176
		$this->object->getItem( $item->getId() );
177
	}
178
179
180
	public function testCreateSearch()
181
	{
182
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
183
	}
184
185
186
	public function testSearchItems()
187
	{
188
		$total = 0;
189
		$search = $this->object->createSearch();
190
191
		$expr = array();
192
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
193
		$expr[] = $search->compare( '!=', 'customer.address.siteid', null );
194
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
195
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
196
		$expr[] = $search->compare( '==', 'customer.address.company', 'Example company LLC' );
197
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
198
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
199
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
200
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
201
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
202
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
203
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
204
		$expr[] = $search->compare( '==', 'customer.address.postal', '20457' );
205
		$expr[] = $search->compare( '==', 'customer.address.city', 'Hamburg' );
206
		$expr[] = $search->compare( '==', 'customer.address.state', 'Hamburg' );
207
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
208
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
209
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332211' );
210
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
211
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544332212' );
212
		$expr[] = $search->compare( '==', 'customer.address.website', 'www.example.com' );
213
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
214
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
215
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
216
		$expr[] = $search->compare( '>', 'customer.address.mtime', '1970-01-01 00:00:00' );
217
		$expr[] = $search->compare( '>', 'customer.address.ctime', '1970-01-01 00:00:00' );
218
219
		$search->setConditions( $search->combine( '&&', $expr ) );
220
		$result = $this->object->searchItems( $search, array(), $total );
221
222
		$this->assertEquals( 1, count( $result ) );
223
		$this->assertEquals( 1, $total );
224
225
226
		// search without base criteria
227
		$search = $this->object->createSearch();
228
		$results = $this->object->searchItems( $search );
229
		$this->assertEquals( 4, count( $results ) );
230
231
232
		// search with base criteria
233
		$search = $this->object->createSearch(true);
234
		$results = $this->object->searchItems( $search );
235
		$this->assertEquals( 4, count( $results ) );
236
237
		foreach( $results as $itemId => $item ) {
238
			$this->assertEquals( $itemId, $item->getId() );
239
		}
240
	}
241
242
243
	public function testGetSubManager()
244
	{
245
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
246
		$this->object->getSubManager( 'unknown' );
247
	}
248
249
250
	public function testGetSubManagerInvalidName()
251
	{
252
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
253
		$this->object->getSubManager( 'address', 'unknown' );
254
	}
255
}
256