public function testGetCartWithExistingCartWithoutCustomerConnected() { $session = $this->session; $testCart = new Cart(); $testCart->setToken(uniqid("testSessionGetCart1", true)); $testCart->save(); $session->setCart($testCart->getId()); $cart = $session->getCart(); $this->assertNotNull($cart); $this->assertInstanceOf("\\Thelia\\Model\\Cart", $cart, '$cart must be an instance of Thelia\\Model\\Cart'); $this->assertEquals($testCart->getToken(), $cart->getToken()); }
public function testGetCartWithExistingCartAndCustomerAndReferencesEachOther() { $session = $this->session; //create a fake customer just for test. If not persists test fails ! $customer = new Customer(); $customer->setFirstname("john test session"); $customer->setLastname("doe"); $customer->setTitleId(1); $customer->save(); $session->setCustomerUser($customer); $testCart = new Cart(); $testCart->setToken(uniqid("testSessionGetCart3", true)); $testCart->setCustomerId($customer->getId()); $testCart->save(); $this->request->cookies->set(ConfigQuery::read("cart.cookie_name", 'thelia_cart'), $testCart->getToken()); $cart = $session->getSessionCart($this->dispatcher); $this->assertNotNull($cart); $this->assertInstanceOf("\\Thelia\\Model\\Cart", $cart, '$cart must be an instance of Thelia\\Model\\Cart'); }
/** * Customer is connected but cart not associated to him * * A new cart must be created (duplicated) containing customer id */ public function testGetCartWithExistingCartAndCustomerButNotSameCustomerId() { $cartTrait = $this->cartTrait; $request = $this->request; //create a fake customer just for test. If not persists test fails ! $customer = new Customer(); $customer->setFirstname("john"); $customer->setLastname("doe"); $customer->setTitleId(1); $customer->save(); $uniqid = uniqid("test3", true); //create a fake cart in database; $cart = new Cart(); $cart->setToken($uniqid); $cart->save(); $request->cookies->set("thelia_cart", $uniqid); $request->getSession()->setCustomerUser($customer); $getCart = $cartTrait->getCart($this->dispatcher, $request); $this->assertInstanceOf("Thelia\\Model\\Cart", $getCart, '$cart must be an instance of cart model Thelia\\Model\\Cart'); $this->assertNotNull($getCart->getCustomerId()); $this->assertNull($getCart->getAddressDeliveryId()); $this->assertNull($getCart->getAddressInvoiceId()); $this->assertNotEquals($cart->getToken(), $getCart->getToken(), "token must be different"); $this->assertEquals($customer->getId(), $getCart->getCustomerId()); }