Completed
Push — master ( 24eac7...3bd471 )
by Robbie
11s
created

testDMSDocumentRequestFormIsExtensible()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
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
    /**
17
     * @var DMSDocumentCartCheckoutPage
18
     */
19
    protected $page;
20
21
    public function setUp()
22
    {
23
        parent::setUp();
24
        $this->page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1');
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->objFromFixture('D...CheckoutPage', 'page1') can also be of type object<DataObject>. However, the property $page is declared as type object<DMSDocumentCartCheckoutPage>. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
25
        DMSDocumentCartCheckoutPage_Controller::add_extension('StubDMSDocumentCheckoutPageExtension');
26
        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...
27
        $this->controller = ModelAsController::controller_for($this->page);
0 ignored issues
show
Documentation introduced by
$this->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...
28
        $this->cart = $this->controller->getCart();
29
    }
30
31
    /**
32
     * Tests DMSDocumentRequest form has a FieldList
33
     */
34
    public function testDMSDocumentRequestForm()
35
    {
36
        $form = $this->controller->DMSDocumentRequestForm();
37
        $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...
38
    }
39
40
    /**
41
     * Tests if the DMSDocumentRequestForm is extensible
42
     */
43
    public function testDMSDocumentRequestFormIsExtensible()
44
    {
45
        $controller = $this->controller;
46
        $form = $controller->DMSDocumentRequestForm();
47
        $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...
48
            $form->Fields()->fieldByName('NewTextField'),
49
            'DMSDocumentRequestForm() is extensible as it included the field from the extension'
50
        );
51
    }
52
53
    /**
54
     * Tests if print requests are incremented
55
     */
56 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...
57
    {
58
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
59
        /** @var DMSRequestItem $item */
60
        $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...
61
        $this->cart->addItem($item);
62
63
        $this->controller->trackTimestampedPrintRequest();
64
        $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...
65
    }
66
67
    /**
68
     * Tests if a Cart is received
69
     */
70
    public function testGetCart()
71
    {
72
        $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...
73
    }
74
75
    /**
76
     * Tests whether the cart items are updated from the controller
77
     */
78
    public function testUpdateCartItems()
79
    {
80
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
81
        /** @var DMSRequestItem $item */
82
        $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...
83
        $this->cart->addItem($item);
84
        $updatedQuantities = array(
85
            'ItemQuantity' => array($doc->ID => 5),
86
        );
87
        $this->controller->updateCartItems($updatedQuantities);
88
        $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...
89
    }
90
91
    /**
92
     * Tests whether the recipient details are updated from the controller
93
     */
94
    public function testUpdateCartReceiverInfo()
95
    {
96
        $newInfo = array(
97
            'ReceiverName'            => 'Joe Soap',
98
            'ReceiverPhone'           => '111',
99
            'ReceiverEmail'           => '[email protected]',
100
            'DeliveryAddressLine1'    => 'A1',
101
            'DeliveryAddressLine2'    => 'A2',
102
            'DeliveryAddressCountry'  => 'NZ',
103
            'DeliveryAddressPostCode' => '6011',
104
        );
105
        $this->controller->updateCartReceiverInfo($newInfo);
106
        $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...
107
    }
108
109
    /**
110
     * Tests whether emails are sent. Emails are mocked so not actually sent.
111
     */
112
    public function testSend()
113
    {
114
        // Set admin email
115
        Config::inst()->update('Email', 'admin_email', 'admin');
116
        $data = array(
117
            'ReceiverName'            => 'Joe Soap',
118
            'ReceiverPhone'           => '111',
119
            'ReceiverEmail'           => '[email protected]',
120
            'DeliveryAddressLine1'    => 'A1',
121
            'DeliveryAddressLine2'    => 'A2',
122
            'DeliveryAddressCountry'  => 'NZ',
123
            'DeliveryAddressPostCode' => '6011'
124
        );
125
        $this->cart->setReceiverInfo($data);
126
        $result = $this->controller->send();
127
        $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...
128
        $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...
129
        $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...
130
    }
131
132
    /**
133
     * Tests whether email sending is extensible.
134
     */
135
    public function testSendIsExtensible()
136
    {
137
        $result = $this->controller->send();
138
        $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...
139
    }
140
141
    /**
142
     * Test to see whether the cart is empty after a request is sent.
143
     */
144
    public function testDoRequestSend()
145
    {
146
        // Form for use later
147
        $form = $this->controller->DMSDocumentRequestForm();
148
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
149
        // Add some an item to the cart to assert later that its empty
150
        $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...
151
        $this->controller->getCart()->addItem($item);
152
        $data = array(
153
            'ReceiverName'            => 'Joe Soap',
154
            'ReceiverPhone'           => '111',
155
            'ReceiverEmail'           => '[email protected]',
156
            'DeliveryAddressLine1'    => 'A1',
157
            'DeliveryAddressLine2'    => 'A2',
158
            'DeliveryAddressCountry'  => 'NZ',
159
            'DeliveryAddressPostCode' => '6011',
160
            'ItemQuantity'            => array($doc->ID => 5),
161
        );
162
        $request = new SS_HTTPRequest('POST', 'mock/url');
163
        // Assert cart is empty
164
        $this->assertFalse($this->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...
165
        $result = $this->controller->doRequestSend($data, $form, $request);
166
        $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...
167
        $this->assertTrue($this->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...
168
    }
169
}
170