1 | <?php |
||
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() |
||
15 | |||
16 | public function setUp() |
||
24 | |||
25 | public function testAddToCart() |
||
32 | |||
33 | public function testRemoveFromCart() |
||
41 | |||
42 | public function testSetQuantity() |
||
43 | { |
||
44 | $this->assertTrue((boolean)$this->cart->setQuantity($this->product, 25), "quantity set"); |
||
45 | $item = $this->cart->get($this->product); |
||
46 | $this->assertEquals($item->Quantity, 25, "quantity is 25"); |
||
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"); |
||
53 | $this->assertTrue((boolean)$this->cart->add($this->product), "add another item"); |
||
54 | $this->assertEquals($this->cart->current()->class, "Order", "there a cart"); |
||
55 | $this->assertTrue($this->cart->clear(), "clear the cart"); |
||
56 | $this->assertFalse($this->cart->current(), "there is no cart"); |
||
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"); |
||
66 | $this->assertTrue((boolean)$this->cart->add($ball2), "add another item"); |
||
67 | $this->assertTrue($this->cart->remove($ball1), "remove first item"); |
||
68 | $this->assertFalse($this->cart->get($ball1), "first item not in cart"); |
||
69 | $this->assertNotNull($this->cart->get($ball1), "second item is in cart"); |
||
70 | } |
||
71 | |||
72 | public function testCartSingleton() |
||
79 | } |
||
80 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: