All Unit Test are green
This commit is contained in:
gmorel
2013-08-28 11:22:49 +02:00
parent 47106f562d
commit 3696ce4a4b
5 changed files with 289 additions and 132 deletions

View File

@@ -41,7 +41,7 @@ use Thelia\Exception\InvalidRuleValueException;
*/ */
class AvailableForXArticles extends CouponRuleAbstract class AvailableForXArticles extends CouponRuleAbstract
{ {
/** Rule 1st parameter : price */ /** Rule 1st parameter : quantity */
CONST PARAM1_QUANTITY = 'quantity'; CONST PARAM1_QUANTITY = 'quantity';
/** @var array Available Operators (Operators::CONST) */ /** @var array Available Operators (Operators::CONST) */
@@ -121,7 +121,7 @@ class AvailableForXArticles extends CouponRuleAbstract
protected function setParametersToValidate() protected function setParametersToValidate()
{ {
$this->paramsToValidate = array( $this->paramsToValidate = array(
self::PARAM1_QUANTITY => $this->adapter->getCartTotalPrice() self::PARAM1_QUANTITY => $this->adapter->getNbArticlesInCart()
); );
return $this; return $this;
@@ -130,11 +130,21 @@ class AvailableForXArticles extends CouponRuleAbstract
/** /**
* Check if Checkout inputs are relevant or not * Check if Checkout inputs are relevant or not
* *
* @throws \Thelia\Exception\InvalidRuleValueException
* @return bool * @return bool
*/ */
public function checkCheckoutInput() public function checkCheckoutInput()
{ {
// TODO: Implement checkCheckoutInput() method. if (!isset($this->paramsToValidate)
|| empty($this->paramsToValidate)
||!isset($this->paramsToValidate[self::PARAM1_QUANTITY])
) {
throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
}
$price = $this->paramsToValidate[self::PARAM1_QUANTITY];
return $this->isQuantityValid($price);
} }
/** /**

View File

@@ -100,6 +100,12 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
if (!$validator instanceof RuleValidator) { if (!$validator instanceof RuleValidator) {
throw new InvalidRuleException(get_class()); throw new InvalidRuleException(get_class());
} }
if (!in_array($validator->getOperator(), $this->availableOperators)) {
throw new InvalidRuleOperatorException(
get_class(),
$validator->getOperator()
);
}
} }
$this->validators = $validators; $this->validators = $validators;

View File

@@ -47,9 +47,6 @@ class QuantityParam extends IntegerParam
*/ */
public function __construct(CouponAdapterInterface $adapter, $integer) public function __construct(CouponAdapterInterface $adapter, $integer)
{ {
if ($integer < 0) {
$integer = 0;
}
$this->integer = $integer; $this->integer = $integer;
$this->adapter = $adapter; $this->adapter = $adapter;
} }

View File

@@ -43,6 +43,8 @@ use Thelia\Exception\InvalidRuleValueException;
*/ */
class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
@@ -51,30 +53,33 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
protected function setUp() protected function setUp()
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */ /** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
} }
/** /**
* Generate valid CouponBaseAdapter * Generate valid CouponBaseAdapter
* *
* @param float $cartTotalPrice Total amount of the current Cart
*
* @return CouponAdapterInterface * @return CouponAdapterInterface
*/ */
protected function generateValidCouponBaseAdapterMock() protected function generateValidCouponBaseAdapterMock($cartTotalPrice = 421.23)
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */ /** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->getMock( $stubTheliaAdapter = $this->getMock(
'CouponBaseAdapter', 'Thelia\Coupon\CouponBaseAdapter',
array('getCartTotalPrice'), array('getCartTotalPrice'),
array() array()
); );
$stubTheliaAdapter->expects($this->any()) $stubTheliaAdapter->expects($this->any())
->method('getCartTotalPrice') ->method('getCartTotalPrice')
->will($this->returnValue(421.23)); ->will($this->returnValue($cartTotalPrice));
return $stubTheliaAdapter; return $stubTheliaAdapter;
} }
/** /**
* Check if validity test on BackOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
* *
@@ -91,10 +96,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = true; $expected = true;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
@@ -102,6 +104,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if validity test on BackOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
* @expectedException \Thelia\Exception\InvalidRuleOperatorException * @expectedException \Thelia\Exception\InvalidRuleOperatorException
@@ -120,10 +123,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
@@ -131,6 +131,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if validity test on BackOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
* @expectedException \ErrorException * @expectedException \ErrorException
@@ -138,7 +139,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInValidBackOfficeInputValue() public function testInValidBackOfficeInputValue()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock();
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -147,10 +148,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
@@ -160,13 +158,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
/** /**
* Check if validity test on FrontOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
* *
*/ */
public function testValidCheckoutInput() public function testValidCheckoutInput()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -177,10 +176,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = true; $expected = true;
$actual = $rule->checkCheckoutInput(); $actual = $rule->checkCheckoutInput();
@@ -188,6 +184,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if validity test on FrontOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException * @expectedException \Thelia\Exception\InvalidRuleValueException
@@ -195,7 +192,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInValidCheckoutInputValue() public function testInValidCheckoutInputValue()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -206,10 +203,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->checkCheckoutInput(); $actual = $rule->checkCheckoutInput();
@@ -217,6 +211,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if validity test on FrontOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
* @expectedException \Thelia\Exception\InvalidRuleValueException * @expectedException \Thelia\Exception\InvalidRuleValueException
@@ -224,7 +219,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
*/ */
public function testInValidCheckoutInputType() public function testInValidCheckoutInputType()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -235,10 +230,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->checkCheckoutInput(); $actual = $rule->checkCheckoutInput();
@@ -246,13 +238,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test inferior operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testMatchingRuleInferior() public function testMatchingRuleInferior()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421.22);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -263,10 +256,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421.22
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = true; $expected = true;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -274,13 +264,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test inferior operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testNotMatchingRuleInferior() public function testNotMatchingRuleInferior()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421.23);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -291,10 +282,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421.23
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -302,13 +290,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test equals operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testMatchingRuleEqual() public function testMatchingRuleEqual()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -319,10 +308,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = true; $expected = true;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -330,13 +316,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test equals operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testNotMatchingRuleEqual() public function testNotMatchingRuleEqual()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421.22);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -347,10 +334,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421.22
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -358,13 +342,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test superior operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testMatchingRuleSuperior() public function testMatchingRuleSuperior()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421.24);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -375,10 +360,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421.24
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = true; $expected = true;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -386,13 +368,14 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test superior operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
* *
*/ */
public function testNotMatchingRuleSuperior() public function testNotMatchingRuleSuperior()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(421.23);
$validators = array( $validators = array(
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
@@ -403,10 +386,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
) )
); );
$validated = array( $rule = new AvailableForTotalAmount($adapter, $validators);
AvailableForTotalAmount::PARAM1_PRICE => 421.23
);
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->isMatching(); $actual = $rule->isMatching();

