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
{
/** Rule 1st parameter : price */
/** Rule 1st parameter : quantity */
CONST PARAM1_QUANTITY = 'quantity';
/** @var array Available Operators (Operators::CONST) */
@@ -121,7 +121,7 @@ class AvailableForXArticles extends CouponRuleAbstract
protected function setParametersToValidate()
{
$this->paramsToValidate = array(
self::PARAM1_QUANTITY => $this->adapter->getCartTotalPrice()
self::PARAM1_QUANTITY => $this->adapter->getNbArticlesInCart()
);
return $this;
@@ -130,11 +130,21 @@ class AvailableForXArticles extends CouponRuleAbstract
/**
* Check if Checkout inputs are relevant or not
*
* @throws \Thelia\Exception\InvalidRuleValueException
* @return bool
*/
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) {
throw new InvalidRuleException(get_class());
}
if (!in_array($validator->getOperator(), $this->availableOperators)) {
throw new InvalidRuleOperatorException(
get_class(),
$validator->getOperator()
);
}
}
$this->validators = $validators;