Passed
Push — master ( ae8cc8...b4d665 )
by Aimeos
04:50
created

StandardTest::testGetLabel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 */
7
8
namespace Aimeos\MShop\Group\Item\Group;
9
10
11
class StandardTest extends \PHPUnit\Framework\TestCase
12
{
13
	private $object;
14
	private $values;
15
16
17
	protected function setUp() : void
18
	{
19
		$this->values = array(
20
			'group.id' => '123',
21
			'group.siteid' => '456',
22
			'group.code' => 'unitgroup',
23
			'group.label' => 'unittest',
24
			'group.ctime' => '1970-01-01 00:00:00',
25
			'group.mtime' => '2000-01-01 00:00:00',
26
			'group.editor' => 'unittest',
27
		);
28
29
		$this->object = new \Aimeos\MShop\Group\Item\Standard( $this->values );
30
	}
31
32
33
	protected function tearDown() : void
34
	{
35
		unset( $this->object, $this->values );
36
	}
37
38
39
	public function testGetId()
40
	{
41
		$this->assertEquals( 123, $this->object->getId() );
42
	}
43
44
45
	public function testSetId()
46
	{
47
		$return = $this->object->setId( null );
48
49
		$this->assertInstanceOf( \Aimeos\MShop\Group\Item\Iface::class, $return );
50
		$this->assertTrue( $this->object->isModified() );
51
		$this->assertNull( $this->object->getId() );
52
	}
53
54
55
	public function testGetSiteId()
56
	{
57
		$this->assertEquals( 456, $this->object->getSiteId() );
58
	}
59
60
61
	public function testGetCode()
62
	{
63
		$this->assertEquals( 'unitgroup', $this->object->getCode() );
64
	}
65
66
67
	public function testSetCode()
68
	{
69
		$return = $this->object->setCode( 'unitgroup2' );
70
71
		$this->assertInstanceOf( \Aimeos\MShop\Group\Item\Iface::class, $return );
72
		$this->assertEquals( 'unitgroup2', $this->object->getCode() );
73
		$this->assertTrue( $this->object->isModified() );
74
	}
75
76
77
	public function testGetLabel()
78
	{
79
		$this->assertEquals( 'unittest', $this->object->getLabel() );
80
	}
81
82
83
	public function testSetLabel()
84
	{
85
		$return = $this->object->setLabel( 'unittest1' );
86
87
		$this->assertInstanceOf( \Aimeos\MShop\Group\Item\Iface::class, $return );
88
		$this->assertEquals( 'unittest1', $this->object->getLabel() );
89
		$this->assertTrue( $this->object->isModified() );
90
	}
91
92
93
	public function testIsModified()
94
	{
95
		$this->assertFalse( $this->object->isModified() );
96
	}
97
98
99
	public function testGetResourceType()
100
	{
101
		$this->assertEquals( 'group', $this->object->getResourceType() );
102
	}
103
104
105
	public function testFromArray()
106
	{
107
		$item = new \Aimeos\MShop\Group\Item\Standard();
108
109
		$list = $entries = array(
110
			'group.id' => 12,
111
			'group.code' => 'unitgroup',
112
			'group.label' => 'unittest12',
113
		);
114
115
		$item = $item->fromArray( $entries, true );
116
117
		$this->assertEquals( [], $entries );
118
		$this->assertEquals( '', $item->getSiteId() );
119
		$this->assertEquals( $list['group.id'], $item->getId() );
120
		$this->assertEquals( $list['group.code'], $item->getCode() );
121
		$this->assertEquals( $list['group.label'], $item->getLabel() );
122
	}
123
124
125
	public function testToArray()
126
	{
127
		$list = $this->object->toArray( true );
128
129
		$this->assertEquals( count( $this->values ), count( $list ) );
130
131
		$this->assertEquals( $this->object->getId(), $list['group.id'] );
132
		$this->assertEquals( $this->object->getSiteId(), $list['group.siteid'] );
133
		$this->assertEquals( $this->object->getCode(), $list['group.code'] );
134
		$this->assertEquals( $this->object->getLabel(), $list['group.label'] );
135
		$this->assertEquals( $this->object->getTimeCreated(), $list['group.ctime'] );
136
		$this->assertEquals( $this->object->getTimeModified(), $list['group.mtime'] );
137
		$this->assertEquals( $this->object->editor(), $list['group.editor'] );
138
	}
139
}
140