From dc97b65590f77d19070fb9b153fafd9b2039dca5 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Tue, 22 Jul 2014 14:31:27 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20bugs=20and=20add=20ProductPricesExport=20?= =?UTF-8?q?tests=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/The?= =?UTF-8?q?lia/Core/DependencyInjection/Loader/XmlFileLoader.php=20=09modi?= =?UTF-8?q?fi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/ImportExpor?= =?UTF-8?q?t/Export/Type/MailingExport.php=20=09nouveau=20fichier:=20core/?= =?UTF-8?q?lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.ph?= =?UTF-8?q?p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Loader/XmlFileLoader.php | 16 ---- .../Export/Type/MailingExport.php | 3 +- .../Export/ProductPricesExportTest.php | 89 +++++++++++++++++++ 3 files changed, 91 insertions(+), 17 deletions(-) create mode 100644 core/lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.php diff --git a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php index b98cc9204..727ad6b22 100644 --- a/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php +++ b/core/lib/Thelia/Core/DependencyInjection/Loader/XmlFileLoader.php @@ -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); 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); if (null === $category) { diff --git a/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php b/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php index aa2be5303..f42c9b3b3 100644 --- a/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php +++ b/core/lib/Thelia/ImportExport/Export/Type/MailingExport.php @@ -16,6 +16,7 @@ use Thelia\Core\FileFormat\FormatType; use Thelia\Core\Translation\Translator; use Thelia\ImportExport\Export\ExportHandler; use Thelia\Model\CustomerQuery; +use Thelia\Model\Lang; use Thelia\Model\Map\CustomerTableMap; use Thelia\Model\Map\NewsletterTableMap; use Thelia\Model\NewsletterQuery; @@ -32,7 +33,7 @@ class MailingExport extends ExportHandler * * The method builds */ - public function buildFormatterData() + public function buildFormatterData(Lang $lang) { $translator = Translator::getInstance(); diff --git a/core/lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.php b/core/lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.php new file mode 100644 index 000000000..fa74938f0 --- /dev/null +++ b/core/lib/Thelia/Tests/ImportExport/Export/ProductPricesExportTest.php @@ -0,0 +1,89 @@ + + */ +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); + } + } +} \ No newline at end of file