Fix tests and bugs

modifié:         core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php
	modifié:         core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php
	modifié:         core/lib/Thelia/ImportExport/Export/Type/CustomerExport.php
	modifié:         core/lib/Thelia/Tests/Controller/ImportControllerTest.php
	modifié:         core/lib/Thelia/Tests/ImportExport/Export/CustomerExportTest.php
This commit is contained in:
Benjamin Perche
2014-07-25 08:50:16 +02:00
parent f73703c578
commit 7adc31514e
5 changed files with 32 additions and 27 deletions

View File

@@ -31,7 +31,7 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface
protected $logger; protected $logger;
/** @var array */ /** @var array */
protected $order; protected $order = array();
public function __construct() public function __construct()
{ {
@@ -54,7 +54,7 @@ abstract class AbstractFormatter implements FormatInterface, FormatterInterface
public function checkOrders(array $values) public function checkOrders(array $values)
{ {
foreach ($this->order as $order) { foreach ($this->getOrder() as $order) {
if (!array_key_exists($order, $values)) { if (!array_key_exists($order, $values)) {
throw new \ErrorException( throw new \ErrorException(
$this->translator->trans( $this->translator->trans(

View File

@@ -77,12 +77,6 @@ class FormatterData
*/ */
public function setData(array $data) public function setData(array $data)
{ {
if (empty($this->aliases)) {
$this->data = $data;
return $this;
}
$this->data = $this->applyAliases($data, $this->aliases); $this->data = $this->applyAliases($data, $this->aliases);
return $this; return $this;

View File

@@ -224,16 +224,15 @@ class CustomerExport extends ExportHandler
$lastOrderDate = null; $lastOrderDate = null;
$lastOrder = null; $lastOrder = null;
$lastOrderCurrencyCode = null; $lastOrderCurrencyCode = null;
$lastOrderId = 0;
$defaultCurrency = Currency::getDefaultCurrency(); $defaultCurrency = Currency::getDefaultCurrency();
$defaultCurrencyCode = $defaultCurrency $defaultCurrencyCode = $defaultCurrency
->setLocale($locale)
->getCode() ->getCode()
; ;
if (empty($defaultCurrencyCode)) { if (empty($defaultCurrencyCode)) {
$defaultCurrencyCode = $defaultCurrency $defaultCurrencyCode = $defaultCurrency
->setLocale($defaultLocale)
->getCode() ->getCode()
; ;
} }
@@ -256,9 +255,10 @@ class CustomerExport extends ExportHandler
/** @var \DateTime $date */ /** @var \DateTime $date */
$date = $currentOrder->getCreatedAt(); $date = $currentOrder->getCreatedAt();
if (null === $lastOrderDate || $date > $lastOrderDate) { if (null === $lastOrderDate || ($date >= $lastOrderDate && $lastOrderId < $currentOrder->getId())) {
$lastOrder = $currentOrder; $lastOrder = $currentOrder;
$lastOrderDate = $date; $lastOrderDate = $date;
$lastOrderId = $currentOrder->getId();
} }
$orders->next(); $orders->next();
@@ -269,13 +269,11 @@ class CustomerExport extends ExportHandler
$orderCurrency = $lastOrder->getCurrency(); $orderCurrency = $lastOrder->getCurrency();
$lastOrderCurrencyCode = $orderCurrency $lastOrderCurrencyCode = $orderCurrency
->setLocale($locale)
->getCode() ->getCode()
; ;
if (empty($lastOrderCurrencyCode)) { if (empty($lastOrderCurrencyCode)) {
$lastOrderCurrencyCode = $orderCurrency $lastOrderCurrencyCode = $orderCurrency
->setLocale($defaultLocale)
->getCode() ->getCode()
; ;
} }

View File

@@ -116,7 +116,11 @@ class ImportControllerTrait extends ControllerTestBase
$handler = $this $handler = $this
->getMock( ->getMock(
"\\Thelia\\ImportExport\\Import\\ImportHandler", "\\Thelia\\ImportExport\\Import\\ImportHandler",
[], [
"getMandatoryColumns",
"retrieveFromFormatterData",
"getHandledTypes"
],
[ [
$this->container $this->container
] ]
@@ -157,7 +161,11 @@ class ImportControllerTrait extends ControllerTestBase
$handler = $this $handler = $this
->getMock( ->getMock(
"\\Thelia\\ImportExport\\Import\\ImportHandler", "\\Thelia\\ImportExport\\Import\\ImportHandler",
[], [
"getMandatoryColumns",
"retrieveFromFormatterData",
"getHandledTypes"
],
[ [
$this->container $this->container
] ]
@@ -204,7 +212,11 @@ class ImportControllerTrait extends ControllerTestBase
$handler = $this $handler = $this
->getMock( ->getMock(
"\\Thelia\\ImportExport\\Import\\ImportHandler", "\\Thelia\\ImportExport\\Import\\ImportHandler",
[], [
"getMandatoryColumns",
"retrieveFromFormatterData",
"getHandledTypes"
],
[ [
$this->container $this->container
] ]

View File

@@ -100,6 +100,7 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase
$lastOrder = OrderQuery::create() $lastOrder = OrderQuery::create()
->filterByCustomer($customer) ->filterByCustomer($customer)
->orderByCreatedAt(Criteria::DESC) ->orderByCreatedAt(Criteria::DESC)
->orderById(Criteria::DESC)
->findOne() ->findOne()
; ;
@@ -135,15 +136,7 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase
->filterByCustomer($customer) ->filterByCustomer($customer)
->filterByAddress1($rawData[$i]["address1"]) ->filterByAddress1($rawData[$i]["address1"])
->filterByAddress2($rawData[$i]["address2"]) ->filterByAddress2($rawData[$i]["address2"])
->_if(empty($rawData[$i]["address2"]))
->_or()
->filterByAddress2(null, Criteria::ISNULL)
->_endif()
->filterByAddress3($rawData[$i]["address3"]) ->filterByAddress3($rawData[$i]["address3"])
->_if(empty($rawData[$i]["address2"]))
->_or()
->filterByAddress2(null, Criteria::ISNULL)
->_endif()
->filterByFirstname($rawData[$i]["address_first_name"]) ->filterByFirstname($rawData[$i]["address_first_name"])
->filterByLastname($rawData[$i]["address_last_name"]) ->filterByLastname($rawData[$i]["address_last_name"])
->filterByCountryId( ->filterByCountryId(
@@ -163,20 +156,28 @@ class CustomerExportTest extends \PHPUnit_Framework_TestCase
->filterByCellphone($rawData[$i]["cellphone"]) ->filterByCellphone($rawData[$i]["cellphone"])
->_if(empty($rawData[$i]["cellphone"])) ->_if(empty($rawData[$i]["cellphone"]))
->_or() ->_or()
->filterByCompany(null, Criteria::ISNULL) ->filterByCellphone(null, Criteria::ISNULL)
->_endif() ->_endif()
->filterByPhone($rawData[$i]["phone"]) ->filterByPhone($rawData[$i]["phone"])
->_if(empty($rawData[$i]["phone"]))
->_or()
->filterByPhone(null, Criteria::ISNULL)
->_endif()
->filterByLabel($rawData[$i]["label"]) ->filterByLabel($rawData[$i]["label"])
->_if(empty($rawData[$i]["label"]))
->_or()
->filterByLabel(null, Criteria::ISNULL)
->_endif()
->filterByTitleId( ->filterByTitleId(
CustomerTitleI18nQuery::create() CustomerTitleI18nQuery::create()
->filterByLocale($lang->getLocale()) ->filterByLocale($lang->getLocale())
->findOneByShort($rawData[$i]["address_title"]) ->findOneByShort($rawData[$i]["address_title"])
->getId() ->getId()
) )
->find() ->findOne()
; ;
$this->assertEquals(1, $address->count()); $this->assertNotNull($address);
$rowKeys = array_keys($rawData[$i]); $rowKeys = array_keys($rawData[$i]);
sort($rowKeys); sort($rowKeys);