Completed
Push — master ( 027b78...4ee65e )
by Aimeos
07:42
created

StandardTest::testGetDateEnd()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @copyright Aimeos (aimeos.org), 2015-2016
7
 */
8
9
namespace Aimeos\MShop\Service\Item;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $values = [];
16
17
18
	protected function setUp()
19
	{
20
		$this->values = array(
21
			'service.id' => 541,
22
			'service.siteid' => 99,
23
			'service.position' => '0',
24
			'service.typeid' => 1,
25
			'service.type' => 'delivery',
26
			'service.typename' => 'Delivery',
27
			'service.code' => 'wa34Hg',
28
			'service.label' => 'deliveryObject',
29
			'service.provider' => 'Standard',
30
			'service.datestart' => '2000-01-01 00:00:00',
31
			'service.dateend' => '2100-01-01 00:00:00',
32
			'service.config' => array( 'url' => 'https://localhost/' ),
33
			'service.status' => 0,
34
			'service.mtime' => '2011-01-01 00:00:02',
35
			'service.ctime' => '2011-01-01 00:00:01',
36
			'service.editor' => 'unitTestUser'
37
		);
38
39
		$this->object = new \Aimeos\MShop\Service\Item\Standard( $this->values );
40
	}
41
42
43
	protected function tearDown()
44
	{
45
		$this->object = null;
46
	}
47
48
49
	public function testGetId()
50
	{
51
		$this->assertEquals( 541, $this->object->getId() );
52
	}
53
54
55
	public function testSetId()
56
	{
57
		$return = $this->object->setId( null );
58
59
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
60
		$this->assertNull( $this->object->getId() );
61
		$this->assertTrue( $this->object->isModified() );
62
	}
63
64
65
	public function testGetSiteId()
66
	{
67
		$this->assertEquals( 99, $this->object->getSiteId() );
68
	}
69
70
71
	public function testGetPosition()
72
	{
73
		$this->assertEquals( 0, $this->object->getPosition() );
74
	}
75
76
77
	public function testSetPosition()
78
	{
79
		$return = $this->object->setPosition( 4 );
80
81
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
82
		$this->assertEquals( 4, $this->object->getPosition() );
83
		$this->assertTrue( $this->object->isModified() );
84
	}
85
86
87
	public function testGetCode()
88
	{
89
		$this->assertEquals( 'wa34Hg', $this->object->getCode() );
90
	}
91
92
93
	public function testSetCode()
94
	{
95
		$return = $this->object->setCode( 'newCode' );
96
97
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
98
		$this->assertEquals( 'newCode', $this->object->getCode() );
99
		$this->assertTrue( $this->object->isModified() );
100
	}
101
102
103
	public function testGetProvider()
104
	{
105
		$this->assertEquals( 'Standard', $this->object->getProvider() );
106
	}
107
108
109
	public function testSetProvider()
110
	{
111
		$return = $this->object->setProvider( 'TestProvider' );
112
113
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
114
		$this->assertEquals( 'TestProvider', $this->object->getProvider() );
115
		$this->assertTrue( $this->object->isModified() );
116
	}
117
118
119
	public function testGetLabel()
120
	{
121
		$this->assertEquals( 'deliveryObject', $this->object->getLabel() );
122
	}
123
124
125
	public function testSetLabel()
126
	{
127
		$return = $this->object->setLabel( 'newName' );
128
129
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
130
		$this->assertEquals( 'newName', $this->object->getLabel() );
131
		$this->assertTrue( $this->object->isModified() );
132
	}
133
134
135
	public function testGetDateStart()
136
	{
137
		$this->assertEquals( '2000-01-01 00:00:00', $this->object->getDateStart() );
138
	}
139
140
141
	public function testSetDateStart()
142
	{
143
		$return = $this->object->setDateStart( '2010-04-22 06:22:22' );
144
145
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
146
		$this->assertEquals( '2010-04-22 06:22:22', $this->object->getDateStart() );
147
		$this->assertTrue( $this->object->isModified() );
148
	}
149
150
151
	public function testGetDateEnd()
152
	{
153
		$this->assertEquals( '2100-01-01 00:00:00', $this->object->getDateEnd() );
154
	}
155
156
157
	public function testSetDateEnd()
158
	{
159
		$return = $this->object->setDateEnd( '2010-05-22 06:22:22' );
160
161
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
162
		$this->assertEquals( '2010-05-22 06:22:22', $this->object->getDateEnd() );
163
		$this->assertTrue( $this->object->isModified() );
164
	}
165
166
167
	public function testGetStatus()
168
	{
169
		$this->assertEquals( 0, $this->object->getStatus() );
170
	}
171
172
173
	public function testSetStatus()
174
	{
175
		$return = $this->object->setStatus( 10 );
176
177
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
178
		$this->assertEquals( 10, $this->object->getStatus() );
179
		$this->assertTrue( $this->object->isModified() );
180
	}
