Completed
Pull Request — master (#18)
by Franco
02:02
created

DMSDocumentCartTest::testIsInCart()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 0
1
<?php
2
3
/**
4
 * Class DMSDocumentCartTest contains all the tests for {@link DMSDocumentCart}
5
 */
6
class DMSDocumentCartTest extends SapphireTest
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 DMSDocumentCart
12
     */
13
    protected $cart;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
        $this->cart = singleton('DMSDocumentCart');
19
    }
20
21 View Code Duplication
    public function testAddItem()
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...
22
    {
23
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
24
        /** @var DMSRequestItem $item */
25
        $item = DMSRequestItem::create();
26
        $item->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...
27
        $this->cart->addItem($item);
28
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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...
29
    }
30
31 View Code Duplication
    public function testEmptyCart()
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...
32
    {
33
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
34
        /** @var DMSRequestItem $item */
35
        $item = DMSRequestItem::create();
36
        $item->setDocument($doc)->setQuantity(18);
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...
37
        $this->cart->addItem($item);
38
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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...
39
40
        $this->cart->emptyCart();
41
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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
    }
43
44
    public function testGetBackend()
45
    {
46
        /** @var DMSDocumentCart $cart */
47
        $this->assertEquals('DMSSessionBackend', get_class($this->cart->getBackend()));
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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
    }
49
50
    public function testGetBackURL()
51
    {
52
        $url = 'TestURL';
53
        $this->cart->setBackUrl($url);
54
        $this->assertEquals($url, $this->cart->getBackUrl());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
55
    }
56
57 View Code Duplication
    public function testGetItem()
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...
58
    {
59
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
60
        /** @var DMSRequestItem $item */
61
        $item = DMSRequestItem::create();
62
        $item->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...
63
        $this->cart->addItem($item);
64
65
        $this->assertEquals($doc, $this->cart->getItem($doc->ID)->getDocument());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
66
    }
67
68 View Code Duplication
    public function testGetItems()
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...
69
    {
70
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
71
        /** @var DMSRequestItem $item */
72
        $item = DMSRequestItem::create();
73
        $item->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...
74
        $this->cart->addItem($item);
75
76
        $this->assertCount(1, $this->cart->getItems());
0 ignored issues
show
Bug introduced by
The method assertCount() does not seem to exist on object<DMSDocumentCartTest>.

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
    }
78
79
    public function testGetReceiverInfo()
80
    {
81
        $info = array('Name' => 'Jane');
82
        $this->cart->setReceiverInfo($info);
83
        $this->assertEquals($info, $this->cart->getReceiverInfo());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
84
    }
85
86
    public function testIsCartEmpty()
87
    {
88
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
90
        /** @var DMSRequestItem $item */
91
        $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...
92
        $this->cart->addItem($item);
93
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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
96 View Code Duplication
    public function testRemoveItem()
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...
97
    {
98
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
99
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
100
        /** @var DMSRequestItem $item */
101
        $item = DMSRequestItem::create();
102
        $item->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...
103
        $this->cart->addItem($item);
104
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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...
105
106
        $this->cart->removeItem($item);
107
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
108
    }
109
110 View Code Duplication
    public function testRemoveItemByID()
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...
111
    {
112
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
113
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
114
        /** @var DMSRequestItem $item */
115
        $item = DMSRequestItem::create();
116
        $item->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...
117
        $this->cart->addItem($item);
118
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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...
119
120
        $this->cart->removeItemByID($doc->ID);
121
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
122
    }
123
124
    public function testUpdateItemQuantity()
125
    {
126
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
127
128
        // Test Update
129
        /** @var DMSRequestItem $item */
130
        $item = DMSRequestItem::create();
131
        $item->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...
132
        $this->cart->addItem($item);
133
        $this->assertEquals(2, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
134
135
        $this->cart->updateItemQuantity($item->getItemID(), 17);
136
        $this->assertEquals(19, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
137
138
        // Test Add
139
        $this->cart->updateItemQuantity($doc->ID, 16);
140
        $this->assertEquals(35, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
141
142
        // Test Deduct
143
        $this->cart->updateItemQuantity($doc->ID, -16);
144
        $this->assertEquals(19, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
145
146
        // Test deduct all items that it removes it
147
        $this->cart->updateItemQuantity($doc->ID, -19);
148
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
149
    }
150
151
    public function testSaveSubmission()
152
    {
153
        $page = $this->objFromFixture('DMSDocumentCartCheckoutPage', 'page1');
154
        /** @var DMSDocumentCartCheckoutPage_Controller $controller */
155
        $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...
156
        // Form for use later
157
        $form = $controller->DMSDocumentRequestForm();
158
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
159
        // Add some an item to the cart to assert later that its empty
160
        $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...
161
        $controller->getCart()->addItem($item);
162
163
        $submissionID = $controller->getCart()->saveSubmission($form);
164
        $submission = DMSDocumentCartSubmission::get()->byID($submissionID);
165
        $this->assertEquals(15, $submission->Items()->first()->Quantity);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<DMSDocumentCartTest>.

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...
166
    }
167
168
169 View Code Duplication
    public function testIsInCart()
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...
170
    {
171
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
172
        /** @var DMSRequestItem $item */
173
        $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...
174
        $this->assertFalse($this->cart->isInCart($item->getItemId()));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<DMSDocumentCartTest>.

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->cart->addItem($item);
176
        $this->assertTrue($this->cart->isInCart($item->getItemId()));
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<DMSDocumentCartTest>.

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...
177
    }
178
}
179