WIP : Coupon : unit tests on Rules
This commit is contained in:
@@ -26,19 +26,20 @@ namespace Thelia\Coupon;
|
|||||||
use Thelia\Constraint\ConstraintValidator;
|
use Thelia\Constraint\ConstraintValidator;
|
||||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||||
use Thelia\Constraint\Rule\Operators;
|
use Thelia\Constraint\Rule\Operators;
|
||||||
|
use Thelia\Exception\InvalidRuleValueException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Created by JetBrains PhpStorm.
|
||||||
* Date: 8/19/13
|
* Date: 8/19/13
|
||||||
* Time: 3:24 PM
|
* Time: 3:24 PM
|
||||||
*
|
*
|
||||||
* Unit Test AvailableForTotalAmount Class
|
* Unit Test AvailableForTotalAmountManager Class
|
||||||
*
|
*
|
||||||
* @package Constraint
|
* @package Constraint
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||||
protected $stubTheliaAdapter = null;
|
protected $stubTheliaAdapter = null;
|
||||||
@@ -49,108 +50,168 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
|
||||||
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Generate valid CouponBaseAdapter
|
* Check if validity test on BackOffice inputs are working
|
||||||
// *
|
*
|
||||||
// * @param float $cartTotalPrice Total amount of the current Cart
|
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
|
||||||
// *
|
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
||||||
// * @return CouponAdapterInterface
|
*
|
||||||
// */
|
*/
|
||||||
// protected function generateValidCouponBaseAdapterMock($cartTotalPrice = 421.23)
|
public function testInValidBackOfficeInputOperator()
|
||||||
// {
|
{
|
||||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
// $stubTheliaAdapter = $this->getMock(
|
->disableOriginalConstructor()
|
||||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
->getMock();
|
||||||
// array('getCartTotalPrice'),
|
|
||||||
// array()
|
|
||||||
// );
|
|
||||||
// $stubTheliaAdapter->expects($this->any())
|
|
||||||
// ->method('getCartTotalPrice')
|
|
||||||
// ->will($this->returnValue($cartTotalPrice));
|
|
||||||
//
|
|
||||||
// return $stubTheliaAdapter;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
$stubAdapter->expects($this->any())
|
||||||
// * Check if validity test on BackOffice inputs are working
|
->method('getCartTotalPrice')
|
||||||
// *
|
->will($this->returnValue(399));
|
||||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
$stubAdapter->expects($this->any())
|
||||||
// *
|
->method('getCheckoutCurrency')
|
||||||
// */
|
->will($this->returnValue('EUR'));
|
||||||
// public function testValidBackOfficeInput()
|
$stubAdapter->expects($this->any())
|
||||||
// {
|
->method('getConstraintValidator')
|
||||||
// $adapter = new CouponBaseAdapter();
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
//
|
|
||||||
// $validators = array(
|
|
||||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
|
||||||
// Operators::SUPERIOR,
|
|
||||||
// new PriceParam(
|
|
||||||
// $adapter, 421.23, 'EUR'
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
|
||||||
//
|
|
||||||
// $expected = true;
|
|
||||||
// $actual = $rule->checkBackOfficeInput();
|
|
||||||
// $this->assertEquals($expected, $actual);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||||
// * Check if validity test on BackOffice inputs are working
|
$operators = array(
|
||||||
// *
|
AvailableForTotalAmountManager::INPUT1 => Operators::IN,
|
||||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
// * @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
);
|
||||||
// *
|
$values = array(
|
||||||
// */
|
AvailableForTotalAmountManager::INPUT1 => '400',
|
||||||
// public function testInValidBackOfficeInputOperator()
|
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||||
// {
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
// $adapter = new CouponBaseAdapter();
|
|
||||||
//
|
|
||||||
// $validators = array(
|
|
||||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
|
||||||
// 'X',
|
|
||||||
// new PriceParam(
|
|
||||||
// $adapter, 421.23, 'EUR'
|
|
||||||
// )
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
//
|
|
||||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
|
||||||
//
|
|
||||||
// $expected = false;
|
|
||||||
// $actual = $rule->checkBackOfficeInput();
|
|
||||||
// $this->assertEquals($expected, $actual);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
$isValid = $rule1->isMatching();
|
||||||
// * Check if validity test on BackOffice inputs are working
|
|
||||||
// *
|
$expected = true;
|
||||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
$actual =$isValid;
|
||||||
// * @expectedException \ErrorException
|
$this->assertEquals($expected, $actual);
|
||||||
// *
|
}
|
||||||
// */
|
|
||||||
// public function testInValidBackOfficeInputValue()
|
/**
|
||||||
// {
|
* Check if validity test on BackOffice inputs are working
|
||||||
// $adapter = $this->generateValidCouponBaseAdapterMock();
|
*
|
||||||
//
|
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
|
||||||
// $validators = array(
|
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
||||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
*
|
||||||
// Operators::SUPERIOR,
|
*/
|
||||||
// 421
|
public function testInValidBackOfficeInputOperator2()
|
||||||
// )
|
{
|
||||||
// );
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
//
|
->disableOriginalConstructor()
|
||||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
->getMock();
|
||||||
//
|
|
||||||
// $expected = false;
|
$stubAdapter->expects($this->any())
|
||||||
// $actual = $rule->checkBackOfficeInput();
|
->method('getCartTotalPrice')
|
||||||
// $this->assertEquals($expected, $actual);
|
->will($this->returnValue(399));
|
||||||
// }
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getCheckoutCurrency')
|
||||||
|
->will($this->returnValue('EUR'));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getConstraintValidator')
|
||||||
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
|
|
||||||
|
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||||
|
$operators = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => Operators::INFERIOR
|
||||||
|
);
|
||||||
|
$values = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => '400',
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||||
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
|
$isValid = $rule1->isMatching();
|
||||||
|
|
||||||
|
$expected = true;
|
||||||
|
$actual =$isValid;
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if validity test on BackOffice inputs are working
|
||||||
|
*
|
||||||
|
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
|
||||||
|
* @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testInValidBackOfficeInputValue()
|
||||||
|
{
|
||||||
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getCartTotalPrice')
|
||||||
|
->will($this->returnValue(399));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getCheckoutCurrency')
|
||||||
|
->will($this->returnValue('EUR'));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getConstraintValidator')
|
||||||
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
|
|
||||||
|
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||||
|
$operators = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
|
);
|
||||||
|
$values = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => 'X',
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||||
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
|
$isValid = $rule1->isMatching();
|
||||||
|
|
||||||
|
$expected = true;
|
||||||
|
$actual =$isValid;
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if validity test on BackOffice inputs are working
|
||||||
|
*
|
||||||
|
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
|
||||||
|
* @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testInValidBackOfficeInputValue2()
|
||||||
|
{
|
||||||
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getCartTotalPrice')
|
||||||
|
->will($this->returnValue(399));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getCheckoutCurrency')
|
||||||
|
->will($this->returnValue('EUR'));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getConstraintValidator')
|
||||||
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
|
|
||||||
|
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||||
|
$operators = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||||
|
);
|
||||||
|
$values = array(
|
||||||
|
AvailableForTotalAmountManager::INPUT1 => 400,
|
||||||
|
AvailableForTotalAmountManager::INPUT2 => 'FLA');
|
||||||
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
|
$isValid = $rule1->isMatching();
|
||||||
|
|
||||||
|
$expected = true;
|
||||||
|
$actual =$isValid;
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if test inferior operator is working
|
* Check if test inferior operator is working
|
||||||
@@ -33,13 +33,13 @@ use Thelia\Constraint\Rule\SerializableRule;
|
|||||||
* Date: 8/19/13
|
* Date: 8/19/13
|
||||||
* Time: 3:24 PM
|
* Time: 3:24 PM
|
||||||
*
|
*
|
||||||
* Unit Test AvailableForXArticles Class
|
* Unit Test AvailableForXArticlesManager Class
|
||||||
*
|
*
|
||||||
* @package Constraint
|
* @package Constraint
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||||
@@ -51,30 +51,8 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
protected function setUp()
|
protected function setUp()
|
||||||
{
|
{
|
||||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
|
||||||
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
}
|
||||||
// * Generate valid CouponBaseAdapter
|
|
||||||
// *
|
|
||||||
// * @param int $nbArticlesInCart Total articles in the current Cart
|
|
||||||
// *
|
|
||||||
// * @return CouponAdapterInterface
|
|
||||||
// */
|
|
||||||
// protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4)
|
|
||||||
// {
|
|
||||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
|
||||||
// $stubTheliaAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
|
||||||
// ->disableOriginalConstructor()
|
|
||||||
// ->setMethods(array('getNbArticlesInCart'))
|
|
||||||
// ->getMock();
|
|
||||||
// $stubTheliaAdapter->expects($this->any())
|
|
||||||
// ->method('getNbArticlesInCart')
|
|
||||||
// ->will($this->returnValue($nbArticlesInCart));
|
|
||||||
//
|
|
||||||
// return $stubTheliaAdapter;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Check if validity test on BackOffice inputs are working
|
// * Check if validity test on BackOffice inputs are working
|
||||||
@@ -100,31 +78,75 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
|||||||
// $this->assertEquals($expected, $actual);
|
// $this->assertEquals($expected, $actual);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// /**
|
/**
|
||||||
// * Check if validity test on BackOffice inputs are working
|
* Check if validity test on BackOffice inputs are working
|
||||||
// *
|
*
|
||||||
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||||
// * @expectedException \Thelia\Exception\InvalidRuleValueException
|
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
||||||
// */
|
*/
|
||||||
// public function testInValidBackOfficeInputFloat()
|
public function testInValidBackOfficeInputOperator()
|
||||||
// {
|
{
|
||||||
// $adapter = $this->stubTheliaAdapter;
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
//
|
->disableOriginalConstructor()
|
||||||
// $validators = array(
|
->getMock();
|
||||||
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
|
|
||||||
// Operators::SUPERIOR,
|
$stubAdapter->expects($this->any())
|
||||||
// new QuantityParam(
|
->method('getNbArticlesInCart')
|
||||||
// $adapter,
|
->will($this->returnValue(4));
|
||||||
// 4.5
|
$stubAdapter->expects($this->any())
|
||||||
// )
|
->method('getConstraintValidator')
|
||||||
// )
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
// );
|
|
||||||
// $rule = new AvailableForXArticles($adapter, $validators);
|
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||||
//
|
$operators = array(
|
||||||
// $expected = false;
|
AvailableForXArticlesManager::INPUT1 => Operators::IN
|
||||||
// $actual = $rule->checkBackOfficeInput();
|
);
|
||||||
// $this->assertEquals($expected, $actual);
|
$values = array(
|
||||||
// }
|
AvailableForXArticlesManager::INPUT1 => 5
|
||||||
|
);
|
||||||
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
|
$isValid = $rule1->isMatching();
|
||||||
|
|
||||||
|
$expected = true;
|
||||||
|
$actual =$isValid;
|
||||||
|
$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 testInValidBackOfficeInputValue()
|
||||||
|
{
|
||||||
|
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getNbArticlesInCart')
|
||||||
|
->will($this->returnValue(4));
|
||||||
|
$stubAdapter->expects($this->any())
|
||||||
|
->method('getConstraintValidator')
|
||||||
|
->will($this->returnValue(new ConstraintValidator()));
|
||||||
|
|
||||||
|
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||||
|
$operators = array(
|
||||||
|
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||||
|
);
|
||||||
|
$values = array(
|
||||||
|
AvailableForXArticlesManager::INPUT1 => 'X'
|
||||||
|
);
|
||||||
|
$rule1->setValidatorsFromForm($operators, $values);
|
||||||
|
|
||||||
|
$isValid = $rule1->isMatching();
|
||||||
|
|
||||||
|
$expected = true;
|
||||||
|
$actual =$isValid;
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Check if validity test on BackOffice inputs are working
|
// * Check if validity test on BackOffice inputs are working
|
||||||
@@ -96,6 +96,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
|
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
|
||||||
$expected = 'not in';
|
$expected = 'not in';
|
||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
$actual = Operators::getI18n($stubTranslator, 'unexpected operator');
|
||||||
|
$expected = 'unexpected operator';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user