- Add Coupon, Rules, CouponManager, Adapter as Services
- Refactor Coupon to use these services
This commit is contained in:
gmorel
2013-09-06 11:47:00 +02:00
parent eea29cba06
commit 8a5e12f814
12 changed files with 190 additions and 149 deletions

View File

@@ -23,6 +23,8 @@
namespace Thelia\Constraint;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Constraint\Rule\AvailableForXArticles;
use Thelia\Constraint\Validator\PriceParam;
use Thelia\Constraint\Validator\RuleValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmount;
@@ -50,12 +52,10 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
public function setUp()
{
}
public function incompleteTest()
{
$this->markTestIncomplete(
@@ -63,6 +63,62 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
);
}
/**
* Check the Rules serialization module
*/
public function testRuleSerialisation()
{
$translator = $this->getMock('\Thelia\Core\Translation\Translator');
$rule1 = new AvailableForTotalAmount($translator);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 40.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
);
$rule1->populateFromForm($operators, $values);
$rule2 = new AvailableForTotalAmount($translator);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'EUR'
);
$rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection(array($rule1, $rule2));
/** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($this->getContainer());
$serializedRules = $constraintManager->serializeCouponRuleCollection($rules);
$unserializedRules = $constraintManager->unserializeCouponRuleCollection($serializedRules);
$expected = $rules;
$actual = $unserializedRules;
$this->assertEquals($expected, $actual);
}
/**
* Get Mocked Container with 2 Rules
*
* @return ContainerBuilder
*/
public function getContainer()
{
$container = new ContainerBuilder();
$translator = $this->getMock('\Thelia\Core\Translation\Translator');
$rule1 = new AvailableForTotalAmount($translator);
$rule2 = new AvailableForXArticles($translator);
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
$container->set('thelia.constraint.rule.available_for_x_articles', $rule2);
return $container;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.