Completed
Push — master ( e2afa7...c0744c )
by Aimeos
12:33
created

StandardTest::testSetCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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