protected function addPrototype($id)
 {
     $object = new CartItem();
     $object->setCartItemId($id);
     $this->index[$id] = array('object' => $object, 'hydrated' => false);
     return $object;
 }
Exemplo n.º 2
0
 public function testPostAddItem()
 {
     $item = new CartItem();
     $item->setCartItemId(1);
     $event = new CartEvent();
     $event->setCartItem($item);
     $pi1 = new PerformanceIndicator('product_id', 5, PerformanceIndicator::TYPE_INT);
     $pi2 = new PerformanceIndicator('revision_id', 'a');
     $pis = array($pi1, $pi2);
     $event->setParam('performance_indicators', $pis);
     $this->piService->postAddItem($event);
     $pis = $this->piService->findByItem(1);
     $this->assertEquals(2, count($pis));
     $pi = $pis[0];
     $this->assertEquals(1, $pi->getItemId());
     $this->assertEquals('product_id', $pi->getKey());
     $this->assertEquals(5, $pi->getValue());
     $this->assertTrue(is_int($pi->getValue()));
     $this->assertEquals(PerformanceIndicator::TYPE_INT, $pi->getType());
     $pi = $pis[1];
     $this->assertEquals(1, $pi->getItemId());
     $this->assertEquals('revision_id', $pi->getKey());
     $this->assertEquals('a', $pi->getValue());
     $this->assertEquals(PerformanceIndicator::TYPE_STRING, $pi->getType());
 }
 public function testFindItemByIdReturnsCartItemModel()
 {
     $cartItem = new \SpeckCart\Entity\CartItem();
     $cartItem->setCartItemId(123);
     $mockCart = $this->getMock('\\SpeckCart\\Entity\\Cart');
     $mockCart->expects($this->once())->method('getItems')->will($this->returnValue(array($cartItem)));
     $mockSpeckCartService = $this->getMock('\\SpeckCart\\Service\\CartService');
     $mockSpeckCartService->expects($this->once())->method('getSessionCart')->will($this->returnValue($mockCart));
     $service = $this->getService();
     $service->setCartService($mockSpeckCartService);
     $return = $service->findItemById(123);
     $this->assertInstanceOf('\\SpeckCart\\Entity\\CartItem', $return);
 }
Exemplo n.º 4
0
 public function testRecursiveItems()
 {
     $item = new CartItem();
     $item->setDescription("parent");
     $child = new CartItem();
     $child->setDescription("child");
     $item->addItem($child);
     $this->cartService->addItemToCart($item);
     $items = $this->cartService->getSessionCart()->getItems();
     $parent = $items[1];
     $this->assertEquals("parent", $parent->getDescription());
     $children = $parent->getItems();
     $this->assertEquals(1, count($parent->getItems()));
     $child = $children[2];
     $this->assertEquals("child", $child->getDescription());
 }