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
|
<?php
class CatalogModelCheckoutOrderTest extends OpenCartTest {
/**
* @before
*/
public function setupTest() {
$this->loadModelByRoute('checkout/order');
$this->loadModelByRoute('account/custom_field');
$this->emptyTables();
}
/**
* @after
*/
public function completeTest() {
$this->emptyTables();
}
private function emptyTables() {
$this->db->query("DELETE FROM " . DB_PREFIX . "order");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_custom_field");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_fraud");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_history");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_option");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_product");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_recurring_transaction");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_total");
$this->db->query("DELETE FROM " . DB_PREFIX . "order_voucher");
}
private function getOrderArray() {
$order = array(
'invoice_prefix' => '',
'store_id' => 0,
'store_url' => '',
'store_name' => '',
'customer_id' => 0,
'customer_group_id' => 0,
'firstname' => '',
'lastname' => '',
'email' => '',
'telephone' => '',
'fax' => '',
'custom_field' => array(),
'payment_firstname' => '',
'payment_lastname' => '',
'payment_company' => '',
'payment_address_1' => '',
'payment_address_2' => '',
'payment_city' => '',
'payment_postcode' => '',
'payment_zone' => '',
'payment_zone_id' => 0,
'payment_country' => '',
'payment_country_id' => 0,
'payment_address_format' => '',
'payment_custom_field' => array(),
'payment_method' => '',
'payment_code' => '',
'shipping_firstname' => '',
'shipping_lastname' => '',
'shipping_company' => '',
'shipping_address_1' => '',
'shipping_address_2' => '',
'shipping_city' => '',
'shipping_postcode' => '',
'shipping_zone' => '',
'shipping_zone_id' => 0,
'shipping_country' => '',
'shipping_country_id' => 0,
'shipping_address_format' => '',
'shipping_custom_field' => array(),
'shipping_method' => '',
'shipping_code' => '',
'products' => array(
array(
'product_id' => 0,
'name' => '',
'model' => '',
'quantity' => 0,
'price' => 0.00,
'total' => 0.00,
'tax' => 0.00,
'reward' => 0.00,
'option' => array(
array(
'product_option_id' => 0,
'product_option_value_id' => 0,
'name' => '',
'value' => '',
'type' => '',
),
)
),
),
'vouchers' => array(
array(
'description' => '',
'code' => '',
'from_name' => '',
'from_email' => '',
'to_name' => '',
'to_email' => '',
'voucher_theme_id' => 0,
'message' => '',
'amount' => 0.00,
),
),
'comment' => '',
'total' => '',
'affiliate_id' => 0,
'commission' => 0,
'marketing_id' => 0,
'tracking' => '',
'language_id' => 0,
'currency_id' => 0,
'currency_code' => '',
'currency_value' => 0,
'ip' => '',
'forwarded_ip' => '',
'user_agent' => '',
'accept_language' => '',
'totals' => array(
array(
'code' => '',
'title' => '',
'value' => 0.00,
'sort_order' => 0,
),
array(
'code' => '',
'title' => '',
'value' => 0.00,
'sort_order' => 0,
),
),
);
return $order;
}
public function testAddOrder() {
$orderData = $this->getOrderArray();
$orderId = $this->model_checkout_order->addOrder($orderData);
$this->assertNotNull($orderId);
$numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order`")->row['total'];
$this->assertEquals(1, $numRows);
$numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_product`")->row['total'];
$this->assertEquals(1, $numRows);
$numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_option`")->row['total'];
$this->assertEquals(1, $numRows);
$numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_voucher`")->row['total'];
$this->assertEquals(1, $numRows);
$numRows = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order_total`")->row['total'];
$this->assertEquals(2, $numRows);
}
// The following three tests should be completed when custom fields are implemented
public function testGetOrder() {
$this->markTestIncomplete();
$orderData = $this->getOrderArray();
$this->model_checkout_order->addOrder($orderData);
$orderId = $this->db->query("SELECT order_id FROM `" . DB_PREFIX . "order` LIMIT 1")->row['order_id'];
$order = $this->model_checkout_order->getOrder($orderId);
$this->assertEquals($orderId, $order['order_id']);
}
public function testConfirm() {
$this->markTestIncomplete();
$orderData = $this->getOrderArray();
$orderId = $this->model_checkout_order->addOrder($orderData);
$this->model_checkout_order->confirm($orderId, $this->config->get('config_complete_status_id'));
}
public function testUpdate() {
$this->markTestIncomplete();
$orderData = $this->getOrderArray();
$orderId = $this->model_checkout_order->addOrder($orderData);
$this->model_checkout_order->update($orderId, $this->config->get('config_complete_status_id'));
}
}
|