End formatter data and refactor Thelia\Core\FileFormat\Formatter
renommé: core/lib/Thelia/Core/FileFormat/Formatter/AbstractFormatter.php -> core/lib/Thelia/Core/FileFormat/Formatting/AbstractFormatter.php renommé: core/lib/Thelia/Core/FileFormat/Formatter/Exception/BadFormattedStringException.php -> core/lib/Thelia/Core/FileFormat/Formatting/Exception/BadFormattedStringException.php renommé: core/lib/Thelia/Core/FileFormat/Formatter/FormatterData.php -> core/lib/Thelia/Core/FileFormat/Formatting/FormatterData.php renommé: core/lib/Thelia/Core/FileFormat/Formatter/FormatterInterface.php -> core/lib/Thelia/Core/FileFormat/Formatting/FormatterInterface.php renommé: core/lib/Thelia/Core/FileFormat/Formatter/FormatterManager.php -> core/lib/Thelia/Core/FileFormat/Formatting/FormatterManager.php renommé: core/lib/Thelia/Tests/FileFormat/Formatter/FormatterDataTest.php -> core/lib/Thelia/Tests/FileFormat/Formatting/FormatterDataTest.php renommé: core/lib/Thelia/Tests/FileFormat/Formatter/FormatterManagerTest.php -> core/lib/Thelia/Tests/FileFormat/Formatting/FormatterManagerTest.php
This commit is contained in:
@@ -10,12 +10,12 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatter;
|
namespace Thelia\Core\FileFormat\Formatting;
|
||||||
use Thelia\Core\FileFormat\FormatInterface;
|
use Thelia\Core\FileFormat\FormatInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class AbstractFormatter
|
* Class AbstractFormatter
|
||||||
* @package Thelia\Core\FileFormat\Formatter
|
* @package Thelia\Core\FileFormat\Formatting
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
abstract class AbstractFormatter implements FormatInterface, FormatterInterface
|
abstract class AbstractFormatter implements FormatInterface, FormatterInterface
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatter;
|
namespace Thelia\Core\FileFormat\Formatting;
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
use Propel\Runtime\ActiveQuery\Criteria;
|
||||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||||
use Propel\Runtime\ActiveQuery\ModelJoin;
|
use Propel\Runtime\ActiveQuery\ModelJoin;
|
||||||
@@ -19,7 +19,7 @@ use Thelia\Core\Translation\Translator;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterData
|
* Class FormatterData
|
||||||
* @package Thelia\Core\FileFormat\Formatter
|
* @package Thelia\Core\FileFormat\Formatting
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class FormatterData
|
class FormatterData
|
||||||
@@ -90,10 +90,9 @@ class FormatterData
|
|||||||
* @return $this|null
|
* @return $this|null
|
||||||
*
|
*
|
||||||
* Loads a model criteria.
|
* Loads a model criteria.
|
||||||
* Warning: if you want to do multi table export,
|
* Warning: This doesn't goodly support multi table queries.
|
||||||
* you'll have to use you own select and not the joinYourTable method.
|
* If you need to use more than one table, use a PDO instance and
|
||||||
* For more details, please see the unit test
|
* use the fetchArray() method, or select every columns you need
|
||||||
* Thelia\Tests\FileFormat\Formatter\FormatterDataTest::testFormatSimpleMultipleTableQuery
|
|
||||||
*/
|
*/
|
||||||
public function loadModelCriteria(ModelCriteria $criteria)
|
public function loadModelCriteria(ModelCriteria $criteria)
|
||||||
{
|
{
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatter;
|
namespace Thelia\Core\FileFormat\Formatting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface FormatterInterface
|
* Interface FormatterInterface
|
||||||
@@ -10,12 +10,12 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Core\FileFormat\Formatter;
|
namespace Thelia\Core\FileFormat\Formatting;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterManager
|
* Class FormatterManager
|
||||||
* @package Thelia\Core\FileFormat\Formatter
|
* @package Thelia\Core\FileFormat\Formatting
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class FormatterManager
|
class FormatterManager
|
||||||
@@ -10,26 +10,18 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Tests\FileFormat\Formatter;
|
namespace Thelia\Tests\FileFormat\Formatting;
|
||||||
use Propel\Generator\Builder\Om\QueryBuilder;
|
|
||||||
use Propel\Runtime\ActiveQuery\Criteria;
|
|
||||||
use Propel\Runtime\DataFetcher\ArrayDataFetcher;
|
|
||||||
use Propel\Runtime\Formatter\ArrayFormatter;
|
|
||||||
use Propel\Runtime\Map\TableMap;
|
|
||||||
use Propel\Runtime\Propel;
|
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Thelia\Core\FileFormat\Formatter\FormatterData;
|
use Thelia\Core\FileFormat\Formatting\FormatterData;
|
||||||
use Thelia\Core\Thelia;
|
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
use Thelia\Model\Base\ProductQuery;
|
|
||||||
use Thelia\Model\Base\ProductSaleElementsQuery;
|
use Thelia\Model\Base\ProductSaleElementsQuery;
|
||||||
use Thelia\Model\ConfigQuery;
|
use Thelia\Model\ConfigQuery;
|
||||||
|
use Thelia\Model\Map\ProductSaleElementsTableMap;
|
||||||
use Thelia\Model\Map\ProductTableMap;
|
use Thelia\Model\Map\ProductTableMap;
|
||||||
use Thelia\Model\Product;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterDataTest
|
* Class FormatterDataTest
|
||||||
* @package Thelia\Tests\FileFormat\Formatter
|
* @package Thelia\Tests\FileFormat\Formatting
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -38,33 +30,6 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function setUp()
|
public function setUp()
|
||||||
{
|
{
|
||||||
new Translator(new Container());
|
new Translator(new Container());
|
||||||
|
|
||||||
/*
|
|
||||||
->filterById([3,4,5], Criteria::IN);
|
|
||||||
|
|
||||||
$this->data->loadModelCriteria($query);
|
|
||||||
|
|
||||||
$query = ProductSaleElementsQuery::create()
|
|
||||||
->joinProduct()
|
|
||||||
->select(["ProductSaleElements.id", "Product.id"])
|
|
||||||
->filterById([3,4,5], Criteria::IN)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->data->loadModelCriteria($query);
|
|
||||||
|
|
||||||
$query = ProductSaleElementsQuery::create()
|
|
||||||
->joinProduct()
|
|
||||||
->select(["ProductSaleElements.id"])
|
|
||||||
->filterById([3,4,5], Criteria::IN)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->data->loadModelCriteria($query);
|
|
||||||
|
|
||||||
$query = ProductQuery::create()
|
|
||||||
->joinProductSaleElements()
|
|
||||||
->filterById([3,4,5], Criteria::IN);
|
|
||||||
|
|
||||||
$this->data->loadModelCriteria($query);*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormatSimpleQuery()
|
public function testFormatSimpleQuery()
|
||||||
@@ -140,29 +105,20 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($formattedResult,$formattedData);
|
$this->assertEquals($formattedResult,$formattedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testFormatSimpleMultipleTableQuery()
|
public function testFormatComplexQuery()
|
||||||
{
|
{
|
||||||
$formatterData = new FormatterData();
|
$formatterData = new FormatterData();
|
||||||
|
|
||||||
|
$query = ProductSaleElementsQuery::create()
|
||||||
}
|
->useProductQuery()
|
||||||
|
->addAsColumn("\"".ProductTableMap::ID."\"", ProductTableMap::ID)
|
||||||
public function testFormatSimpleMultipleTableQueryWithAliases()
|
->endUse()
|
||||||
{
|
->select(
|
||||||
/**
|
[
|
||||||
* Aliases must not be case sensitive
|
ProductSaleElementsTableMap::ID,
|
||||||
*/
|
ProductSaleElementsTableMap::QUANTITY,
|
||||||
$aliases = [
|
]
|
||||||
"coNfiG.iD" => "id",
|
)
|
||||||
"conFig.NaMe" => "name",
|
|
||||||
"CoNfIg.Value" => "value",
|
|
||||||
"config.hidden" => "hidden",
|
|
||||||
"ConFig.Secured" => "secured",
|
|
||||||
];
|
|
||||||
|
|
||||||
$formatterData = new FormatterData($aliases);
|
|
||||||
|
|
||||||
$query = ConfigQuery::create()
|
|
||||||
->limit(1)
|
->limit(1)
|
||||||
;
|
;
|
||||||
|
|
||||||
@@ -170,23 +126,59 @@ class FormatterDataTest extends \PHPUnit_Framework_TestCase
|
|||||||
->loadModelCriteria($query)
|
->loadModelCriteria($query)
|
||||||
->getData()
|
->getData()
|
||||||
;
|
;
|
||||||
|
/** @var array $data */
|
||||||
|
$data = $query->findOne();
|
||||||
|
|
||||||
/** @var \Thelia\Model\Config $result */
|
$expectedData = [
|
||||||
$result = $query->findOne();
|
|
||||||
|
|
||||||
$formattedResult = [
|
|
||||||
[
|
[
|
||||||
"id" => $result->getId(),
|
"product.id" => $data["product.ID"],
|
||||||
"name" => $result->getName(),
|
"product_sale_elements.id" => $data["product_sale_elements.ID"],
|
||||||
"value" => $result->getValue(),
|
"product_sale_elements.quantity" => $data["product_sale_elements.QUANTITY"],
|
||||||
"config.created_at" => $result->getCreatedAt(),
|
]
|
||||||
"config.updated_at" => $result->getUpdatedAt(),
|
|
||||||
"hidden" => $result->getHidden(),
|
|
||||||
"secured" => $result->getHidden(),
|
|
||||||
],
|
|
||||||
];
|
];
|
||||||
|
|
||||||
$this->assertEquals($formattedResult,$formattedData);
|
$this->assertEquals($expectedData, $formattedData);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormatComplexQueryWithAliases()
|
||||||
|
{
|
||||||
|
$aliases = [
|
||||||
|
"product.id" => "pid",
|
||||||
|
"product_sale_elements.id" => "pseid",
|
||||||
|
"product_sale_elements.quantity" => "stock"
|
||||||
|
];
|
||||||
|
|
||||||
|
$formatterData = new FormatterData($aliases);
|
||||||
|
|
||||||
|
$query = ProductSaleElementsQuery::create()
|
||||||
|
->useProductQuery()
|
||||||
|
->addAsColumn("\"".ProductTableMap::ID."\"", ProductTableMap::ID)
|
||||||
|
->endUse()
|
||||||
|
->select(
|
||||||
|
[
|
||||||
|
ProductSaleElementsTableMap::ID,
|
||||||
|
ProductSaleElementsTableMap::QUANTITY,
|
||||||
|
]
|
||||||
|
)
|
||||||
|
->limit(1)
|
||||||
|
;
|
||||||
|
|
||||||
|
$formattedData = $formatterData
|
||||||
|
->loadModelCriteria($query)
|
||||||
|
->getData()
|
||||||
|
;
|
||||||
|
/** @var array $data */
|
||||||
|
$data = $query->findOne();
|
||||||
|
|
||||||
|
$expectedData = [
|
||||||
|
[
|
||||||
|
"pid" => $data["product.ID"],
|
||||||
|
"pseid" => $data["product_sale_elements.ID"],
|
||||||
|
"stock" => $data["product_sale_elements.QUANTITY"],
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertEquals($expectedData, $formattedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testSetRawDataDepth1() {
|
public function testSetRawDataDepth1() {
|
||||||
@@ -10,15 +10,15 @@
|
|||||||
/* file that was distributed with this source code. */
|
/* file that was distributed with this source code. */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Tests\FileFormat\Formatter;
|
namespace Thelia\Tests\FileFormat\Formatting;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Thelia\Core\FileFormat\Formatter\AbstractFormatter;
|
use Thelia\Core\FileFormat\Formatting\AbstractFormatter;
|
||||||
use Thelia\Core\FileFormat\Formatter\FormatterManager;
|
use Thelia\Core\FileFormat\Formatting\FormatterManager;
|
||||||
use Thelia\Core\Translation\Translator;
|
use Thelia\Core\Translation\Translator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class FormatterManagerTest
|
* Class FormatterManagerTest
|
||||||
* @package Thelia\Tests\FileFormat\Formatter
|
* @package Thelia\Tests\FileFormat\Formatting
|
||||||
* @author Benjamin Perche <bperche@openstudio.fr>
|
* @author Benjamin Perche <bperche@openstudio.fr>
|
||||||
*/
|
*/
|
||||||
class FormatterManagerTest extends \PHPUnit_Framework_TestCase
|
class FormatterManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
@@ -39,7 +39,7 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testAddFormatter()
|
public function testAddFormatter()
|
||||||
{
|
{
|
||||||
/** @var AbstractFormatter $instance */
|
/** @var AbstractFormatter $instance */
|
||||||
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter");
|
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatting\\AbstractFormatter");
|
||||||
|
|
||||||
$this->manager->add($instance);
|
$this->manager->add($instance);
|
||||||
|
|
||||||
@@ -53,7 +53,7 @@ class FormatterManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testDeleteFormatter()
|
public function testDeleteFormatter()
|
||||||
{
|
{
|
||||||
/** @var AbstractFormatter $instance */
|
/** @var AbstractFormatter $instance */
|
||||||
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatter\\AbstractFormatter");
|
$instance = $this->getMock("Thelia\\Core\\FileFormat\\Formatting\\AbstractFormatter");
|
||||||
|
|
||||||
$this->manager->add($instance);
|
$this->manager->add($instance);
|
||||||
|
|
||||||
Reference in New Issue
Block a user