diff --git a/core/lib/Thelia/Tests/Core/HttpFoundation/Session/SessionTest.php b/core/lib/Thelia/Tests/Core/HttpFoundation/Session/SessionTest.php index 408a4de4b..67fbfd1c2 100644 --- a/core/lib/Thelia/Tests/Core/HttpFoundation/Session/SessionTest.php +++ b/core/lib/Thelia/Tests/Core/HttpFoundation/Session/SessionTest.php @@ -26,6 +26,7 @@ namespace Thelia\Tests\Core\HttpFoundation\Session; use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; use Thelia\Core\HttpFoundation\Session\Session; use Thelia\Model\Cart; +use Thelia\Model\Customer; class SessionTest extends \PHPUnit_Framework_TestCase { @@ -58,9 +59,78 @@ class SessionTest extends \PHPUnit_Framework_TestCase $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 testGetCartWithExistingCustomerButNoCart() + { + $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); + + $cart = $session->getCart(); + + $this->assertNull($cart); + } + + public function testGetCartWithExistingCartAndCustomerButWithoutReferenceToCustomerInCart() + { + $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("testSessionGetCart2", true)); + $testCart->save(); + + $session->setCart($testCart->getId()); + + $cart = $session->getCart(); + + $this->assertNull($cart); + } + + 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(); + + $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'); + } + } \ No newline at end of file