Completed
Push — master ( 94b58b...843436 )
by Aimeos
02:17
created

LaravelTest::setUp()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 46
rs 9.1781
c 1
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2017
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager\Address;
10
11
12
class LaravelTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $fixture = null;
15
	private $object = null;
16
	private $editor = '';
17
18
19
	protected function setUp()
20
	{
21
		$context = \TestHelper::getContext();
22
		$this->editor = $context->getEditor();
23
		$customer = new \Aimeos\MShop\Customer\Manager\Laravel( $context );
24
25
		$search = $customer->createSearch();
26
		$conditions = array(
27
			$search->compare( '==', 'customer.code', 'UTC001' ),
28
			$search->compare( '==', 'customer.editor', $this->editor )
29
		);
30
		$search->setConditions( $search->combine( '&&', $conditions ) );
31
		$result = $customer->searchItems( $search );
32
33
		if( ( $customerItem = reset( $result ) ) === false ) {
34
			throw new \RuntimeException( sprintf( 'No customer item found for code "%1$s"', 'UTC001' ) );
35
		}
36
37
		$this->fixture = array(
38
			'customer.address.parentid' => $customerItem->getId(),
39
			'customer.address.company' => 'ABC GmbH',
40
			'customer.address.vatid' => 'DE999999999',
41
			'customer.address.salutation' => \Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR,
42
			'customer.address.title' => 'Herr',
43
			'customer.address.firstname' => 'firstunit',
44
			'customer.address.lastname' => 'lastunit',
45
			'customer.address.address1' => 'unit str.',
46
			'customer.address.address2' => ' 166',
47
			'customer.address.address3' => '4.OG',
48
			'customer.address.postal' => '22769',
49
			'customer.address.city' => 'Hamburg',
50
			'customer.address.state' => 'Hamburg',
51
			'customer.address.countryid' => 'de',
52
			'customer.address.languageid' => 'de',
53
			'customer.address.telephone' => '05554433221',
54
			'customer.address.email' => '[email protected]',
55
			'customer.address.telefax' => '05554433222',
56
			'customer.address.website' => 'unittest.aimeos.org',
57
			'customer.address.longitude' => '10.0',
58
			'customer.address.latitude' => '50.0',
59
			'customer.address.position' => 1,
60
			'customer.address.siteid' => $context->getLocale()->getSiteId(),
61
		);
62
63
		$this->object = $customer->getSubManager( 'address', 'Laravel' );
64
	}
65
66
67
	protected function tearDown()
68
	{
69
		unset( $this->object, $this->fixture );
70
	}
71
72
73
	public function testCleanup()
74
	{
75
		$this->object->cleanup( array( -1 ) );
76
	}
77
78
	public function testGetSearchAttributes()
79
	{
80
		foreach( $this->object->getSearchAttributes() as $attribute ) {
81
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
82
		}
83
	}
84
85
	public function testGetSubManager()
86
	{
87
		$this->setExpectedException( '\\Aimeos\\MShop\\Exception' );
88
		$this->object->getSubManager( 'unknown' );
89
	}
90
91
	public function testCreateItem()
92
	{
93
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Address\\Iface', $this->object->createItem() );
94
	}
95
96 View Code Duplication
	public function testGetItem()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
	{
98
		$search = $this->object->createSearch();
99
		$search->setConditions( $search->compare( '~=', 'customer.address.company', 'ABC GmbH' ) );
100
101
		$items = $this->object->searchItems( $search );
102
103
		if( ( $item = reset( $items ) ) === false ) {
104
			throw new \RuntimeException( 'No address item with company "ABC" found' );
105
		}
106
107
		$this->assertEquals( $item, $this->object->getItem( $item->getId() ) );
108
	}
109
110
	public function testSaveUpdateDeleteItem()
111
	{
112
		$item = new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.', $this->fixture );
113
		$item->setId( null );
114
		$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...
115
		$itemSaved = $this->object->getItem( $item->getId() );
116
117
		$itemExp = clone $itemSaved;
118
		$itemExp->setPosition( 1 );
119
		$itemExp->setCity( 'Berlin' );
120
		$itemExp->setState( 'Berlin' );
121
		$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...
122
		$itemUpd = $this->object->getItem( $itemExp->getId() );
123
124
		$this->object->deleteItem( $itemSaved->getId() );
125
126
127
		$this->assertTrue( $item->getId() !== null );
128
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
129
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId());
130
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition());
131
		$this->assertEquals( $item->getCompany(), $itemSaved->getCompany());
132
		$this->assertEquals( $item->getVatID(), $itemSaved->getVatID());
133
		$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation());
134
		$this->assertEquals( $item->getTitle(), $itemSaved->getTitle());
135
		$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname());
136
		$this->assertEquals( $item->getLastname(), $itemSaved->getLastname());
