Completed
Pull Request — master (#482)
by Roman
29:46
created

ShoppingCartControllerTest::testSecurityToken()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 45
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 45
rs 8.8571
cc 2
eloc 24
nc 2
nop 0
1
<?php
2
3
/**
4
 * @link ShoppingCart_Controller
5
 *
6
 * Test manipulating via urls.
7
 */
8
class ShoppingCartControllerTest extends FunctionalTest
9
{
10
    public static $fixture_file   = 'silvershop/tests/fixtures/shop.yml';
11
    public static $disable_theme  = true;
12
    public static $use_draft_site = false;
13
    protected $autoFollowRedirection = false;
14
15
    public function setUp()
16
    {
17
        parent::setUp();
18
19
        ShopTest::setConfiguration(); //reset config
20
21
        $this->mp3player = $this->objFromFixture('Product', 'mp3player');
0 ignored issues
show
Bug introduced by
The property mp3player does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
22
        $this->socks = $this->objFromFixture('Product', 'socks');
0 ignored issues
show
Bug introduced by
The property socks does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
23
        //products that can't be purchased
24
        $this->noPurchaseProduct = $this->objFromFixture('Product', 'beachball');
0 ignored issues
show
Bug introduced by
The property noPurchaseProduct does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
25
        $this->draftProduct = $this->objFromFixture('Product', 'tshirt');
0 ignored issues
show
Bug introduced by
The property draftProduct does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
26
        $this->noPriceProduct = $this->objFromFixture('Product', 'hdtv');
0 ignored issues
show
Bug introduced by
The property noPriceProduct does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
27
28
        //publish some products
29
        $this->mp3player->publish('Stage', 'Live');
30
        $this->socks->publish('Stage', 'Live');
31
        $this->noPurchaseProduct->publish('Stage', 'Live');
32
        $this->noPriceProduct->publish('Stage', 'Live');
33
        //note that we don't publish 'tshirt'... we want it to remain in draft form.
34
35
        $this->cart = ShoppingCart::singleton();
0 ignored issues
show
Bug introduced by
The property cart does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
36
    }
37
38
    public function testAddToCart()
39
    {
40
        // add 2 of the same items via url
41
        $this->get(ShoppingCart_Controller::add_item_link($this->mp3player)); //add item via url
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller..._link($this->mp3player) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
42
        $this->get(ShoppingCart_Controller::add_item_link($this->mp3player)); //add another
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller..._link($this->mp3player) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
43
        $this->get(ShoppingCart_Controller::add_item_link($this->socks)); //add a different product
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
44
        $this->get(
45
            ShoppingCart_Controller::add_item_link($this->noPurchaseProduct)
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...his->noPurchaseProduct) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
46
        );  //add a product that you can't add
47
        $this->get(ShoppingCart_Controller::add_item_link($this->draftProduct));  //add a product that is draft
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...nk($this->draftProduct) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
48
        $this->get(ShoppingCart_Controller::add_item_link($this->noPriceProduct));  //add a product that has no price
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...($this->noPriceProduct) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
49
50
        // See what's in the cart
51
        $items = ShoppingCart::curr()->Items();
0 ignored issues
show
Documentation Bug introduced by
The method Items does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
52
        $this->assertNotNull($items);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShoppingCartControllerTest>.

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...
53
54
        $this->assertEquals($items->Count(), 2, 'There are 2 items in the cart');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        //join needed to provide ProductID
56
        $mp3playeritem =
57
            $items->innerJoin("Product_OrderItem", "\"OrderItem\".\"ID\" = \"Product_OrderItem\".\"ID\"")->find(
58
                'ProductID',
59
                $this->mp3player->ID
60
            );    //join needed to provide ProductID
61
        $this->assertNotNull($mp3playeritem, "Mp3 player is in cart");
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShoppingCartControllerTest>.

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...
62
63
        // We have the product that we asserted in our fixture file, with a quantity of 2 in the cart
64
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
            $mp3playeritem->ProductID,
66
            $this->mp3player->ID,
67
            'We have the correct Product ID in the cart.'
68
        );
69
        $this->assertEquals($mp3playeritem->Quantity, 2, 'We have 2 of this product in the cart.');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
70
71
        // set item quantiy
72
        $this->get(
73
            ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5))
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
74
        ); //add item via url
75
        $items = ShoppingCart::curr()->Items();
0 ignored issues
show
Documentation Bug introduced by
The method Items does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
76
        $mp3playeritem =
