1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2018 |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
namespace Aimeos\MShop\Subscription\Item; |
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
|
|
|
'subscription.id' => 15, |
22
|
|
|
'subscription.siteid' => 99, |
23
|
|
|
'subscription.ordprodid' => 123, |
24
|
|
|
'subscription.datenext' => '2000-01-01 00:00:00', |
25
|
|
|
'subscription.dateend' => '2100-01-01 00:00:00', |
26
|
|
|
'subscription.interval' => 'P1Y', |
27
|
|
|
'subscription.status' => 1, |
28
|
|
|
'subscription.mtime' => '2018-01-01 00:00:02', |
29
|
|
|
'subscription.ctime' => '2018-01-01 00:00:01', |
30
|
|
|
'subscription.editor' => 'unitTestUser' |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
$this->object = new \Aimeos\MShop\Subscription\Item\Standard( $this->values ); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function tearDown() |
37
|
|
|
{ |
38
|
|
|
unset( $this->object ); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testGetId() |
42
|
|
|
{ |
43
|
|
|
$this->assertEquals( $this->values['subscription.id'], $this->object->getId() ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testSetId() |
47
|
|
|
{ |
48
|
|
|
$return = $this->object->setId( null ); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
51
|
|
|
$this->assertEquals( null, $this->object->getId() ); |
52
|
|
|
$this->assertTrue( $this->object->isModified() ); |
53
|
|
|
|
54
|
|
|
$return = $this->object->setId( 15 ); |
55
|
|
|
|
56
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
57
|
|
|
$this->assertEquals( 15, $this->object->getId() ); |
58
|
|
|
$this->assertFalse( $this->object->isModified() ); |
59
|
|
|
|
60
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
61
|
|
|
$this->object->setId( 6 ); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testGetSiteId() |
65
|
|
|
{ |
66
|
|
|
$this->assertEquals( 99, $this->object->getSiteId() ); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function testGetOrderProductId() |
70
|
|
|
{ |
71
|
|
|
$this->assertEquals( $this->values['subscription.ordprodid'], $this->object->getOrderProductId() ); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function testSetOrderProductId() |
75
|
|
|
{ |
76
|
|
|
$return = $this->object->setOrderProductId( 15 ); |
77
|
|
|
|
78
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
79
|
|
|
$this->assertEquals( 15, $this->object->getOrderProductId() ); |
80
|
|
|
$this->assertTrue( $this->object->isModified() ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testGetDateNext() |
84
|
|
|
{ |
85
|
|
|
$this->assertEquals( $this->values['subscription.datenext'], $this->object->getDateNext() ); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
public function testSetDateNext() |
89
|
|
|
{ |
90
|
|
|
$return = $this->object->setDateNext( '2018-01-01 00:00:00' ); |
91
|
|
|
|
92
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
93
|
|
|
$this->assertEquals( '2018-01-01 00:00:00', $this->object->getDateNext() ); |
94
|
|
|
$this->assertTrue( $this->object->isModified() ); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function testGetDateEnd() |
98
|
|
|
{ |
99
|
|
|
$this->assertEquals( $this->values['subscription.dateend'], $this->object->getDateEnd() ); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testSetDateEnd() |
103
|
|
|
{ |
104
|
|
|
$return = $this->object->setDateEnd( '2020-01-01 00:00:00' ); |
105
|
|
|
|
106
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
107
|
|
|
$this->assertEquals( '2020-01-01 00:00:00', $this->object->getDateEnd() ); |
108
|
|
|
$this->assertTrue( $this->object->isModified() ); |
109
|
|
|
|
110
|
|
|
$this->setExpectedException( '\\Aimeos\\MShop\\Exception' ); |
111
|
|
|
$this->object->setDateEnd( '2008-34-12' ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetInterval() |
115
|
|
|
{ |
116
|
|
|
$this->assertEquals( $this->values['subscription.interval'], $this->object->getInterval() ); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
public function testSetInterval() |
120
|
|
|
{ |
121
|
|
|
$return = $this->object->setInterval( 'P1M' ); |
122
|
|
|
|
123
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
124
|
|
|
$this->assertEquals( 'P1M', $this->object->getInterval() ); |
125
|
|
|
$this->assertTrue( $this->object->isModified() ); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
public function testGetStatus() |
129
|
|
|
{ |
130
|
|
|
$this->assertEquals( $this->values['subscription.status'], $this->object->getStatus() ); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function testSetStatus() |
134
|
|
|
{ |
135
|
|
|
$return = $this->object->setStatus( 0 ); |
136
|
|
|
|
137
|
|
|
$this->assertInstanceOf( '\Aimeos\MShop\Subscription\Item\Iface', $return ); |
138
|
|
|
$this->assertEquals( 0, $this->object->getStatus() ); |
139
|
|
|
$this->assertTrue( $this->object->isModified() ); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function testGetTimeModified() |
143
|
|
|
{ |
144
|
|
|
$this->assertEquals( '2018-01-01 00:00:02', $this->object->getTimeModified() ); |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
public function testGetTimeCreated() |
148
|
|
|
{ |
149
|
|
|
$this->assertEquals( '2018-01-01 00:00:01', $this->object->getTimeCreated() ); |
150
|
|
|
} |
151
|
|
|
|
152
|
|
|
public function testGetEditor() |
153
|
|
|
{ |
154
|
|
|
$this->assertEquals( 'unitTestUser', $this->object->getEditor() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
|
158
|
|
|
public function testGetResourceType() |
159
|
|
|
{ |
160
|
|
|
$this->assertEquals( 'subscription', $this->object->getResourceType() ); |
161
|
|
|
} |
162
|
|
|
|
163
|
|
|
|
164
|
|
|
public function testFromArray() |
165
|
|
|
{ |
166
|
|
|
$item = new \Aimeos\MShop\Subscription\Item\Standard(); |
167
|
|
|
|
168
|
|
|
$list = array( |
169
|
|
|
'subscription.id' => 1, |
170
|
|
|
'subscription.ordprodid' => 2, |
171
|
|
|
'subscription.datenext' => '2019-01-01 00:00:00', |
172
|
|
|
'subscription.dateend' => '2020-01-01 00:00:00', |
173
|
|
|
'subscription.interval' => 'P1Y', |
174
|
|
|
'subscription.status' => 1, |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$unknown = $item->fromArray( $list ); |
178
|
|
|
|
179
|
|
|
$this->assertEquals( [], $unknown ); |
180
|
|
|
|
181
|
|
|
$this->assertEquals( $list['subscription.id'], $item->getId() ); |
182
|
|
|
$this->assertEquals( $list['subscription.ordprodid'], $item->getOrderProductId() ); |
183
|
|
|
$this->assertEquals( $list['subscription.datenext'], $item->getDateNext() ); |
184
|
|
|
$this->assertEquals( $list['subscription.dateend'], $item->getDateEnd() ); |
185
|
|
|
$this->assertEquals( $list['subscription.interval'], $item->getInterval() ); |
186
|
|
|
$this->assertEquals( $list['subscription.status'], $item->getStatus() ); |
187
|
|
|
} |
188
|
|
|
|
189
|
|
|
|
190
|
|
|
public function testToArray() |
191
|
|
|
{ |
192
|
|
|
$list = $this->object->toArray( true ); |
193
|
|
|
$this->assertEquals( count( $this->values ), count( $list ) ); |
194
|
|
|
|
195
|
|
|
$this->assertEquals( $this->object->getId(), $list['subscription.id'] ); |
196
|
|
|
$this->assertEquals( $this->object->getSiteId(), $list['subscription.siteid'] ); |
197
|
|
|
$this->assertEquals( $this->object->getOrderProductId(), $list['subscription.ordprodid'] ); |
198
|
|
|
$this->assertEquals( $this->object->getDateNext(), $list['subscription.datenext'] ); |
199
|
|
|
$this->assertEquals( $this->object->getDateEnd(), $list['subscription.dateend'] ); |
200
|
|
|
$this->assertEquals( $this->object->getInterval(), $list['subscription.interval'] ); |
201
|
|
|
$this->assertEquals( $this->object->getStatus(), $list['subscription.status'] ); |
202
|
|
|
$this->assertEquals( $this->object->getTimeModified(), $list['subscription.mtime'] ); |
203
|
|
|
$this->assertEquals( $this->object->getTimeCreated(), $list['subscription.ctime'] ); |
204
|
|
|
$this->assertEquals( $this->object->getEditor(), $list['subscription.editor'] ); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public function testIsModified() |
208
|
|
|
{ |
209
|
|
|
$this->assertFalse( $this->object->isModified() ); |
210
|
|
|
} |
211
|
|
|
} |
212
|
|
|
|