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

SteppedCheckoutPageGuestTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 26
rs 9.7333
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace AntonyThorpe\SilverShopBankDeposit\Tests;
4
5
use SilverStripe\Dev\FunctionalTest;
6
use SilverStripe\SiteConfig\SiteConfig;
7
use SilverStripe\Core\Config\Config;
8
use SilverStripe\ORM\DataObject;
9
use SilverStripe\Security\Member;
10
use SilverStripe\View\SSViewer;
11
use SilverShop\Tests\ShopTest;
12
use SilverShop\Extension\SteppedCheckoutExtension;
13
use SilverShop\Page\Product;
14
use SilverShop\Page\CheckoutPage;
15
use SilverShop\Page\AccountPage;
16
use SilverShop\Model\Order;
17
use SilverShop\Cart\ShoppingCart;
18
use SilverShop\Cart\ShoppingCartController;
19
20
/**
21
 * Test that the Manual payment method can be used on a stepped checkout and
22
 * that an email is sent upon completing the form
23
 */
24
class SteppedCheckoutPageGuestTest extends FunctionalTest
25
{
26
    protected static $fixture_file = array(
27
        'vendor/silvershop/core/tests/php/Fixtures/Pages.yml',
28
        'vendor/silvershop/core/tests/php/Fixtures/shop.yml',
29
        'vendor/silvershop/core/tests/php/Fixtures/Orders.yml',
30
        'Orders.yml'
31
    );
32
33
    protected static $disable_theme  = true;
34
35
    /**
36
     * @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...
37
     */
38
    protected $laptop;
39
40
    public function setUp()
41
    {
42
        parent::setUp();
43
        ShopTest::setConfiguration();
44
        ShoppingCart::singleton()->clear();
45
        SteppedCheckoutExtension::setupSteps(); //use default steps
46
47
        $siteconfig = DataObject::get_one(SiteConfig::class);
48
        $siteconfig->BankAccountPaymentMethodMessage = "You will be notified of the bank account details";
49
        $siteconfig->BankAccountNumber = "XX-3456-7891011-XX";
50
        $siteconfig->BankAccountDetails = "TestBank, Business Branch";
51
        $siteconfig->BankAccountInvoiceMessage = "Hey bo, just pop the dosh in the account";
52
        $siteconfig->write();
53
54
        SSViewer::config()->source_file_comments = true;
55
56
        // establish products
57
        $this->laptop = $this->objFromFixture(Product::class, "laptop");
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture(Si...oduct::class, 'laptop') of type SilverStripe\ORM\DataObject is incompatible with the declared type AntonyThorpe\SilverShopB...erStripe\ORM\DataObject of property $laptop.

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...
58
        $this->laptop->publishSingle();
59
60
        // publish pages
61
        $checkoutpage = $this->objFromFixture(CheckoutPage::class, "checkout");
62
        $checkoutpage->publishSingle();
63
64
        //add item to cart via url
65
        $this->get(ShoppingCartController::add_item_link($this->laptop));
0 ignored issues
show
Bug introduced by
It seems like SilverShop\Cart\Shopping...tem_link($this->laptop) can also be of type false; however, parameter $url of SilverStripe\Dev\FunctionalTest::get() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $this->get(/** @scrutinizer ignore-type */ ShoppingCartController::add_item_link($this->laptop));
Loading history...
Bug introduced by
$this->laptop of type SilverStripe\ORM\DataObject is incompatible with the type SilverShop\Model\Buyable expected by parameter $buyable of SilverShop\Cart\Shopping...roller::add_item_link(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

65
        $this->get(ShoppingCartController::add_item_link(/** @scrutinizer ignore-type */ $this->laptop));
Loading history...
66
    }
67
68
    public function testEmailIsSentUponStepCheckoutCompletionByGuest()
69
    {
70
        $self = $this;
71
        $this->useTestTheme(
72
            dirname(__FILE__),
73
            'testtheme',
74
            function () use ($self) {
75
                $page = $self->get("checkout/");
76
                $self->assertEquals(
77
                    200,
78
                    $page->getStatusCode(),
79
                    "page should load"
80
                );
81
82
                $page = $self->submitForm("Form_MembershipForm", "action_guestcontinue", []);
83
                $self->assertEquals(
84
                    200,
85
                    $page->getStatusCode(),
86
                    "page should load"
87
                );
88
89
                // contact form
90
                $page = $self->submitForm("CheckoutForm_ContactDetailsForm", "action_checkoutSubmit", array(
91
                    'SilverShop-Checkout-Component-CustomerDetails_FirstName' => 'James',
92
                    'SilverShop-Checkout-Component-CustomerDetails_Surname' => 'Stark',
93
                    'SilverShop-Checkout-Component-CustomerDetails_Email' => '[email protected]'
94
                ));
95
                $self->assertEquals(
96
                    200,
97
                    $page->getStatusCode(),
98
                    "a page should load"
99
                );
100
101
                // Shipping Address form
102
                $page = $self->submitForm("CheckoutForm_ShippingAddressForm", "action_setshippingaddress", array(
103
                    'SilverShop-Checkout-Component-ShippingAddress_Country' => 'AU',
104
                    'SilverShop-Checkout-Component-ShippingAddress_Address' => '201-203 BROADWAY AVE',
105
                    'SilverShop-Checkout-Component-ShippingAddress_AddressLine2' => 'U 235',
106
                    'SilverShop-Checkout-Component-ShippingAddress_City' => 'WEST BEACH',
107
                    'SilverShop-Checkout-Component-ShippingAddress_State' => 'South Australia',
108
                    'SilverShop-Checkout-Component-ShippingAddress_PostalCode' => '5024',
109
                    'SilverShop-Checkout-Component-ShippingAddress_Phone' => '',
110
                    'SeperateBilling' => '0'
111
112
                ));
113
                $self->assertEquals(
114
                    200,
115
                    $page->getStatusCode(),
116
                    "payment methods page should load"
117
                );
118
119
                $self->assertContains(
120
                    "CheckoutForm_PaymentMethodForm_PaymentMethod_Manual",
121
                    $page->getBody(),
122
                    "Manual payment method available"
123
                );
124
125
                $self->assertContains(
126
                    "You will be notified of the bank account details",
127
                    $page->getBody(),
128
                    "Bank Account Message presented during the payment method section"
129
                );
130
131
                // Payment Method can be manual
132
                $page = $self->submitForm("CheckoutForm_PaymentMethodForm", "action_setpaymentmethod", array(
133
                    'PaymentMethod' => 'Manual',
134
                ));
135
                $self->assertEquals(
136
                    200,
137
                    $page->getStatusCode(),
138
                    "Payment Method set.  The summary page should load."
139
                );
140
141
                // Summary
142
                $page = $self->submitForm("PaymentForm_ConfirmationForm", "action_checkoutSubmit", array(
143
                    'PaymentForm_ConfirmationForm_Notes' => 'Test',
144
                ));
145
                $self->assertEquals(
146
                    200,
147
                    $page->getStatusCode(),
148
                    "a page should load"
149
                );
150
151
152
                $self->assertContains(
153
                    'XX-3456-7891011-XX',
154
                    $page->getBody(),
155
                    "Account Page contains bank deposit instructions"
156
                );
157
158
                $self->assertContains(
159
                    'Hey bo, just pop the dosh in the account',
160
                    $page->getBody(),
161
                    "Bank Account Invoice Message delivered"
162
                );
163
164
                $self->assertContains(
165
                    'CheckoutPage_order.ss',
166
                    $page->getBody(),
167
                    "CheckoutPage_order.ss template is used"
168
                );
169
170
                $self->assertEmailSent(
171
                    '[email protected]'
172
                );
173
            }
174
        );
175
    }
176
}
177