Completed
Push — 2.0 ( 7f87f2...afdd14 )
by Roman
16:48
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 setUpOnce()
16
    {
17
        parent::setUpOnce();
18
        // clear session
19
        ShoppingCart::singleton()->clear();
20
    }
21
22
    public function setUp()
23
    {
24
        parent::setUp();
25
26
        ShopTest::setConfiguration(); //reset config
27
28
        $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...
29
        $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...
30
        //products that can't be purchased
31
        $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...
32
        $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...
33
        $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...
34
35
        //publish some products
36
        $this->mp3player->publish('Stage', 'Live');
37
        $this->socks->publish('Stage', 'Live');
38
        $this->noPurchaseProduct->publish('Stage', 'Live');
39
        $this->noPriceProduct->publish('Stage', 'Live');
40
        //note that we don't publish 'tshirt'... we want it to remain in draft form.
41
42
        $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...
43
    }
44
45
    public function testAddToCart()
46
    {
47
        // add 2 of the same items via url
48
        $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...
49
        $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...
50
        $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...
51
        $this->get(
52
            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...
53
        );  //add a product that you can't add
54
        $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...
55
        $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...
56
57
        // See what's in the cart
58
        $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...
59
        $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...
60
61
        $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...
62
        //join needed to provide ProductID
63
        $mp3playeritem =
64
            $items->innerJoin("Product_OrderItem", "\"OrderItem\".\"ID\" = \"Product_OrderItem\".\"ID\"")->find(
65
                'ProductID',
66
                $this->mp3player->ID
67
            );    //join needed to provide ProductID
68
        $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...
69
70
        // We have the product that we asserted in our fixture file, with a quantity of 2 in the cart
71
        $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...
72
            $mp3playeritem->ProductID,
73
            $this->mp3player->ID,
74
            'We have the correct Product ID in the cart.'
75
        );
76
        $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...
77
78
        // set item quantiy
79
        $this->get(
80
            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...
81
        ); //add item via url
82
        $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...
83
        $mp3playeritem =
84
            $items->innerJoin("Product_OrderItem", "\"OrderItem\".\"ID\" = \"Product_OrderItem\".\"ID\"")->find(
85
                'ProductID',
86
                $this->mp3player->ID
87
            ); //join needed to provide ProductID
88
        $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...
89
90
        // non purchasable product checks
91
        $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...
92
            $this->noPurchaseProduct->canPurchase(),
93
            false,
94
            'non-purcahseable product is not purchaseable'
95
        );
96
        $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...
97
            $this->noPurchaseProduct->ID,
98
            $items->map('ProductID')->toArray(),
99
            'non-purcahable product is not in cart'
100
        );
101
        $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...
102
        $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...
103
            $this->draftProduct->ID,
104
            $items->map('ProductID')->toArray(),
105
            'draft product is not in cart'
106
        );
107
        $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...
108
        $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...
109
            $this->noPriceProduct->ID,
110
            $items->map('ProductID')->toArray(),
111
            'product without price is not in cart'
112
        );
113
114
        $this->cart->clear();
115
    }
116
117
    public function testRemoveFromCart()
118
    {
119
120
        // add items via url
121
        $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...
122
        $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...
123
        $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...
124
        $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...
125
126
        // remove items via url
127
        $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...
128
        $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...
129
130
        $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...
131
132
        $mp3playeritem = $this->cart->get($this->mp3player);
133
        $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...
134
        $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...
135
136
        $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...
137
        $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...
138
139
        $this->cart->clear(); //test clearing cart
140
        $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...
141
            ShoppingCart::curr(),
142
            null,
143
            'Cart is clear'
144
        ); //items is a databoject set, and will therefore be null when cart is empty.
145
    }
146
147
    public function testVariations()
148
    {
149
        $this->loadFixture('silvershop/tests/fixtures/variations.yml');
150
        $ballRoot = $this->objFromFixture('Product', 'ball');
151
        $ballRoot->publish('Stage', 'Live');
152
        $ball1 = $this->objFromFixture('ProductVariation', 'redlarge');
153
        $ball2 = $this->objFromFixture('ProductVariation', 'redsmall');
154
155
        // Add the two variation items
156
        $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...
157
        $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...
158
        $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...
159
        $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...
160
        $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...
161
162
        // Remove one and see what happens
163
        $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...
164
        $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...
165
        $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...
166
        $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...
167
    }
168
169
    public function testSecurityToken()
170
    {
171
        $enabled = SecurityToken::is_enabled();
172
        // enable security tokens
173
        SecurityToken::enable();
174
175
        $productId = $this->mp3player->ID;
176
        // link should contain the security-token
177
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
178
        $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...
179
180
        // should redirect back to the shop
181
        $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 177 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...
182
        $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...
183
184
        // disable security token for cart-links
185
        Config::inst()->update('ShoppingCart_Controller', 'disable_security_token', true);
186
187
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
188
        $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...
189
190
        // should redirect back to the shop
191
        $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 187 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...
192
        $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...
193
194
        SecurityToken::disable();
195
196
        Config::inst()->update('ShoppingCart_Controller', 'disable_security_token', false);
197
        $link = ShoppingCart_Controller::add_item_link($this->mp3player);
198
        $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...
199
200
        // should redirect back to the shop
201
        $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 197 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...
202
        $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...
203
204
        SecurityToken::enable();
205
        // should now return a 400 status
206
        $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 197 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...
207
        $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...
208
209
        // restore previous setting
210
        if(!$enabled){
211
            SecurityToken::disable();
212
        }
213
    }
214
}
215