This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | class DMSCheckoutControllerTest extends FunctionalTest |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | protected static $fixture_file = 'dms-cart/tests/DMSDocumentCartTest.yml'; |
||
6 | |||
7 | /** |
||
8 | * @var DMSCheckoutController |
||
9 | */ |
||
10 | protected $controller; |
||
11 | |||
12 | /** |
||
13 | * @var DMSDocumentCart |
||
14 | */ |
||
15 | protected $cart; |
||
16 | |||
17 | public function setUp() |
||
18 | { |
||
19 | parent::setUp(); |
||
20 | |||
21 | DMSCheckoutController::add_extension('StubDMSDocumentCheckoutPageExtension'); |
||
22 | Injector::inst()->registerService(new StubEmail(), 'Email'); |
||
0 ignored issues
–
show
new \StubEmail() is of type object<StubEmail> , but the function expects a object<stdClass> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
23 | |||
24 | $this->controller = DMSCheckoutController::create(); |
||
25 | $this->cart = $this->controller->getCart(); |
||
26 | } |
||
27 | |||
28 | /** |
||
29 | * Tests DMSDocumentRequest form has a FieldList |
||
30 | */ |
||
31 | public function testDMSDocumentRequestForm() |
||
32 | { |
||
33 | $form = $this->controller->DMSDocumentRequestForm(); |
||
34 | $this->assertInstanceOf('FieldList', $form->Fields()); |
||
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<DMSCheckoutControllerTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
35 | } |
||
36 | |||
37 | /** |
||
38 | * Tests if the DMSDocumentRequestForm is extensible |
||
39 | */ |
||
40 | public function testDMSDocumentRequestFormIsExtensible() |
||
41 | { |
||
42 | $controller = $this->controller; |
||
43 | $form = $controller->DMSDocumentRequestForm(); |
||
44 | $this->assertNotNull( |
||
0 ignored issues
–
show
The method
assertNotNull() does not seem to exist on object<DMSCheckoutControllerTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
45 | $form->Fields()->fieldByName('NewTextField'), |
||
46 | 'DMSDocumentRequestForm() is extensible as it included the field from the extension' |
||
47 | ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * Tests whether the recipient details are updated from the controller |
||
52 | */ |
||
53 | public function testUpdateCartReceiverInfo() |
||
54 | { |
||
55 | $newInfo = array( |
||
56 | 'ReceiverName' => 'Joe Soap', |
||
57 | 'ReceiverPhone' => '111', |
||
58 | 'ReceiverEmail' => '[email protected]', |
||
59 | 'DeliveryAddressLine1' => 'A1', |
||
60 | 'DeliveryAddressLine2' => 'A2', |
||
61 | 'DeliveryAddressCountry' => 'NZ', |
||
62 | 'DeliveryAddressPostCode' => '6011', |
||
63 | ); |
||
64 | $this->controller->updateCartReceiverInfo($newInfo); |
||
65 | $this->assertEquals($newInfo, $this->cart->getReceiverInfo()); |
||
66 | } |
||
67 | |||
68 | /** |
||
69 | * Tests whether emails are sent. Emails are mocked so not actually sent. |
||
70 | */ |
||
71 | public function testSend() |
||
72 | { |
||
73 | // Set admin email |
||
74 | Config::inst()->update('Email', 'admin_email', 'admin'); |
||
75 | $data = array( |
||
76 | 'ReceiverName' => 'Joe Soap', |
||
77 | 'ReceiverPhone' => '111', |
||
78 | 'ReceiverEmail' => '[email protected]', |
||
79 | 'DeliveryAddressLine1' => 'A1', |
||
80 | 'DeliveryAddressLine2' => 'A2', |
||
81 | 'DeliveryAddressCountry' => 'NZ', |
||
82 | 'DeliveryAddressPostCode' => '6011' |
||
83 | ); |
||
84 | $this->cart->setReceiverInfo($data); |
||
85 | $result = $this->controller->send(); |
||
86 | $this->assertTrue(is_array($result)); |
||
87 | $this->assertEquals('[email protected]', $result['to']); |
||
88 | $this->assertEquals('admin', $result['from']); |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * Tests whether email sending is extensible. |
||
93 | */ |
||
94 | public function testSendIsExtensible() |
||
95 | { |
||
96 | $result = $this->controller->send(); |
||
97 | $this->assertEquals('Subject is changed', $result['subject']); |
||
98 | } |
||
99 | |||
100 | /** |
||
101 | * Test to see whether the cart is empty after a request is sent. |
||
102 | */ |
||
103 | public function testDoRequestSend() |
||
104 | { |
||
105 | // Form for use later |
||
106 | $form = $this->controller->DMSDocumentRequestForm(); |
||
107 | $doc = $this->objFromFixture('DMSDocument', 'doc1'); |
||
108 | // Add some an item to the cart to assert later that its empty |
||
109 | $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(15); |
||
0 ignored issues
–
show
$doc is of type object<DataObject>|null , but the function expects a object<DMSDocument> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
![]() |
|||
110 | $this->controller->getCart()->addItem($item); |
||
111 | $data = array( |
||
112 | 'ReceiverName' => 'Joe Soap', |
||
113 | 'ReceiverPhone' => '111', |
||
114 | 'ReceiverEmail' => '[email protected]', |
||
115 | 'DeliveryAddressLine1' => 'A1', |
||
116 | 'DeliveryAddressLine2' => 'A2', |
||
117 | 'DeliveryAddressCountry' => 'NZ', |
||
118 | 'DeliveryAddressPostCode' => '6011', |
||
119 | 'ItemQuantity' => array($doc->ID => 5), |
||
120 | ); |
||
121 | $request = new SS_HTTPRequest('POST', 'mock/url'); |
||
122 | // Assert cart is empty |
||
123 | $this->assertFalse($this->controller->getCart()->isCartEmpty()); |
||
0 ignored issues
–
show
The method
assertFalse() does not seem to exist on object<DMSCheckoutControllerTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
124 | $result = $this->controller->doRequestSend($data, $form, $request); |
||
125 | $this->assertInstanceOf('SS_HTTPResponse', $result); |
||
0 ignored issues
–
show
The method
assertInstanceOf() does not seem to exist on object<DMSCheckoutControllerTest> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
126 | $this->assertTrue($this->controller->getCart()->isCartEmpty()); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * Test the checkout success page shows a pretty message |
||
131 | */ |
||
132 | public function testCompletePage() |
||
133 | { |
||
134 | $result = (string) $this->get('checkout/complete')->getBody(); |
||
135 | $this->assertContains('Thanks!', $result); |
||
136 | $this->assertContains('You will receive a confirmation email', $result); |
||
137 | } |
||
138 | |||
139 | /** |
||
140 | * Test that the items in my cart are listed on the checkout page, and that some form fields exist |
||
141 | */ |
||
142 | public function testIndexCheckoutForm() |
||
143 | { |
||
144 | $backend = DMSSessionBackend::singleton(); |
||
145 | $document = $this->objFromFixture('DMSDocument', 'limited_supply'); |
||
146 | $requestItem = DMSRequestItem::create($document); |
||
147 | $backend->addItem($requestItem); |
||
148 | |||
149 | $response = $this->get('checkout'); |
||
150 | $this->assertEquals(200, $response->getStatusCode()); |
||
151 | |||
152 | $body = (string) $response->getBody(); |
||
153 | $this->assertContains('Checkout', $body); |
||
154 | $this->assertContains('Your request in summary', $body); |
||
155 | $this->assertContains('Doc3', $body); |
||
156 | $this->assertContains('Receiver Name', $body); |
||
157 | } |
||
158 | |||
159 | /** |
||
160 | * Ensure the link is "friendly", not a class name |
||
161 | */ |
||
162 | public function testLink() |
||
163 | { |
||
164 | $this->assertSame('checkout', $this->controller->Link()); |
||
165 | $this->assertSame('checkout/complete', $this->controller->Link('complete')); |
||
166 | } |
||
167 | } |
||
168 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.