Completed
Pull Request — master (#497)
by Antony
20:59
created

ShoppingCartTest::testCartSingleton()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
class ShoppingCartTest extends SapphireTest
4
{
5
    public static $fixture_file   = 'silvershop/tests/fixtures/shop.yml';
6
    public static $disable_theme  = true;
7
    public static $use_draft_site = false;
8
9
    public function setUpOnce()
10
    {
11
        parent::setUpOnce();
12
        // clear session
13
        ShoppingCart::singleton()->clear();
14
    }
15
16
    public function setUp()
17
    {
18
        parent::setUp();
19
        ShopTest::setConfiguration(); //reset config
20
        $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...
21
        $this->product = $this->objFromFixture('Product', 'mp3player');
0 ignored issues
show
Bug introduced by
The property product 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->product->publish('Stage', 'Live');
23
    }
24
25
    public function testAddToCart()
26
    {
27
        $this->assertTrue((boolean)$this->cart->add($this->product), "add one item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
28
        $this->assertTrue((boolean)$this->cart->add($this->product), "add another item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        $item = $this->cart->get($this->product);
30
        $this->assertEquals($item->Quantity, 2, "quantity is 2");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartTest>.

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...
31
    }
32
33
    public function testRemoveFromCart()
34
    {
35
        $this->assertTrue((boolean)$this->cart->add($this->product), "add item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
36
        $this->assertTrue($this->cart->remove($this->product), "item was removed");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
39
        $this->assertFalse($this->cart->remove($this->product), "try remove non-existent item");
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShoppingCartTest>.

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...
40
    }
41
42
    public function testSetQuantity()
43
    {
44
        $this->assertTrue((boolean)$this->cart->setQuantity($this->product, 25), "quantity set");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
45
        $item = $this->cart->get($this->product);
46
        $this->assertEquals($item->Quantity, 25, "quantity is 25");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
47
    }
48
49
    public function testClear()
50
    {
51
        //$this->assertFalse($this->cart->current(),"there is no cart initally");
52
        $this->assertTrue((boolean)$this->cart->add($this->product), "add one item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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
        $this->assertTrue((boolean)$this->cart->add($this->product), "add another item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
54
        $this->assertEquals($this->cart->current()->class, "Order", "there a cart");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartTest>.

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
        $this->assertTrue($this->cart->clear(), "clear the cart");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
56
        $this->assertFalse($this->cart->current(), "there is no cart");
0 ignored issues
show
Bug introduced by
The method assertFalse() does not seem to exist on object<ShoppingCartTest>.

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...
57
    }
58
59
    public function testProductVariations()
60
    {
61
        $this->loadFixture('silvershop/tests/fixtures/variations.yml');
62
        $ball1 = $this->objFromFixture('ProductVariation', 'redlarge');
63
        $ball2 = $this->objFromFixture('ProductVariation', 'redsmall');
64
65
        $this->assertTrue((boolean)$this->cart->add($ball1), "add one item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
66
        $this->assertTrue((boolean)$this->cart->add($ball2), "add another item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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

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...
68
        $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<ShoppingCartTest>.

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
        $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<ShoppingCartTest>.

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
72
    public function testCartSingleton()
73
    {
74
        $this->assertTrue((boolean)$this->cart->add($this->product), "add one item");
0 ignored issues
show
Bug introduced by
The method assertTrue() does not seem to exist on object<ShoppingCartTest>.

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...
75
        $order = $this->cart->current();
76
77
        $this->assertEquals($order->ID, ShoppingCart::curr()->ID, "if singleton order ids will match");
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ShoppingCartTest>.

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...
78
    }
79
}
80