From 7adc31514e599ba80a773443247630dbfc78fad0 Mon Sep 17 00:00:00 2001 From: Benjamin Perche Date: Fri, 25 Jul 2014 08:50:16 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20tests=20and=20bugs=20=09modifi=C3=A9:=20?= =?UTF-8?q?=20=20=20=20=20=20=20=20core/lib/Thelia/Core/FileFormat/Formatt?= =?UTF-8?q?ing/AbstractFormatter.php=20=09modifi=C3=A9:=20=20=20=20=20=20?= =?UTF-8?q?=20=20=20core/lib/Thelia/Core/FileFormat/Formatting/FormatterDa?= =?UTF-8?q?ta.php=20=09modifi=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Th?= =?UTF-8?q?elia/ImportExport/Export/Type/CustomerExport.php=20=09modifi?= =?UTF-8?q?=C3=A9:=20=20=20=20=20=20=20=20=20core/lib/Thelia/Tests/Control?= =?UTF-8?q?ler/ImportControllerTest.php=20=09modifi=C3=A9:=20=20=20=20=20?= =?UTF-8?q?=20=20=20=20core/lib/Thelia/Tests/ImportExport/Export/CustomerE?= =?UTF-8?q?xportTest.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Formatting/AbstractFormatter.php | 4 ++-- .../FileFormat/Formatting/FormatterData.php | 6 ----- .../Export/Type/CustomerExport.php | 8 +++---- .../Tests/Controller/ImportControllerTest.php | 18 ++++++++++++--- .../Export/CustomerExportTest.php | 23 ++++++++++--------- 5 files changed, 32 insertions(+), 27 deletions(-) diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php index a6a867405..f8c9993a6 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php @@ -31,7 +31,7 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface protected $logger; /** @var array */ - protected $order; + protected $order = array(); public function __construct() { @@ -54,7 +54,7 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface public function checkOrders(array $values) { - foreach ($this->order as $order) { + foreach ($this->getOrder() as $order) { if (!array_key_exists($order, $values)) { throw new \ErrorException( $this->translator->trans( diff --git a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php index 9d048e543..cef6547c9 100644 --- a/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php +++ b/core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php @@ -77,12 +77,6 @@ class FormatterData */ public function setData(array $data) { - if (empty($this->aliases)) { - $this->data = $data; - - return $this; - } - $this->data = $this->applyAliases($data, $this->aliases); return $this; diff --git a/core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php b/core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php index bbfa5bf8b..e2ffa87ac 100644 --- a/core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php +++ b/core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php @@ -224,16 +224,15 @@ class CustomerExport extends ExportHandler $lastOrderDate = null; $lastOrder = null; $lastOrderCurrencyCode = null; + $lastOrderId = 0; $defaultCurrency = Currency::getDefaultCurrency(); $defaultCurrencyCode = $defaultCurrency - ->setLocale($locale) ->getCode() ; if (empty($defaultCurrencyCode)) { $defaultCurrencyCode = $defaultCurrency - ->setLocale($defaultLocale) ->getCode() ; } @@ -256,9 +255,10 @@ class CustomerExport extends ExportHandler /** @var \DateTime $date */ $date = $currentOrder->getCreatedAt(); - if (null === $lastOrderDate || $date > $lastOrderDate) { + if (null === $lastOrderDate || ($date >= $lastOrderDate && $lastOrderId < $currentOrder->getId())) { $lastOrder = $currentOrder; $lastOrderDate = $date; + $lastOrderId = $currentOrder->getId(); } $orders->next(); @@ -269,13 +269,11 @@ class CustomerExport extends ExportHandler $orderCurrency = $lastOrder->getCurrency(); $lastOrderCurrencyCode = $orderCurrency - ->setLocale($locale) ->getCode() ; if (empty($lastOrderCurrencyCode)) { $lastOrderCurrencyCode = $orderCurrency - ->setLocale($defaultLocale) ->getCode() ; } diff --git a/core/lib/Thelia/Tests/Controller/ImportControllerTest.php b/core/lib/Thelia/Tests/Controller/ImportControllerTest.php index d6ae59ed8..685541b6e 100644 --- a/core/lib/Thelia/Tests/Controller/ImportControllerTest.php +++ b/core/lib/Thelia/Tests/Controller/ImportControllerTest.php @@ -116,7 +116,11 @@ class ImportControllerTrait extends ControllerTestBase $handler = $this ->getMock( "\\Thelia\\ImportExport\\Import\\ImportHandler", - [], + [ + "getMandatoryColumns", + "retrieveFromFormatterData", + "getHandledTypes" + ], [ $this->container ] @@ -157,7 +161,11 @@ class ImportControllerTrait extends ControllerTestBase $handler = $this ->getMock( "\\Thelia\\ImportExport\\Import\\ImportHandler", - [], + [ + "getMandatoryColumns", + "retrieveFromFormatterData", + "getHandledTypes" + ], [ $this->container ] @@ -204,7 +212,11 @@ class ImportControllerTrait extends ControllerTestBase $handler = $this ->getMock( "\\Thelia\\ImportExport\\Import\\ImportHandler", - [], + [ + "getMandatoryColumns", + "retrieveFromFormatterData", + "getHandledTypes" + ], [ $this->container ] diff --git a/core/lib/Thelia/Tests/ImportExport/Export/CustomerExportTest.php b/core/lib/Thelia/Tests/ImportExport/Export/CustomerExportTest.php index 52c7359f2..bd8ec09b0 100644 --- a/core/lib/Thelia/Tests/ImportExport/Export/CustomerExportTest.php +++ b/core/lib/Thelia/Tests/ImportExport/Export/CustomerExportTest.php @@ -100,6 +100,7 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase $lastOrder = OrderQuery::create() ->filterByCustomer($customer) ->orderByCreatedAt(Criteria::DESC) + ->orderById(Criteria::DESC) ->findOne() ; @@ -135,15 +136,7 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase ->filterByCustomer($customer) ->filterByAddress1($rawData[$i]["address1"]) ->filterByAddress2($rawData[$i]["address2"]) - ->_if(empty($rawData[$i]["address2"])) - ->_or() - ->filterByAddress2(null, Criteria::ISNULL) - ->_endif() ->filterByAddress3($rawData[$i]["address3"]) - ->_if(empty($rawData[$i]["address2"])) - ->_or() - ->filterByAddress2(null, Criteria::ISNULL) - ->_endif() ->filterByFirstname($rawData[$i]["address_first_name"]) ->filterByLastname($rawData[$i]["address_last_name"]) ->filterByCountryId( @@ -163,20 +156,28 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase ->filterByCellphone($rawData[$i]["cellphone"]) ->_if(empty($rawData[$i]["cellphone"])) ->_or() - ->filterByCompany(null, Criteria::ISNULL) + ->filterByCellphone(null, Criteria::ISNULL) ->_endif() ->filterByPhone($rawData[$i]["phone"]) + ->_if(empty($rawData[$i]["phone"])) + ->_or() + ->filterByPhone(null, Criteria::ISNULL) + ->_endif() ->filterByLabel($rawData[$i]["label"]) + ->_if(empty($rawData[$i]["label"])) + ->_or() + ->filterByLabel(null, Criteria::ISNULL) + ->_endif() ->filterByTitleId( CustomerTitleI18nQuery::create() ->filterByLocale($lang->getLocale()) ->findOneByShort($rawData[$i]["address_title"]) ->getId() ) - ->find() + ->findOne() ; - $this->assertEquals(1, $address->count()); + $this->assertNotNull($address); $rowKeys = array_keys($rawData[$i]); sort($rowKeys);