WIP Coupon
Refactor : creating dedicated reusable module for Constraints Adding ConstraintManager Secured : - Effects : RemoveXPercent + RemoveXAmount - Validators : all except ModelParam (need CustomerModelParam, AreaModelParam, CountryModelParam ?) - Conditions : AvailableForTotalAmount
This commit is contained in:
@@ -61,14 +61,16 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
*/
|
||||
public function __construct(array $validators)
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators)
|
||||
{
|
||||
parent::__construct($validators);
|
||||
parent::__construct($adapter, $validators);
|
||||
|
||||
if (isset($validators[self::PARAM1_PRICE])
|
||||
&& $validators[self::PARAM1_PRICE] instanceof RuleValidator
|
||||
@@ -77,7 +79,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
} else {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -109,8 +110,6 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
|
||||
$this->checkBackOfficeInputsOperators();
|
||||
|
||||
|
||||
|
||||
return $this->isPriceValid($price->getPrice());
|
||||
}
|
||||
|
||||
@@ -129,9 +128,9 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
|
||||
}
|
||||
|
||||
$quantity = $this->paramsToValidate[self::PARAM1_PRICE];
|
||||
$price = $this->paramsToValidate[self::PARAM1_PRICE];
|
||||
|
||||
return $this->isPriceValid($quantity);
|
||||
return $this->isPriceValid($price);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -157,15 +156,12 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setParametersToValidate(CouponAdapterInterface $adapter)
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
self::PARAM1_PRICE => $this->adapter->getCartTotalPrice()
|
||||
);
|
||||
|
||||
return $this;
|
||||
|
||||
@@ -23,6 +23,11 @@
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
@@ -36,15 +41,90 @@ namespace Thelia\Constraint\Rule;
|
||||
*/
|
||||
class AvailableForXArticles extends CouponRuleAbstract
|
||||
{
|
||||
/** Rule 1st parameter : price */
|
||||
CONST PARAM1_QUANTITY = 'quantity';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
Operators::INFERIOR,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR,
|
||||
);
|
||||
|
||||
/** @var RuleValidator Quantity Validator */
|
||||
protected $quantityValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*
|
||||
* @throws InvalidRuleException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators)
|
||||
{
|
||||
parent::__construct($adapter, $validators);
|
||||
|
||||
if (isset($validators[self::PARAM1_QUANTITY])
|
||||
&& $validators[self::PARAM1_QUANTITY] instanceof RuleValidator
|
||||
) {
|
||||
$this->quantityValidator = $validators[self::PARAM1_QUANTITY];
|
||||
} else {
|
||||
throw new InvalidRuleException(get_class());
|
||||
}
|
||||
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
if (!isset($this->validators)
|
||||
|| empty($this->validators)
|
||||
||!isset($this->validators[self::PARAM1_QUANTITY])
|
||||
||!isset($this->validators[self::PARAM1_QUANTITY])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
}
|
||||
|
||||
/** @var RuleValidator $ruleValidator */
|
||||
$ruleValidator = $this->validators[self::PARAM1_QUANTITY];
|
||||
/** @var QuantityParam $quantity */
|
||||
$quantity = $ruleValidator->getParam();
|
||||
|
||||
if (!$quantity instanceof QuantityParam) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
}
|
||||
|
||||
$this->checkBackOfficeInputsOperators();
|
||||
|
||||
return $this->isQuantityValid($quantity->getInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1_QUANTITY => $this->adapter->getCartTotalPrice()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,4 +137,61 @@ class AvailableForXArticles extends CouponRuleAbstract
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a quantity is valid
|
||||
*
|
||||
* @param float $quantity Quantity to check
|
||||
*
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
protected function isQuantityValid($quantity)
|
||||
{
|
||||
$quantityValidator = $this->quantityValidator;
|
||||
try {
|
||||
$quantityValidator->getParam()->compareTo($quantity);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1_QUANTITY);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Number of articles in cart', null, 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$i18nOperator = Operators::getI18n(
|
||||
$this->adapter, $this->priceValidator->getOperator()
|
||||
);
|
||||
|
||||
$toolTip = $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'If cart products quantity is %operator% %quantity%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->quantityValidator->getParam()->getInteger(),
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -57,6 +57,9 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/** @var array Parameters to be validated */
|
||||
protected $paramsToValidate = array();
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Ex:
|
||||
@@ -70,14 +73,16 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
* Param 2 :
|
||||
* $paramsToValidate[AvailableForTotalAmount::PARAM1_PRICE] = 9
|
||||
*
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*
|
||||
* @throws InvalidRuleException
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
* @param array $validators Array of RuleValidator
|
||||
* validating $paramsToValidate against
|
||||
*/
|
||||
public function __construct(array $validators)
|
||||
public function __construct(CouponAdapterInterface $adapter, array $validators)
|
||||
{
|
||||
$this->setValidators($validators);
|
||||
$this->adapter = $adapter;
|
||||
$this->setParametersToValidate($this->adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,14 +109,10 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/**
|
||||
* Check if the current Checkout matches this condition
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(CouponAdapterInterface $adapter)
|
||||
public function isMatching()
|
||||
{
|
||||
$this->setParametersToValidate($adapter);
|
||||
$this->checkBackOfficeInput();
|
||||
$this->checkCheckoutInput();
|
||||
|
||||
@@ -165,13 +166,10 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @throws \Thelia\Exception\NotImplementedException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setParametersToValidate(CouponAdapterInterface $adapter)
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
throw new \Thelia\Exception\NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,9 @@ interface CouponRuleInterface
|
||||
/**
|
||||
* Check if the current Checkout matches this condition
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(CouponAdapterInterface $adapter);
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
|
||||
@@ -168,12 +168,9 @@ abstract class CouponAbstract implements CouponInterface
|
||||
* Return effects generated by the coupon
|
||||
* A negative value
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function getDiscount(CouponAdapterInterface $adapter)
|
||||
public function getDiscount()
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
@@ -88,16 +88,13 @@ interface CouponInterface
|
||||
* A positive value
|
||||
*
|
||||
* Effects could also affect something else than the final Checkout price
|
||||
* CouponAdapter could be use to directly pass a Session value
|
||||
* CouponAdapter $adapter could be use to directly pass a Session value
|
||||
* some would wish to modify
|
||||
* Hence affecting a wide variety of Thelia elements
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @return float Amount removed from the Total Checkout
|
||||
*/
|
||||
public function getDiscount(CouponAdapterInterface $adapter);
|
||||
public function getDiscount();
|
||||
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
|
||||
@@ -92,14 +92,11 @@ class RemoveXPercent extends CouponAbstract
|
||||
* Return effects generated by the coupon
|
||||
* A negative value
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @throws \Thelia\Exception\MissingAdapterException
|
||||
* @throws \InvalidArgumentException
|
||||
* @return float
|
||||
*/
|
||||
public function getDiscount(CouponAdapterInterface $adapter)
|
||||
public function getDiscount()
|
||||
{
|
||||
if ($this->percent >= 100) {
|
||||
throw new \InvalidArgumentException(
|
||||
@@ -107,7 +104,7 @@ class RemoveXPercent extends CouponAbstract
|
||||
);
|
||||
}
|
||||
|
||||
$basePrice = $adapter->getCartTotalPrice();
|
||||
$basePrice = $this->adapter->getCartTotalPrice();
|
||||
|
||||
return $basePrice * (( $this->percent ) / 100);
|
||||
}
|
||||
|
||||
@@ -56,36 +56,11 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate valid CouponRuleInterfaces
|
||||
*
|
||||
* @return array Array of CouponRuleInterface
|
||||
*/
|
||||
public static function generateValidRules()
|
||||
public function incompleteTest()
|
||||
{
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
$rule2 = new AvailableForTotalAmount(
|
||||
array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
, 400.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$rules = new CouponRuleCollection(array($rule1, $rule2));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -95,48 +70,4 @@ class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a fake Adapter
|
||||
*
|
||||
* @param array $coupons Coupons
|
||||
* @param float $cartTotalPrice Cart total price
|
||||
* @param float $checkoutTotalPrice Checkout total price
|
||||
* @param float $postagePrice Checkout postage price
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFakeAdapter(array $coupons, $cartTotalPrice, $checkoutTotalPrice, $postagePrice = 6.00)
|
||||
{
|
||||
$stubCouponBaseAdapter = $this->getMock(
|
||||
'Thelia\Coupon\CouponBaseAdapter',
|
||||
array(
|
||||
'getCurrentCoupons',
|
||||
'getCartTotalPrice',
|
||||
'getCheckoutTotalPrice',
|
||||
'getCheckoutPostagePrice'
|
||||
),
|
||||
array()
|
||||
);
|
||||
|
||||
$stubCouponBaseAdapter->expects($this->any())
|
||||
->method('getCurrentCoupons')
|
||||
->will($this->returnValue(($coupons)));
|
||||
|
||||
// Return Cart product amount = $cartTotalPrice euros
|
||||
$stubCouponBaseAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
// Return Checkout amount = $checkoutTotalPrice euros
|
||||
$stubCouponBaseAdapter->expects($this->any())
|
||||
->method('getCheckoutTotalPrice')
|
||||
->will($this->returnValue($checkoutTotalPrice));
|
||||
|
||||
$stubCouponBaseAdapter->expects($this->any())
|
||||
->method('getCheckoutPostagePrice')
|
||||
->will($this->returnValue($postagePrice));
|
||||
|
||||
return $stubCouponBaseAdapter;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,6 +50,8 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,11 +64,11 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getCheckoutTotalPrice'),
|
||||
array('getCartTotalPrice'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapter->expects($this->any())
|
||||
->method('getCheckoutTotalPrice')
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(421.23));
|
||||
|
||||
return $stubTheliaAdapter;
|
||||
@@ -79,21 +81,20 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
@@ -108,22 +109,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
'X',
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
@@ -138,8 +138,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
@@ -149,9 +148,9 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
@@ -167,22 +166,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
@@ -197,11 +195,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidCheckoutInputValue()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -209,7 +209,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
@@ -224,11 +224,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidCheckoutInputType()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -236,7 +238,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
@@ -250,11 +252,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleInferior()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -262,7 +266,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.22
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -276,11 +280,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotMatchingRuleInferior()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -288,7 +294,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.23
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -302,22 +308,21 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::EQUAL,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $adapter->getCartTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -331,11 +336,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotMatchingRuleEqual()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::EQUAL,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -343,7 +350,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.22
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -357,11 +364,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -369,7 +378,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.24
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -383,11 +392,13 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotMatchingRuleSuperior()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 421.23, 'EUR'
|
||||
$adapter, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -395,7 +406,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.23
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
$rule = new AvailableForTotalAmount($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
|
||||
@@ -45,16 +45,23 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Adapter Mock wick 4 products int the Cart
|
||||
*
|
||||
* @return CouponAdapterInterface
|
||||
*/
|
||||
protected function generateValidCouponBaseAdapterMock()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getNbArticlesInCart'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getNbArticlesInCart'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
@@ -69,12 +76,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
@@ -88,28 +94,27 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
@@ -125,12 +130,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
@@ -144,28 +147,26 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
@@ -179,12 +180,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -198,12 +197,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(5);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
@@ -217,12 +214,10 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotMatchingRule()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(3);
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
$validated = array($adapter->getNbArticlesInCart());
|
||||
$rule = new AvailableForXArticles($adapter, $validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
|
||||
@@ -55,10 +55,11 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testOperatorInferiorValidBefore()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -75,9 +76,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInferiorInvalidEquals()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -94,9 +96,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInferiorInvalidAfter()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 13;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -113,9 +116,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInferiorOrEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -132,9 +136,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInferiorOrEqualValidBefore()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 10;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -151,9 +156,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInferiorOrEqualInValidAfter()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -170,9 +176,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -189,9 +196,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorEqualInValidBefore()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 11;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -208,9 +216,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorEqualInValidAfter()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 13;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -227,9 +236,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorOrEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 13);
|
||||
$b = new QuantityParam($adapter, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -246,9 +256,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorOrEqualAfter()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 14;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 13);
|
||||
$b = new QuantityParam($adapter, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -265,9 +276,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorOrEqualInvalidBefore()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(, 13);
|
||||
$b = new QuantityParam($adapter, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -284,9 +296,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorValidAfter()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -303,9 +316,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorInvalidEqual()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -322,9 +336,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorSuperiorInvalidBefore()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 11;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(, 12);
|
||||
$b = new QuantityParam($adapter, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -341,9 +356,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorDifferentValid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -360,9 +376,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorDifferentInvalidEquals()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 11;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -379,9 +396,10 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
public function testOperatorInValid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$a = 12;
|
||||
$operator = 'X';
|
||||
$b = new QuantityParam(, 11);
|
||||
$b = new QuantityParam($adapter, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
|
||||
/**
|
||||
@@ -173,7 +174,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
|
||||
$new = new PriceParam($adapter, $unserialized->getInteger());
|
||||
$new = new QuantityParam($adapter, $unserialized->getInteger());
|
||||
$this->assertEquals($param->getInteger(), $new->getInteger());
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
protected function generateValidRules()
|
||||
{
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -214,7 +214,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
$rule2 = new AvailableForTotalAmount(
|
||||
array(
|
||||
, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
|
||||
@@ -110,7 +110,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
/** @var CouponInterface $coupon1 */
|
||||
$coupon1 = self::generateValidCoupon();
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
$adapter, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -148,7 +148,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$checkoutTotalPrice = 26.00;
|
||||
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
$adapter, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -185,7 +185,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$checkoutTotalPrice = 27.00;
|
||||
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
$adapter, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -642,7 +642,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
$adapter, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -652,7 +652,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
)
|
||||
);
|
||||
$rule2 = new AvailableForTotalAmount(
|
||||
array(
|
||||
$adapter, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
|
||||
@@ -47,7 +47,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testRuleSerialisation()
|
||||
{
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
@@ -57,7 +57,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
$rule2 = new AvailableForTotalAmount(
|
||||
array(
|
||||
, array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
|
||||
@@ -45,6 +45,13 @@ class RemoveXAmountForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
public function incompleteTest()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
|
||||
@@ -151,7 +151,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
$coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$expected = 10;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -234,7 +234,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -259,7 +259,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -284,7 +284,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -309,7 +309,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -334,7 +334,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -371,7 +371,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
|
||||
return new AvailableForTotalAmount($validators);
|
||||
return new AvailableForTotalAmount($adapter, $validators);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -45,6 +45,13 @@ class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
public function incompleteTest()
|
||||
{
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
|
||||
@@ -63,7 +63,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testIsCumulative()
|
||||
{
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
$this->assertTrue($actual);
|
||||
@@ -77,7 +77,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testIsNotCumulative()
|
||||
{
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
$this->assertFalse($actual);
|
||||
@@ -92,7 +92,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testIsRemovingPostage()
|
||||
{
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
|
||||
$actual = $coupon->isRemovingPostage();
|
||||
$this->assertTrue($actual);
|
||||
@@ -105,7 +105,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testIsNotRemovingPostage()
|
||||
{
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isRemovingPostage();
|
||||
$this->assertFalse($actual);
|
||||
@@ -120,7 +120,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffect()
|
||||
{
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
@@ -149,7 +149,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
421.23
|
||||
);
|
||||
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
@@ -179,7 +179,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
$rule2 = $this;
|
||||
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
@@ -194,19 +194,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
400.00
|
||||
);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -219,19 +218,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -244,19 +242,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -269,19 +266,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -294,19 +290,18 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
400.00
|
||||
);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
$coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$actual = $coupon->getDiscount();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -331,7 +326,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
*
|
||||
* @return CouponInterface
|
||||
*/
|
||||
public static function generateValidCoupon(
|
||||
public function generateValidCoupon(
|
||||
$code = null,
|
||||
$title = null,
|
||||
$shortDescription = null,
|
||||
@@ -345,7 +340,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
$isAvailableOnSpecialOffers = null,
|
||||
$maxUsage = null
|
||||
) {
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
|
||||
if ($code === null) {
|
||||
$code = CouponManagerTest::VALID_CODE;
|
||||
}
|
||||
@@ -417,7 +413,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
)
|
||||
);
|
||||
|
||||
return new AvailableForTotalAmount($validators);
|
||||
return new AvailableForTotalAmount($adapter, $validators);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user