initialize cart test
This commit is contained in:
103
core/lib/Thelia/Tests/Action/CartTest.php
Normal file
103
core/lib/Thelia/Tests/Action/CartTest.php
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* */
|
||||||
|
/* Thelia */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : info@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* This program is free software; you can redistribute it and/or modify */
|
||||||
|
/* it under the terms of the GNU General Public License as published by */
|
||||||
|
/* the Free Software Foundation; either version 3 of the License */
|
||||||
|
/* */
|
||||||
|
/* This program is distributed in the hope that it will be useful, */
|
||||||
|
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||||
|
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||||
|
/* GNU General Public License for more details. */
|
||||||
|
/* */
|
||||||
|
/* You should have received a copy of the GNU General Public License */
|
||||||
|
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||||
|
/* */
|
||||||
|
/*************************************************************************************/
|
||||||
|
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());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user