Passed
Push — master ( 2cc80f...ef78f2 )
by Aimeos
05:36
created

StandardTest::testSetItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
4
 * @copyright Aimeos (aimeos.org), 2022-2024
5
 */
6
7
namespace Aimeos\MShop\Basket\Item;
8
9
10
class StandardTest extends \PHPUnit\Framework\TestCase
11
{
12
	private $basket;
13
	private $object;
14
	private $values;
15
16
17
	protected function setUp() : void
18
	{
19
		$this->values = array(
20
			'basket.id' => '123-456-789',
21
			'basket.siteid' => '1.',
22
			'basket.customerid' => '11',
23
			'basket.name' => 'testbasket',
24
			'basket.mtime' => '2011-01-01 00:00:02',
25
			'basket.ctime' => '2011-01-01 00:00:01',
26
			'basket.editor' => 'unitTestUser',
27
		);
28
29
		$this->basket = \Aimeos\MShop::create( \TestHelper::context(), 'order' )->create()->off();
30
		$this->object = new \Aimeos\MShop\Basket\Item\Standard( $this->values, $this->basket );
31
	}
32
33
34
	protected function tearDown() : void
35
	{
36
		unset( $this->object, $this->basket );
37
	}
38
39
40
	public function testGetId()
41
	{
42
		$this->assertEquals( '123-456-789', $this->object->getId() );
43
	}
44
45
46
	public function testSetId()
47
	{
48
		$return = $this->object->setId( '987-654-321' );
49
50
		$this->assertInstanceOf( \Aimeos\MShop\Basket\Item\Iface::class, $return );
51
		$this->assertEquals( '987-654-321', $this->object->getId() );
52
		$this->assertTrue( $this->object->isModified() );
53
	}
54
55
56
	public function testGetSiteId()
57
	{
58
		$this->assertEquals( '1.', $this->object->getSiteId() );
59
	}
60
61
62
	public function testGetCustomerId()
63
	{
64
		$this->assertEquals( '11', $this->object->getCustomerId() );
65
	}
66
67
68
	public function testSetCustomerId()
69
	{
70
		$return = $this->object->setCustomerId( '12' );
71
72
		$this->assertInstanceOf( \Aimeos\MShop\Basket\Item\Iface::class, $return );
73
		$this->assertEquals( '12', $this->object->getCustomerId() );
74
		$this->assertTrue( $this->object->isModified() );
75
	}
76
77
78
	public function testGet()
79
	{
80
		$this->assertInstanceOf( \Aimeos\MShop\Order\Item\Iface::class, $this->object->getItem() );
81
	}
82
83
84
	public function testSetItem()
85
	{
86
		$return = $this->object->setItem( $this->basket );
87
88
		$this->assertInstanceOf( \Aimeos\MShop\Basket\Item\Iface::class, $return );
89
		$this->assertSame( $this->basket, $this->object->getItem() );
90
		$this->assertTrue( $this->object->isModified() );
91
	}
92
93
94
	public function testGetName()
95
	{
96
		$this->assertEquals( 'testbasket', $this->object->getName() );
97
	}
98
99
100
	public function testSetName()
101
	{
102
		$return = $this->object->setName( 'unittest' );
103
104
		$this->assertInstanceOf( \Aimeos\MShop\Basket\Item\Iface::class, $return );
105
		$this->assertEquals( 'unittest', $this->object->getName() );
106
		$this->assertTrue( $this->object->isModified() );
107
	}
108
109
110
	public function testGetTimeModified()
111
	{
112
		$this->assertEquals( '2011-01-01 00:00:02', $this->object->getTimeModified() );
113
	}
114
115
116
	public function testGetTimeCreated()
117
	{
118
		$this->assertEquals( '2011-01-01 00:00:01', $this->object->getTimeCreated() );
119
	}
120
121
122
	public function testGetEditor()
123
	{
124
		$this->assertEquals( 'unitTestUser', $this->object->editor() );
125
	}
126
127
128
	public function testGetResourceType()
129
	{
130
		$this->assertEquals( 'basket', $this->object->getResourceType() );
131
	}
132
133
134
	public function testFromArray()
135
	{
136
		$item = new \Aimeos\MShop\Basket\Item\Standard();
137
138
		$list = $entries = array(
139
			'basket.id' => '123-456',
140
			'basket.customerid' => '123',
141
			'basket.name' => 'test basket name',
142
		);
143
144
		$item = $item->fromArray( $entries, true );
145
146
		$this->assertEquals( [], $entries );
147
		$this->assertEquals( '', $item->getSiteId() );
148
		$this->assertEquals( $list['basket.id'], $item->getId() );
149
		$this->assertEquals( $list['basket.customerid'], $item->getCustomerId() );
150
		$this->assertEquals( $list['basket.name'], $item->getName() );
151
	}
152
153
154
	public function testToArray()
155
	{
156
		$list = $this->object->toArray( true );
157
158
		$this->assertEquals( count( $this->values ), count( $list ) );
159
160
		$this->assertEquals( $this->object->getId(), $list['basket.id'] );
161
		$this->assertEquals( $this->object->getSiteId(), $list['basket.siteid'] );
162
		$this->assertEquals( $this->object->getCustomerId(), $list['basket.customerid'] );
163
		$this->assertEquals( $this->object->getName(), $list['basket.name'] ); ;
164
		$this->assertEquals( $this->object->getTimeModified(), $list['basket.mtime'] );
165
		$this->assertEquals( $this->object->getTimeCreated(), $list['basket.ctime'] );
166
		$this->assertEquals( $this->object->editor(), $list['basket.editor'] );
167
	}
168
}
169