Merge branch 'master' of https://github.com/thelia/thelia into coupon
# By Manuel Raynaud (68) and others # Via Manuel Raynaud (12) and others * 'master' of https://github.com/thelia/thelia: (119 commits) order tests action order tests cache dataccessfunctions order action test fire event on insert content in createmethod fix issue, default foler is set on content creation allow to create new content update default param of content model create content listener for crud management dispatch event in pre/post crud method for content model display content modification page create contentUpdateEvent create contentCreateEvent create ContentEvent create contentModificationForm create content controller change folder_id parm by parent in list folder view use placeholder in folder update route implement process for changing folder position allow possibility to change folder visibility ... Conflicts: core/lib/Thelia/Coupon/CouponBaseAdapter.php templates/admin/default/coupon-list.html templates/admin/default/coupon-read.html
This commit is contained in:
353
core/lib/Thelia/Tests/Action/OrderTest.php
Normal file
353
core/lib/Thelia/Tests/Action/OrderTest.php
Normal file
@@ -0,0 +1,353 @@
|
||||
<?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 Propel\Runtime\ActiveQuery\Criteria;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
use Thelia\Core\Event\OrderEvent;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\SecurityContext;
|
||||
use Thelia\Model\AddressQuery;
|
||||
use Thelia\Model\Base\OrderProductQuery;
|
||||
use Thelia\Model\OrderStatus;
|
||||
use Thelia\Model\ProductSaleElementsQuery;
|
||||
use Thelia\Model\Cart;
|
||||
use Thelia\Model\CartItem;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Model\Order as OrderModel;
|
||||
use Thelia\Model\Customer as CustomerModel;
|
||||
use Thelia\Action\Order;
|
||||
use Thelia\Model\ProductQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
/**
|
||||
* Class CustomerTest
|
||||
* @package Thelia\Tests\Action
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class OrderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @var ContainerBuilder $container
|
||||
*/
|
||||
protected $container;
|
||||
|
||||
/**
|
||||
* @var Order $orderAction
|
||||
*/
|
||||
protected $orderAction;
|
||||
|
||||
/**
|
||||
* @var OrderEvent $orderEvent
|
||||
*/
|
||||
protected $orderEvent;
|
||||
|
||||
/**
|
||||
* @var CustomerModel $customer
|
||||
*/
|
||||
protected $customer;
|
||||
|
||||
/**
|
||||
* @var Cart $customer
|
||||
*/
|
||||
protected $cart;
|
||||
|
||||
/**
|
||||
* @var CartItem[]
|
||||
*/
|
||||
protected $cartItems;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = new Request();
|
||||
$dispatcher = $this->getMock("Symfony\Component\EventDispatcher\EventDispatcherInterface");
|
||||
|
||||
$request->setSession($session);
|
||||
|
||||
$container->set("event_dispatcher", $dispatcher);
|
||||
$container->set('request', $request);
|
||||
$container->set('thelia.securityContext', new SecurityContext($request));
|
||||
|
||||
$this->container = $container;
|
||||
|
||||
$this->orderEvent = new OrderEvent(new OrderModel());
|
||||
|
||||
$this->orderAction = new Order($this->container);
|
||||
|
||||
/* load customer */
|
||||
$this->customer = $this->loadCustomer();
|
||||
if(null === $this->customer) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* fill cart */
|
||||
$this->cart = $this->fillCart();
|
||||
|
||||
}
|
||||
|
||||
public function loadCustomer()
|
||||
{
|
||||
$customer = CustomerQuery::create()->findOne();
|
||||
if(null === $customer) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->container->get('thelia.securityContext')->setCustomerUser($customer);
|
||||
|
||||
return $customer;
|
||||
}
|
||||
|
||||
public function fillCart()
|
||||
{
|
||||
$currency = CurrencyQuery::create()->findOne();
|
||||
|
||||
//create a fake cart in database;
|
||||
$cart = new Cart();
|
||||
$cart->setToken(uniqid("createorder", true))
|
||||
->setCustomer($this->customer)
|
||||
->setCurrency($currency)
|
||||
->save();
|
||||
|
||||
/* add 3 items */
|
||||
$productList = array();
|
||||
for($i=0; $i<3; $i++) {
|
||||
$pse = ProductSaleElementsQuery::create()
|
||||
->filterByProduct(
|
||||
ProductQuery::create()
|
||||
->filterByVisible(1)
|
||||
->filterById($productList, Criteria::NOT_IN)
|
||||
->find()
|
||||
)
|
||||
->filterByQuantity(5, Criteria::GREATER_EQUAL)
|
||||
->joinProductPrice('pp', Criteria::INNER_JOIN)
|
||||
->addJoinCondition('pp', 'currency_id = ?', $currency->getId(), null, \PDO::PARAM_INT)
|
||||
->withColumn('`pp`.price', 'price_PRICE')
|
||||
->withColumn('`pp`.promo_price', 'price_PROMO_PRICE')
|
||||
->findOne();
|
||||
|
||||
$productList[] = $pse->getProductId();
|
||||
|
||||
$cartItem = new CartItem();
|
||||
$cartItem
|
||||
->setCart($cart)
|
||||
->setProduct($pse->getProduct())
|
||||
->setProductSaleElements($pse)
|
||||
->setQuantity($i)
|
||||
->setPrice($pse->getPrice())
|
||||
->setPromoPrice($pse->getPromoPrice())
|
||||
->setPromo($pse->getPromo())
|
||||
->setPriceEndOfLife(time() + 60*60*24*30)
|
||||
->save();
|
||||
$this->cartItems[] = $cartItem;
|
||||
}
|
||||
|
||||
$this->container->get('request')->getSession()->setCart($cart->getId());
|
||||
|
||||
return $cart;
|
||||
}
|
||||
|
||||
public function testSetDeliveryAddress()
|
||||
{
|
||||
//$validAddressId = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$this->orderEvent->setDeliveryAddress(321);
|
||||
|
||||
$this->orderAction->setDeliveryAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
321,
|
||||
$this->orderEvent->getOrder()->chosenDeliveryAddress
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetinvoiceAddress()
|
||||
{
|
||||
$this->orderEvent->setInvoiceAddress(654);
|
||||
|
||||
$this->orderAction->setInvoiceAddress($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
654,
|
||||
$this->orderEvent->getOrder()->chosenInvoiceAddress
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetDeliveryModule()
|
||||
{
|
||||
$this->orderEvent->setDeliveryModule(123);
|
||||
|
||||
$this->orderAction->setDeliveryModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
123,
|
||||
$this->orderEvent->getOrder()->getDeliveryModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetPaymentModule()
|
||||
{
|
||||
$this->orderEvent->setPaymentModule(456);
|
||||
|
||||
$this->orderAction->setPaymentModule($this->orderEvent);
|
||||
|
||||
$this->assertEquals(
|
||||
456,
|
||||
$this->orderEvent->getOrder()->getPaymentModuleId()
|
||||
);
|
||||
}
|
||||
|
||||
public function testCreate()
|
||||
{
|
||||
$validDeliveryAddress = AddressQuery::create()->findOneByCustomerId($this->customer->getId());
|
||||
$validInvoiceAddress = AddressQuery::create()->filterById($validDeliveryAddress->getId(), Criteria::NOT_EQUAL)->findOneByCustomerId($this->customer->getId());
|
||||
|
||||
$deliveryModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::DELIVERY_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if(null === $deliveryModule) {
|
||||
return;
|
||||
}
|
||||
|
||||
$paymentModule = ModuleQuery::create()
|
||||
->filterByType(BaseModule::PAYMENT_MODULE_TYPE)
|
||||
->filterByActivate(1)
|
||||
->findOne();
|
||||
|
||||
if(null === $paymentModule) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->orderEvent->getOrder()->chosenDeliveryAddress = $validDeliveryAddress->getId();
|
||||
$this->orderEvent->getOrder()->chosenInvoiceAddress = $validInvoiceAddress->getId();
|
||||
$this->orderEvent->getOrder()->setDeliveryModuleId($deliveryModule->getId());
|
||||
$this->orderEvent->getOrder()->setPostage(20);
|
||||
$this->orderEvent->getOrder()->setPaymentModuleId($paymentModule->getId());
|
||||
|
||||
/* memorize current stocks */
|
||||
$itemsStock = array();
|
||||
foreach($this->cartItems as $index => $cartItem) {
|
||||
$itemsStock[$index] = $cartItem->getProductSaleElements()->getQuantity();
|
||||
}
|
||||
|
||||
$this->orderAction->create($this->orderEvent);
|
||||
|
||||
$placedOrder = $this->orderEvent->getPlacedOrder();
|
||||
|
||||
$this->assertNotNull($placedOrder);
|
||||
$this->assertNotNull($placedOrder->getId());
|
||||
|
||||
/* check customer */
|
||||
$this->assertEquals($this->customer->getId(), $placedOrder->getCustomerId(), 'customer i does not match');
|
||||
|
||||
/* check delivery address */
|
||||
$deliveryOrderAddress = $placedOrder->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||
$this->assertEquals($validDeliveryAddress->getCustomerTitle()->getId(), $deliveryOrderAddress->getCustomerTitleId(), 'delivery address title does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCompany(), $deliveryOrderAddress->getCompany(), 'delivery address company does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getFirstname(), $deliveryOrderAddress->getFirstname(), 'delivery address fistname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getLastname(), $deliveryOrderAddress->getLastname(), 'delivery address lastname does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress1(), $deliveryOrderAddress->getAddress1(), 'delivery address address1 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress2(), $deliveryOrderAddress->getAddress2(), 'delivery address address2 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getAddress3(), $deliveryOrderAddress->getAddress3(), 'delivery address address3 does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getZipcode(), $deliveryOrderAddress->getZipcode(), 'delivery address zipcode does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCity(), $deliveryOrderAddress->getCity(), 'delivery address city does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getPhone(), $deliveryOrderAddress->getPhone(), 'delivery address phone does not match');
|
||||
$this->assertEquals($validDeliveryAddress->getCountryId(), $deliveryOrderAddress->getCountryId(), 'delivery address country does not match');
|
||||
|
||||
/* check invoice address */
|
||||
$invoiceOrderAddress = $placedOrder->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||
$this->assertEquals($validInvoiceAddress->getCustomerTitle()->getId(), $invoiceOrderAddress->getCustomerTitleId(), 'invoice address title does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCompany(), $invoiceOrderAddress->getCompany(), 'invoice address company does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getFirstname(), $invoiceOrderAddress->getFirstname(), 'invoice address fistname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getLastname(), $invoiceOrderAddress->getLastname(), 'invoice address lastname does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress1(), $invoiceOrderAddress->getAddress1(), 'invoice address address1 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress2(), $invoiceOrderAddress->getAddress2(), 'invoice address address2 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getAddress3(), $invoiceOrderAddress->getAddress3(), 'invoice address address3 does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getZipcode(), $invoiceOrderAddress->getZipcode(), 'invoice address zipcode does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCity(), $invoiceOrderAddress->getCity(), 'invoice address city does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getPhone(), $invoiceOrderAddress->getPhone(), 'invoice address phone does not match');
|
||||
$this->assertEquals($validInvoiceAddress->getCountryId(), $invoiceOrderAddress->getCountryId(), 'invoice address country does not match');
|
||||
|
||||
/* check currency */
|
||||
$this->assertEquals($this->cart->getCurrencyId(), $placedOrder->getCurrencyId(), 'currency id does not match');
|
||||
$this->assertEquals($this->cart->getCurrency()->getRate(), $placedOrder->getCurrencyRate(), 'currency rate does not match');
|
||||
|
||||
/* check delivery module */
|
||||
$this->assertEquals(20, $placedOrder->getPostage(), 'postage does not match');
|
||||
$this->assertEquals($deliveryModule->getId(), $placedOrder->getDeliveryModuleId(), 'delivery module does not match');
|
||||
|
||||
/* check payment module */
|
||||
$this->assertEquals($paymentModule->getId(), $placedOrder->getPaymentModuleId(), 'payment module does not match');
|
||||
|
||||
/* check status */
|
||||
$this->assertEquals(OrderStatus::CODE_NOT_PAID, $placedOrder->getOrderStatus()->getCode(), 'status does not match');
|
||||
|
||||
/* check lang */
|
||||
$this->assertEquals($this->container->get('request')->getSession()->getLang()->getId(), $placedOrder->getLangId(), 'lang does not match');
|
||||
|
||||
/* check ordered product */
|
||||
foreach($this->cartItems as $index => $cartItem) {
|
||||
$orderProduct = OrderProductQuery::create()
|
||||
->filterByOrderId($placedOrder->getId())
|
||||
->filterByProductRef($cartItem->getProduct()->getRef())
|
||||
->filterByProductSaleElementsRef($cartItem->getProductSaleElements()->getRef())
|
||||
->filterByQuantity($cartItem->getQuantity())
|
||||
->filterByPrice($cartItem->getPrice(), Criteria::LIKE)
|
||||
->filterByPromoPrice($cartItem->getPromoPrice(), Criteria::LIKE)
|
||||
->filterByWasNew($cartItem->getProductSaleElements()->getNewness())
|
||||
->filterByWasInPromo($cartItem->getPromo())
|
||||
->filterByWeight($cartItem->getProductSaleElements()->getWeight())
|
||||
->findOne();
|
||||
|
||||
$this->assertNotNull($orderProduct);
|
||||
|
||||
/* check attribute combinations */
|
||||
$this->assertEquals(
|
||||
$cartItem->getProductSaleElements()->getAttributeCombinations()->count(),
|
||||
$orderProduct->getOrderProductAttributeCombinations()->count()
|
||||
);
|
||||
|
||||
/* check stock decrease */
|
||||
$this->assertEquals(
|
||||
$itemsStock[$index] - $orderProduct->getQuantity(),
|
||||
$cartItem->getProductSaleElements()->getQuantity()
|
||||
);
|
||||
|
||||
/* check tax */
|
||||
$orderProductTaxList = $orderProduct->getOrderProductTaxes();
|
||||
foreach($cartItem->getProduct()->getTaxRule()->getTaxDetail($validDeliveryAddress->getCountry(), $cartItem->getPromo() == 1 ? $cartItem->getPromoPrice() : $cartItem->getPrice()) as $index => $tax) {
|
||||
$orderProductTax = $orderProductTaxList[$index];
|
||||
$this->assertEquals($tax->getAmount(), $orderProductTax->getAmount());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
106
core/lib/Thelia/Tests/Command/ModuleActivateCommandTest.php
Executable file
106
core/lib/Thelia/Tests/Command/ModuleActivateCommandTest.php
Executable file
@@ -0,0 +1,106 @@
|
||||
<?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\Command;
|
||||
|
||||
use Symfony\Component\Console\Tester\CommandTester;
|
||||
use Thelia\Command\ModuleActivateCommand;
|
||||
use Thelia\Core\Application;
|
||||
use Thelia\Model\ModuleQuery;
|
||||
use Thelia\Module\BaseModule;
|
||||
|
||||
/**
|
||||
* Class ModuleActivateCommandTest
|
||||
*
|
||||
* @package Thelia\Tests\Command
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*/
|
||||
class ModuleActivateCommandTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testModuleActivateCommand()
|
||||
{
|
||||
$module = ModuleQuery::create()->findOne();
|
||||
|
||||
if(null !== $module) {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
$module->setActivate(BaseModule::IS_NOT_ACTIVATED);
|
||||
$module->save();
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => $module->getCode(),
|
||||
));
|
||||
|
||||
$this->assertEquals(BaseModule::IS_ACTIVATED, ModuleQuery::create()->findPk($module->getId())->getActivate());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage module Letshopethismoduledoesnotexists not found
|
||||
*/
|
||||
public function testModuleActivateCommandUnknownModule()
|
||||
{
|
||||
$testedModule = ModuleQuery::create()->findOneByCode('Letshopethismoduledoesnotexists');
|
||||
|
||||
if(null == $testedModule) {
|
||||
$application = new Application($this->getKernel());
|
||||
|
||||
|
||||
$moduleActivate = new ModuleActivateCommand();
|
||||
$moduleActivate->setContainer($this->getContainer());
|
||||
|
||||
$application->add($moduleActivate);
|
||||
|
||||
$command = $application->find("module:activate");
|
||||
$commandTester = new CommandTester($command);
|
||||
$commandTester->execute(array(
|
||||
"command" => $command->getName(),
|
||||
"module" => "letshopethismoduledoesnotexists",
|
||||
));
|
||||
|
||||
$out = true;
|
||||
}
|
||||
}
|
||||
|
||||
public function getKernel()
|
||||
{
|
||||
$kernel = $this->getMock("Symfony\Component\HttpKernel\KernelInterface");
|
||||
|
||||
return $kernel;
|
||||
}
|
||||
|
||||
public function getContainer()
|
||||
{
|
||||
$container = new \Symfony\Component\DependencyInjection\ContainerBuilder();
|
||||
|
||||
return $container;
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
|
||||
$this->assertInstanceOf('\Thelia\Core\Template\Element\LoopResult', $methodReturn);
|
||||
}
|
||||
|
||||
public function baseTestSearchById($id)
|
||||
public function baseTestSearchById($id, $other_args = array())
|
||||
{
|
||||
$this->instance->initializeArgs(array_merge(
|
||||
$this->getMandatoryArguments(),
|
||||
@@ -140,7 +140,8 @@ abstract class BaseLoopTestor extends \PHPUnit_Framework_TestCase
|
||||
"type" => "foo",
|
||||
"name" => "foo",
|
||||
"id" => $id,
|
||||
)
|
||||
),
|
||||
$other_args
|
||||
));
|
||||
|
||||
$dummy = null;
|
||||
|
||||
@@ -58,32 +58,27 @@ class DocumentTest extends BaseLoopTestor
|
||||
{
|
||||
$document = ProductDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId());
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'product'));
|
||||
}
|
||||
|
||||
public function testSearchByFolderId()
|
||||
{
|
||||
$document = FolderDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId());
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'folder'));
|
||||
}
|
||||
|
||||
public function testSearchByContentId()
|
||||
{
|
||||
$document = ContentDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId());
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'content'));
|
||||
}
|
||||
|
||||
public function testSearchByCategoryId()
|
||||
{
|
||||
$document = CategoryDocumentQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($document->getId());
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(1);
|
||||
$this->baseTestSearchById($document->getId(), array('source' => 'category'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,32 +58,27 @@ class ImageTest extends BaseLoopTestor
|
||||
{
|
||||
$image = ProductImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId());
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'product'));
|
||||
}
|
||||
|
||||
public function testSearchByFolderId()
|
||||
{
|
||||
$image = FolderImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId());
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'folder'));
|
||||
}
|
||||
|
||||
public function testSearchByContentId()
|
||||
{
|
||||
$image = ContentImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId());
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'content'));
|
||||
}
|
||||
|
||||
public function testSearchByCategoryId()
|
||||
{
|
||||
$image = CategoryImageQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($image->getId());
|
||||
}
|
||||
|
||||
public function testSearchLimit()
|
||||
{
|
||||
$this->baseTestSearchWithLimit(1);
|
||||
$this->baseTestSearchById($image->getId(), array('source' => 'category'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ use Thelia\Model\ProductQuery;
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
use Thelia\Core\Template\Loop\Product;
|
||||
use Propel\Runtime\ActiveQuery\Criteria;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -52,7 +53,7 @@ class ProductTest extends BaseLoopTestor
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$product = ProductQuery::create()->findOne();
|
||||
$product = ProductQuery::create()->orderById(Criteria::ASC)->findOne();
|
||||
|
||||
$this->baseTestSearchById($product->getId());
|
||||
}
|
||||
|
||||
60
core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php
Normal file
60
core/lib/Thelia/Tests/Core/Template/Loop/TaxRuleTest.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?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\Core\Template\Loop;
|
||||
|
||||
use Thelia\Tests\Core\Template\Element\BaseLoopTestor;
|
||||
|
||||
use Thelia\Core\Template\Loop\TaxRule;
|
||||
use Thelia\Model\TaxRuleQuery;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class TaxRuleTest extends BaseLoopTestor
|
||||
{
|
||||
public function getTestedClassName()
|
||||
{
|
||||
return 'Thelia\Core\Template\Loop\TaxRule';
|
||||
}
|
||||
|
||||
public function getTestedInstance()
|
||||
{
|
||||
return new TaxRule($this->container);
|
||||
}
|
||||
|
||||
public function getMandatoryArguments()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
public function testSearchById()
|
||||
{
|
||||
$tr = TaxRuleQuery::create()->findOne();
|
||||
|
||||
$this->baseTestSearchById($tr->getId(), array('force_return' => true));
|
||||
}
|
||||
|
||||
}
|
||||
32
core/lib/Thelia/Tests/Form/OrderDeliveryTest.php
Executable file
32
core/lib/Thelia/Tests/Form/OrderDeliveryTest.php
Executable file
@@ -0,0 +1,32 @@
|
||||
<?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\Form;
|
||||
|
||||
class OrderDeliveryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
public function testOrderDelivery()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
53
core/lib/Thelia/Tests/Module/BaseModuleTestor.php
Normal file
53
core/lib/Thelia/Tests/Module/BaseModuleTestor.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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\Module;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Etienne Roudeix <eroudeix@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class BaseModuleTestor extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected $instance;
|
||||
|
||||
abstract public function getTestedClassName();
|
||||
abstract public function getTestedInstance();
|
||||
|
||||
/*protected function getMethod($name)
|
||||
{
|
||||
$class = new \ReflectionClass($this->getTestedClassName());
|
||||
$method = $class->getMethod($name);
|
||||
$method->setAccessible(true);
|
||||
|
||||
return $method;
|
||||
}*/
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->instance = $this->getTestedInstance();
|
||||
}
|
||||
}
|
||||
|
||||
108
core/lib/Thelia/Tests/Rewriting/BaseRewritingObject.php
Normal file
108
core/lib/Thelia/Tests/Rewriting/BaseRewritingObject.php
Normal file
@@ -0,0 +1,108 @@
|
||||
<?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\Rewriting;
|
||||
|
||||
|
||||
/**
|
||||
* Class BaseRewritingObject
|
||||
* @package Thelia\Tests\Rewriting
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
abstract class BaseRewritingObject extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed an instance of Product, Folder, Content or Category Model
|
||||
*/
|
||||
abstract function getObject();
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
*/
|
||||
public function testSimpleFrenchRewrittenUrl()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$object->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('fr_FR')
|
||||
->setTitle('Mon super titre en français')
|
||||
->save();
|
||||
|
||||
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $object->getRewrittenUrl('fr_FR'));
|
||||
|
||||
$rewrittenUrl = $object->generateRewrittenUrl('fr_FR');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
//mon-super-titre-en-français-2.html
|
||||
|
||||
$object->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
*/
|
||||
public function testSimpleEnglishRewrittenUrl()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$object->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('My english super Title')
|
||||
->save();
|
||||
|
||||
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $object->getRewrittenUrl('en_US'));
|
||||
|
||||
$rewrittenUrl = $object->generateRewrittenUrl('en_US');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
|
||||
$object->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Impossible to create an url if title is null
|
||||
*/
|
||||
public function testRewrittenWithoutTitle()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
$object->setVisible(1)
|
||||
->setPosition(1)
|
||||
->setLocale('en_US')
|
||||
->setDescription('My english super Description')
|
||||
->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
* @expectedException \RuntimeException
|
||||
*/
|
||||
public function testOnNotSavedObject()
|
||||
{
|
||||
$object = $this->getObject();
|
||||
|
||||
$object->generateRewrittenUrl('fr_FR');
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Tests/Rewriting/CategoryRewritingTest.php
Normal file
43
core/lib/Thelia/Tests/Rewriting/CategoryRewritingTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Rewriting;
|
||||
use Thelia\Model\Category;
|
||||
|
||||
|
||||
/**
|
||||
* Class CategoryRewritingTest
|
||||
* @package Thelia\Tests\Rewriting
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class CategoryRewritingTest extends BaseRewritingObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Category
|
||||
*/
|
||||
function getObject()
|
||||
{
|
||||
return new Category();
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Tests/Rewriting/ContentRewritingTest.php
Normal file
43
core/lib/Thelia/Tests/Rewriting/ContentRewritingTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Rewriting;
|
||||
use Thelia\Model\Content;
|
||||
|
||||
|
||||
/**
|
||||
* Class ContentRewritingTest
|
||||
* @package Thelia\Tests\Rewriting
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ContentRewritingTest extends BaseRewritingObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @return \Thelia\Model\Content
|
||||
*/
|
||||
function getObject()
|
||||
{
|
||||
return new Content();
|
||||
}
|
||||
}
|
||||
43
core/lib/Thelia/Tests/Rewriting/FolderRewritingTest.php
Normal file
43
core/lib/Thelia/Tests/Rewriting/FolderRewritingTest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?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\Rewriting;
|
||||
use Thelia\Model\Folder;
|
||||
|
||||
|
||||
/**
|
||||
* Class FolderRewritingTest
|
||||
* @package Thelia\Tests\Rewriting
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class FolderRewritingTest extends BaseRewritingObject
|
||||
{
|
||||
|
||||
/**
|
||||
* @return mixed an instance of Product, Folder, Content or Category Model
|
||||
*/
|
||||
function getObject()
|
||||
{
|
||||
return new Folder();
|
||||
}
|
||||
}
|
||||
@@ -31,59 +31,14 @@ use Thelia\Model\ProductQuery;
|
||||
* @package Thelia\Tests\Rewriting
|
||||
* @author Manuel Raynaud <mraynaud@openstudio.fr>
|
||||
*/
|
||||
class ProductRewriteTest extends \PHPUnit_Framework_TestCase
|
||||
class ProductRewriteTest extends BaseRewritingObject
|
||||
{
|
||||
protected static $productId;
|
||||
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
$product = new Product();
|
||||
$product->setRef(sprintf("TestRewrittenProduct%s",uniqid()))
|
||||
->setPosition(1)
|
||||
->setVisible(1)
|
||||
->setLocale('en_US')
|
||||
->setTitle('My english super Title')
|
||||
->setLocale('fr_FR')
|
||||
->setTitle('Mon super titre en français')
|
||||
->save();
|
||||
|
||||
self::$productId = $product->getId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
* @return mixed an instance of Product, Folder, Content or Category Model
|
||||
*/
|
||||
public function testFrenchRewrittenUrl()
|
||||
function getObject()
|
||||
{
|
||||
$product = ProductQuery::create()->findPk(self::$productId);
|
||||
|
||||
$rewrittenUrl = $product->generateRewrittenUrl('fr_FR');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^mon-super-titre-en-français(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
//mon-super-titre-en-français-2.html
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
*/
|
||||
public function testEnglishRewrittenUrl()
|
||||
{
|
||||
$product = ProductQuery::create()->findPk(self::$productId);
|
||||
|
||||
$rewrittenUrl = $product->generateRewrittenUrl('en_US');
|
||||
$this->assertNotNull($rewrittenUrl, "rewritten url can not be null");
|
||||
$this->assertRegExp('/^my-english-super-title(-[0-9]+)?\.html$/', $rewrittenUrl);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Model\Tools\UrlRewritingTrait::generateRewrittenUrl
|
||||
* @expectedException \RuntimeException
|
||||
* @expectedExceptionMessage Object product must be saved before generating url
|
||||
*/
|
||||
public function testOnNotSavedProduct()
|
||||
{
|
||||
$product = new Product();
|
||||
|
||||
$product->generateRewrittenUrl('fr_FR');
|
||||
return new Product();
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$productQuery = ProductQuery::create()->findOneById(1);
|
||||
$productQuery = ProductQuery::create()->findOne();
|
||||
$countryQuery = CountryQuery::create()->findOneById(64);
|
||||
|
||||
$calculator = new Calculator();
|
||||
@@ -86,7 +86,7 @@ class CalculatorTest extends \PHPUnit_Framework_TestCase
|
||||
$taxRuleQuery = $this->getMock('\Thelia\Model\TaxRuleQuery', array('getTaxCalculatorCollection'));
|
||||
$taxRuleQuery->expects($this->once())
|
||||
->method('getTaxCalculatorCollection')
|
||||
->with($productQuery, $countryQuery)
|
||||
->with($productQuery->getTaxRule(), $countryQuery)
|
||||
->will($this->returnValue('foo'));
|
||||
|
||||
$rewritingUrlQuery = $this->getProperty('taxRuleQuery');
|
||||
|
||||
Reference in New Issue
Block a user