1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
class UnleashedCustomerTest extends SapphireTest |
|
|
|
|
4
|
|
|
{ |
5
|
|
|
protected static $fixture_file = array( |
6
|
|
|
'silvershop/tests/fixtures/ShopMembers.yml', |
7
|
|
|
'silvershop/tests/fixtures/Orders.yml', |
8
|
|
|
'silvershop-unleashed/tests/fixtures/models.yml' |
9
|
|
|
); |
10
|
|
|
|
11
|
|
|
public function setUp() |
12
|
|
|
{ |
13
|
|
|
Order::config()->send_sales_orders_to_unleashed = false; |
14
|
|
|
parent::setUp(); |
15
|
|
|
ShopTest::setConfiguration(); //reset config |
16
|
|
|
$this->order = $this->objFromFixture("Order", "cart1"); |
|
|
|
|
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
public function testGetAddressNameFromOrder() |
20
|
|
|
{ |
21
|
|
|
$this->assertSame( |
|
|
|
|
22
|
|
|
'201-203 BROADWAY AVE U 235 WEST BEACH', |
23
|
|
|
$this->order->getAddressName($this->order->ShippingAddress()), |
24
|
|
|
'Result matches 201-203 Broadway Ave U 235 West Beach' |
25
|
|
|
); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testGetAddressNameItems() |
29
|
|
|
{ |
30
|
|
|
$apidata_array = json_decode($this->jsondata, true); |
31
|
|
|
$apidata_array = reset($apidata_array); |
32
|
|
|
$apidata = $apidata_array['Items']; |
33
|
|
|
|
34
|
|
|
$this->assertSame( |
|
|
|
|
35
|
|
|
'31 Hurstmere Road RD1 Auckland', |
36
|
|
|
$this->order->getAddressName($apidata[0]['Addresses'][1]), |
37
|
|
|
'Result matches 31 Hurstmere Road RD1 Auckland' |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testMatchCustomerAddress() |
42
|
|
|
{ |
43
|
|
|
$apidata_array = json_decode($this->jsondata, true); |
44
|
|
|
$apidata_array = reset($apidata_array); |
45
|
|
|
$apidata = $apidata_array['Items']; |
46
|
|
|
|
47
|
|
|
// Test a failed match |
48
|
|
|
$this->assertFalse( |
|
|
|
|
49
|
|
|
$this->order->matchCustomerAddress($apidata, $this->order->ShippingAddress()), |
50
|
|
|
"The address in the API data does not match the order's shipping address" |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
// Test a direct match |
54
|
|
|
$shipping_address = $this->order->ShippingAddress(); |
55
|
|
|
$shipping_address->Address = '31 Hurstmere Road'; |
56
|
|
|
$shipping_address->AddressLine2 = 'RD1'; |
57
|
|
|
$shipping_address->City = 'Auckland'; |
58
|
|
|
|
59
|
|
|
$this->assertTrue( |
|
|
|
|
60
|
|
|
$this->order->matchCustomerAddress($apidata, $shipping_address), |
61
|
|
|
"The address in the API data matches the order's shipping address" |
62
|
|
|
); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* JSON data for test |
67
|
|
|
* |
68
|
|
|
* @link (Unleashed Software API Documentation, https://apidocs.unleashedsoftware.com/Products) |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
protected $jsondata = '[ |
72
|
|
|
{ |
73
|
|
|
"Pagination": { |
74
|
|
|
"NumberOfItems": 11, |
75
|
|
|
"PageSize": 200, |
76
|
|
|
"PageNumber": 1, |
77
|
|
|
"NumberOfPages": 1 |
78
|
|
|
}, |
79
|
|
|
"Items": [ |
80
|
|
|
{ |
81
|
|
|
"Addresses": [ |
82
|
|
|
{ |
83
|
|
|
"AddressType": "Postal", |
84
|
|
|
"AddressName": "1 Queen St", |
85
|
|
|
"StreetAddress": "1 Queen St", |
86
|
|
|
"StreetAddress2": "RD 2", |
87
|
|
|
"Suburb": "", |
88
|
|
|
"City": "Pukekohe", |
89
|
|
|
"Region": "Auckland", |
90
|
|
|
"Country": "New Zealand", |
91
|
|
|
"PostalCode": "0622" |
92
|
|
|
}, |
93
|
|
|
{ |
94
|
|
|
"AddressType": "Physical", |
95
|
|
|
"AddressName": "Main Warehouse", |
96
|
|
|
"StreetAddress": "31 Hurstmere Road", |
97
|
|
|
"StreetAddress2": "RD1", |
98
|
|
|
"Suburb": "Takapuna", |
99
|
|
|
"City": "Auckland", |
100
|
|
|
"Region": "North Shore", |
101
|
|
|
"Country": "New Zealand", |
102
|
|
|
"PostalCode": "0622" |
103
|
|
|
} |
104
|
|
|
], |
105
|
|
|
"CustomerCode": "FRANCK", |
106
|
|
|
"CustomerName": "Franck & Co.", |
107
|
|
|
"GSTVATNumber": null, |
108
|
|
|
"BankName": null, |
109
|
|
|
"BankBranch": null, |
110
|
|
|
"BankAccount": null, |
111
|
|
|
"Website": null, |
112
|
|
|
"PhoneNumber": null, |
113
|
|
|
"FaxNumber": null, |
114
|
|
|
"MobileNumber": null, |
115
|
|
|
"DDINumber": null, |
116
|
|
|
"TollFreeNumber": null, |
117
|
|
|
"Email": null, |
118
|
|
|
"EmailCC": null, |
119
|
|
|
"Currency": { |
120
|
|
|
"CurrencyCode": "USD", |
121
|
|
|
"Description": "United States of America, Dollars", |
122
|
|
|
"Guid": "3088672d-2a24-4d23-bb1c-c91813ed4c76", |
123
|
|
|
"LastModifiedOn": "/Date(1458675959843)/" |
124
|
|
|
}, |
125
|
|
|
"Notes": null, |
126
|
|
|
"Taxable": true, |
127
|
|
|
"XeroContactId": null, |
128
|
|
|
"SalesPerson": { |
129
|
|
|
"FullName": "John Smith", |
130
|
|
|
"Email": "[email protected]", |
131
|
|
|
"Obsolete": false, |
132
|
|
|
"Guid": "224ae802-88d3-43c1-b9cc-208d5d6d0ccf", |
133
|
|
|
"LastModifiedOn": "/Date(1459218946890)/" |
134
|
|
|
}, |
135
|
|
|
"DiscountRate": 0, |
136
|
|
|
"PrintPackingSlipInsteadOfInvoice": false, |
137
|
|
|
"PrintInvoice": false, |
138
|
|
|
"StopCredit": false, |
139
|
|
|
"Obsolete": false, |
140
|
|
|
"XeroSalesAccount": null, |
141
|
|
|
"XeroCostOfGoodsAccount": null, |
142
|
|
|
"SellPriceTier": "", |
143
|
|
|
"SellPriceTierReference": null, |
144
|
|
|
"CustomerType": "Cash", |
145
|
|
|
"PaymentTerm": "20th Month following", |
146
|
|
|
"ContactFirstName": null, |
147
|
|
|
"ContactLastName": null, |
148
|
|
|
"SourceId": null, |
149
|
|
|
"CreatedBy": "admin", |
150
|
|
|
"CreatedOn": "/Date(1411781315923)/", |
151
|
|
|
"Guid": "d32d0ca7-fd8e-4a99-9da6-be546ac5252b", |
152
|
|
|
"LastModifiedOn": "/Date(1459218740823)/" |
153
|
|
|
} |
154
|
|
|
] |
155
|
|
|
}]'; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.