Completed
Push — master ( 3bd471...8319fc )
by
unknown
32s queued 27s
created

DMSDocumentCartControllerTest::testAdd()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 27
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 18
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class DMSDocumentCartControllerTest contains all the tests for {@link DMSDocumentCartController}
5
 */
6
class DMSDocumentCartControllerTest 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...
7
{
8
    protected static $fixture_file = 'DMSDocumentCartTest.yml';
9
10
    /**
11
     * @var DMSDocumentCartController
12
     */
13
    protected $controller;
14
15
    /**
16
     * @var DMSDocumentCart
17
     */
18
    protected $cart;
19
20
    public function setUp()
21
    {
22
        parent::setUp();
23
        $this->controller = DMSDocumentCartController::create();
24
        $this->cart = $this->controller->getCart();
25
    }
26
27
    /**
28
     * Test the items method of the controller
29
     */
30
    public function testItems()
31
    {
32
        /** @var DMSDocument $doc1 */
33
        $doc1 = $this->objFromFixture('DMSDocument', 'doc1');
34
        /** @var DMSDocument $doc2 */
35
        $doc2 = $this->objFromFixture('DMSDocument', 'doc2');
36
        /** @var DMSRequestItem $item */
37
        $item1 = DMSRequestItem::create()->setDocument($doc1)->setQuantity(2);
38
        $item2 = DMSRequestItem::create()->setDocument($doc2)->setQuantity(5);
39
        $this->cart->addItem($item1);
40
        $this->cart->addItem($item2);
41
        $this->assertInstanceOf(
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartControllerTest>.

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
            'ArrayList',
43
            $this->controller->items(),
44
            'DMSDocumentCartController->Items() returned an ArrayList'
45
        );
46
        $this->assertCount(
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
47
            2,
48
            $this->controller->items(),
49
            'DMSDocumentCartController->Items()->count() returned the requisite number of items'
50
        );
51
    }
52
53
    public function testReceiverInfo()
54
    {
55
        // Now add some info
56
        $this->cart->setReceiverInfo(array('Name' => 'Joe', 'Surname' => 'Soap'));
57
        $this->assertCount(2, $this->controller->getReceiverInfo());
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
58
    }
59
60
    public function testIsCartEmpty()
61
    {
62
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
63
        /** @var DMSDocument $doc */
64
        $doc1 = $this->objFromFixture('DMSDocument', 'doc1');
65
        /** @var DMSRequestItem $item */
66
        $item1 = DMSRequestItem::create()->setDocument($doc1)->setQuantity(2);
0 ignored issues
show
Documentation introduced by
$doc1 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...
67
        $this->cart->addItem($item1);
68
        $this->assertFalse($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
69
    }
70
71
    public function testAdd()
72
    {
73
        $this->logInWithPermission();
74
        $doc1 = $this->objFromFixture('DMSDocument', 'doc1');
75
        // Check cart is initially empty
76
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
77
        // Now call controller add
78
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => 5));
79
        $request->setRouteParams(array('ID' => $doc1->ID));
80
        $this->controller->add($request);
81
        $this->assertFalse($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
82
83
        // Do it again and assert quantity was updated
84
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => 7));
85
        $request->setRouteParams(array('ID' => $doc1->ID));
86
        $this->controller->add($request);
87
88
        // Test ajax
89
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => 7, 'ajax' => 1));
90
        $request->setRouteParams(array('ID' => $doc1->ID));
91
        $response = $this->controller->add($request);
92
        $this->assertTrue($request->isAjax());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
93
        $this->assertJson($response, 'Confirmed that an ajax call to add() responded with json JSON');
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
94
95
        $item = $this->cart->getItem($doc1->ID);
96
        $this->assertEquals(19, $item->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
97
    }
98
99
100
101
    public function testDeduct()
102
    {
103
        $doc1 = $this->objFromFixture('DMSDocument', 'doc1');
104
        // Check catty is initially empty
105
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
106
        // Now call controller add
107
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity'=>5));
108
        $request->setRouteParams(array('ID' => $doc1->ID));
109
        $this->controller->deduct($request);
110
        // Assert cart still empty because item doesn't exist
111
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
112
        // Now add item
113
        $this->controller->add($request);
114
        $this->assertFalse($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
115
116
117
        // Now try and deduct 2 from the items
118
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => -2));
119
        $request->setRouteParams(array('ID' => $doc1->ID));
120
        $this->controller->deduct($request);
121
122
        $item = $this->cart->getItem($doc1->ID);
123
        $this->assertEquals(3, $item->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
124
125
        // Test ajax
126
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => 7, 'ajax' => 1));
127
        $request->setRouteParams(array('ID' => $doc1->ID));
128
        $response = $this->controller->deduct($request);
129
        $this->assertTrue($request->isAjax());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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
        $this->assertJson($response, 'Confirmed that an ajax call to deduct() method responded with JSON');
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
131
    }
132
133
    public function testRemove()
134
    {
135
        $doc1 = $this->objFromFixture('DMSDocument', 'doc1');
136
        // Check catty is initially empty
137
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
138
        // Now call controller add
139
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity'=>5));
140
        $request->setRouteParams(array('ID' => $doc1->ID));
141
        // Now add item
142
        $this->controller->add($request);
143
        $this->assertFalse($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
144
        $this->controller->remove($request);
145
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
146
147
        // Test ajax
148
        $request = new SS_HTTPRequest('POST', '', array(), array('quantity' => 7, 'ajax' => 1));
149
        $request->setRouteParams(array('ID' => $doc1->ID));
150
        $response = $this->controller->remove($request);
151
        $this->assertTrue($request->isAjax());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
152
        $this->assertJson($response, 'Confirmed that  an ajax call to remove() method responded with JSON');
0 ignored issues
show
Bug introduced by
The method assertJson() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
153
    }
154
155
    public function testCart()
156
    {
157
        $this->assertInstanceOf('DMSDocumentCart', $this->controller->getCart());
0 ignored issues
show
Bug introduced by
The method assertInstanceOf() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
158
        //For good measure assert it's empty
159
        $this->assertTrue($this->controller->getIsCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartControllerTest>.

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...
160
    }
161
}
162