diff --git a/core/lib/Thelia/Tests/Action/CartTest.php b/core/lib/Thelia/Tests/Action/CartTest.php new file mode 100644 index 000000000..bf7eb4376 --- /dev/null +++ b/core/lib/Thelia/Tests/Action/CartTest.php @@ -0,0 +1,103 @@ +. */ +/* */ +/*************************************************************************************/ +namespace Thelia\Tests\Action; + + +use Symfony\Component\HttpFoundation\Session\Attribute\AttributeBag; +use Symfony\Component\HttpFoundation\Session\Flash\FlashBag; +use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage; +use Thelia\Core\HttpFoundation\Request; +use Thelia\Core\HttpFoundation\Session\Session; +use Thelia\Model\Customer; + +class CartTest extends \PHPUnit_Framework_TestCase +{ + + public $session; + + public $request; + + public $actionCart; + + public $uniqid; + + + + public function setUp() + { + $this->session = new Session(new MockArraySessionStorage()); + $this->request = new Request(); + + $this->request->setSession($this->session); + + $this->uniqid = uniqid('', true); + + $this->actionCart = $this->getMock( + "\Thelia\Action\Cart", + array("generateCookie") + ); + + $this->actionCart + ->expects($this->any()) + ->method("generateCookie") + ->will($this->returnValue($this->uniqid)); + } + + public function testGetCartWithoutCustomerAndWithoutExistingCart() + { + $actionCart = $this->actionCart; + + $cart = $actionCart->getCart($this->request); + + $this->assertInstanceOf("Thelia\Model\Cart", $cart, '$cart must be an instance of cart model Thelia\Model\Cart'); + $this->assertNull($cart->getCustomerId()); + $this->assertNull($cart->getAddressDeliveryId()); + $this->assertNull($cart->getAddressInvoiceId()); + + } + + public function testGetCartWithCustomerAndWithoutExistingCart() + { + $actionCart = $this->actionCart; + + $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(); + + $request->getSession()->setCustomerUser($customer); + + $cart = $actionCart->getCart($request); + $this->assertInstanceOf("Thelia\Model\Cart", $cart, '$cart must be an instance of cart model Thelia\Model\Cart'); + $this->assertNotNull($cart->getCustomerId()); + $this->assertEquals($customer->getId(), $cart->getCustomerId()); + $this->assertNull($cart->getAddressDeliveryId()); + $this->assertNull($cart->getAddressInvoiceId()); + + } + +} \ No newline at end of file