Add ProductPriceImport test
modifié: core/lib/Thelia/ImportExport/Import/Type/ProductPriceImport.php modifié: core/lib/Thelia/Tests/Controller/ControllerTestBase.php nouveau fichier: core/lib/Thelia/Tests/ImportExport/Import/ProductPriceImportTest.php
This commit is contained in:
@@ -15,6 +15,7 @@ use Thelia\Core\FileFormat\Formatting\FormatterData;
|
|||||||
use Thelia\Core\FileFormat\FormatType;
|
use Thelia\Core\FileFormat\FormatType;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\ImportExport\Import\ImportHandler;
|
use Thelia\ImportExport\Import\ImportHandler;
|
||||||
|
use Thelia\Model\Currency;
|
||||||
use Thelia\Model\CurrencyQuery;
|
use Thelia\Model\CurrencyQuery;
|
||||||
use Thelia\Model\ProductPrice;
|
use Thelia\Model\ProductPrice;
|
||||||
use Thelia\Model\ProductPriceQuery;
|
use Thelia\Model\ProductPriceQuery;
|
||||||
@@ -82,7 +83,7 @@ class ProductPriceImport extends ImportHandler
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($currency === null) {
|
if ($currency === null) {
|
||||||
$currency = $this->getRequest()->getSession()->getCurrency();
|
$currency = Currency::getDefaultCurrency();
|
||||||
}
|
}
|
||||||
|
|
||||||
$price = ProductPriceQuery::create()
|
$price = ProductPriceQuery::create()
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
namespace Thelia\Tests\Controller;
|
namespace Thelia\Tests\Controller;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Thelia\Controller\Admin\ImportController;
|
use Thelia\Controller\Admin\ImportController;
|
||||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
|
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarArchiveBuilder;
|
||||||
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
|
use Thelia\Core\FileFormat\Archive\ArchiveBuilder\TarBz2ArchiveBuilder;
|
||||||
@@ -36,7 +37,10 @@ abstract class ControllerTestBase extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
protected $import;
|
protected $import;
|
||||||
|
|
||||||
|
/** @var ContainerInterface */
|
||||||
protected $container;
|
protected $container;
|
||||||
|
|
||||||
|
/** @var Session */
|
||||||
protected $session;
|
protected $session;
|
||||||
|
|
||||||
/** @var ImportController */
|
/** @var ImportController */
|
||||||
@@ -51,13 +55,13 @@ abstract class ControllerTestBase extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$container->set("event_dispatcher", $dispatcher);
|
$container->set("event_dispatcher", $dispatcher);
|
||||||
|
|
||||||
$this->buildContainer($container);
|
|
||||||
|
|
||||||
$request = new Request();
|
$request = new Request();
|
||||||
$request->setSession($this->session);
|
$request->setSession($this->session);
|
||||||
|
|
||||||
$container->set("request", $request);
|
$container->set("request", $request);
|
||||||
|
|
||||||
|
$this->buildContainer($container);
|
||||||
|
|
||||||
return $container;
|
return $container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,114 @@
|
|||||||
|
<?php
|
||||||
|
/*************************************************************************************/
|
||||||
|
/* This file is part of the Thelia package. */
|
||||||
|
/* */
|
||||||
|
/* Copyright (c) OpenStudio */
|
||||||
|
/* email : dev@thelia.net */
|
||||||
|
/* web : http://www.thelia.net */
|
||||||
|
/* */
|
||||||
|
/* For the full copyright and license information, please view the LICENSE.txt */
|
||||||
|
/* file that was distributed with this source code. */
|
||||||
|
/*************************************************************************************/
|
||||||
|
|
||||||
|
namespace Thelia\Tests\ImportExport\Import;
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Thelia\Controller\Admin\ImportController;
|
||||||
|
use Thelia\Core\FileFormat\Formatting\Formatter\JsonFormatter;
|
||||||
|
use Thelia\ImportExport\Import\Type\ProductPriceImport;
|
||||||
|
use Thelia\Model\Currency;
|
||||||
|
use Thelia\Model\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Tests\Controller\ControllerTestBase;
|
||||||
|
use Thelia\Tests\Controller\ImportExportControllerTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductPriceImportTest
|
||||||
|
* @package Thelia\Tests\ImportExport\Import
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ProductPriceImportTest extends ControllerTestBase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Use this method to build the container with the services that you need.
|
||||||
|
*/
|
||||||
|
protected function buildContainer(ContainerBuilder $container)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return \Thelia\Controller\BaseController The controller you want to test
|
||||||
|
*/
|
||||||
|
protected function getController()
|
||||||
|
{
|
||||||
|
return new ImportController();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
|
||||||
|
$this->import = new ProductPriceImport($this->container);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testImport()
|
||||||
|
{
|
||||||
|
$currency = Currency::getDefaultCurrency();
|
||||||
|
|
||||||
|
$query = ProductSaleElementsQuery::create()
|
||||||
|
->addAscendingOrderByColumn('RAND()')
|
||||||
|
->limit(3)
|
||||||
|
->find()
|
||||||
|
;
|
||||||
|
|
||||||
|
$jsonData = [];
|
||||||
|
$data = [];
|
||||||
|
|
||||||
|
/** @var \Thelia\Model\ProductSaleElements $pse */
|
||||||
|
foreach ($query as $pse) {
|
||||||
|
|
||||||
|
$entry = [];
|
||||||
|
|
||||||
|
$entry["ref"] = $pse->getRef();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Be sure to get a different value.
|
||||||
|
*/
|
||||||
|
while ($pse->getPricesByCurrency($currency)->getPrice() === $entry["price"] = rand(0, 1000));
|
||||||
|
while ($pse->getPricesByCurrency($currency)->getPromoPrice() === $entry["promo_price"] = rand(0, 1000));
|
||||||
|
|
||||||
|
$data[$pse->getId()] = $entry;
|
||||||
|
|
||||||
|
$jsonData[] = $entry;
|
||||||
|
}
|
||||||
|
|
||||||
|
$jsonString = json_encode($jsonData);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
"Import successfully done",
|
||||||
|
$this->controller->processImport(
|
||||||
|
$jsonString,
|
||||||
|
$this->import,
|
||||||
|
new JsonFormatter(),
|
||||||
|
null
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
$query = ProductSaleElementsQuery::create()->findPks(array_keys($data));
|
||||||
|
|
||||||
|
/** @var \Thelia\Model\ProductSaleElements $entry */
|
||||||
|
foreach ($query as $entry) {
|
||||||
|
$this->assertEquals(
|
||||||
|
$data[$entry->getId()],
|
||||||
|
[
|
||||||
|
"price" => $entry->getPricesByCurrency($currency)->getPrice(),
|
||||||
|
"promo_price" => $entry->getPricesByCurrency($currency)->getPromoPrice(),
|
||||||
|
"ref" => $entry->getRef()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user