Add tests on OrderExport
modifié: core/lib/Thelia/ImportExport/Export/Type/OrderExport.php nouveau fichier: core/lib/Thelia/Tests/ImportExport/Export/OrderExportTest.php
This commit is contained in:
@@ -28,6 +28,7 @@ use Thelia\Model\Map\OrderCouponTableMap;
|
|||||||
use Thelia\Model\Map\OrderProductTableMap;
|
use Thelia\Model\Map\OrderProductTableMap;
|
||||||
use Thelia\Model\Map\OrderProductTaxTableMap;
|
use Thelia\Model\Map\OrderProductTaxTableMap;
|
||||||
use Thelia\Model\Map\OrderStatusI18nTableMap;
|
use Thelia\Model\Map\OrderStatusI18nTableMap;
|
||||||
|
use Thelia\Model\Map\OrderStatusTableMap;
|
||||||
use Thelia\Model\Map\OrderTableMap;
|
use Thelia\Model\Map\OrderTableMap;
|
||||||
use Thelia\Model\OrderQuery;
|
use Thelia\Model\OrderQuery;
|
||||||
|
|
||||||
@@ -61,11 +62,7 @@ class OrderExport extends ExportHandler
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function getQuery(Lang $lang)
|
||||||
* @param Lang $lang
|
|
||||||
* @return ModelCriteria|array|BaseLoop
|
|
||||||
*/
|
|
||||||
public function buildDataSet(Lang $lang)
|
|
||||||
{
|
{
|
||||||
$locale = $lang->getLocale();
|
$locale = $lang->getLocale();
|
||||||
|
|
||||||
@@ -85,15 +82,16 @@ class OrderExport extends ExportHandler
|
|||||||
"SUM(".OrderProductTaxTableMap::AMOUNT.")".
|
"SUM(".OrderProductTaxTableMap::AMOUNT.")".
|
||||||
")"
|
")"
|
||||||
)
|
)
|
||||||
->addAsColumn("tax_TITLE", OrderProductTaxTableMap::TITLE)
|
->addAsColumn("tax_TITLE", OrderProductTableMap::TAX_RULE_TITLE)
|
||||||
->endUse()
|
->endUse()
|
||||||
->addAsColumn("product_TITLE", OrderProductTableMap::TITLE)
|
->addAsColumn("product_TITLE", OrderProductTableMap::TITLE)
|
||||||
->addAsColumn(
|
->addAsColumn(
|
||||||
"product_PRICE",
|
"product_PRICE",
|
||||||
"IF(".OrderProductTableMap::WAS_IN_PROMO.",".
|
"IF(".OrderProductTableMap::WAS_IN_PROMO.",".
|
||||||
OrderProductTableMap::PROMO_PRICE .",".
|
OrderProductTableMap::PROMO_PRICE .",".
|
||||||
OrderProductTableMap::PRICE .")"
|
OrderProductTableMap::PRICE .
|
||||||
)
|
")"
|
||||||
|
)
|
||||||
->addAsColumn("product_QUANTITY", OrderProductTableMap::QUANTITY)
|
->addAsColumn("product_QUANTITY", OrderProductTableMap::QUANTITY)
|
||||||
->addAsColumn("product_WAS_IN_PROMO", OrderProductTableMap::WAS_IN_PROMO)
|
->addAsColumn("product_WAS_IN_PROMO", OrderProductTableMap::WAS_IN_PROMO)
|
||||||
->groupById()
|
->groupById()
|
||||||
@@ -120,16 +118,16 @@ class OrderExport extends ExportHandler
|
|||||||
->useCountryI18nQuery("delivery_address_country_i18n_join")
|
->useCountryI18nQuery("delivery_address_country_i18n_join")
|
||||||
->addAsColumn("delivery_address_country_TITLE", "`delivery_address_country_i18n_join`.TITLE")
|
->addAsColumn("delivery_address_country_TITLE", "`delivery_address_country_i18n_join`.TITLE")
|
||||||
->endUse()
|
->endUse()
|
||||||
|
->addAsColumn("delivery_address_COMPANY", "`delivery_address_join`.COMPANY")
|
||||||
|
->addAsColumn("delivery_address_FIRSTNAME", "`delivery_address_join`.FIRSTNAME")
|
||||||
|
->addAsColumn("delivery_address_LASTNAME", "`delivery_address_join`.LASTNAME")
|
||||||
|
->addAsColumn("delivery_address_ADDRESS1", "`delivery_address_join`.ADDRESS1")
|
||||||
|
->addAsColumn("delivery_address_ADDRESS2", "`delivery_address_join`.ADDRESS2")
|
||||||
|
->addAsColumn("delivery_address_ADDRESS3", "`delivery_address_join`.ADDRESS3")
|
||||||
|
->addAsColumn("delivery_address_ZIPCODE", "`delivery_address_join`.ZIPCODE")
|
||||||
|
->addAsColumn("delivery_address_CITY", "`delivery_address_join`.CITY")
|
||||||
|
->addAsColumn("delivery_address_PHONE", "`delivery_address_join`.PHONE")
|
||||||
->endUse()
|
->endUse()
|
||||||
->addAsColumn("delivery_address_COMPANY", "`delivery_address_join`.COMPANY")
|
|
||||||
->addAsColumn("delivery_address_FIRSTNAME", "`delivery_address_join`.FIRSTNAME")
|
|
||||||
->addAsColumn("delivery_address_LASTNAME", "`delivery_address_join`.LASTNAME")
|
|
||||||
->addAsColumn("delivery_address_ADDRESS1", "`delivery_address_join`.ADDRESS1")
|
|
||||||
->addAsColumn("delivery_address_ADDRESS2", "`delivery_address_join`.ADDRESS2")
|
|
||||||
->addAsColumn("delivery_address_ADDRESS3", "`delivery_address_join`.ADDRESS3")
|
|
||||||
->addAsColumn("delivery_address_ZIPCODE", "`delivery_address_join`.ZIPCODE")
|
|
||||||
->addAsColumn("delivery_address_CITY", "`delivery_address_join`.CITY")
|
|
||||||
->addAsColumn("delivery_address_PHONE", "`delivery_address_join`.PHONE")
|
|
||||||
->endUse()
|
->endUse()
|
||||||
->useOrderAddressRelatedByInvoiceOrderAddressIdQuery("invoice_address_join")
|
->useOrderAddressRelatedByInvoiceOrderAddressIdQuery("invoice_address_join")
|
||||||
->useCustomerTitleQuery("invoice_address_customer_title_join")
|
->useCustomerTitleQuery("invoice_address_customer_title_join")
|
||||||
@@ -175,6 +173,7 @@ class OrderExport extends ExportHandler
|
|||||||
// total ttc +postage
|
// total ttc +postage
|
||||||
"payment_module_TITLE",
|
"payment_module_TITLE",
|
||||||
OrderTableMap::INVOICE_REF,
|
OrderTableMap::INVOICE_REF,
|
||||||
|
OrderTableMap::DELIVERY_REF,
|
||||||
"delivery_module_TITLE",
|
"delivery_module_TITLE",
|
||||||
"delivery_address_TITLE",
|
"delivery_address_TITLE",
|
||||||
"delivery_address_COMPANY",
|
"delivery_address_COMPANY",
|
||||||
@@ -239,6 +238,27 @@ class OrderExport extends ExportHandler
|
|||||||
$locale
|
$locale
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->addI18nCondition(
|
||||||
|
$query,
|
||||||
|
OrderStatusI18nTableMap::TABLE_NAME,
|
||||||
|
OrderStatusI18nTableMap::ID,
|
||||||
|
OrderStatusTableMap::ID,
|
||||||
|
OrderStatusI18nTableMap::LOCALE,
|
||||||
|
$locale
|
||||||
|
);
|
||||||
|
|
||||||
|
return $query;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Lang $lang
|
||||||
|
* @return ModelCriteria|array|BaseLoop
|
||||||
|
*/
|
||||||
|
public function buildDataSet(Lang $lang)
|
||||||
|
{
|
||||||
|
|
||||||
|
$query = $this->getQuery($lang);
|
||||||
|
|
||||||
$dataSet = $query
|
$dataSet = $query
|
||||||
->find()
|
->find()
|
||||||
->toArray()
|
->toArray()
|
||||||
@@ -315,4 +335,101 @@ class OrderExport extends ExportHandler
|
|||||||
return $dataSet;
|
return $dataSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getAliases()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
OrderTableMap::REF => "ref",
|
||||||
|
"customer_REF" => "customer_ref",
|
||||||
|
"product_TITLE" => "product_title",
|
||||||
|
"product_PRICE" => "price",
|
||||||
|
"product_TAX" => "tax_amount",
|
||||||
|
"tax_TITLE" => "tax_title",
|
||||||
|
"order_TOTAL_TTC" => "total_including_taxes",
|
||||||
|
"product_QUANTITY" => "quantity",
|
||||||
|
"product_WAS_IN_PROMO" => "was_in_promo",
|
||||||
|
"order_TOTAL_WITH_DISCOUNT" => "total_with_discount",
|
||||||
|
OrderTableMap::DISCOUNT => "discount",
|
||||||
|
"coupon_COUPONS" => "coupons",
|
||||||
|
"order_TOTAL_WITH_DISCOUNT_AND_POSTAGE" => "total_discount_and_postage",
|
||||||
|
OrderTableMap::POSTAGE => "postage",
|
||||||
|
"product_TAXED_PRICE" => "taxed_price",
|
||||||
|
"payment_module_TITLE" => "payment_module",
|
||||||
|
OrderTableMap::INVOICE_REF => "invoice_ref",
|
||||||
|
OrderTableMap::DELIVERY_REF => "delivery_ref",
|
||||||
|
"delivery_module_TITLE" => "delivery_module",
|
||||||
|
"delivery_address_TITLE" => "delivery_title",
|
||||||
|
"delivery_address_COMPANY" => "delivery_company",
|
||||||
|
"delivery_address_FIRSTNAME" => "delivery_first_name",
|
||||||
|
"delivery_address_LASTNAME" => "delivery_last_name",
|
||||||
|
"delivery_address_ADDRESS1" => "delivery_address1",
|
||||||
|
"delivery_address_ADDRESS2" => "delivery_address2",
|
||||||
|
"delivery_address_ADDRESS3" => "delivery_address3",
|
||||||
|
"delivery_address_ZIPCODE" => "delivery_zip_code",
|
||||||
|
"delivery_address_CITY" => "delivery_city",
|
||||||
|
"delivery_address_country_TITLE" => "delivery_country",
|
||||||
|
"delivery_address_PHONE" => "delivery_phone",
|
||||||
|
"invoice_address_TITLE" => "invoice_title",
|
||||||
|
"invoice_address_COMPANY" => "invoice_company",
|
||||||
|
"invoice_address_FIRSTNAME" => "invoice_first_name",
|
||||||
|
"invoice_address_LASTNAME" => "invoice_last_name",
|
||||||
|
"invoice_address_ADDRESS1" => "invoice_address1",
|
||||||
|
"invoice_address_ADDRESS2" => "invoice_address2",
|
||||||
|
"invoice_address_ADDRESS3" => "invoice_address3",
|
||||||
|
"invoice_address_ZIPCODE" => "invoice_zip_code",
|
||||||
|
"invoice_address_CITY" => "invoice_city",
|
||||||
|
"invoice_address_country_TITLE" => "invoice_country",
|
||||||
|
"invoice_address_PHONE" => "invoice_phone",
|
||||||
|
"order_status_TITLE" => "status",
|
||||||
|
"currency_CODE" => "currency",
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getOrder()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
"ref",
|
||||||
|
"customer_ref",
|
||||||
|
"discount",
|
||||||
|
"coupons",
|
||||||
|
"postage",
|
||||||
|
"total_including_taxes",
|
||||||
|
"total_with_discount",
|
||||||
|
"total_discount_and_postage",
|
||||||
|
"delivery_module",
|
||||||
|
"delivery_ref",
|
||||||
|
"payment_module",
|
||||||
|
"invoice_ref",
|
||||||
|
"status",
|
||||||
|
"delivery_title",
|
||||||
|
"delivery_company",
|
||||||
|
"delivery_first_name",
|
||||||
|
"delivery_last_name",
|
||||||
|
"delivery_address1",
|
||||||
|
"delivery_address2",
|
||||||
|
"delivery_address3",
|
||||||
|
"delivery_zip_code",
|
||||||
|
"delivery_city",
|
||||||
|
"delivery_country",
|
||||||
|
"delivery_phone",
|
||||||
|
"invoice_title",
|
||||||
|
"invoice_company",
|
||||||
|
"invoice_first_name",
|
||||||
|
"invoice_last_name",
|
||||||
|
"invoice_address1",
|
||||||
|
"invoice_address2",
|
||||||
|
"invoice_address3",
|
||||||
|
"invoice_zip_code",
|
||||||
|
"invoice_city",
|
||||||
|
"invoice_country",
|
||||||
|
"invoice_phone",
|
||||||
|
"product_title",
|
||||||
|
"price",
|
||||||
|
"taxed_price",
|
||||||
|
"currency",
|
||||||
|
"was_in_promo",
|
||||||
|
"quantity",
|
||||||
|
"tax_amount",
|
||||||
|
"tax_title",
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
149
core/lib/Thelia/Tests/ImportExport/Export/OrderExportTest.php
Normal file
149
core/lib/Thelia/Tests/ImportExport/Export/OrderExportTest.php
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
<?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\OrderExport;
|
||||||
|
use Thelia\Model\Lang;
|
||||||
|
use Thelia\Model\Map\OrderCouponTableMap;
|
||||||
|
use Thelia\Model\Map\OrderProductTableMap;
|
||||||
|
use Thelia\Model\Map\OrderProductTaxTableMap;
|
||||||
|
use Thelia\Model\OrderCouponQuery;
|
||||||
|
use Thelia\Model\OrderProductQuery;
|
||||||
|
use Thelia\Model\OrderQuery;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class OrderExportTest
|
||||||
|
* @package Thelia\Tests\ImportExport\Export
|
||||||
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
|
*/
|
||||||
|
class OrderExportTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function testQuery()
|
||||||
|
{
|
||||||
|
$container = new Container();
|
||||||
|
new Translator($container);
|
||||||
|
|
||||||
|
$handler = new OrderExport($container);
|
||||||
|
|
||||||
|
$lang = Lang::getDefaultLanguage();
|
||||||
|
$locale = $lang->getLocale();
|
||||||
|
|
||||||
|
$data = $handler->buildData($lang)->getData();
|
||||||
|
|
||||||
|
$ordersProductQuery = OrderProductQuery::create();
|
||||||
|
$orders = OrderQuery::create()->find();
|
||||||
|
|
||||||
|
$count = $ordersProductQuery->count();
|
||||||
|
$this->assertEquals(count($data), $count);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For the rest of the test, 50 orders are much enough
|
||||||
|
*/
|
||||||
|
if ($count > 50) {
|
||||||
|
$count = 50;
|
||||||
|
}
|
||||||
|
|
||||||
|
$current = 0;
|
||||||
|
|
||||||
|
for ($i = 0; $i < $count; ++$current) {
|
||||||
|
$row = $data[$i];
|
||||||
|
/** @var \Thelia\Model\Order $order */
|
||||||
|
$order = $orders->get($current);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$ref = $order->getRef(), $row["ref"]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$order->getCustomer()->getRef(), $row["customer_ref"]
|
||||||
|
);
|
||||||
|
|
||||||
|
$coupons = OrderCouponQuery::create()
|
||||||
|
->filterByOrder($order)
|
||||||
|
->select(OrderCouponTableMap::TITLE)
|
||||||
|
->find()
|
||||||
|
->toArray()
|
||||||
|
;
|
||||||
|
$coupons = implode(",", $coupons);
|
||||||
|
|
||||||
|
$this->assertTrue(
|
||||||
|
empty($coupons) ?
|
||||||
|
empty($row["coupons"]):
|
||||||
|
$coupons === $row["coupons"]
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertEquals($order->getCurrency()->getCode(), $row["currency"]);
|
||||||
|
$this->assertEquals($order->getCustomer()->getRef(), $row["customer_ref"]);
|
||||||
|
$this->assertEquals($order->getOrderStatus()->setLocale($locale)->getTitle(), $row["status"]);
|
||||||
|
|
||||||
|
$this->assertEquals($order->getDeliveryRef(), $row["delivery_ref"]);
|
||||||
|
$this->assertEquals($order->getModuleRelatedByDeliveryModuleId()->getCode(), $row["delivery_module"]);
|
||||||
|
$this->assertEquals($order->getInvoiceRef(), $row["invoice_ref"]);
|
||||||
|
$this->assertEquals($order->getModuleRelatedByPaymentModuleId()->getCode(), $row["payment_module"]);
|
||||||
|
|
||||||
|
$this->assertEquals($order->getTotalAmount($tax, false, false), $row["total_including_taxes"]);
|
||||||
|
$this->assertEquals($order->getTotalAmount($tax, false, true), $row["total_with_discount"]);
|
||||||
|
$this->assertEquals($order->getTotalAmount($tax, true, true), $row["total_discount_and_postage"]);
|
||||||
|
|
||||||
|
|
||||||
|
$invoiceAddress = $order->getOrderAddressRelatedByInvoiceOrderAddressId();
|
||||||
|
$deliveryAddress = $order->getOrderAddressRelatedByDeliveryOrderAddressId();
|
||||||
|
|
||||||
|
$addresses = [
|
||||||
|
"delivery" => $deliveryAddress,
|
||||||
|
"invoice" => $invoiceAddress
|
||||||
|
];
|
||||||
|
|
||||||
|
/** @var \Thelia\Model\OrderAddress $address */
|
||||||
|
foreach ($addresses as $prefix => $address) {
|
||||||
|
$this->assertEquals($address->getCustomerTitle()->setLocale($locale)->getShort(), $row[$prefix."_title"]);
|
||||||
|
$this->assertEquals($address->getAddress1(), $row[$prefix."_address1"]);
|
||||||
|
$this->assertEquals($address->getAddress2(), $row[$prefix."_address2"]);
|
||||||
|
$this->assertEquals($address->getAddress3(), $row[$prefix."_address3"]);
|
||||||
|
$this->assertEquals($address->getCity(), $row[$prefix."_city"]);
|
||||||
|
$this->assertEquals($address->getZipcode(), $row[$prefix."_zip_code"]);
|
||||||
|
$this->assertEquals($address->getCompany(), $row[$prefix."_company"]);
|
||||||
|
$this->assertEquals($address->getFirstname(), $row[$prefix."_first_name"]);
|
||||||
|
$this->assertEquals($address->getLastname(), $row[$prefix."_last_name"]);
|
||||||
|
$this->assertEquals($address->getCountry()->setLocale($locale)->getTitle(), $row[$prefix."_country"]);
|
||||||
|
$this->assertEquals($address->getPhone(), $row[$prefix."_phone"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
while ($data[$i]["ref"] === $ref) {
|
||||||
|
/** @var \Thelia\Model\OrderProduct $product */
|
||||||
|
$product = OrderProductQuery::create()
|
||||||
|
->filterByTitle($data[$i]["product_title"])
|
||||||
|
->filterByTaxRuleTitle($data[$i]["tax_title"])
|
||||||
|
->filterByWasInPromo($data[$i]["was_in_promo"])
|
||||||
|
->_if((bool)((int)$data[$i]["was_in_promo"]))
|
||||||
|
->filterByPromoPrice($data[$i]["price"])
|
||||||
|
->_else()
|
||||||
|
->filterByPrice($data[$i]["price"])
|
||||||
|
->_endif()
|
||||||
|
->filterByQuantity($data[$i]["quantity"])
|
||||||
|
->findOne()
|
||||||
|
;
|
||||||
|
$this->assertNotNull($product);
|
||||||
|
|
||||||
|
$sum = 0;
|
||||||
|
foreach ($product->getOrderProductTaxes() as $tax) {
|
||||||
|
$sum += $product->getWasInPromo() ? $tax->getPromoAmount() : $tax->getAmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->assertEquals($sum, $data[$i++]["tax_amount"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user