diff --git a/core/lib/Thelia/Action/Cart.php b/core/lib/Thelia/Action/Cart.php index d1d5ec0dd..61629bde8 100755 --- a/core/lib/Thelia/Action/Cart.php +++ b/core/lib/Thelia/Action/Cart.php @@ -174,7 +174,7 @@ class Cart implements EventSubscriberInterface protected function generateCookie() { $id = uniqid('', true); - setcookie("thelia_cart", $id, uniqid('', true)); + setcookie("thelia_cart", $id, time()+(60*60*24*365)); return $id; } diff --git a/core/lib/Thelia/Tests/Action/CartTest.php b/core/lib/Thelia/Tests/Action/CartTest.php index b3ff87f8e..274203d0f 100644 --- a/core/lib/Thelia/Tests/Action/CartTest.php +++ b/core/lib/Thelia/Tests/Action/CartTest.php @@ -61,6 +61,11 @@ class CartTest extends \PHPUnit_Framework_TestCase ->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() { $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() { $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() { $actionCart = $this->actionCart; @@ -121,6 +136,11 @@ class CartTest extends \PHPUnit_Framework_TestCase $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() { $actionCart = $this->actionCart; @@ -138,6 +158,9 @@ class CartTest extends \PHPUnit_Framework_TestCase $this->assertNotEquals($token, $cart->getToken()); } + /** + * + */ public function testGetCartWithExistingCartAndCustomer() { $actionCart = $this->actionCart;