Merge branch 'master' of https://github.com/thelia/thelia into coupon

# By Manuel Raynaud (18) and others
# Via franck (9) and others
* 'master' of https://github.com/thelia/thelia: (39 commits)
  Working :
  Working :
  Working :
  Working :
  Fixed minor visual glitches
  Working : Resize countries flag + Add bootstrap-switch
  fix test suite
  clear asset cache in cache:cler command
  Added a 'development mode' to assetic smarty plugin
  rewriting router
  use good Request object
  Added Tools\URL test case, and a test case superclass for initializing Tools\URL
  remove unused UrlWritin controller
  create router for rewriting matching
  customer substitutions
  fix typo in front id
  Working : For attributes on labels
  Working : For attributes on labels
  add label_attr attribute to form smarty plugin
  start refactorin rewriting routing
  ...

Conflicts:
	core/lib/Thelia/Config/Resources/routing/front.xml
	templates/admin/default/assets/less/thelia/bootstrap-editable.less
	templates/admin/default/categories.html
This commit is contained in:
gmorel
2013-09-06 19:38:08 +02:00
parent 86d6a0fa05
commit 49be95a2e7
18 changed files with 646 additions and 420 deletions

View File

@@ -29,6 +29,8 @@ use Thelia\Constraint\Validator\PriceParam;
use Thelia\Constraint\Validator\RuleValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmount;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponBaseAdapter;
use Thelia\Coupon\CouponBaseAdapterTest;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Coupon\Type\RemoveXAmount;
@@ -56,11 +58,58 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
{
}
public function incompleteTest()
/**
* Check the if the Constraint Manager is able to check RuleValidators
*/
public function testIsMatching()
{
$this->markTestIncomplete(
'This test has not been implemented yet.'
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$stubAdapter->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue(321.98));
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue('USD'));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 40.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'USD'
);
$rule1->populateFromForm($operators, $values);
$rule2 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
AvailableForTotalAmount::PARAM1_CURRENCY => 'USD'
);
$rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($this->getContainer());
$expected = true;
$actual = $constraintManager->isMatching($rules);
$this->assertEquals($expected, $actual, 'The ConstraintManager is no more able to check if a Rule is matching');
}
/**
@@ -68,9 +117,19 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
*/
public function testRuleSerialisation()
{
$translator = $this->getMock('\Thelia\Core\Translation\Translator');
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$rule1 = new AvailableForTotalAmount($translator);
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::SUPERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 40.00,
@@ -78,7 +137,7 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
);
$rule1->populateFromForm($operators, $values);
$rule2 = new AvailableForTotalAmount($translator);
$rule2 = new AvailableForTotalAmount($stubAdapter);
$operators = array(AvailableForTotalAmount::PARAM1_PRICE => Operators::INFERIOR);
$values = array(
AvailableForTotalAmount::PARAM1_PRICE => 400.00,
@@ -86,7 +145,9 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
);
$rule2->populateFromForm($operators, $values);
$rules = new CouponRuleCollection(array($rule1, $rule2));
$rules = new CouponRuleCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */
$constraintManager = new ConstraintManager($this->getContainer());
@@ -94,8 +155,8 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
$serializedRules = $constraintManager->serializeCouponRuleCollection($rules);
$unserializedRules = $constraintManager->unserializeCouponRuleCollection($serializedRules);
$expected = $rules;
$actual = $unserializedRules;
$expected = (string)$rules;
$actual = (string)$unserializedRules;
$this->assertEquals($expected, $actual);
}
@@ -109,12 +170,26 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
{
$container = new ContainerBuilder();
$translator = $this->getMock('\Thelia\Core\Translation\Translator');
$rule1 = new AvailableForTotalAmount($translator);
$rule2 = new AvailableForXArticles($translator);
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmount($stubAdapter);
$rule2 = new AvailableForXArticles($stubAdapter);
$adapter = new CouponBaseAdapter($container);
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
$container->set('thelia.constraint.rule.available_for_x_articles', $rule2);
$container->set('thelia.adapter', $adapter);
return $container;
}

View File

