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 SteppedCheckoutPageTest extends FunctionalTest |
||||||
25 | { |
||||||
26 | protected static $fixture_file = [ |
||||||
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 Product |
||||||
37 | */ |
||||||
38 | protected $laptop; |
||||||
39 | |||||||
40 | public function setUp(): void |
||||||
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
|
|||||||
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
$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
Loading history...
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
Loading history...
|
|||||||
73 | ShoppingCart::curr()->calculate(); |
||||||
74 | } |
||||||
75 | |||||||
76 | public function testEmailIsSentUponStepCheckoutCompletion() |
||||||
77 | { |
||||||
78 | $self = $this; |
||||||
79 | $this->useTestTheme( |
||||||
80 | dirname(__FILE__), |
||||||
81 | 'testtheme', |
||||||
82 | function () use ($self) { |
||||||
83 | $page = $self->get("checkout/"); |
||||||
84 | $self->assertEquals( |
||||||
85 | 200, |
||||||
86 | $page->getStatusCode(), |
||||||
87 | "contact details page should load" |
||||||
88 | ); |
||||||
89 | |||||||
90 | // contact form |
||||||
91 | $page = $self->submitForm("CheckoutForm_ContactDetailsForm", "action_checkoutSubmit", [ |
||||||
92 | 'CustomerDetailsCheckoutComponent_FirstName' => 'Joe', |
||||||
93 | 'CustomerDetailsCheckoutComponent_Surname' => 'Bloggs', |
||||||
94 | 'CustomerDetailsCheckoutComponent_Email' => '[email protected]' |
||||||
95 | ]); |
||||||
96 | $self->assertEquals( |
||||||
97 | 200, |
||||||
98 | $page->getStatusCode(), |
||||||
99 | "enter contact details page should load" |
||||||
100 | ); |
||||||
101 | |||||||
102 | // Shipping Address form |
||||||
103 | $page = $self->submitForm("CheckoutForm_ShippingAddressForm", "action_setshippingaddress", [ |
||||||
104 | 'ShippingAddressCheckoutComponent_Country' => 'AU', |
||||||
105 | 'ShippingAddressCheckoutComponent_Address' => '201-203 BROADWAY AVE', |
||||||
106 | 'ShippingAddressCheckoutComponent_AddressLine2' => 'U 235', |
||||||
107 | 'ShippingAddressCheckoutComponent_City' => 'WEST BEACH', |
||||||
108 | 'ShippingAddressCheckoutComponent_State' => 'South Australia', |
||||||
109 | 'ShippingAddressCheckoutComponent_PostalCode' => '5024', |
||||||
110 | 'ShippingAddressCheckoutComponent_Phone' => '', |
||||||
111 | 'SeperateBilling' => false |
||||||
112 | |||||||
113 | ]); |
||||||
114 | $self->assertEquals( |
||||||
115 | 200, |
||||||
116 | $page->getStatusCode(), |
||||||
117 | "payment methods page should load" |
||||||
118 | ); |
||||||
119 | |||||||
120 | $self->assertStringContainsString( |
||||||
121 | "CheckoutForm_PaymentMethodForm_PaymentMethod_Manual", |
||||||
122 | $page->getBody(), |
||||||
123 | "Manual payment method available" |
||||||
124 | ); |
||||||
125 | |||||||
126 | $self->assertStringContainsString( |
||||||
127 | "You will be notified of the bank account details", |
||||||
128 | $page->getBody(), |
||||||
129 | "Bank Account Message presented during the payment method section" |
||||||
130 | ); |
||||||
131 | |||||||
132 | // Payment Method can be manual |
||||||
133 | $page = $self->submitForm("CheckoutForm_PaymentMethodForm", "action_setpaymentmethod", [ |
||||||
134 | 'PaymentMethod' => 'Manual', |
||||||
135 | ]); |
||||||
136 | $self->assertEquals( |
||||||
137 | 200, |
||||||
138 | $page->getStatusCode(), |
||||||
139 | "Payment Method set. The summary page should load." |
||||||
140 | ); |
||||||
141 | |||||||
142 | // Summary |
||||||
143 | $page = $self->submitForm("PaymentForm_ConfirmationForm", "action_checkoutSubmit", [ |
||||||
144 | 'PaymentForm_ConfirmationForm_Notes' => 'Test', |
||||||
145 | ]); |
||||||
146 | $self->assertEquals( |
||||||
147 | 200, |
||||||
148 | $page->getStatusCode(), |
||||||
149 | "enter summary page should load" |
||||||
150 | ); |
||||||
151 | $self->assertStringContainsString( |
||||||
152 | 'XX-3456-7891011-XX', |
||||||
153 | $page->getBody(), |
||||||
154 | "Account Page contains bank deposit instructions" |
||||||
155 | ); |
||||||
156 | $self->assertEmailSent( |
||||||
157 | '[email protected]' |
||||||
158 | ); |
||||||
159 | } |
||||||
160 | ); |
||||||
161 | } |
||||||
162 | } |
||||||
163 |
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..