Fix bugs and add ProductPricesExport tests
modifié: core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php modifié: core/lib/Thelia/ImportExport/Export/Type/MailingExport.php nouveau fichier: core/lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.php
This commit is contained in:
@@ -368,14 +368,6 @@ class XmlFileLoader extends FileLoader
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$classInstance = new $class($this->container);
|
|
||||||
|
|
||||||
if (!$classInstance instanceof ExportHandler) {
|
|
||||||
throw new \ErrorException(
|
|
||||||
"The class \"$class\" must extend Thelia\\ImportExport\\Export\\ExportHandler"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = ExportCategoryQuery::create()->findOneByRef($categoryRef);
|
$category = ExportCategoryQuery::create()->findOneByRef($categoryRef);
|
||||||
|
|
||||||
if (null === $category) {
|
if (null === $category) {
|
||||||
@@ -505,14 +497,6 @@ class XmlFileLoader extends FileLoader
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$classInstance = new $class($this->container);
|
|
||||||
|
|
||||||
if (!$classInstance instanceof ImportHandler) {
|
|
||||||
throw new \ErrorException(
|
|
||||||
"The class \"$class\" must extend Thelia\\ImportImport\\ImportHandler"
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
$category = ImportCategoryQuery::create()->findOneByRef($categoryRef);
|
$category = ImportCategoryQuery::create()->findOneByRef($categoryRef);
|
||||||
|
|
||||||
if (null === $category) {
|
if (null === $category) {
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use Thelia\Core\FileFormat\FormatType;
|
|||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\ImportExport\Export\ExportHandler;
|
use Thelia\ImportExport\Export\ExportHandler;
|
||||||
use Thelia\Model\CustomerQuery;
|
use Thelia\Model\CustomerQuery;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
use Thelia\Model\Map\CustomerTableMap;
|
use Thelia\Model\Map\CustomerTableMap;
|
||||||
use Thelia\Model\Map\NewsletterTableMap;
|
use Thelia\Model\Map\NewsletterTableMap;
|
||||||
use Thelia\Model\NewsletterQuery;
|
use Thelia\Model\NewsletterQuery;
|
||||||
@@ -32,7 +33,7 @@ class MailingExport extends ExportHandler
|
|||||||
*
|
*
|
||||||
* The method builds
|
* The method builds
|
||||||
*/
|
*/
|
||||||
public function buildFormatterData()
|
public function buildFormatterData(Lang $lang)
|
||||||
{
|
{
|
||||||
$translator = Translator::getInstance();
|
$translator = Translator::getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
<?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\Export;
|
||||||
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
|
use Thelia\Core\Translation\Translator;
|
||||||
|
use Thelia\ImportExport\Export\Type\ProductPricesExport;
|
||||||
|
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||||
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
|
use Thelia\Model\LangQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class ProductPricesExportTest
|
||||||
|
* @package Thelia\Tests\ImportExport\Export
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class ProductPricesExportTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testQuery()
|
||||||
|
{
|
||||||
|
new Translator(new Container());
|
||||||
|
$export = new ProductPricesExport(new Container());
|
||||||
|
|
||||||
|
$data = $export->buildFormatterData(Lang::getDefaultLanguage());
|
||||||
|
|
||||||
|
$keys = ["attributes","currency","ean","price","promo_price","ref","title"];
|
||||||
|
|
||||||
|
$rawData = $data->getData();
|
||||||
|
|
||||||
|
$max = count($rawData);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If there's more that 50 entries,
|
||||||
|
* just pick 50, it would be faster and as tested as if we test 1000 entries.
|
||||||
|
*/
|
||||||
|
if ($max > 50) {
|
||||||
|
$max = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
for ($i = 0; $i < $max; ++$i)
|
||||||
|
{
|
||||||
|
$row = $rawData[$i];
|
||||||
|
|
||||||
|
$rowKeys = array_keys($row);
|
||||||
|
|
||||||
|
$this->assertTrue(sort($rowKeys));
|
||||||
|
$this->assertEquals($keys, $rowKeys);
|
||||||
|
|
||||||
|
$pse = ProductSaleElementsQuery::create()
|
||||||
|
->findOneByRef($row["ref"])
|
||||||
|
;
|
||||||
|
|
||||||
|
$this->assertNotNull($pse);
|
||||||
|
$this->assertEquals($pse->getEanCode(),$row["ean"]);
|
||||||
|
|
||||||
|
$currency = CurrencyQuery::create()->findOneByCode($row["currency"]);
|
||||||
|
$this->assertNotNull($currency);
|
||||||
|
|
||||||
|
$price = $pse->getPricesByCurrency($currency);
|
||||||
|
$this->assertEquals($price->getPrice(), $row["price"]);
|
||||||
|
$this->assertEquals($price->getPromoPrice(), $row["promo_price"]);
|
||||||
|
$this->assertEquals($pse->getProduct()->getTitle(), $row["title"]);
|
||||||
|
|
||||||
|
$attributeCombinations = $pse->getAttributeCombinations();
|
||||||
|
$attributes = [];
|
||||||
|
|
||||||
|
foreach ($attributeCombinations as $attributeCombination) {
|
||||||
|
$attributes[] = $attributeCombination->getAttributeAv()->getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
$rowAttributes = explode(",", $row["attributes"]);
|
||||||
|
|
||||||
|
sort($rowAttributes);
|
||||||
|
sort($attributes);
|
||||||
|
|
||||||
|
$this->assertEquals($attributes, $rowAttributes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user