Issues (199)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

tests/DMSDocumentCartTest.php (39 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
    /**
22
     * @expectedException DMSDocumentCartException
23
     * @expectedExceptionMessage Backend must implement DMSCartBackendInterface!
24
     */
25
    public function testConstructorThrowsExceptionWhenProvidedBackendDoesNotImplementInterface()
26
    {
27
        DMSDocumentCart::create(new DMSDocument);
28
    }
29
30 View Code Duplication
    public function testAddItem()
0 ignored issues
show
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...
31
    {
32
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
33
34
        $item = DMSRequestItem::create();
35
        $item->setDocument($doc)->setQuantity(2);
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);
Loading history...
36
        $this->cart->addItem($item);
37
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
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...
38
    }
39
40 View Code Duplication
    public function testEmptyCart()
0 ignored issues
show
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...
41
    {
42
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
43
44
        $item = DMSRequestItem::create();
45
        $item->setDocument($doc)->setQuantity(18);
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);
Loading history...
46
        $this->cart->addItem($item);
47
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
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...
48
49
        $this->cart->emptyCart();
50
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
51
    }
52
53
    public function testGetBackend()
54
    {
55
        $this->assertInstanceOf('DMSSessionBackend', $this->cart->getBackend());
56
    }
57
58
    public function testGetBackURL()
59
    {
60
        $url = 'TestURL';
61
        $this->cart->setBackUrl($url);
62
        $this->assertEquals($url, $this->cart->getBackUrl());
0 ignored issues
show
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...
63
    }
64
65 View Code Duplication
    public function testGetItem()
0 ignored issues
show
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...
66
    {
67
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
68
69
        $item = DMSRequestItem::create();
70
        $item->setDocument($doc)->setQuantity(2);
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);
Loading history...
71
        $this->cart->addItem($item);
72
73
        $this->assertEquals($doc, $this->cart->getItem($doc->ID)->getDocument());
0 ignored issues
show
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...
74
    }
75
76
    public function testGetItems()
77
    {
78
        $item = DMSRequestItem::create();
79
        $item->setDocument($this->objFromFixture('DMSDocument', 'doc1'))->setQuantity(2);
80
        $this->cart->addItem($item);
81
        $this->assertCount(1, $this->cart->getItems());
0 ignored issues
show
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...
82
83
        $item2 = DMSRequestItem::create();
84
        $item2->setDocument($this->objFromFixture('DMSDocument', 'limited_supply'))->setQuantity(2);
85
        $this->cart->addItem($item2);
86
        $this->assertCount(2, $this->cart->getItems());
87
88
        // Edge case handling for when a document is deleted in the background
89
        $item2->getDocument()->delete();
90
        $this->assertCount(1, $this->cart->getItems());
0 ignored issues
show
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...
91
    }
92
93
    public function testGetReceiverInfo()
94
    {
95
        $info = array('Name' => 'Jane');
96
        $this->cart->setReceiverInfo($info);
97
        $this->assertEquals($info, $this->cart->getReceiverInfo());
0 ignored issues
show
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...
98
    }
99
100
    public function testIsCartEmpty()
101
    {
102
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
103
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
104
        $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2);
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);
Loading history...
105
        $this->cart->addItem($item);
106
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
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...
107
    }
108
109 View Code Duplication
    public function testRemoveItem()
0 ignored issues
show
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...
110
    {
111
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
112
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
113
114
        $item = DMSRequestItem::create();
115
        $item->setDocument($doc)->setQuantity(2);
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);
Loading history...
116
        $this->cart->addItem($item);
117
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
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...
118
119
        $this->cart->removeItem($item);
120
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
121
    }
122
123 View Code Duplication
    public function testRemoveItemByID()
0 ignored issues
show
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...
124
    {
125
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
126
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
127
128
        $item = DMSRequestItem::create();
129
        $item->setDocument($doc)->setQuantity(2);
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);
Loading history...
130
        $this->cart->addItem($item);
131
        $this->assertFalse($this->cart->isCartEmpty());
0 ignored issues
show
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...
132
133
        $this->cart->removeItemByID($doc->ID);
134
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
135
    }
136
137
    public function testUpdateItemQuantity()
138
    {
139
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
140
141
        // Test Update
142
        $item = DMSRequestItem::create();
143
        $item->setDocument($doc)->setQuantity(2);
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);
Loading history...
144
        $this->cart->addItem($item);
145
        $this->assertEquals(2, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
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...
146
147
        $this->cart->updateItemQuantity($item->getItemID(), 17);
148
        $this->assertEquals(19, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
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...
149
150
        // Test Add
151
        $this->cart->updateItemQuantity($doc->ID, 16);
152
        $this->assertEquals(35, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
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...
153
154
        // Test Deduct
155
        $this->cart->updateItemQuantity($doc->ID, -16);
156
        $this->assertEquals(19, $this->cart->getItem($doc->ID)->getQuantity());
0 ignored issues
show
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...
157
158
        // Test deduct all items that it removes it
159
        $this->cart->updateItemQuantity($doc->ID, -19);
160
        $this->assertTrue($this->cart->isCartEmpty());
0 ignored issues
show
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...
161
    }
162
163
    public function testSaveSubmission()
164
    {
165
        $controller = DMSCheckoutController::create();
166
167
        // Form for use later
168
        $form = $controller->DMSDocumentRequestForm();
169
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
170
171
        // Add some an item to the cart to assert later that its empty
172
        $item = DMSRequestItem::create($doc)->setQuantity(15);
173
        $controller->getCart()->addItem($item);
174
175
        $submissionID = $controller->getCart()->saveSubmission($form);
176
        $submission = DMSDocumentCartSubmission::get()->byID($submissionID);
177
        $this->assertEquals(15, $submission->Items()->first()->Quantity);
0 ignored issues
show
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...
178
    }
179
180
181 View Code Duplication
    public function testIsInCart()
0 ignored issues
show
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...
182
    {
183
        $doc = $this->objFromFixture('DMSDocument', 'doc1');
184
        $item = DMSRequestItem::create()->setDocument($doc)->setQuantity(2);
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);
Loading history...
185
        $this->assertFalse($this->cart->isInCart($item->getItemId()));
0 ignored issues
show
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...
186
187
        $this->cart->addItem($item);
188
        $this->assertTrue($this->cart->isInCart($item->getItemId()));
0 ignored issues
show
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...
189
    }
190
191
    /**
192
     * Ensure that the cart contents are hashed an used for the cart summary cache key
193
     */
194
    public function testGetCartSummaryCacheKey()
195
    {
196
        $item = DMSRequestItem::create($this->objFromFixture('DMSDocument', 'doc1'))->setQuantity(2);
197
        $item2 = DMSRequestItem::create($this->objFromFixture('DMSDocument', 'limited_supply'))->setQuantity(2);
198
199
        $this->cart->addItem($item)->addItem($item2);
200
201
        $hash = md5(serialize($this->cart->getItems()));
202
        $this->assertContains($hash, $this->cart->getCartSummaryCacheKey());
203
    }
204
}
205