Completed
Push — master ( 7c1ebe...deb645 )
by Aimeos
05:11
created

Typo3Test::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
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-2017
7
 */
8
9
namespace Aimeos\MShop\Customer\Manager\Address;
10
11
12
class Typo3Test extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $editor = '';
16
17
18
	protected function setUp()
19
	{
20
		$this->editor = \TestHelper::getContext()->getEditor();
21
		$manager = \Aimeos\MShop\Customer\Manager\Factory::createManager( \TestHelper::getContext(), 'Typo3' );
22
		$this->object = $manager->getSubManager( 'address', 'Typo3' );
23
	}
24
25
26
	protected function tearDown()
27
	{
28
		unset( $this->object );
29
		\Aimeos\MShop\Factory::clear();
30
	}
31
32
33
	public function testGetSearchAttributes()
34
	{
35
		foreach( $this->object->getSearchAttributes() as $attribute )
36
		{
37
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
38
		}
39
	}
40
41
42
	public function testCreateItem()
43
	{
44
		$item = $this->object->createItem();
45
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Address\\Iface', $item );
46
	}
47
48
49
	public function testGetItem()
50
	{
51
		$search = $this->object->createSearch();
52
		$search->setConditions( $search->compare( '==', 'customer.address.email', '[email protected]' ) );
53
		$items = $this->object->searchItems( $search );
54
55
		if( ( $expected = reset( $items ) ) === false ) {
56
			throw new \RuntimeException( 'No customer address found' );
57
		}
58
59
		$actual = $this->object->getItem( $expected->getId() );
60
61
		$this->assertEquals( $expected, $actual );
62
63
		$this->assertEquals( 'mr', $actual->getSalutation() );
64
		$this->assertEquals( 'ABC', $actual->getCompany() );
65
		$this->assertEquals( 'DE999999999', $actual->getVatID() );
66
		$this->assertEquals( 'Dr', $actual->getTitle() );
67
		$this->assertEquals( 'Our', $actual->getFirstname() );
68
		$this->assertEquals( 'Unittest', $actual->getLastname() );
69
		$this->assertEquals( 'Pickhuben', $actual->getAddress1() );
70
		$this->assertEquals( '2-4', $actual->getAddress2() );
71
		$this->assertEquals( '', $actual->getAddress3() );
72
		$this->assertEquals( '20457', $actual->getPostal() );
73
		$this->assertEquals( 'Hamburg', $actual->getCity() );
74
		$this->assertEquals( 'Hamburg', $actual->getState() );
75
		$this->assertEquals( 'de', $actual->getLanguageId() );
76
		$this->assertEquals( 'DE', $actual->getCountryId() );
77
		$this->assertEquals( '055544332211', $actual->getTelephone() );
78
		$this->assertEquals( '[email protected]', $actual->getEMail() );
79
		$this->assertEquals( '055544332212', $actual->getTelefax() );
80
		$this->assertEquals( 'unittest.aimeos.org', $actual->getWebsite() );
81
		$this->assertEquals( '10.0', $actual->getLongitude() );
82
		$this->assertEquals( '50.0', $actual->getLatitude() );
83
		$this->assertEquals( 0, $actual->getFlag() );
84
		$this->assertEquals( 0, $actual->getPosition() );
85
		$this->assertEquals( $this->editor, $actual->getEditor() );
86
	}
87
88
89
	public function testSaveUpdateDeleteItem()
90
	{
91
		$search = $this->object->createSearch();
92
		$search->setConditions( $search->compare( '==', 'customer.address.email', '[email protected]' ) );
93
		$results = $this->object->searchItems( $search );
94
95
		if( ( $item = reset( $results ) ) === false ) {
96
			throw new \RuntimeException( 'No customer address found' );
97
		}
98
99
		$item->setId( null );
100
		$resultSaved = $this->object->saveItem( $item );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $resultSaved is correct as $this->object->saveItem($item) (which targets Aimeos\MShop\Common\Manager\Iface::saveItem()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
101
		$itemSaved = $this->object->getItem( $item->getId() );
102
103
		$itemExp = clone $itemSaved;
104
		$itemExp->setCompany( 'unitTest' );
105
		$resultUpd = $this->object->saveItem( $itemExp );
0 ignored issues
show
Bug introduced by
Are you sure the assignment to $resultUpd is correct as $this->object->saveItem($itemExp) (which targets Aimeos\MShop\Common\Manager\Iface::saveItem()) seems to always return null.

This check looks for function or method calls that always return null and whose return value is assigned to a variable.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
$object = $a->getObject();

The method getObject() can return nothing but null, so it makes no sense to assign that value to a variable.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
106
		$itemUpd = $this->object->getItem( $itemExp->getId() );
107
108
		$this->object->deleteItem( $item->getId() );
109
110
111
		$this->assertTrue( $item->getId() !== null );
112
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
113
		$this->assertEquals( $item->getSiteId(), $itemSaved->getSiteId() );
114
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId() );
115
		$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation() );
116
		$this->assertEquals( $item->getCompany(), $itemSaved->getCompany() );
117
		$this->assertEquals( $item->getVatID(), $itemSaved->getVatID() );
