Completed
Push — master ( 4cbc21...c64f37 )
by Antony
02:07
created

AccountPageTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 152
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 105
dl 0
loc 152
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testCanViewAccountPagePastOrdersAndIndividualOrders() 0 115 2
A setUp() 0 16 1
1
<?php
2
3
namespace AntonyThorpe\SilverShopBankDeposit\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
use SilverStripe\SiteConfig\SiteConfig;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Control\Controller;
9
use SilverShop\Tests\ShopTestControllerExtension;
10
use SilverShop\Tests\ShopTest;
11
use SilverShop\Page\AccountPage;
12
use SilverShop\Page\AccountPageController;
13
use SilverStripe\Security\Member;
14
use SilverShop\Model\Order;
15
16
/**
17
 * Ensure that the template includes work on the AccountPage
18
 */
19
class AccountPageTest extends FunctionalTest
20
{
21
    protected static $fixture_file = array(
22
        'vendor/silvershop/core/tests/php/Fixtures/Pages.yml',
23
        'vendor/silvershop/core/tests/php/Fixtures/shop.yml',
24
        'vendor/silvershop/core/tests/php/Fixtures/Orders.yml',
25
        'Orders.yml'
26
    );
27
28
    /**
29
     * @var SilverStripe\ORM\DataObject
0 ignored issues
show
Bug introduced by
The type AntonyThorpe\SilverShopB...erStripe\ORM\DataObject was not found. Did you mean SilverStripe\ORM\DataObject? If so, make sure to prefix the type with \.
Loading history...
30
     */
31
    protected $accountpage;
32
33
    /**
34
     * @var AccountPageController
35
     */
36
    protected $controller;
37
38
    public function setUp()
39
    {
40
        parent::setUp();
41
        ShopTest::setConfiguration();
42
43
        $siteconfig = DataObject::get_one(SiteConfig::class);
44
        $siteconfig->BankAccountPaymentMethodMessage = "You will be notified of the bank account details";
45
        $siteconfig->BankAccountNumber = "XX-3456-7891011-XX";
46
        $siteconfig->BankAccountDetails = "TestBank, Business Branch";
47
        $siteconfig->BankAccountInvoiceMessage = "Hey bo, just pop the dosh in the account";
48
        $siteconfig->write();
49
50
        Controller::add_extension(ShopTestControllerExtension::class);
51
        $this->accountpage = $this->objFromFixture(AccountPage::class, "accountpage");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture(Si...::class, 'accountpage') of type SilverStripe\ORM\DataObject is incompatible with the declared type AntonyThorpe\SilverShopB...erStripe\ORM\DataObject of property $accountpage.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
52
        $this->accountpage->publishSingle();
53
        $this->controller = new AccountPageController($this->accountpage);
54
    }
55
56
    public function testCanViewAccountPagePastOrdersAndIndividualOrders()
57
    {
58
        $self = $this;
59
        $this->useTestTheme(
60
            dirname(__FILE__),
61
            'testtheme',
62
            function () use ($self) {
63
                $member = $self->objFromFixture(Member::class, "joebloggs");
64
                $self->logInAs($member);
65
                $self->controller->init(); //re-init to connect up member
66
67
                // Open Address Book page
68
                $page = $self->get("account/"); // Past Orders page
69
                $self->assertEquals(AccountPageController::class, $page->getHeader('X-TestPageClass'), "Account page should open");
70
71
                $self->assertContains(
72
                    "Past Orders",
73
                    $page->getBody(),
74
                    "Account Page is open"
75
                );
76
                $self->assertContains(
77
                    "Joe Bloggs",
78
                    $page->getBody(),
79
                    "Joe Bloggs is logged in"
80
                );
81
                $self->assertContains(
82
                    "<td>$408.00</td>",
83
                    $page->getBody(),
84
                    "Past Order is listed"
85
                );
86
87
                // Open unpaid order
88
                $page = $self->get("account/order/10");
89
                $self->assertEquals(
90
                    200,
91
                    $page->getStatusCode(),
92
                    "a page should load"
93
                );
94
                $self->assertContains(
95
                    "Please deposit",
96
                    $page->getBody(),
97
                    "Opening statement is shown"
98
                );
99
                $self->assertContains(
100
                    "XX-3456-7891011-XX",
101
                    $page->getBody(),
102
                    "Bank Account number is shown"
103
                );
104
                $self->assertContains(
105
                    "Reference:",
106
                    $page->getBody(),
107
                    "Reference is shown"
108
                );
109
                $self->assertContains(
110
                    "Your name",
111
                    $page->getBody(),
112
                    "Code is shown"
113
                );
114
                $self->assertContains(
115
                    "$3950.00",
116
                    $page->getBody(),
117
                    "Total Outstanding is shown"
118
                );
119
120
                // Open paid order
121
                $page = $self->get("account/order/11");
122
                $self->assertEquals(
123
                    200,
124
                    $page->getStatusCode(),
125
                    "a page should load"
126
                );
127
128
                $self->assertNotContains(
129
                    "Please deposit",
130
                    $page->getBody(),
131
                    "Opening statement is not shown"
132
                );
133
                $self->assertContains(
134
                    "$7900.00",
135
                    $page->getBody(),
136
                    "Total Outstanding is shown"
137
                );
138
139
                $self->assertContains(
140
                    "Paid",
141
                    $page->getBody(),
142
                    "'Paid' is displayed in place of Total Outstanding"
143
                );
144
145
                // test other order statuses
146
                $order = Order::get()->byId("11");
147
                $statuses = ["Sent", "Complete", "AdminCancelled", "MemberCancelled"];
148
                foreach ($statuses as $status) {
149
                    $order->Status = $status;
150
151
                    $page = $self->get("account/order/11");
152
                    $self->assertEquals(
153
                        200,
154
                        $page->getStatusCode(),
155
                        "a page should load"
156
                    );
157
                    $self->assertNotContains(
158
                        "Please deposit",
159
                        $page->getBody(),
160
                        "Opening statement is not shown"
161
                    );
162
                    $self->assertContains(
163
                        "$7900.00",
164
                        $page->getBody(),
165
                        "Total Outstanding is shown"
166
                    );
167
                    $self->assertContains(
168
                        "Paid",
169
                        $page->getBody(),
170
                        "'Paid' is displayed in place of Total Outstanding"
171
                    );
172
                }
173
            }
174
        );
175
    }
176
}
177