This repository has been archived by the owner on Oct 17, 2022. It is now read-only.
forked from aimeos/aimeos-core
/
DefaultTest.php
263 lines (217 loc) · 7.81 KB
/
DefaultTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
<?php
/**
* @copyright Copyright (c) Metaways Infosystems GmbH, 2011
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
*/
/**
* Test class for MShop_Order_Item_Default.
*/
class MShop_Order_Item_DefaultTest extends PHPUnit_Framework_TestCase
{
private $_object;
private $_values;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*
* @access protected
*/
protected function setUp()
{
$this->_values = array(
'id' => 15,
'siteid'=>99,
'type' => MShop_Order_Item_Abstract::TYPE_WEB,
'statusdelivery' => MShop_Order_Item_Abstract::STAT_PENDING,
'statuspayment' => MShop_Order_Item_Abstract::PAY_RECEIVED,
'datepayment' => '2004-12-01 12:34:56',
'datedelivery' => '2004-01-03 12:34:56',
'relatedid' => 1,
'baseid' => 4,
'mtime' => '2011-01-01 00:00:02',
'ctime' => '2011-01-01 00:00:01',
'editor' => 'unitTestUser'
);
$this->_object = new MShop_Order_Item_Default( $this->_values );
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*
* @access protected
*/
protected function tearDown()
{
unset( $this->_object );
}
public function testGetId()
{
$this->assertEquals( $this->_values['id'], $this->_object->getId() );
}
public function testSetId()
{
$this->_object->setId( null );
$this->assertEquals( null, $this->_object->getId() );
$this->assertTrue( $this->_object->isModified() );
$this->_object->setId( 15 );
$this->assertEquals( 15, $this->_object->getId() );
$this->assertFalse( $this->_object->isModified() );
$this->setExpectedException( 'MShop_Exception' );
$this->_object->setId( 6 );
}
public function testSetId2()
{
$this->setExpectedException( 'MShop_Exception' );
$this->_object->setId( 'test' );
}
public function testGetSiteId()
{
$this->assertEquals( 99, $this->_object->getSiteId() );
}
public function testGetBaseId()
{
$this->assertSame( $this->_values['baseid'], $this->_object->getBaseId() );
}
public function testSetBaseId()
{
$this->_object->setBaseId( 15 );
$this->assertEquals( 15, $this->_object->getBaseId() );
$this->assertTrue( $this->_object->isModified() );
}
public function testGetType()
{
$this->assertEquals( $this->_values['type'], $this->_object->getType() );
}
public function testSetType()
{
$this->_object->setType( MShop_Order_Item_Abstract::TYPE_PHONE );
$this->assertEquals( MShop_Order_Item_Abstract::TYPE_PHONE, $this->_object->getType() );
$this->assertTrue( $this->_object->isModified() );
$this->setExpectedException( 'MShop_Order_Exception' );
$this->_object->setType( 500 );
}
public function testGetDateDelivery()
{
$this->assertEquals( $this->_values['datedelivery'], $this->_object->getDateDelivery() );
}
public function testSetDateDelivery()
{
$this->_object->setDateDelivery( '2008-04-12 12:34:56' );
$this->assertEquals( '2008-04-12 12:34:56', $this->_object->getDateDelivery() );
$this->assertTrue( $this->_object->isModified() );
$this->setExpectedException( 'MShop_Order_Exception' );
$this->_object->setDateDelivery( '2008-34-12' );
}
public function testGetDatePayment()
{
$this->assertEquals( $this->_values['datepayment'], $this->_object->getDatePayment() );
}
public function testSetDatePayment()
{
$this->_object->setDatePayment( '2008-04-12 12:34:56' );
$this->assertEquals( '2008-04-12 12:34:56', $this->_object->getDatePayment() );
$this->assertTrue( $this->_object->isModified() );
$this->setExpectedException( 'MShop_Order_Exception' );
$this->_object->setDatePayment( '2008-34-12' );
}
public function testGetDeliveryStatus()
{
$this->assertEquals( $this->_values['statusdelivery'], $this->_object->getDeliveryStatus() );
}
public function testSetDeliveryStatus()
{
$this->_object->setDeliveryStatus( MShop_Order_Item_Abstract::STAT_PROGRESS );
$this->assertEquals( MShop_Order_Item_Abstract::STAT_PROGRESS, $this->_object->getDeliveryStatus() );
$this->assertTrue( $this->_object->isModified() );
}
public function testGetPaymentStatus()
{
$this->assertEquals( $this->_values['statuspayment'], $this->_object->getPaymentStatus() );
}
public function testSetPaymentStatus()
{
$this->_object->setPaymentStatus( MShop_Order_Item_Abstract::PAY_DELETED );
$this->assertEquals( MShop_Order_Item_Abstract::PAY_DELETED, $this->_object->getPaymentStatus() );
$this->assertTrue( $this->_object->isModified() );
}
public function testGetRelatedId()
{
$this->assertEquals( $this->_values['relatedid'], $this->_object->getRelatedId() );
}
public function testSetRelatedId()
{
$this->_object->setRelatedId( 22 );
$this->assertEquals( 22, $this->_object->getRelatedId() );
$this->assertTrue( $this->_object->isModified() );
}
public function testGetTimeModified()
{
$this->assertEquals( '2011-01-01 00:00:02', $this->_object->getTimeModified() );
}
public function testGetTimeCreated()
{
$this->assertEquals( '2011-01-01 00:00:01', $this->_object->getTimeCreated() );
}
public function testGetEditor()
{
$this->assertEquals( 'unitTestUser', $this->_object->getEditor() );
}
public function testFromArray()
{
$item = new MShop_Order_Item_Default();
$list = array(
'order.id' => 1,
'order.type' => MShop_Order_Item_Abstract::TYPE_WEB,
'order.baseid' => 2,
'order.relatedid' => 3,
'order.statusdelivery' => 4,
'order.statuspayment' => 5,
'order.datepayment' => '2000-01-01 00:00:00',
'order.datedelivery' => '2001-01-01 00:00:00',
);
$unknown = $item->fromArray( $list );
$this->assertEquals( array(), $unknown );
$this->assertEquals( $list['order.id'], $item->getId() );
$this->assertEquals( $list['order.type'], $item->getType() );
$this->assertEquals( $list['order.baseid'], $item->getBaseId() );
$this->assertEquals( $list['order.relatedid'], $item->getRelatedId() );
$this->assertEquals( $list['order.statusdelivery'], $item->getDeliveryStatus() );
$this->assertEquals( $list['order.statuspayment'], $item->getPaymentStatus() );
$this->assertEquals( $list['order.datepayment'], $item->getDatePayment() );
$this->assertEquals( $list['order.datedelivery'], $item->getDateDelivery() );
}
public function testToArray()
{
$list = $this->_object->toArray();
$this->assertEquals( count( $this->_values ), count( $list ) );
$this->assertEquals( $this->_object->getId(), $list['order.id'] );
$this->assertEquals( $this->_object->getSiteId(), $list['order.siteid'] );
$this->assertEquals( $this->_object->getType(), $list['order.type'] );
$this->assertEquals( $this->_object->getDeliveryStatus(), $list['order.statusdelivery'] );
$this->assertEquals( $this->_object->getPaymentStatus(), $list['order.statuspayment'] );
$this->assertEquals( $this->_object->getDatePayment(), $list['order.datepayment'] );
$this->assertEquals( $this->_object->getDateDelivery(), $list['order.datedelivery'] );
$this->assertEquals( $this->_object->getBaseId(), $list['order.baseid'] );
$this->assertEquals( $this->_object->getRelatedId(), $list['order.relatedid'] );
$this->assertEquals( $this->_object->getTimeModified(), $list['order.mtime'] );
$this->assertEquals( $this->_object->getTimeCreated(), $list['order.ctime'] );
$this->assertEquals( $this->_object->getEditor(), $list['order.editor'] );
}
public function testIsModified()
{
$this->assertFalse( $this->_object->isModified() );
}
public function testMagicGetOldPaymentStatus()
{
$this->assertEquals( MShop_Order_Item_Abstract::PAY_RECEIVED, $this->_object->oldPaymentStatus );
}
public function testMagicGetOldDeliveryStatus()
{
$this->assertEquals( MShop_Order_Item_Abstract::STAT_PENDING, $this->_object->oldDeliveryStatus );
}
public function testMagicGetException()
{
$this->setExpectedException( 'MShop_Order_Exception' );
$this->_object->notExisting;
}
}