Completed
Push — master ( e73c04...6d0dfa )
by Antony
02:23
created

testEmailIsSentUponStepCheckoutCompletion()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 83
Code Lines 57

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 57
dl 0
loc 83
rs 8.9381
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Core\Manifest\ModuleManifest;
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 BankDepositCheckoutPageTest 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 laptop
0 ignored issues
show
Bug introduced by
The type AntonyThorpe\SilverShopBankDeposit\Tests\laptop 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...
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
        ModuleManifest::config()->set('module_priority', ['silvershop-bankdeposit', 'silvershop']);
48
49
        $siteconfig = DataObject::get_one(SiteConfig::class);
50
        $siteconfig->BankAccountPaymentMethodMessage = "You will be notified of the bank account details";
51
        $siteconfig->BankAccountNumber = "XX-3456-7891011-XX";
52
        $siteconfig->BankAccountDetails = "TestBank, Business Branch";
53
        $siteconfig->BankAccountInvoiceMessage = "Hey bo, just pop the dosh in the account";
54
        $siteconfig->write();
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\SilverShopBankDeposit\Tests\laptop 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
        $accountpage = $this->objFromFixture(AccountPage::class, "accountpage");
65
        $accountpage->publishSingle();
66
67
        // Login member
68
        $member = $this->objFromFixture(Member::class, "joebloggs");
69
        $this->logInAs($member);
70
71
        //add item to cart via url
72
        $this->get(ShoppingCartController::add_item_link($this->laptop));
0 ignored issues
show
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

72
        $this->get(ShoppingCartController::add_item_link(/** @scrutinizer ignore-type */ $this->laptop));
Loading history...
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

72
        $this->get(/** @scrutinizer ignore-type */ ShoppingCartController::add_item_link($this->laptop));
Loading history...
73
    }
74
75
    public function testEmailIsSentUponStepCheckoutCompletion()
76
    {
77
        $self = $this;
78
        $this->useTestTheme(
79
            dirname(__FILE__),
80
            'testtheme',
81
            function () use ($self) {
82
                $page = $self->get("checkout/");
83
                $self->assertEquals(
84
                    200,
85
                    $page->getStatusCode(),
86
                    "contact details page should load"
87
                );
88
89
                // contact form
90
                $page = $self->submitForm("CheckoutForm_ContactDetailsForm", "action_checkoutSubmit", array(
91
                    'CustomerDetailsCheckoutComponent_FirstName' => 'Joe',
92
                    'CustomerDetailsCheckoutComponent_Surname' => 'Bloggs',
93
                    'CustomerDetailsCheckoutComponent_Email' => '[email protected]'
94
                ));
95
                $self->assertEquals(
96
                    200,
97
                    $page->getStatusCode(),
98
                    "enter contact details page should load"
99
                );
100
101
                // Shipping Address form
102
                $page = $self->submitForm("CheckoutForm_ShippingAddressForm", "action_setshippingaddress", array(
103
                    'ShippingAddressCheckoutComponent_Country' => 'AU',
104
                    'ShippingAddressCheckoutComponent_Address' => '201-203 BROADWAY AVE',
105
                    'ShippingAddressCheckoutComponent_AddressLine2' => 'U 235',
106
                    'ShippingAddressCheckoutComponent_City' => 'WEST BEACH',
107
                    'ShippingAddressCheckoutComponent_State' => 'South Australia',
108
                    'ShippingAddressCheckoutComponent_PostalCode' => '5024',
109
                    'ShippingAddressCheckoutComponent_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
                // Payment Method can be manual
126
                $page = $self->submitForm("CheckoutForm_PaymentMethodForm", "action_setpaymentmethod", array(
127
                    'PaymentMethod' => 'Manual',
128
                ));
129
                $self->assertEquals(
130
                    200,
131
                    $page->getStatusCode(),
132
                    "enter summary page should load"
133
                );
134
135
                // Summary
136
                $page = $self->submitForm("PaymentForm_ConfirmationForm", "action_checkoutSubmit", array(
137
                    'PaymentForm_ConfirmationForm_Notes' => 'Test',
138
                ));
139
                $self->assertEquals(
140
                    200,
141
                    $page->getStatusCode(),
142
                    "enter summary page should load"
143
                );
144
                $self->assertContains(
145
                    '<h2>My Account</h2>',
146
                    $page->getBody(),
147
                    "Account Page should load"
148
                );
149
150
                $self->assertContains(
151
                    'XX-3456-7891011-XX',
152
                    $page->getBody(),
153
                    "Account Page contains bank deposit instructions"
154
                );
155
156
                $self->assertEmailSent(
157
                    '[email protected]'
158
                );
159
            }
160
        );
161
    }
162
}
163