Completed
Pull Request — master (#10)
by Franco
01:51
created

testDoRequestSend()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 29
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
class DMSDocumentCartCheckoutPageTest extends FunctionalTest
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
    protected static $fixture_file = 'DMSDocumentCartTest.yml';
6
    /**
7
     * @var DMSDocumentCartCheckoutPage_Controller
8
     */
9
    protected $controller;
10
11
    /**
12
     * @var DMSDocumentCart
13
     */
14
    protected $cart;
15
16
    public function setUp()
17
    {
18
        parent::setUp();
19
        $this->controller = DMSDocumentCartCheckoutPage_Controller::create();
20
        $this->cart = $this->controller->getCart();
21
    }
22
23
    /*
24
     * Tests DMSDocumentRequest form has a FieldList
25
     */
26
    public function testDMSDocumentRequestForm()
27
    {
28
        $form = $this->controller->DMSDocumentRequestForm();
29
        $this->assertInstanceOf('FieldList', $form->Fields());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
30
    }
31
32
    /**
33
     * Tests if the DMSDocumentRequestForm is extensible
34
     */
35
    public function testDMSDocumentRequestFormIsExtensible()
36
    {
37
        DMSDocumentCartCheckoutPage_Controller::add_extension('StubDMSDocumentCheckoutPageExtension');
38
39
        $controller = DMSDocumentCartCheckoutPage_Controller::create();
40
        $form = $controller->DMSDocumentRequestForm();
41
        $this->assertNotNull(
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
42
            $form->Fields()->fieldByName('NewTextField'),
43
            'DMSDocumentRequestForm() is extensible as it included the field from the extension'
44
        );
45
    }
46
47
    /**
48
     * Tests if print requests are incremented
49
     */
50 View Code Duplication
    public function testTrackTimestampedPrintRequest()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
53
        /** @var DMSRequestItem $item */
54
        $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2);
0 ignored issues
show
Documentation introduced by
$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);
Loading history...
55
        $this->cart->addItem($item);
56
57
        $this->controller->trackTimestampedPrintRequest();
58
        $this->assertEquals(1, $item->getDocument()->PrintRequestCount);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
59
    }
60
61
    /**
62
     * Tests if a Cart is received
63
     */
64
    public function testGetCart()
65
    {
66
        $this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
67
    }
68
69
    /**
70
     * Tests whether the cart items are updated from the controller
71
     */
72
    public function testUpdateCartItems()
73
    {
74
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
75
        /** @var DMSRequestItem $item */
76
        $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2);
0 ignored issues
show
Documentation introduced by
$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);
Loading history...
77
        $this->cart->addItem($item);
78
        $updatedQuantities = array(
79
            'ItemQuantity' => array($doc->ID => 5),
80
        );
81
        $this->controller->updateCartItems($updatedQuantities);
82
        $this->assertEquals(6, $this->cart->getItem($item->getItemId())->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
83
    }
84
85
    /**
86
     * Tests whether the recipient details are updated from the controller
87
     */
88
    public function testUpdateCartReceiverInfo()
89
    {
90
        $newInfo = array(
91
            'ReceiverName'            => 'Joe Soap',
92
            'ReceiverPhone'           => '111',
93
            'ReceiverEmail'           => '[email protected]',
94
            'DeliveryAddressLine1'    => 'A1',
95
            'DeliveryAddressLine2'    => 'A2',
96
            'DeliveryAddressCountry'  => 'NZ',
97
            'DeliveryAddressPostCode' => '6011',
98
        );
99
        $this->controller->updateCartReceiverInfo($newInfo);
100
        $this->assertEquals($newInfo, $this->cart->getReceiverInfo());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
101
    }
102
103
    /**
104
     * Tests whether emails are sent. Emails are mocked so not actually sent.
105
     */
106
    public function testSend()
107
    {
108
        // Set admin email
109
        Config::inst()->update('Email', 'admin_email', 'admin');
110
        // Temporarily replace default email service
111
        Injector::inst()->registerService(new StubEmail(), 'Email');
0 ignored issues
show
Documentation introduced by
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);
Loading history...
112
        $page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1');
113
        /** @var DMSDocumentCartCheckoutPage_Controller $controller */
114
        $controller = ModelAsController::controller_for($page);
0 ignored issues
show
Documentation introduced by
$page is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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);
Loading history...
115
        $data = array(
116
            'ReceiverName'            => 'Joe Soap',
117
            'ReceiverPhone'           => '111',
118
            'ReceiverEmail'           => '[email protected]',
119
            'DeliveryAddressLine1'    => 'A1',
120
            'DeliveryAddressLine2'    => 'A2',
121
            'DeliveryAddressCountry'  => 'NZ',
122
            'DeliveryAddressPostCode' => '6011'
123
        );
124
        $this->cart->setReceiverInfo($data);
125
        $result = $controller->send();
126
        $this->assertTrue(is_array($result));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
127
        $this->assertEquals('[email protected]', $result['to']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
128
        $this->assertEquals('admin', $result['from']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
129
    }
130
131
    /**
132
     * Tests whether email sending is extensible.
133
     */
134
    public function testSendIsExtensible()
135
    {
136
        DMSDocumentCartCheckoutPage_Controller::add_extension('StubDMSDocumentCheckoutPageExtension');
137
        Injector::inst()->registerService(new StubEmail(), 'Email');
0 ignored issues
show
Documentation introduced by
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);
Loading history...
138
        $page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1');
139
        /** @var DMSDocumentCartCheckoutPage_Controller $controller */
140
        $controller = ModelAsController::controller_for($page);
0 ignored issues
show
Documentation introduced by
$page is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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);
Loading history...
141
        $result = $controller->send();
142
        $this->assertEquals('Subject is changed', $result['subject']);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
143
    }
144
145
    /**
146
     * Test to see whether the cart is empty after a request is sent.
147
     */
148
    public function testDoRequestSend()
149
    {
150
        Injector::inst()->registerService(new StubEmail(), 'Email');
0 ignored issues
show
Documentation introduced by
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);
Loading history...
151
        $page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1');
152
        /** @var DMSDocumentCartCheckoutPage_Controller $controller */
153
        $controller = ModelAsController::controller_for($page);
0 ignored issues
show
Documentation introduced by
$page is of type object<DataObject>|null, but the function expects a object<SiteTree>.

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);
Loading history...
154
        // Form for use later
155
        $form = $controller->DMSDocumentRequestForm();
156
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
157
        // Add some an item to the cart to assert later that its empty
158
        $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(15);
0 ignored issues
show
Documentation introduced by
$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);
Loading history...
159
        $controller->getCart()->addItem($item);
160
        $data = array(
161
            'ReceiverName'            => 'Joe Soap',
162
            'ReceiverPhone'           => '111',
163
            'ReceiverEmail'           => '[email protected]',
164
            'DeliveryAddressLine1'    => 'A1',
165
            'DeliveryAddressLine2'    => 'A2',
166
            'DeliveryAddressCountry'  => 'NZ',
167
            'DeliveryAddressPostCode' => '6011',
168
            'ItemQuantity'            => array($doc->ID => 5),
169
        );
170
        $request = new SS_HTTPRequest('POST', 'mock/url');
171
        // Assert cart is empty
172
        $this->assertFalse($controller->getCart()->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
173
        $result = $controller->doRequestSend($data, $form, $request);
174
        $this->assertInstanceOf('SS_HTTPResponse', $result);
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
175
        $this->assertTrue($controller->getCart()->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartCheckoutPageTest>.

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.

Loading history...
176
    }
177
}
178