181
182
	public function testGetConfig()
183
	{
184
		$this->assertEquals( array( 'url' => 'https://localhost/' ), $this->object->getConfig() );
185
	}
186
187
188
	public function testSetConfig()
189
	{
190
		$return = $this->object->setConfig( array( 'account' => 'testAccount' ) );
191
192
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
193
		$this->assertEquals( array( 'account' => 'testAccount' ), $this->object->getConfig() );
194
		$this->assertTrue( $this->object->isModified() );
195
	}
196
197
	public function testGetTypeId()
198
	{
199
		$this->assertEquals( 1, $this->object->getTypeId() );
200
	}
201
202
	public function testSetTypeId()
203
	{
204
		$return = $this->object->setTypeId( 2 );
205
206
		$this->assertInstanceOf( '\Aimeos\MShop\Service\Item\Iface', $return );
207
		$this->assertEquals( 2, $this->object->getTypeId() );
208
		$this->assertTrue( $this->object->isModified() );
209
	}
210
211
	public function testGetType()
212
	{
213
		$this->assertEquals( 'delivery', $this->object->getType() );
214
	}
215
216
	public function testGetTypeName()
217
	{
218
		$this->assertEquals( 'Delivery', $this->object->getTypeName() );
219
	}
220
221
	public function testGetTimeModified()
222
	{
223
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
224
	}
225
226
	public function testGetTimeCreated()
227
	{
228
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
229
	}
230
231
	public function testGetEditor()
232
	{
233
		$this->assertEquals( 'unitTestUser', $this->object->getEditor() );
234
	}
235
236
237
	public function testGetResourceType()
238
	{
239
		$this->assertEquals( 'service', $this->object->getResourceType() );
240
	}
241
242
243
	public function testFromArray()
244
	{
245
		$item = new \Aimeos\MShop\Service\Item\Standard();
246
247
		$list = array(
248
			'service.id' => 1,
249
			'service.typeid' => 2,
250
			'service.type' => 'test',
251
			'service.typename' => 'Test',
252
			'service.code' => 'test',
253
			'service.label' => 'test item',
254
			'service.provider' => 'PayPal',
255
			'service.datestart' => '2000-01-01 00:00:02',
256
			'service.dateend' => '2100-01-01 00:00:01',
257
			'service.config' => array( 'test' ),
258
			'service.position' => 3,
259
			'service.status' => 0,
260
		);
261
262
		$unknown = $item->fromArray( $list );
263
264
		$this->assertEquals( [], $unknown );
265
266
		$this->assertEquals( $list['service.id'], $item->getId() );
267
		$this->assertEquals( $list['service.code'], $item->getCode() );
268
		$this->assertEquals( $list['service.label'], $item->getLabel() );
269
		$this->assertEquals( $list['service.typeid'], $item->getTypeId() );
270
		$this->assertEquals( $list['service.provider'], $item->getProvider() );
271
		$this->assertEquals( $list['service.position'], $item->getPosition() );
272
		$this->assertEquals( $list['service.datestart'], $item->getDateStart() );
273
		$this->assertEquals( $list['service.dateend'], $item->getDateEnd() );
274
		$this->assertEquals( $list['service.config'], $item->getConfig() );
275
		$this->assertEquals( $list['service.status'], $item->getStatus() );
276
		$this->assertNull( $item->getSiteId() );
277
		$this->assertNull( $item->getTypeName() );
278
		$this->assertNull( $item->getType() );
279
	}
280
281
282
	public function testToArray()
283
	{
284
		$arrayObject = $this->object->toArray( true );
285
286
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
287
288
		$this->assertEquals( $this->object->getId(), $arrayObject['service.id'] );
289
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['service.siteid'] );
290
		$this->assertEquals( $this->object->getTypename(), $arrayObject['service.typename'] );
291
		$this->assertEquals( $this->object->getTypeId(), $arrayObject['service.typeid'] );
292
		$this->assertEquals( $this->object->getType(), $arrayObject['service.type'] );
293
		$this->assertEquals( $this->object->getCode(), $arrayObject['service.code'] );
294
		$this->assertEquals( $this->object->getLabel(), $arrayObject['service.label'] );
295
		$this->assertEquals( $this->object->getProvider(), $arrayObject['service.provider'] );
296
		$this->assertEquals( $this->object->getPosition(), $arrayObject['service.position'] );
297
		$this->assertEquals( $this->object->getDateStart(), $arrayObject['service.datestart'] );
298
		$this->assertEquals( $this->object->getDateEnd(), $arrayObject['service.dateend'] );
299
		$this->assertEquals( $this->object->getConfig(), $arrayObject['service.config'] );
300
		$this->assertEquals( $this->object->getStatus(), $arrayObject['service.status'] );
301
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['service.ctime'] );
302
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['service.mtime'] );
303
		$this->assertEquals( $this->object->getEditor(), $arrayObject['service.editor'] );
304
	}
305
}
306