finish session test for cart part
This commit is contained in:
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user