Completed
Push — master ( d29f07...779818 )
by Aimeos
21:15
created

StandardTest::testGetPosition()   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-2017
7
 */
8
9
10
namespace Aimeos\MShop\Common\Item\Type;
11
12
13
class StandardTest extends \PHPUnit\Framework\TestCase
14
{
15
	private $object;
16
	private $values;
17
18
19
	protected function setUp()
20
	{
21
		$this->values = array(
22
			'common.type.id'   => 1,
23
			'common.type.siteid' => 2,
24
			'common.type.code' => 'code',
25
			'common.type.domain' => 'domain',
26
			'common.type.label' => 'label',
27
			'common.type.name' => 'name',
28
			'common.type.position' => 5,
29
			'common.type.status' => 1,
30
			'common.type.mtime' => '2011-01-01 00:00:02',
31
			'common.type.ctime' => '2011-01-01 00:00:01',
32
			'common.type.editor' => 'unitTestUser',
33
		);
34
35
		$this->object = new \Aimeos\MShop\Common\Item\Type\Standard( 'common.type.', $this->values );
36
	}
37
38
39
	protected function tearDown()
40
	{
41
		$this->object = null;
42
	}
43
44
	public function testGetId()
45
	{
46
		$this->assertEquals( 1, $this->object->getId() );
47
	}
48
49
	public function testSetId()
50
	{
51
		$return = $this->object->setId( null );
52
53
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
54
		$this->assertTrue( $this->object->isModified() );
55
		$this->assertNull( $this->object->getId() );
56
	}
57
58
	public function testGetCode()
59
	{
60
		$this->assertEquals( 'code', $this->object->getCode() );
61
	}
62
63
	public function testSetCode()
64
	{
65
		$return = $this->object->setCode( 'code2' );
66
67
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
68
		$this->assertEquals( 'code2', $this->object->getCode() );
69
		$this->assertTrue( $this->object->isModified() );
70
	}
71
72
	public function testGetDomain()
73
	{
74
		$this->assertEquals( 'domain', $this->object->getDomain() );
75
	}
76
77
	public function testSetDomain()
78
	{
79
		$return = $this->object->setDomain( 'domain2' );
80
81
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
82
		$this->assertEquals( 'domain2', $this->object->getDomain() );
83
		$this->assertTrue( $this->object->isModified() );
84
	}
85
86
	public function testGetName()
87
	{
88
		$this->assertEquals( 'name', $this->object->getName() );
89
	}
90
91
	public function testGetLabel()
92
	{
93
		$this->assertEquals( 'label', $this->object->getLabel() );
94
	}
95
96
	public function testSetLabel()
97
	{
98
		$return = $this->object->setLabel( 'label2' );
99
100
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
101
		$this->assertEquals( 'label2', $this->object->getLabel() );
102
		$this->assertTrue( $this->object->isModified() );
103
	}
104
105
	public function testGetPosition()
106
	{
107
		$this->assertEquals( 5, $this->object->getPosition() );
108
	}
109
110
	public function testSetPosition()
111
	{
112
		$return = $this->object->setPosition( 4 );
113
114
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
115
		$this->assertEquals( 4, $this->object->getPosition() );
116
		$this->assertTrue( $this->object->isModified() );
117
	}
118
119
	public function testGetStatus()
120
	{
121
		$this->assertEquals( 1, $this->object->getStatus() );
122
	}
123
124
	public function testSetStatus()
125
	{
126
		$return = $this->object->setStatus( 0 );
127
128
		$this->assertInstanceOf( '\Aimeos\MShop\Common\Item\Type\Iface', $return );
129
		$this->assertEquals( 0, $this->object->getStatus() );
130
		$this->assertTrue( $this->object->isModified() );
131
	}
132
133
	public function testGetSiteId()
134
	{
135
		$this->assertEquals( 2, $this->object->getSiteId() );
136
	}
137
138
	public function testGetTimeModified()
139
	{
140
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
141
	}
142
143
	public function testGetTimeCreated()
144
	{
145
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
146
	}
147
148
	public function testGetEditor()
149
	{
150
		$this->assertEquals( 'unitTestUser', $this->object->getEditor() );
151
	}
152
153
154
	public function testGetResourceType()
155
	{
156
		$this->assertEquals( 'common/type', $this->object->getResourceType() );
157
	}
158
159
160
	public function testFromArray()
161
	{
162
		$item = new \Aimeos\MShop\Common\Item\Type\Standard( 'common.type.' );
163
164
		$list = array(
165
			'common.type.id' => 8,
166
			'common.type.code' => 'test',
167
			'common.type.domain' => 'testDomain',
168
			'common.type.label' => 'test item',
169
			'common.type.name' => 'Testeintrag',
170
			'common.type.position' => 2,
171
			'common.type.status' => 1,
172
		);
173
174
		$unknown = $item->fromArray( $list );
175
176
		$this->assertEquals( [], $unknown );
177
178
		$this->assertEquals( $list['common.type.id'], $item->getId() );
179
		$this->assertEquals( $list['common.type.code'], $item->getCode() );
180
		$this->assertEquals( $list['common.type.domain'], $item->getDomain() );
181
		$this->assertEquals( $list['common.type.label'], $item->getName() ); // fallback to label
182
		$this->assertEquals( $list['common.type.label'], $item->getLabel() );
183
		$this->assertEquals( $list['common.type.position'], $item->getPosition() );
184
		$this->assertEquals( $list['common.type.status'], $item->getStatus() );
185
		$this->assertNull( $item->getSiteId() );
186
	}
187
188
	public function testToArray()
189
	{
190
		$arrayObject = $this->object->toArray( true );
191
192
		$this->assertEquals( count( $this->values ), count( $arrayObject ) );
193
194
		$this->assertEquals( $this->object->getId(), $arrayObject['common.type.id'] );
195
		$this->assertEquals( $this->object->getCode(), $arrayObject['common.type.code'] );
196
		$this->assertEquals( $this->object->getDomain(), $arrayObject['common.type.domain'] );
197
		$this->assertEquals( $this->object->getName(), $arrayObject['common.type.name'] );
198
		$this->assertEquals( $this->object->getLabel(), $arrayObject['common.type.label'] );
199
		$this->assertEquals( $this->object->getPosition(), $arrayObject['common.type.position'] );
200
		$this->assertEquals( $this->object->getStatus(), $arrayObject['common.type.status'] );
201
		$this->assertEquals( $this->object->getSiteId(), $arrayObject['common.type.siteid'] );
202
		$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['common.type.ctime'] );
203
		$this->assertEquals( $this->object->getTimeModified(), $arrayObject['common.type.mtime'] );
204
		$this->assertEquals( $this->object->getEditor(), $arrayObject['common.type.editor'] );
205
	}
206
207
208
	public function testIsAvailable()
209
	{
210
		$this->assertTrue( $this->object->isAvailable() );
211
	}
212
213
214
	public function testIsModified()
215
	{
216
		$this->assertFalse( $this->object->isModified() );
217
	}
218
}
219