118
		$this->assertEquals( $item->getTitle(), $itemSaved->getTitle() );
119
		$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname() );
120
		$this->assertEquals( $item->getLastname(), $itemSaved->getLastname() );
121
		$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1() );
122
		$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2() );
123
		$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3() );
124
		$this->assertEquals( $item->getPostal(), $itemSaved->getPostal() );
125
		$this->assertEquals( $item->getCity(), $itemSaved->getCity() );
126
		$this->assertEquals( $item->getState(), $itemSaved->getState() );
127
		$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId() );
128
		$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId() );
129
		$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone() );
130
		$this->assertEquals( $item->getEMail(), $itemSaved->getEMail() );
131
		$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax() );
132
		$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite() );
133
		$this->assertEquals( $item->getLongitude(), $itemSaved->getLongitude() );
134
		$this->assertEquals( $item->getLatitude(), $itemSaved->getLatitude() );
135
		$this->assertEquals( $item->getFlag(), $itemSaved->getFlag() );
136
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition() );
137
		$this->assertEquals( $item->getEditor(), $itemSaved->getEditor() );
138
139
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeCreated() );
140
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemSaved->getTimeModified() );
141
142
		$this->assertEquals( $itemExp->getId(), $itemUpd->getId() );
143
		$this->assertEquals( $itemExp->getSiteId(), $itemUpd->getSiteId() );
144
		$this->assertEquals( $itemExp->getParentId(), $itemUpd->getParentId() );
145
		$this->assertEquals( $itemExp->getSalutation(), $itemUpd->getSalutation() );
146
		$this->assertEquals( $itemExp->getCompany(), $itemUpd->getCompany() );
147
		$this->assertEquals( $itemExp->getVatID(), $itemUpd->getVatID() );
148
		$this->assertEquals( $itemExp->getTitle(), $itemUpd->getTitle() );
149
		$this->assertEquals( $itemExp->getFirstname(), $itemUpd->getFirstname() );
150
		$this->assertEquals( $itemExp->getLastname(), $itemUpd->getLastname() );
151
		$this->assertEquals( $itemExp->getAddress1(), $itemUpd->getAddress1() );
152
		$this->assertEquals( $itemExp->getAddress2(), $itemUpd->getAddress2() );
153
		$this->assertEquals( $itemExp->getAddress3(), $itemUpd->getAddress3() );
154
		$this->assertEquals( $itemExp->getPostal(), $itemUpd->getPostal() );
155
		$this->assertEquals( $itemExp->getCity(), $itemUpd->getCity() );
156
		$this->assertEquals( $itemExp->getState(), $itemUpd->getState() );
157
		$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId() );
158
		$this->assertEquals( $itemExp->getCountryId(), $itemUpd->getCountryId() );
159
		$this->assertEquals( $itemExp->getTelephone(), $itemUpd->getTelephone() );
160
		$this->assertEquals( $itemExp->getEMail(), $itemUpd->getEMail() );
161
		$this->assertEquals( $itemExp->getTelefax(), $itemUpd->getTelefax() );
162
		$this->assertEquals( $itemExp->getWebsite(), $itemUpd->getWebsite() );
163
		$this->assertEquals( $itemExp->getLongitude(), $itemUpd->getLongitude() );
164
		$this->assertEquals( $itemExp->getLatitude(), $itemUpd->getLatitude() );
165
		$this->assertEquals( $itemExp->getFlag(), $itemUpd->getFlag() );
166
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition() );
167
		$this->assertEquals( $itemExp->getEditor(), $itemUpd->getEditor() );
168
169
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
170
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
171
172
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved );
173
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd );
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 testSearchItem()
187
	{
188
		$search = $this->object->createSearch();
189
190
		$expr = [];
191
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
192
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
193
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
194
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
195
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
196
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
197
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
198
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
199
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
200
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
201
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
202
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
203
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
204
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
205
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
206
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
207
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
208
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
209
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
210
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
211
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '10.0' );
212
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '50.0' );
213
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
214
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
215
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
216
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
217
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
218
219
		$search->setConditions( $search->combine( '&&', $expr ) );
220
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
221
	}
222
223
224
	public function testSearchItemTotal()
225
	{
226
		$total = 0;
227
		$search = $this->object->createSearch();
228
229
		$conditions = array(
230
			$search->compare( '~=', 'customer.address.company', 'ABC GmbH' ),
231
			$search->compare( '==', 'customer.address.editor', $this->editor )
232
		);
233
234
		$search->setConditions( $search->combine( '&&', $conditions ) );
235
		$search->setSlice( 0, 1 );
236
237
		$results = $this->object->searchItems( $search, [], $total );
238
239
		$this->assertEquals( 1, count( $results ) );
240
		$this->assertEquals( 2, $total );
241
242
		foreach( $results as $id => $item ) {
243
			$this->assertEquals( $id, $item->getId() );
244
		}
245
	}
246
247
248
	public function testGetSubManager()
249
	{
250
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
251
		$this->object->getSubManager( 'unknown' );
252
	}
253
254
255
	public function testGetSubManagerInvalidName()
256
	{
257
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
258
		$this->object->getSubManager( 'address', 'unknown' );
259
	}
260
}
261