1 | <?php |
||
2 | |||
3 | namespace AntonyThorpe\SilverShopBankDeposit\Tests; |
||
4 | |||
5 | use SilverStripe\Dev\FunctionalTest; |
||
6 | use SilverStripe\Omnipay\Model\Payment; |
||
7 | use SilverStripe\SiteConfig\SiteConfig; |
||
8 | use SilverStripe\Core\Config\Config; |
||
9 | use SilverStripe\ORM\DataObject; |
||
10 | use SilverShop\Tests\ShopTest; |
||
11 | use SilverShop\Extension\SteppedCheckoutExtension; |
||
12 | use SilverShop\Page\Product; |
||
13 | use SilverShop\Page\CheckoutPage; |
||
14 | use SilverShop\Page\AccountPage; |
||
15 | use SilverStripe\Security\Member; |
||
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 | /** |
||
34 | * @var $laptop |
||
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
35 | */ |
||
36 | protected $laptop; |
||
37 | |||
38 | public function setUp() |
||
39 | { |
||
40 | parent::setUp(); |
||
41 | ShopTest::setConfiguration(); |
||
42 | ShoppingCart::singleton()->clear(); |
||
43 | SteppedCheckoutExtension::setupSteps(); //use default steps |
||
44 | //set supported gateways |
||
45 | Payment::config()->allowed_gateways = array( |
||
46 | 'Manual', |
||
47 | 'Dummy' |
||
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"); |
||
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 via url |
||
72 | $this->get(ShoppingCartController::add_item_link($this->laptop)); |
||
73 | } |
||
74 | |||
75 | public function testEmailIsSentUponStepCheckoutCompletion() |
||
76 | { |
||
77 | $page = $this->get("checkout/"); |
||
78 | $this->assertEquals( |
||
79 | 200, |
||
80 | $page->getStatusCode(), |
||
81 | "contact details page should load" |
||
82 | ); |
||
83 | |||
84 | // contact form |
||
85 | $page = $this->submitForm("CheckoutForm_ContactDetailsForm", "action_checkoutSubmit", array( |
||
86 | 'CustomerDetailsCheckoutComponent_FirstName' => 'Joe', |
||
87 | 'CustomerDetailsCheckoutComponent_Surname' => 'Bloggs', |
||
88 | 'CustomerDetailsCheckoutComponent_Email' => '[email protected]' |
||
89 | )); |
||
90 | $this->assertEquals( |
||
91 | 200, |
||
92 | $page->getStatusCode(), |
||
93 | "enter contact details page should load" |
||
94 | ); |
||
95 | |||
96 | // Shipping Address form |
||
97 | $page = $this->submitForm("CheckoutForm_ShippingAddressForm", "action_setshippingaddress", array( |
||
98 | 'ShippingAddressCheckoutComponent_Country' => 'AU', |
||
99 | 'ShippingAddressCheckoutComponent_Address' => '201-203 BROADWAY AVE', |
||
100 | 'ShippingAddressCheckoutComponent_AddressLine2' => 'U 235', |
||
101 | 'ShippingAddressCheckoutComponent_City' => 'WEST BEACH', |
||
102 | 'ShippingAddressCheckoutComponent_State' => 'South Australia', |
||
103 | 'ShippingAddressCheckoutComponent_PostalCode' => '5024', |
||
104 | 'ShippingAddressCheckoutComponent_Phone' => '', |
||
105 | 'SeperateBilling' => '0' |
||
106 | |||
107 | )); |
||
108 | $this->assertEquals( |
||
109 | 200, |
||
110 | $page->getStatusCode(), |
||
111 | "payment methods page should load" |
||
112 | ); |
||
113 | |||
114 | $this->assertContains( |
||
115 | "CheckoutForm_PaymentMethodForm_PaymentMethod_Manual", |
||
116 | $page->getBody(), |
||
117 | "Manual payment method available" |
||
118 | ); |
||
119 | |||
120 | // Payment Method can be manual |
||
121 | $page = $this->submitForm("CheckoutForm_PaymentMethodForm", "action_setpaymentmethod", array( |
||
122 | 'PaymentMethod' => 'Manual', |
||
123 | )); |
||
124 | $this->assertEquals( |
||
125 | 200, |
||
126 | $page->getStatusCode(), |
||
127 | "enter summary page should load" |
||
128 | ); |
||
129 | |||
130 | // Summary |
||
131 | $page = $this->submitForm("PaymentForm_ConfirmationForm", "action_checkoutSubmit", array( |
||
132 | 'PaymentForm_ConfirmationForm_Notes' => 'Test', |
||
133 | )); |
||
134 | $this->assertEquals( |
||
135 | 200, |
||
136 | $page->getStatusCode(), |
||
137 | "enter summary page should load" |
||
138 | ); |
||
139 | $this->assertContains( |
||
140 | '<h2>My Account</h2>', |
||
141 | $page->getBody(), |
||
142 | "Account Page should load" |
||
143 | ); |
||
144 | |||
145 | $this->assertContains( |
||
146 | 'XX-3456-7891011-XX', |
||
147 | $page->getBody(), |
||
148 | "Account Page contains bank deposit instructions" |
||
149 | ); |
||
150 | |||
151 | $this->assertEmailSent( |
||
152 | '[email protected]' |
||
153 | ); |
||
154 | } |
||
155 | } |
||
156 |