View File

@@ -24,6 +24,10 @@
namespace Thelia\Coupon; namespace Thelia\Coupon;
use Thelia\Constraint\Rule\AvailableForXArticles; use Thelia\Constraint\Rule\AvailableForXArticles;
use Thelia\Constraint\Rule\Operators;
use Thelia\Constraint\Validator\QuantityParam;
use Thelia\Constraint\Validator\RuleValidator;
use Thelia\Exception\InvalidRuleOperatorException;
/** /**
* Created by JetBrains PhpStorm. * Created by JetBrains PhpStorm.
@@ -39,6 +43,9 @@ use Thelia\Constraint\Rule\AvailableForXArticles;
class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/** /**
* Sets up the fixture, for example, opens a network connection. * Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed. * This method is called before a test is executed.
@@ -46,41 +53,51 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
protected function setUp() protected function setUp()
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */ /** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
} }
/** /**
* Return an Adapter Mock wick 4 products int the Cart * Generate valid CouponBaseAdapter
*
* @param int $nbArticlesInCart Total articles in the current Cart
* *
* @return CouponAdapterInterface * @return CouponAdapterInterface
*/ */
protected function generateValidCouponBaseAdapterMock() protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4)
{ {
/** @var CouponAdapterInterface $stubTheliaAdapter */ /** @var CouponAdapterInterface $stubTheliaAdapter */
$stubTheliaAdapter = $this->getMock( $stubTheliaAdapter = $this->getMock(
'CouponBaseAdapter', 'Thelia\Coupon\CouponBaseAdapter',
array('getNbArticlesInCart'), array('getNbArticlesInCart'),
array() array()
); );
$stubTheliaAdapter->expects($this->any()) $stubTheliaAdapter->expects($this->any())
->method('getNbArticlesInCart') ->method('getNbArticlesInCart')
->will($this->returnValue(4)); ->will($this->returnValue($nbArticlesInCart));
return $stubTheliaAdapter; return $stubTheliaAdapter;
} }
/** /**
* Check if validity test on BackOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
* *
*/ */
public function testValidBackOfficeInput() public function testValidBackOfficeInput()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(4); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true; $expected = true;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
@@ -88,33 +105,77 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* 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
*/ */
public function testInValidBackOfficeInput() public function testInValidBackOfficeInputFloat()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(4.5); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::SUPERIOR,
new QuantityParam(
$adapter,
4.5
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false; $expected = false;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
}
$validators = array(-1); /**
$validated = array($adapter->getNbArticlesInCart()); * Check if validity test on BackOffice inputs are working
$rule = new AvailableForXArticles($adapter, $validators, $validated); *
* @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; $expected = false;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
}
$validators = array('bad'); /**
$validated = array($adapter->getNbArticlesInCart()); * Check if validity test on BackOffice inputs are working
$rule = new AvailableForXArticles($adapter, $validators, $validated); *
* @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; $expected = false;
$actual = $rule->checkBackOfficeInput(); $actual = $rule->checkBackOfficeInput();
@@ -123,17 +184,26 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
/** /**
* Check if validity test on FrontOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
*
*/ */
public function testValidCheckoutInput() public function testValidCheckoutInput()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(4); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::SUPERIOR,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true; $expected = true;
$actual = $rule->checkCheckoutInput(); $actual = $rule->checkCheckoutInput();
@@ -141,32 +211,24 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if validity test on FrontOffice inputs are working
* *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
* * @expectedException \Thelia\Exception\InvalidRuleValueException
*/ */
public function testInValidCheckoutInput() public function testInValidCheckoutInputFloat()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->generateValidCouponBaseAdapterMock(4.5);
$validators = array(4.5); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::SUPERIOR,
new QuantityParam(
$expected = false; $adapter,
$actual = $rule->checkCheckoutInput(); 4
$this->assertEquals($expected, $actual); )
)
$validators = array(-1); );
$validated = array($adapter->getNbArticlesInCart()); $rule = new AvailableForXArticles($adapter, $validators);
$rule = new AvailableForXArticles($adapter, $validators, $validated);
$expected = false;
$actual = $rule->checkCheckoutInput();
$this->assertEquals($expected, $actual);
$validators = array('bad');
$validated = array($adapter->getNbArticlesInCart());
$rule = new AvailableForXArticles($adapter, $validators, $validated);
$expected = false; $expected = false;
$actual = $rule->checkCheckoutInput(); $actual = $rule->checkCheckoutInput();
@@ -174,16 +236,101 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* 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 * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* *
*/ */
public function testMatchingRuleEqual() public function testMatchingRuleEqual()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(4); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::EQUAL,
new QuantityParam(
$adapter,
4
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true; $expected = true;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -191,16 +338,24 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test superior operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* *
*/ */
public function testMatchingRuleSuperior() public function testMatchingRuleSuperior()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(5); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::SUPERIOR,
new QuantityParam(
$adapter,
3
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = true; $expected = true;
$actual = $rule->isMatching(); $actual = $rule->isMatching();
@@ -208,16 +363,25 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
} }
/** /**
* Check if test unavailable operator is working
* *
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching * @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
* *
*/ */
public function testNotMatchingRule() public function testNotMatchingRule()
{ {
$adapter = new CouponBaseAdapter(); $adapter = $this->stubTheliaAdapter;
$validators = array(3); $validators = array(
$validated = array($adapter->getNbArticlesInCart()); AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
$rule = new AvailableForXArticles($adapter, $validators, $validated); Operators::DIFFERENT,
new QuantityParam(
$adapter,
3
)
)
);
$rule = new AvailableForXArticles($adapter, $validators);
$expected = false; $expected = false;
$actual = $rule->isMatching(); $actual = $rule->isMatching();