77
            $items->innerJoin("Product_OrderItem", "\"OrderItem\".\"ID\" = \"Product_OrderItem\".\"ID\"")->find(
78
                'ProductID',
79
                $this->mp3player->ID
80
            ); //join needed to provide ProductID
81
        $this->assertEquals($mp3playeritem->Quantity, 5, 'We have 5 of this product in the cart.');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        // non purchasable product checks
84
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
85
            $this->noPurchaseProduct->canPurchase(),
86
            false,
87
            'non-purcahseable product is not purchaseable'
88
        );
89
        $this->assertArrayNotHasKey(
0 ignored issues
show
Bug introduced by
The method assertArrayNotHasKey() does not seem to exist on object<ShoppingCartControllerTest>.

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...
90
            $this->noPurchaseProduct->ID,
91
            $items->map('ProductID')->toArray(),
92
            'non-purcahable product is not in cart'
93
        );
94
        $this->assertEquals($this->draftProduct->canPurchase(), true, 'draft products can be purchased');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
95
        $this->assertArrayNotHasKey(
0 ignored issues
show
Bug introduced by
The method assertArrayNotHasKey() does not seem to exist on object<ShoppingCartControllerTest>.

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...
96
            $this->draftProduct->ID,
97
            $items->map('ProductID')->toArray(),
98
            'draft product is not in cart'
99
        );
100
        $this->assertEquals($this->noPriceProduct->canPurchase(), false, 'product without price is not purchaseable');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        $this->assertArrayNotHasKey(
0 ignored issues
show
Bug introduced by
The method assertArrayNotHasKey() does not seem to exist on object<ShoppingCartControllerTest>.

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...
102
            $this->noPriceProduct->ID,
103
            $items->map('ProductID')->toArray(),
104
            'product without price is not in cart'
105
        );
106
107
        $this->cart->clear();
108
    }
109
110
    public function testRemoveFromCart()
111
    {
112
113
        // add items via url
114
        $this->get(ShoppingCart_Controller::set_quantity_item_link($this->mp3player, array('quantity' => 5)));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...array('quantity' => 5)) targeting ShoppingCart_Controller::set_quantity_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
115
        $this->assertTrue($this->cart->get($this->mp3player) !== false, "mp3player item now exists in cart");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartControllerTest>.

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...
116
        $this->get(ShoppingCart_Controller::add_item_link($this->socks));
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
117
        $this->assertTrue($this->cart->get($this->socks) !== false, "socks item now exists in cart");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartControllerTest>.

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
        // remove items via url
120
        $this->get(ShoppingCart_Controller::remove_item_link($this->socks)); //remove one different = remove completely
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller...item_link($this->socks) targeting ShoppingCart_Controller::remove_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
121
        $this->assertFalse($this->cart->get($this->socks));
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShoppingCartControllerTest>.

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
        $this->get(ShoppingCart_Controller::remove_item_link($this->mp3player)); //remove one product = 4 left
0 ignored issues
show
Security Bug introduced by
It seems like \ShoppingCart_Controller..._link($this->mp3player) targeting ShoppingCart_Controller::remove_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
124
125
        $mp3playeritem = $this->cart->get($this->mp3player);
126
        $this->assertTrue($mp3playeritem !== false, "product still exists");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartControllerTest>.

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($mp3playeritem->Quantity, 4, "only 4 of item left");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
129
        $items = ShoppingCart::curr()->Items();
0 ignored issues
show
Documentation Bug introduced by
The method Items does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
130
        $this->assertNotNull($items, "Cart is not empty");
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShoppingCartControllerTest>.

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
        $this->cart->clear(); //test clearing cart
133
        $this->assertEquals(
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
            ShoppingCart::curr(),
135
            null,
136
            'Cart is clear'
137
        ); //items is a databoject set, and will therefore be null when cart is empty.
138
    }
139
140
    public function testVariations()
