Completed
Push — master ( ac66b3...ab3b6f )
by Aimeos
07:35 queued 01:23
created

EzpublishTest::testSaveUpdateDeleteItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 75
Code Lines 65

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 75
rs 9
cc 1
eloc 65
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2016
6
 */
7
8
9
namespace Aimeos\MShop\Customer\Manager\Address;
10
11
12
class EzpublishTest 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\Ezpublish( $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 \Exception( 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.position' => 1,
58
			'customer.address.siteid' => $context->getLocale()->getSiteId(),
59
		);
60
61
		$this->object = $customer->getSubManager( 'address', 'Ezpublish' );
62
	}
63
64
65
	protected function tearDown()
66
	{
67
		unset( $this->object, $this->fixture );
68
	}
69
70
71
	public function testCleanup()
72
	{
73
		$this->object->cleanup( array( -1 ) );
74
	}
75
76
	public function testGetSearchAttributes()
77
	{
78
		foreach( $this->object->getSearchAttributes() as $attribute ) {
79
			$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Attribute\\Iface', $attribute );
80
		}
81
	}
82
83
	public function testCreateItem()
84
	{
85
		$this->assertInstanceOf( '\\Aimeos\\MShop\\Common\\Item\\Address\\Iface', $this->object->createItem() );
86
	}
87
88 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...
89
	{
90
		$search = $this->object->createSearch();
91
		$search->setConditions( $search->compare( '~=', 'customer.address.company', 'ABC GmbH' ) );
92
93
		$items = $this->object->searchItems( $search );
94
95
		if( ( $item = reset( $items ) ) === false ) {
96
			throw new \Exception( 'No address item with company "ABC" found' );
97
		}
98
99
		$this->assertEquals( $item, $this->object->getItem( $item->getId() ) );
100
	}
101
102
	public function testSaveUpdateDeleteItem()
103
	{
104
		$item = new \Aimeos\MShop\Common\Item\Address\Standard( 'customer.address.', $this->fixture );
105
		$item->setId( null );
106
		$this->object->saveItem( $item );
107
		$itemSaved = $this->object->getItem( $item->getId() );
108
109
		$itemExp = clone $itemSaved;
110
		$itemExp->setPosition( 1 );
111
		$itemExp->setCity( 'Berlin' );
112
		$itemExp->setState( 'Berlin' );
113
		$this->object->saveItem( $itemExp );
114
		$itemUpd = $this->object->getItem( $itemExp->getId() );
115
116
		$this->object->deleteItem( $itemSaved->getId() );
117
118
119
		$this->assertTrue( $item->getId() !== null );
120
		$this->assertEquals( $item->getId(), $itemSaved->getId() );
121
		$this->assertEquals( $item->getParentId(), $itemSaved->getParentId());
122
		$this->assertEquals( $item->getPosition(), $itemSaved->getPosition());
123
		$this->assertEquals( $item->getCompany(), $itemSaved->getCompany());
124
		$this->assertEquals( $item->getVatID(), $itemSaved->getVatID());
125
		$this->assertEquals( $item->getSalutation(), $itemSaved->getSalutation());
126
		$this->assertEquals( $item->getTitle(), $itemSaved->getTitle());
127
		$this->assertEquals( $item->getFirstname(), $itemSaved->getFirstname());
128
		$this->assertEquals( $item->getLastname(), $itemSaved->getLastname());
129
		$this->assertEquals( $item->getAddress1(), $itemSaved->getAddress1());
130
		$this->assertEquals( $item->getAddress2(), $itemSaved->getAddress2());
131
		$this->assertEquals( $item->getAddress3(), $itemSaved->getAddress3());
132
		$this->assertEquals( $item->getPostal(), $itemSaved->getPostal());
133
		$this->assertEquals( $item->getCity(), $itemSaved->getCity());
134
		$this->assertEquals( $item->getState(), $itemSaved->getState());
135
		$this->assertEquals( $item->getCountryId(), $itemSaved->getCountryId());
136
		$this->assertEquals( $item->getLanguageId(), $itemSaved->getLanguageId());
137
		$this->assertEquals( $item->getTelephone(), $itemSaved->getTelephone());
138
		$this->assertEquals( $item->getEmail(), $itemSaved->getEmail());
139
		$this->assertEquals( $item->getTelefax(), $itemSaved->getTelefax());
140
		$this->assertEquals( $item->getWebsite(), $itemSaved->getWebsite());
141
		$this->assertEquals( $item->getFlag(), $itemSaved->getFlag());
142
143
		$this->assertEquals( $this->editor, $itemSaved->getEditor() );
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->getParentId(), $itemUpd->getParentId());
149
		$this->assertEquals( $itemExp->getPosition(), $itemUpd->getPosition());
150
		$this->assertEquals( $itemExp->getCompany(), $itemUpd->getCompany());
151
		$this->assertEquals( $itemExp->getVatID(), $itemUpd->getVatID());
152
		$this->assertEquals( $itemExp->getSalutation(), $itemUpd->getSalutation());
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->getCountryId(), $itemUpd->getCountryId());
163
		$this->assertEquals( $itemExp->getLanguageId(), $itemUpd->getLanguageId());
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
170
		$this->assertEquals( $this->editor, $itemUpd->getEditor() );
171
		$this->assertEquals( $itemExp->getTimeCreated(), $itemUpd->getTimeCreated() );
172
		$this->assertRegExp( '/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $itemUpd->getTimeModified() );
173
174
		$this->setExpectedException('\\Aimeos\\MShop\\Exception');
175
		$this->object->getItem( $itemSaved->getId() );
176
	}
177
178
	public function testCreateSearch()
179
	{
180
		$this->assertInstanceOf( '\\Aimeos\\MW\\Criteria\\Iface', $this->object->createSearch() );
181
	}
182
183
184
	public function testSearchItem()
185
	{
186
		$search = $this->object->createSearch();
187
188
		$conditions = array(
189
			$search->compare( '==', 'customer.address.company', 'ABC' ),
190
			$search->compare( '==', 'customer.address.editor', $this->editor )
191
		);
192
		$search->setConditions( $search->combine( '&&', $conditions ) );
193
		$this->assertEquals( 1, count( $this->object->searchItems( $search ) ) );
194
	}
195
196
197
	public function testSearchItemTotal()
198
	{
199
		$total = 0;
200
		$search = $this->object->createSearch();
201
202
		$conditions = array(
203
			$search->compare( '~=', 'customer.address.company', 'ABC GmbH' ),
204
			$search->compare( '==', 'customer.address.editor', $this->editor )
205
		);
206
207
		$search->setConditions( $search->combine( '&&', $conditions ) );
208
		$search->setSlice( 0, 1 );
209
210
		$results = $this->object->searchItems( $search, array(), $total );
211
212
		$this->assertEquals( 1, count( $results ) );
213
		$this->assertEquals( 2, $total );
214
215
		foreach( $results as $id => $item ) {
216
			$this->assertEquals( $id, $item->getId() );
217
		}
218
	}
219
}
220