@@ -66,11 +66,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4)
{
/** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->getMock(
'Thelia\Coupon\CouponBaseAdapter',
array('getNbArticlesInCart'),
array()
);
$stubTheliaAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->setMethods(array('getNbArticlesInCart'))
->getMock();
$stubTheliaAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue($nbArticlesInCart));
@@ -86,307 +85,305 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
*/
public function testValidBackOfficeInput()
{
$adapter = $this->stubTheliaAdapter;
$translator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
$rule = new AvailableForXArticles($translator);
$operators = array(AvailableForXArticles::PARAM1_QUANTITY => Operators::SUPERIOR);
$values = array(
AvailableForXArticles::PARAM1_QUANTITY => 4
);
$rule = new AvailableForXArticles($adapter, $validators);
$rule->populateFromForm($operators, $values);
$expected = true;
$actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidBackOfficeInputFloat()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4.5
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidBackOfficeInputNegative()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
-1
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidBackOfficeInputString()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
'bad'
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on FrontOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
*/
public function testValidCheckoutInput()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true;
$actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on FrontOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidCheckoutInputFloat()
{
$adapter = $this->generateValidCouponBaseAdapterMock(4.5);
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on FrontOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidCheckoutInputNegative()
{
$adapter = $this->generateValidCouponBaseAdapterMock(-1);
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on FrontOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException
*/
public function testInValidCheckoutInputString()
{
$adapter = $this->generateValidCouponBaseAdapterMock('bad');
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
*
*/
public function testMatchingRuleInferior()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::INFERIOR,
new QuantityParam(
$adapter,
5
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true;
$actual = $rule->isMatching();
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
*
*/
public function testMatchingRuleEqual()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::EQUAL,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true;
$actual = $rule->isMatching();
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
*
*/
public function testMatchingRuleSuperior()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::SUPERIOR,
new QuantityParam(
$adapter,
3
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true;
$actual = $rule->isMatching();
$this->assertEquals($expected, $actual);
}
/**
* Check if test unavailable operator is working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
*
*/
public function testNotMatchingRule()
{
$adapter = $this->stubTheliaAdapter;
$validators = array(
AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
Operators::DIFFERENT,
new QuantityParam(
$adapter,
3
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false;
$actual = $rule->isMatching();
$this->assertEquals($expected, $actual);
}
// /**
// * Check if validity test on BackOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidBackOfficeInputFloat()
// {
// $adapter = $this->stubTheliaAdapter;
//
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 4.5
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkBackOfficeInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if validity test on BackOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidBackOfficeInputNegative()
// {
// $adapter = $this->stubTheliaAdapter;
//
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// -1
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkBackOfficeInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if validity test on BackOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidBackOfficeInputString()
// {
// $adapter = $this->stubTheliaAdapter;
//
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 'bad'
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkBackOfficeInput();
// $this->assertEquals($expected, $actual);
// }
//
//
//
//
//
// /**
// * Check if validity test on FrontOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
// */
// public function testValidCheckoutInput()
// {
// $adapter = $this->stubTheliaAdapter;
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 4
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = true;
// $actual = $rule->checkCheckoutInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if validity test on FrontOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidCheckoutInputFloat()
// {
// $adapter = $this->generateValidCouponBaseAdapterMock(4.5);
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 4
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkCheckoutInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if validity test on FrontOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidCheckoutInputNegative()
// {
// $adapter = $this->generateValidCouponBaseAdapterMock(-1);
//
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 4
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkCheckoutInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if validity test on FrontOffice inputs are working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
// * @expectedException \Thelia\Exception\InvalidRuleValueException
// */
// public function testInValidCheckoutInputString()
// {
// $adapter = $this->generateValidCouponBaseAdapterMock('bad');
//
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 4
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->checkCheckoutInput();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if test inferior operator is working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
// *
// */
// public function testMatchingRuleInferior()
// {
// $adapter = $this->stubTheliaAdapter;
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::INFERIOR,
// new QuantityParam(
// $adapter,
// 5
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = true;
// $actual = $rule->isMatching();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if test equals operator is working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
// *
// */
// public function testMatchingRuleEqual()
// {
// $adapter = $this->stubTheliaAdapter;
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::EQUAL,
// new QuantityParam(
// $adapter,
// 4
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = true;
// $actual = $rule->isMatching();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if test superior operator is working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
// *
// */
// public function testMatchingRuleSuperior()
// {
// $adapter = $this->stubTheliaAdapter;
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::SUPERIOR,
// new QuantityParam(
// $adapter,
// 3
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = true;
// $actual = $rule->isMatching();
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check if test unavailable operator is working
// *
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
// * @expectedException \Thelia\Exception\InvalidRuleOperatorException
// *
// */
// public function testNotMatchingRule()
// {
// $adapter = $this->stubTheliaAdapter;
// $validators = array(
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
// Operators::DIFFERENT,
// new QuantityParam(
// $adapter,
// 3
// )
// )
// );
// $rule = new AvailableForXArticles($adapter, $validators);
//
// $expected = false;
// $actual = $rule->isMatching();
// $this->assertEquals($expected, $actual);
// }
/**