141
    {
142
        $this->loadFixture('silvershop/tests/fixtures/variations.yml');
143
        $ballRoot = $this->objFromFixture('Product', 'ball');
144
        $ballRoot->publish('Stage', 'Live');
145
        $ball1 = $this->objFromFixture('ProductVariation', 'redlarge');
146
        $ball2 = $this->objFromFixture('ProductVariation', 'redsmall');
147
148
        // Add the two variation items
149
        $this->get(ShoppingCart_Controller::add_item_link($ball1));
0 ignored issues
show
Documentation introduced by
$ball1 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
Security Bug introduced by
It seems like \ShoppingCart_Controller::add_item_link($ball1) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
150
        $this->get(ShoppingCart_Controller::add_item_link($ball2));
0 ignored issues
show
Documentation introduced by
$ball2 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
Security Bug introduced by
It seems like \ShoppingCart_Controller::add_item_link($ball2) targeting ShoppingCart_Controller::add_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
151
        $items = ShoppingCart::curr()->Items();
0 ignored issues
show
Documentation Bug introduced by
The method Items does not exist on object<Order>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
152
        $this->assertNotNull($items);
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShoppingCartControllerTest>.

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
        $this->assertEquals($items->Count(), 2, 'There are 2 items in the cart');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
154
155
        // Remove one and see what happens
156
        $this->get(ShoppingCart_Controller::remove_all_item_link($ball1));
0 ignored issues
show
Documentation introduced by
$ball1 is of type object<DataObject>|null, but the function expects a object<Buyable>.

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...
Security Bug introduced by
It seems like \ShoppingCart_Controller...e_all_item_link($ball1) targeting ShoppingCart_Controller::remove_all_item_link() can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?
Loading history...
157
        $this->assertEquals($items->Count(), 1, 'There is 1 item in the cart');
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        $this->assertFalse($this->cart->get($ball1), "first item not in cart");
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShoppingCartControllerTest>.

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...
159
        $this->assertNotNull($this->cart->get($ball1), "second item is in cart");
0 ignored issues
show
Bug introduced by
The method assertNotNull() does not seem to exist on object<ShoppingCartControllerTest>.

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
    public function testSecurityToken()
163
    {
164
        $enabled = SecurityToken::is_enabled();
165
        // enable security tokens
166
        SecurityToken::enable();
167
168
        $productId = $this->mp3player->ID;
169
        // link should contain the security-token
170
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
171
        $this->assertRegExp('{^shoppingcart/add/Product/'.$productId.'\?SecurityID=[a-f0-9]+$}', $link);
0 ignored issues
show
Bug introduced by
The method assertRegExp() does not seem to exist on object<ShoppingCartControllerTest>.

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...
172
173
        // should redirect back to the shop
174
        $response = $this->get($link);
0 ignored issues
show
Security Bug introduced by
It seems like $link defined by \ShoppingCart_Controller..._link($this->mp3player) on line 170 can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
175
        $this->assertEquals($response->getStatusCode(), 302);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        // disable security token for cart-links
178
        Config::inst()->update('ShoppingCart_Controller', 'disable_security_token', true);
179
180
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
181
        $this->assertEquals('shoppingcart/add/Product/'.$productId, $link);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
182
183
        // should redirect back to the shop
184
        $response = $this->get($link);
0 ignored issues
show
Security Bug introduced by
It seems like $link defined by \ShoppingCart_Controller..._link($this->mp3player) on line 180 can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
185
        $this->assertEquals($response->getStatusCode(), 302);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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
        SecurityToken::disable();
188
189
        Config::inst()->update('ShoppingCart_Controller', 'disable_security_token', false);
190
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
191
        $this->assertEquals('shoppingcart/add/Product/'.$productId , $link);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
192
193
        // should redirect back to the shop
194
        $response = $this->get($link);
0 ignored issues
show
Security Bug introduced by
It seems like $link defined by \ShoppingCart_Controller..._link($this->mp3player) on line 190 can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
195
        $this->assertEquals($response->getStatusCode(), 302);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
196
197
        SecurityToken::enable();
198
        // should now return a 400 status
199
        $response = $this->get($link);
0 ignored issues
show
Security Bug introduced by
It seems like $link defined by \ShoppingCart_Controller..._link($this->mp3player) on line 190 can also be of type false; however, FunctionalTest::get() does only seem to accept string, did you maybe forget to handle an error condition?

This check looks for type mismatches where the missing type is false. This is usually indicative of an error condtion.

Consider the follow example

<?php

function getDate($date)
{
    if ($date !== null) {
        return new DateTime($date);
    }

    return false;
}

This function either returns a new DateTime object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returned false before passing on the value to another function or method that may not be able to handle a false.

Loading history...
200
        $this->assertEquals($response->getStatusCode(), 400);
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartControllerTest>.

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...
201
202
        // restore previous setting
203
        if(!$enabled){
204
            SecurityToken::disable();
205
        }
206
    }
207
}
208