Completed
Push — master ( 43e406...3aef2a )
by Antony
09:00
created

UnleashedCustomerTest::testGetAddressNameItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 12
rs 9.4285
cc 1
eloc 8
nc 1
nop 0
1
<?php
2
3
class UnleashedCustomerTest extends SapphireTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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");
0 ignored issues
show
Bug introduced by
The property order does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
17
    }
18
    
19
    public function testGetAddressNameFromOrder()
20
    {
21
        $this->assertSame(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<UnleashedCustomerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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(
0 ignored issues
show
Bug introduced by
The method assertSame() does not seem to exist on object<UnleashedCustomerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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(
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<UnleashedCustomerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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(
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<UnleashedCustomerTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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