WIP : Condition : Fix unit text
This commit is contained in:
@@ -24,9 +24,12 @@
|
|||||||
namespace Thelia\Condition\Implementation;
|
namespace Thelia\Condition\Implementation;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
use Thelia\Condition\ConditionEvaluator;
|
||||||
use Thelia\Condition\ConditionFactory;
|
use Thelia\Condition\ConditionFactory;
|
||||||
use Thelia\Condition\Operators;
|
use Thelia\Condition\Operators;
|
||||||
use Thelia\Coupon\AdapterInterface;
|
use Thelia\Coupon\AdapterInterface;
|
||||||
|
use Thelia\Coupon\ConditionCollection;
|
||||||
|
use Thelia\Model\CurrencyQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
@@ -55,12 +58,6 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testBuild()
|
public function testBuild()
|
||||||
{
|
{
|
||||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
|
||||||
->disableOriginalConstructor()
|
|
||||||
->getMock();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
@@ -73,6 +70,31 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$stubAdapter->expects($this->any())
|
$stubAdapter->expects($this->any())
|
||||||
->method('getTranslator')
|
->method('getTranslator')
|
||||||
->will($this->returnValue($stubTranslator));
|
->will($this->returnValue($stubTranslator));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getConditionEvaluator')
|
||||||
|
->will($this->returnValue(new ConditionEvaluator()));
|
||||||
|
|
||||||
|
$currencies = CurrencyQuery::create();
|
||||||
|
$currencies = $currencies->find();
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getAvailableCurrencies')
|
||||||
|
->will($this->returnValue($currencies));
|
||||||
|
|
||||||
|
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
$stubContainer->expects($this->any())
|
||||||
|
->method('get')
|
||||||
|
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||||
|
|
||||||
|
$stubContainer->expects($this->any())
|
||||||
|
->method('has')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getContainer')
|
||||||
|
->will($this->returnValue($stubContainer));
|
||||||
|
|
||||||
|
|
||||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||||
$operators = array(
|
$operators = array(
|
||||||
@@ -85,7 +107,7 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
);
|
);
|
||||||
$condition1->setValidatorsFromForm($operators, $values);
|
$condition1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
$conditionFactory = new ConditionFactory($this->getContainer());
|
$conditionFactory = new ConditionFactory($stubContainer);
|
||||||
$ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
|
$ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
|
||||||
|
|
||||||
$expected = $condition1;
|
$expected = $condition1;
|
||||||
@@ -96,132 +118,146 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
|
$this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Check the Rules serialization module
|
* Check the Rules serialization module
|
||||||
// */
|
*/
|
||||||
// public function testBuildFail()
|
public function testBuildFail()
|
||||||
// {
|
{
|
||||||
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||||
// ->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
// ->getMock();
|
->getMock();
|
||||||
//
|
|
||||||
// /** @var AdapterInterface $stubAdapter */
|
/** @var AdapterInterface $stubAdapter */
|
||||||
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||||
// ->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
// ->getMock();
|
->getMock();
|
||||||
//
|
|
||||||
// $stubAdapter->expects($this->any())
|
$stubAdapter->expects($this->any())
|
||||||
// ->method('getTranslator')
|
->method('getTranslator')
|
||||||
// ->will($this->returnValue($stubTranslator));
|
->will($this->returnValue($stubTranslator));
|
||||||
//
|
$stubAdapter->expects($this->any())
|
||||||
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
|
->method('getConditionEvaluator')
|
||||||
// $operators = array(
|
->will($this->returnValue(new ConditionEvaluator()));
|
||||||
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
|
||||||
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
$currencies = CurrencyQuery::create();
|
||||||
// );
|
$currencies = $currencies->find();
|
||||||
// $values = array(
|
$stubAdapter->expects($this->any())
|
||||||
// MatchForTotalAmountManager::INPUT1 => 40.00,
|
->method('getAvailableCurrencies')
|
||||||
// MatchForTotalAmountManager::INPUT2 => 'EUR'
|
->will($this->returnValue($currencies));
|
||||||
// );
|
|
||||||
// $condition1->setValidatorsFromForm($operators, $values);
|
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||||
//
|
->disableOriginalConstructor()
|
||||||
// $conditionFactory = new ConditionFactory($this->getContainer());
|
->getMock();
|
||||||
// $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values);
|
$stubContainer->expects($this->any())
|
||||||
//
|
->method('get')
|
||||||
// $expected = false;
|
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||||
// $actual = $conditionManager1;
|
|
||||||
//
|
$stubContainer->expects($this->any())
|
||||||
// $this->assertEquals($expected, $actual);
|
->method('has')
|
||||||
// }
|
->will($this->returnValueMap(array('unset.service', false)));
|
||||||
//
|
|
||||||
// /**
|
$stubAdapter->expects($this->any())
|
||||||
// * Check the Rules serialization module
|
->method('getContainer')
|
||||||
// */
|
->will($this->returnValue($stubContainer));
|
||||||
// public function testRuleSerialisation()
|
|
||||||
// {
|
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||||
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
$operators = array(
|
||||||
// ->disableOriginalConstructor()
|
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
// ->getMock();
|
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
//
|
);
|
||||||
// /** @var AdapterInterface $stubAdapter */
|
$values = array(
|
||||||
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||||
// ->disableOriginalConstructor()
|
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||||
// ->getMock();
|
);
|
||||||
//
|
$condition1->setValidatorsFromForm($operators, $values);
|
||||||
// $stubAdapter->expects($this->any())
|
|
||||||
// ->method('getTranslator')
|
$conditionFactory = new ConditionFactory($stubContainer);
|
||||||
// ->will($this->returnValue($stubTranslator));
|
$conditionManager1 = $conditionFactory->build('unset.service', $operators, $values);
|
||||||
//
|
|
||||||
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
|
$expected = false;
|
||||||
// $operators = array(
|
$actual = $conditionManager1;
|
||||||
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
|
||||||
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
$this->assertEquals($expected, $actual);
|
||||||
// );
|
}
|
||||||
// $values = array(
|
|
||||||
// MatchForTotalAmountManager::INPUT1 => 40.00,
|
/**
|
||||||
// MatchForTotalAmountManager::INPUT2 => 'EUR'
|
* Check the Rules serialization module
|
||||||
// );
|
*/
|
||||||
// $condition1->setValidatorsFromForm($operators, $values);
|
public function testRuleSerialisation()
|
||||||
//
|
{
|
||||||
// $condition2 = new MatchForTotalAmountManager($stubAdapter);
|
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||||
// $operators = array(
|
->disableOriginalConstructor()
|
||||||
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
->getMock();
|
||||||
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
|
||||||
// );
|
/** @var AdapterInterface $stubAdapter */
|
||||||
// $values = array(
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||||
// MatchForTotalAmountManager::INPUT1 => 400.00,
|
->disableOriginalConstructor()
|
||||||
// MatchForTotalAmountManager::INPUT2 => 'EUR'
|
->getMock();
|
||||||
// );
|
|
||||||
// $condition2->setValidatorsFromForm($operators, $values);
|
$stubAdapter->expects($this->any())
|
||||||
//
|
->method('getTranslator')
|
||||||
// $conditions = new ConditionCollection();
|
->will($this->returnValue($stubTranslator));
|
||||||
// $conditions->add($condition1);
|
$stubAdapter->expects($this->any())
|
||||||
// $conditions->add($condition2);
|
->method('getConditionEvaluator')
|
||||||
//
|
->will($this->returnValue(new ConditionEvaluator()));
|
||||||
// $conditionFactory = new ConditionFactory($this->getContainer());
|
|
||||||
//
|
$currencies = CurrencyQuery::create();
|
||||||
// $serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
$currencies = $currencies->find();
|
||||||
// $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
|
$stubAdapter->expects($this->any())
|
||||||
//
|
->method('getAvailableCurrencies')
|
||||||
// $expected = (string) $conditions;
|
->will($this->returnValue($currencies));
|
||||||
// $actual = (string) $unserializedConditions;
|
|
||||||
//
|
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||||
// $this->assertEquals($expected, $actual);
|
->disableOriginalConstructor()
|
||||||
// }
|
->getMock();
|
||||||
//
|
$stubContainer->expects($this->any())
|
||||||
// /**
|
->method('get')
|
||||||
// * Get Mocked Container with 2 Rules
|
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||||
// *
|
|
||||||
// * @return ContainerBuilder
|
$stubContainer->expects($this->any())
|
||||||
// */
|
->method('has')
|
||||||
// public function getContainer()
|
->will($this->returnValue(true));
|
||||||
// {
|
|
||||||
// $container = new ContainerBuilder();
|
$stubAdapter->expects($this->any())
|
||||||
//
|
->method('getContainer')
|
||||||
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
->will($this->returnValue($stubContainer));
|
||||||
// ->disableOriginalConstructor()
|
|
||||||
// ->getMock();
|
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||||
//
|
$operators = array(
|
||||||
// /** @var AdapterInterface $stubAdapter */
|
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
// ->disableOriginalConstructor()
|
);
|
||||||
// ->getMock();
|
$values = array(
|
||||||
//
|
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||||
// $stubAdapter->expects($this->any())
|
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||||
// ->method('getTranslator')
|
);
|
||||||
// ->will($this->returnValue($stubTranslator));
|
$condition1->setValidatorsFromForm($operators, $values);
|
||||||
//
|
|
||||||
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
|
$condition2 = new MatchForTotalAmountManager($stubAdapter);
|
||||||
// $condition2 = new MatchForXArticlesManager($stubAdapter);
|
$operators = array(
|
||||||
//
|
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
// $adapter = new BaseAdapter($container);
|
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
//
|
);
|
||||||
// $container->set('thelia.condition.match_for_total_amount', $condition1);
|
$values = array(
|
||||||
// $container->set('thelia.condition.match_for_x_articles', $condition2);
|
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||||
// $container->set('thelia.adapter', $adapter);
|
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||||
//
|
);
|
||||||
// return $container;
|
$condition2->setValidatorsFromForm($operators, $values);
|
||||||
// }
|
|
||||||
|
$conditions = new ConditionCollection();
|
||||||
|
$conditions->add($condition1);
|
||||||
|
$conditions->add($condition2);
|
||||||
|
|
||||||
|
$conditionFactory = new ConditionFactory($stubContainer);
|
||||||
|
|
||||||
|
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
||||||
|
$unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
|
||||||
|
|
||||||
|
$expected = (string) $conditions;
|
||||||
|
$actual = (string) $unserializedConditions;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tears down the fixture, for example, closes a network connection.
|
* Tears down the fixture, for example, closes a network connection.
|
||||||
|
|||||||
Reference in New Issue
Block a user