Issues (8)

tests/AccountPageTest.php (1 issue)

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 = [
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 AccountPage
30
     */
31
    protected $accountpage;
32
33
    /**
34
     * @var AccountPageController
35
     */
36
    protected $controller;
37
38
    public function setUp(): void
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 SilverShop\Page\AccountPage 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(
70
                    AccountPageController::class,
71
                    $page->getHeader('X-TestPageClass'),
72
                    "Account page should open"
73
                );
74
75
                $self->assertStringContainsString(
76
                    "Past Orders",
77
                    $page->getBody(),
78
                    "Account Page is open"
79
                );
80
                $self->assertStringContainsString(
81
                    "Joe Bloggs",
82
                    $page->getBody(),
83
                    "Joe Bloggs is logged in"
84
                );
85
                $self->assertStringContainsString(
86
                    "<td>$408.00</td>",
87
                    $page->getBody(),
88
                    "Past Order is listed"
89
                );
90
91
                // Open unpaid order
92
                $page = $self->get("account/order/10");
93
                $self->assertEquals(
94
                    200,
95
                    $page->getStatusCode(),
96
                    "a page should load"
97
                );
98
                $self->assertStringContainsString(
99
                    "Please deposit",
100
                    $page->getBody(),
101
                    "Opening statement is shown"
102
                );
103
                $self->assertStringContainsString(
104
                    "XX-3456-7891011-XX",
105
                    $page->getBody(),
106
                    "Bank Account number is shown"
107
                );
108
                $self->assertStringContainsString(
109
                    "Reference:",
110
                    $page->getBody(),
111
                    "Reference is shown"
112
                );
113
                $self->assertStringContainsString(
114
                    "Your name",
115
                    $page->getBody(),
116
                    "Code is shown"
117
                );
118
                $self->assertStringContainsString(
119
                    "$3950.00",
120
                    $page->getBody(),
121
                    "Total Outstanding is shown"
122
                );
123
124
                // Open paid order
125
                $page = $self->get("account/order/11");
126
                $self->assertEquals(
127
                    200,
128
                    $page->getStatusCode(),
129
                    "a page should load"
130
                );
131
132
                $self->assertStringNotContainsString(
133
                    "Please deposit",
134
                    $page->getBody(),
135
                    "Opening statement is not shown"
136
                );
137
                $self->assertStringContainsString(
138
                    "$7900.00",
139
                    $page->getBody(),
140
                    "Total Outstanding is shown"
141
                );
142
143
                $self->assertStringContainsString(
144
                    "Paid",
145
                    $page->getBody(),
146
                    "'Paid' is displayed in place of Total Outstanding"
147
                );
148
149
                // test other order statuses
150
                $order = Order::get()->byId("11");
151
                $statuses = ["Sent", "Complete", "AdminCancelled", "MemberCancelled"];
152
                foreach ($statuses as $status) {
153
                    $order->Status = $status;
154
155
                    $page = $self->get("account/order/11");
156
                    $self->assertEquals(
157
                        200,
158
                        $page->getStatusCode(),
159
                        "a page should load"
160
                    );
161
                    $self->assertStringNotContainsString(
162
                        "Please deposit",
163
                        $page->getBody(),
164
                        "Opening statement is not shown"
165
                    );
166
                    $self->assertStringContainsString(
167
                        "$7900.00",
168
                        $page->getBody(),
169
                        "Total Outstanding is shown"
170
                    );
171
                    $self->assertStringContainsString(
172
                        "Paid",
173
                        $page->getBody(),
174
                        "'Paid' is displayed in place of Total Outstanding"
175
                    );
176
                }
177
            }
178
        );
179
    }
180
}
181