1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2014-2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Common\Item\Property; |
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
|
|
|
'common.property.id' => 987, |
22
|
|
|
'common.property.parentid' => 11, |
23
|
|
|
'common.property.siteid' => 99, |
24
|
|
|
'common.property.languageid' => 'en', |
25
|
|
|
'common.property.type' => 'width', |
26
|
|
|
'common.property.value' => '30.0', |
27
|
|
|
'common.property.mtime' => '2011-01-01 00:00:02', |
28
|
|
|
'common.property.ctime' => '2011-01-01 00:00:01', |
29
|
|
|
'common.property.editor' => 'unitTestUser', |
30
|
|
|
'languageid' => 'de', |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$this->object = new \Aimeos\MShop\Common\Item\Property\Standard( 'common.property.', $this->values ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
protected function tearDown() |
38
|
|
|
{ |
39
|
|
|
$this->object = null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testGetId() |
44
|
|
|
{ |
45
|
|
|
$this->assertEquals( 987, $this->object->getId() ); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function testSetId() |
50
|
|
|
{ |
51
|
|
|
$return = $this->object->setId( null ); |
52
|
|
|
|
53
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $return ); |
54
|
|
|
$this->assertNull( $this->object->getId() ); |
55
|
|
|
$this->assertTrue( $this->object->isModified() ); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
|
59
|
|
|
public function testGetSiteId() |
60
|
|
|
{ |
61
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
|
65
|
|
|
public function testGetLanguageId() |
66
|
|
|
{ |
67
|
|
|
$this->assertEquals( 'en', $this->object->getLanguageId() ); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
|
71
|
|
|
public function testSetLanguageId() |
72
|
|
|
{ |
73
|
|
|
$return = $this->object->setLanguageId('fr'); |
74
|
|
|
|
75
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $return ); |
76
|
|
|
$this->assertEquals( 'fr', $this->object->getLanguageId() ); |
77
|
|
|
$this->assertTrue( $this->object->isModified() ); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
|
81
|
|
|
public function testGetParentId() |
82
|
|
|
{ |
83
|
|
|
$this->assertEquals( 11, $this->object->getParentId() ); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
|
87
|
|
|
public function testSetParentId() |
88
|
|
|
{ |
89
|
|
|
$return = $this->object->setParentId( 22 ); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $return ); |
92
|
|
|
$this->assertEquals( 22, $this->object->getParentId() ); |
93
|
|
|
$this->assertTrue( $this->object->isModified() ); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
|
97
|
|
|
public function testGetKey() |
98
|
|
|
{ |
99
|
|
|
$this->assertEquals( 'width|en|30.0', $this->object->getKey() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
|
103
|
|
|
public function testGetType() |
104
|
|
|
{ |
105
|
|
|
$this->assertEquals( 'width', $this->object->getType() ); |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
|
109
|
|
|
public function testSetType() |
110
|
|
|
{ |
111
|
|
|
$return = $this->object->setType( 'height' ); |
112
|
|
|
|
113
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $return ); |
114
|
|
|
$this->assertEquals( 'height', $this->object->getType() ); |
115
|
|
|
$this->assertTrue( $this->object->isModified() ); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
|
119
|
|
|
public function testGetValue() |
120
|
|
|
{ |
121
|
|
|
$this->assertEquals( '30.0', $this->object->getValue() ); |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
|
125
|
|
|
public function testSetValue() |
126
|
|
|
{ |
127
|
|
|
$return = $this->object->setValue( '15.00' ); |
128
|
|
|
|
129
|
|
|
$this->assertInstanceOf( \Aimeos\MShop\Common\Item\Property\Iface::class, $return ); |
130
|
|
|
$this->assertEquals( '15.00', $this->object->getValue() ); |
131
|
|
|
$this->assertTrue( $this->object->isModified() ); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
|
135
|
|
|
public function testGetTimeModified() |
136
|
|
|
{ |
137
|
|
|
$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() ); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
|
141
|
|
|
public function testGetTimeCreated() |
142
|
|
|
{ |
143
|
|
|
$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() ); |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
|
147
|
|
|
public function testGetEditor() |
148
|
|
|
{ |
149
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
|
153
|
|
|
public function testGetResourceType() |
154
|
|
|
{ |
155
|
|
|
$this->assertEquals( 'common/property', $this->object->getResourceType() ); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
159
|
|
|
public function testFromArray() |
160
|
|
|
{ |
161
|
|
|
$item = new \Aimeos\MShop\Common\Item\Property\Standard( 'common.property.' ); |
162
|
|
|
|
163
|
|
|
$list = $entries = array( |
164
|
|
|
'common.property.parentid' => 1, |
165
|
|
|
'common.property.type' => 'default', |
166
|
|
|
'common.property.type' => 'test', |
167
|
|
|
'common.property.languageid' => 'de', |
168
|
|
|
'common.property.value' => 'value', |
169
|
|
|
); |
170
|
|
|
|
171
|
|
|
$item = $item->fromArray( $entries, true ); |
172
|
|
|
|
173
|
|
|
$this->assertEquals([], $entries); |
174
|
|
|
$this->assertEquals($list['common.property.parentid'], $item->getParentId()); |
175
|
|
|
$this->assertEquals($list['common.property.languageid'], $item->getLanguageId()); |
176
|
|
|
$this->assertEquals($list['common.property.value'], $item->getValue()); |
177
|
|
|
$this->assertEquals($list['common.property.type'], $item->getType()); |
178
|
|
|
$this->assertNull( $item->getSiteId() ); |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
|
182
|
|
|
public function testToArray() |
183
|
|
|
{ |
184
|
|
|
$arrayObject = $this->object->toArray( true ); |
185
|
|
|
$this->assertEquals( count( $this->values ), count( $arrayObject ) ); |
186
|
|
|
|
187
|
|
|
$this->assertEquals( $this->object->getId(), $arrayObject['common.property.id'] ); |
188
|
|
|
$this->assertEquals( $this->object->getSiteId(), $arrayObject['common.property.siteid'] ); |
189
|
|
|
$this->assertEquals( $this->object->getKey(), $arrayObject['common.property.key'] ); |
190
|
|
|
$this->assertEquals( $this->object->getType(), $arrayObject['common.property.type'] ); |
191
|
|
|
$this->assertEquals( $this->object->getLanguageId(), $arrayObject['common.property.languageid'] ); |
192
|
|
|
$this->assertEquals( $this->object->getValue(), $arrayObject['common.property.value'] ); |
193
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $arrayObject['common.property.ctime'] ); |
194
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $arrayObject['common.property.mtime'] ); |
195
|
|
|
$this->assertEquals( $this->object->getEditor(), $arrayObject['common.property.editor'] ); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
|
199
|
|
|
public function testIsAvailable() |
200
|
|
|
{ |
201
|
|
|
$this->assertFalse( $this->object->isAvailable() ); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
|
205
|
|
|
public function testIsModified() |
206
|
|
|
{ |
207
|
|
|
$this->assertFalse( $this->object->isModified() ); |
208
|
|
|
} |
209
|
|
|
} |
210
|
|
|
|