fix endlife cookie cart

This commit is contained in:
Manuel Raynaud
2013-07-26 15:40:05 +02:00
parent 74fb217cb4
commit 9f4a2778e3
2 changed files with 24 additions and 1 deletions

View File

@@ -174,7 +174,7 @@ class Cart implements EventSubscriberInterface
protected function generateCookie() protected function generateCookie()
{ {
$id = uniqid('', true); $id = uniqid('', true);
setcookie("thelia_cart", $id, uniqid('', true)); setcookie("thelia_cart", $id, time()+(60*60*24*365));
return $id; return $id;
} }

View File

@@ -61,6 +61,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue($this->uniqid)); ->will($this->returnValue($this->uniqid));
} }
/**
* no cart present in session and cart_id no yet exists in cookies.
*
* In this case, a new cart instance must be create
*/
public function testGetCartWithoutCustomerAndWithoutExistingCart() public function testGetCartWithoutCustomerAndWithoutExistingCart()
{ {
$actionCart = $this->actionCart; $actionCart = $this->actionCart;
@@ -75,6 +80,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
} }
/**
* Customer is connected but his cart does not exists yet
*
* Cart must be created and associated to the current connected Customer
*/
public function testGetCartWithCustomerAndWithoutExistingCart() public function testGetCartWithCustomerAndWithoutExistingCart()
{ {
$actionCart = $this->actionCart; $actionCart = $this->actionCart;
@@ -100,6 +110,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
} }
/**
* Cart exists and his id put in cookies.
*
* Must return the same cart instance
*/
public function testGetCartWithoutCustomerAndWithExistingCart() public function testGetCartWithoutCustomerAndWithExistingCart()
{ {
$actionCart = $this->actionCart; $actionCart = $this->actionCart;
@@ -121,6 +136,11 @@ class CartTest extends \PHPUnit_Framework_TestCase
$this->assertEquals($cart->getToken(), $getCart->getToken()); $this->assertEquals($cart->getToken(), $getCart->getToken());
} }
/**
* a cart id exists in cookies but this id does not exists yet in databases
*
* a new cart must be created (different token)
*/
public function testGetCartWithExistingCartButNotGoodCookies() public function testGetCartWithExistingCartButNotGoodCookies()
{ {
$actionCart = $this->actionCart; $actionCart = $this->actionCart;
@@ -138,6 +158,9 @@ class CartTest extends \PHPUnit_Framework_TestCase
$this->assertNotEquals($token, $cart->getToken()); $this->assertNotEquals($token, $cart->getToken());
} }
/**
*
*/
public function testGetCartWithExistingCartAndCustomer() public function testGetCartWithExistingCartAndCustomer()
{ {
$actionCart = $this->actionCart; $actionCart = $this->actionCart;