137
		$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1());
138
		$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2());
139
		$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3());
140
		$this->assertEquals( $item->getPostal(), $itemSaved->getPostal());
141
		$this->assertEquals( $item->getCity(), $itemSaved->getCity());
142
		$this->assertEquals( $item->getState(), $itemSaved->getState());
143
		$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId());
144
		$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId());
145
		$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone());
146
		$this->assertEquals( $item->getEmail(), $itemSaved->getEmail());
147
		$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax());
148
		$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite());
149
		$this->assertEquals( $item->getLongitude(), $itemSaved->getLongitude());
150
		$this->assertEquals( $item->getLatitude(), $itemSaved->getLatitude());
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->getLongitude(), $itemUpd->getLongitude());
179
		$this->assertEquals( $itemExp->getLatitude(), $itemUpd->getLatitude());
180
		$this->assertEquals( $itemExp->getFlag(), $itemUpd->getFlag());
181
182
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
183
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
184
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
185
186
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultSaved );
187
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Iface', $resultUpd );
188
189
		$this->setExpectedException('\\Aimeos\\MShop\\Exception');
190
		$this->object->getItem( $itemSaved->getId() );
191
	}
192
193
	public function testCreateSearch()
194
	{
195
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
196
	}
197
198
199
	public function testSearchItem()
200
	{
201
		$search = $this->object->createSearch();
202
203
		$expr = [];
204
		$expr[] = $search->compare( '!=', 'customer.address.id', null );
205
		$expr[] = $search->compare( '!=', 'customer.address.parentid', null );
206
		$expr[] = $search->compare( '==', 'customer.address.company', 'ABC GmbH' );
207
		$expr[] = $search->compare( '==', 'customer.address.vatid', 'DE999999999' );
208
		$expr[] = $search->compare( '==', 'customer.address.salutation', 'mr' );
209
		$expr[] = $search->compare( '==', 'customer.address.title', 'Dr.' );
210
		$expr[] = $search->compare( '==', 'customer.address.firstname', 'Good' );
211
		$expr[] = $search->compare( '==', 'customer.address.lastname', 'Unittest' );
212
		$expr[] = $search->compare( '==', 'customer.address.address1', 'Pickhuben' );
213
		$expr[] = $search->compare( '==', 'customer.address.address2', '2-4' );
214
		$expr[] = $search->compare( '==', 'customer.address.address3', '' );
215
		$expr[] = $search->compare( '==', 'customer.address.postal', '11099' );
216
		$expr[] = $search->compare( '==', 'customer.address.city', 'Berlin' );
217
		$expr[] = $search->compare( '==', 'customer.address.state', 'Berlin' );
218
		$expr[] = $search->compare( '==', 'customer.address.languageid', 'de' );
219
		$expr[] = $search->compare( '==', 'customer.address.countryid', 'DE' );
220
		$expr[] = $search->compare( '==', 'customer.address.telephone', '055544332221' );
221
		$expr[] = $search->compare( '==', 'customer.address.email', '[email protected]' );
222
		$expr[] = $search->compare( '==', 'customer.address.telefax', '055544333212' );
223
		$expr[] = $search->compare( '==', 'customer.address.website', 'unittest.aimeos.org' );
224
		$expr[] = $search->compare( '>=', 'customer.address.longitude', '10.0' );
225
		$expr[] = $search->compare( '>=', 'customer.address.latitude', '50.0' );
226
		$expr[] = $search->compare( '==', 'customer.address.flag', 0 );
227
		$expr[] = $search->compare( '==', 'customer.address.position', 1 );
228
		$expr[] = $search->compare( '!=', 'customer.address.mtime', '1970-01-01 00:00:00' );
229
		$expr[] = $search->compare( '!=', 'customer.address.ctime', '1970-01-01 00:00:00' );
230
		$expr[] = $search->compare( '==', 'customer.address.editor', $this->editor );
231
232
		$search->setConditions( $search->combine( '&&', $expr ) );
233
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
234
	}
235
236
237
	public function testSearchItemTotal()
238
	{
239
		$total = 0;
240
		$search = $this->object->createSearch();
241
242
		$conditions = array(
243
			$search->compare( '~=', 'customer.address.company', 'ABC GmbH' ),
244
			$search->compare( '==', 'customer.address.editor', $this->editor )
245
		);
246
247
		$search->setConditions( $search->combine( '&&', $conditions ) );
248
		$search->setSlice( 0, 1 );
249
250
		$results = $this->object->searchItems( $search, [], $total );
251
252
		$this->assertEquals( 1, count( $results ) );
253
		$this->assertEquals( 2, $total );
254
255
		foreach( $results as $id => $item ) {
256
			$this->assertEquals( $id, $item->getId() );
257
		}
258
	}
259
}
260