testGetAddressNameFromOrder()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace AntonyThorpe\SilverShopUnleashed\Tests;
4
5
use AntonyThorpe\SilverShopUnleashed\Defaults;
6
use SilverShop\Model\Order;
0 ignored issues
show
Bug introduced by
The type SilverShop\Model\Order was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverShop\Tests\ShopTest;
0 ignored issues
show
Bug introduced by
The type SilverShop\Tests\ShopTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\Dev\SapphireTest;
0 ignored issues
show
Bug introduced by
The type SilverStripe\Dev\SapphireTest was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

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