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:
82
core/lib/Thelia/Constraint/ConstraintManager.php
Normal file
82
core/lib/Thelia/Constraint/ConstraintManager.php
Normal file
@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Constraint could interact
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintManager
|
||||
{
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/** @var array CouponRuleCollection to process*/
|
||||
protected $rules = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param CouponRuleCollection $rules Rules associated with the Constraint
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter, CouponRuleCollection $rules)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->rule = $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$isMatching = true;
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($this->rules->getRules() as $rule) {
|
||||
if (!$rule->isMatching($this->adapter)) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -21,14 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,14 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,14 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,14 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
@@ -30,7 +30,7 @@ use Thelia\Coupon\CouponAdapterInterface;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,12 +21,12 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
@@ -39,7 +39,7 @@ use Thelia\Exception\InvalidRuleValueException;
|
||||
* Rule AvailableForTotalAmount
|
||||
* Check if a Checkout total amount match criteria
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -182,5 +182,42 @@ class AvailableForTotalAmount extends CouponRuleAbstract
|
||||
return $this->validators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Cart total amount', 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 total amount is %operator% %amount% %currency%',
|
||||
array(
|
||||
'%operator%' => $i18nOperator,
|
||||
'%amount%' => $this->priceValidator->getParam()->getPrice(),
|
||||
'%currency%' => $this->priceValidator->getParam()->getCurrency()
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,14 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +30,7 @@ namespace Thelia\Coupon\Rule;
|
||||
*
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,12 +21,12 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\Validator\ComparableInterface;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
|
||||
@@ -37,7 +37,7 @@ use Thelia\Exception\InvalidRuleOperatorException;
|
||||
*
|
||||
* Assist in writing a condition of whether the Rule is applied or not
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
@@ -32,7 +32,7 @@ use Thelia\Coupon\CouponAdapterInterface;
|
||||
*
|
||||
* Represents a condition of whether the Rule is applied or not
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -69,4 +69,19 @@ interface CouponRuleInterface
|
||||
*/
|
||||
public function getAvailableOperators();
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip();
|
||||
|
||||
}
|
||||
@@ -21,9 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Rule;
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Coupon\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -32,7 +32,7 @@ use Thelia\Coupon\Validator\ComparableInterface;
|
||||
*
|
||||
* Represent available Operations in rule checking
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -106,4 +106,66 @@ abstract class Operators
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get operator translation
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param string $operator Operator const
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function getI18n(CouponAdapterInterface $adapter, $operator)
|
||||
{
|
||||
$translator = $adapter->getTranslator();
|
||||
|
||||
$ret = $operator;
|
||||
switch ($operator) {
|
||||
case self::INFERIOR:
|
||||
$ret = $translator->trans(
|
||||
'inferior to',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::INFERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'inferior or equals to',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'equals to',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'superior or equals to',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR:
|
||||
$ret = $translator->trans(
|
||||
'superior to',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
case self::DIFFERENT:
|
||||
$ret = $translator->trans(
|
||||
'different from',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
/**
|
||||
* Comparable interface
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +32,7 @@ namespace Thelia\Coupon\Validator;
|
||||
*
|
||||
* Represent a DateTime
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -42,11 +44,13 @@ class DateParam extends RuleParameterAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $dateTime DateTime
|
||||
*/
|
||||
public function __construct(\DateTime $dateTime)
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $dateTime)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -101,5 +105,16 @@ class DateParam extends RuleParameterAbstract
|
||||
return clone $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +32,7 @@ namespace Thelia\Coupon\Validator;
|
||||
*
|
||||
* Represent an Integer
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -42,11 +44,13 @@ class IntegerParam extends RuleParameterAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*/
|
||||
public function __construct($integer)
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,4 +106,16 @@ class IntegerParam extends RuleParameterAbstract
|
||||
return $this->integer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A number (ex: 42)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +32,7 @@ namespace Thelia\Coupon\Validator;
|
||||
*
|
||||
* Represent an DateTime period
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -39,17 +41,50 @@ class IntervalParam extends RuleParameterAbstract
|
||||
/** @var \DatePeriod Date period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var \DateTime Start date */
|
||||
protected $start = null;
|
||||
|
||||
/** @var \DateInterval Interval date */
|
||||
protected $interval = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $start Start interval
|
||||
* @param \DateInterval $interval Period
|
||||
*/
|
||||
public function __construct(\DateTime $start, \DateInterval $interval)
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $start, \DateInterval $interval)
|
||||
{
|
||||
$this->datePeriod = new \DatePeriod($start, $interval, 1);
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->start = $start;
|
||||
$this->interval = $interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStart()
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get DatePeriod
|
||||
*
|
||||
@@ -115,4 +150,16 @@ class IntervalParam extends RuleParameterAbstract
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('An interval between two dates', null, 'constraint');
|
||||
}
|
||||
}
|
||||
115
core/lib/Thelia/Constraint/Validator/ModelParam.php
Normal file
115
core/lib/Thelia/Constraint/Validator/ModelParam.php
Normal file
@@ -0,0 +1,115 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Model
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ModelParam extends IntegerParam
|
||||
{
|
||||
/** @var string Model Class name */
|
||||
protected $modelClass = null;
|
||||
|
||||
/** @var ModelCriteria */
|
||||
protected $queryBuilder = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
* @param string $modelClass Model class name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer, $modelClass)
|
||||
{
|
||||
if ($integer < 0) {
|
||||
$integer = 0;
|
||||
}
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->modelClass = $modelClass;
|
||||
$queryClassName = $modelClass . 'Query';
|
||||
try {
|
||||
$this->queryBuilder = $queryClassName::create();
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentException('ModelParam can only compare Models');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A Model',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -31,7 +33,7 @@ namespace Thelia\Coupon\Validator;
|
||||
* Represent a Price
|
||||
* Positive value with currency
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -46,13 +48,15 @@ class PriceParam extends RuleParameterAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param float $price Positive float
|
||||
* @param string $currency Currency Code ISO 4217 EUR|USD|GBP
|
||||
*/
|
||||
public function __construct($price, $currency)
|
||||
public function __construct(CouponAdapterInterface $adapter, $price, $currency)
|
||||
{
|
||||
$this->price = $price;
|
||||
$this->currency = $currency;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,4 +124,22 @@ class PriceParam extends RuleParameterAbstract
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A price in %currency% (ex: 14.50)',
|
||||
array(
|
||||
'%currency%' => $this->currency
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +32,7 @@ namespace Thelia\Coupon\Validator;
|
||||
*
|
||||
* Represent a Quantity
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -40,14 +42,16 @@ class QuantityParam extends IntegerParam
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*/
|
||||
public function __construct($integer)
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
if ($integer < 0) {
|
||||
$integer = 0;
|
||||
}
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,4 +79,21 @@ class QuantityParam extends IntegerParam
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A positive quantity (ex: 42)',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -38,7 +40,7 @@ namespace Thelia\Coupon\Validator;
|
||||
* x5 : $this->recurrences How many repeated cycle, 1st excluded
|
||||
* x6 : How many occurrence
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -46,10 +48,13 @@ class RepeatedDateParam extends RepeatedParam
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -97,4 +102,16 @@ class RepeatedDateParam extends RepeatedParam
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -39,7 +41,7 @@ namespace Thelia\Coupon\Validator;
|
||||
* x6 : How many occurrence
|
||||
* **** : $this->durationInDays Duration of a period
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -75,10 +77,13 @@ class RepeatedIntervalParam extends RepeatedParam
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,4 +136,16 @@ class RepeatedIntervalParam extends RepeatedParam
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
@@ -34,7 +34,7 @@ use DateTime;
|
||||
*
|
||||
* Allow to set the way a parameter can be repeated across the time
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -52,6 +52,52 @@ abstract class RepeatedParam extends RuleParameterAbstract
|
||||
/** @var DatePeriod dates recurring at regular intervals, over a given period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var int Frequency the object will be repeated */
|
||||
protected $frequency = null;
|
||||
|
||||
/** @var int $nbRepetition Time the object will be repeated */
|
||||
protected $nbRepetition = null;
|
||||
|
||||
/**
|
||||
* Get frequency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFrequency()
|
||||
{
|
||||
return $this->frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of time it will be repeated
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNbRepetition()
|
||||
{
|
||||
return $this->nbRepetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of recurrences
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecurrences()
|
||||
{
|
||||
return $this->recurrences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate default repetition
|
||||
* Every 1 week 100 times from now
|
||||
@@ -21,8 +21,9 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\NotImplementedException;
|
||||
|
||||
/**
|
||||
@@ -32,12 +33,15 @@ use Thelia\Exception\NotImplementedException;
|
||||
*
|
||||
* Get a Param value
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class RuleParameterAbstract implements ComparableInterface
|
||||
{
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
@@ -47,4 +51,16 @@ abstract class RuleParameterAbstract implements ComparableInterface
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -21,7 +21,7 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon\Validator;
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -30,7 +30,7 @@ namespace Thelia\Coupon\Validator;
|
||||
*
|
||||
* Allow to validate parameters
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -131,4 +131,12 @@ interface CouponAdapterInterface
|
||||
*/
|
||||
public function getTranslator();
|
||||
|
||||
/**
|
||||
* Return the main currency
|
||||
* THe one used to set prices in BackOffice
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCurrency();
|
||||
|
||||
}
|
||||
@@ -179,7 +179,7 @@ class CouponBaseAdapter implements CouponAdapterInterface
|
||||
*/
|
||||
public function getContainer()
|
||||
{
|
||||
// TODO: Implement getCheckoutPostagePrice() method.
|
||||
// TODO: Implement getContainer() method.
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -191,4 +191,16 @@ class CouponBaseAdapter implements CouponAdapterInterface
|
||||
{
|
||||
return $this->getContainer()->get('thelia.translator');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the main currency
|
||||
* THe one used to set prices in BackOffice
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMainCurrency()
|
||||
{
|
||||
// TODO: Implement getMainCurrency() method.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ use Thelia\Coupon\Type\CouponInterface;
|
||||
*/
|
||||
class CouponManager
|
||||
{
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
/** @var CouponAdapterInterface Provides necessary value from Thelia */
|
||||
protected $adapter;
|
||||
|
||||
/** @var array CouponInterface to process*/
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Thelia\Coupon\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,8 +24,8 @@
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\Rule\CouponRuleInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\RuleOrganizerInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
@@ -43,12 +43,18 @@ use Thelia\Exception\InvalidRuleException;
|
||||
*/
|
||||
abstract class CouponAbstract implements CouponInterface
|
||||
{
|
||||
/** @var CouponAdapterInterface Provides necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var RuleOrganizerInterface */
|
||||
protected $organizer = null;
|
||||
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
|
||||
/** @var ConstraintManager CouponRuleInterface Manager*/
|
||||
protected $constraintManager = null;
|
||||
|
||||
/** @var string Coupon code (ex: XMAS) */
|
||||
protected $code = null;
|
||||
|
||||
@@ -194,6 +200,10 @@ abstract class CouponAbstract implements CouponInterface
|
||||
public function setRules(CouponRuleCollection $rules)
|
||||
{
|
||||
$this->rules = $rules;
|
||||
$this->constraintManager = new ConstraintManager(
|
||||
$this->adapter,
|
||||
$this->rules
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -209,16 +219,7 @@ abstract class CouponAbstract implements CouponInterface
|
||||
*/
|
||||
public function isMatching(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$isMatching = true;
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($this->rules->getRules() as $rule) {
|
||||
if (!$rule->isMatching($adapter)) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
return $this->constraintManager->isMatching();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,4 +165,18 @@ interface CouponInterface
|
||||
* @return bool
|
||||
*/
|
||||
public function isExpired();
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Coupon\Type\CouponAbstract;
|
||||
|
||||
/**
|
||||
@@ -41,6 +42,7 @@ class RemoveXAmount extends CouponAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
||||
* @param string $code Coupon code (ex: XMAS)
|
||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||
* @param string $shortDescription Coupon short description
|
||||
@@ -54,7 +56,20 @@ class RemoveXAmount extends CouponAbstract
|
||||
* @param int $maxUsage How many usage left
|
||||
* @param \Datetime $expirationDate When the Code is expiring
|
||||
*/
|
||||
function __construct($code, $title, $shortDescription, $description, $amount, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, \DateTime $expirationDate)
|
||||
function __construct(
|
||||
$adapter,
|
||||
$code,
|
||||
$title,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$amount,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isEnabled,
|
||||
$maxUsage,
|
||||
\DateTime $expirationDate
|
||||
)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->title = $title;
|
||||
@@ -70,6 +85,36 @@ class RemoveXAmount extends CouponAbstract
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X amount to total cart', null, 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'This coupon will remove the entered amount to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,15 +43,33 @@ class RemoveXPercent extends CouponAbstract
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponInterface $adapter Provides necessary value from Thelia
|
||||
* @param string $code Coupon code (ex: XMAS)
|
||||
* @param string $title Coupon title (ex: Coupon for XMAS)
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param float $percent Coupon % to deduce (ex:3.14 for 3.14%)
|
||||
* @param bool $isCumulative if Coupon is cumulative
|
||||
* @param bool $isRemovingPostage if Coupon is removing postage
|
||||
* @param float $percent Coupon percentage to deduce
|
||||
* @param bool $isCumulative If Coupon is cumulative
|
||||
* @param bool $isRemovingPostage If Coupon is removing postage
|
||||
* @param bool $isAvailableOnSpecialOffers If available on Product already
|
||||
* on special offer price
|
||||
* @param bool $isEnabled False if Coupon is disabled by admin
|
||||
* @param int $maxUsage How many usage left
|
||||
* @param \Datetime $expirationDate When the Code is expiring
|
||||
*/
|
||||
function __construct($code, $title, $shortDescription, $description, $percent, $isCumulative, $isRemovingPostage)
|
||||
function __construct(
|
||||
$adapter,
|
||||
$code,
|
||||
$title,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$percent,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isEnabled,
|
||||
$maxUsage,
|
||||
\DateTime $expirationDate)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->title = $title;
|
||||
@@ -62,6 +80,12 @@ class RemoveXPercent extends CouponAbstract
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
|
||||
$this->percent = $percent;
|
||||
|
||||
$this->isAvailableOnSpecialOffers = $isAvailableOnSpecialOffers;
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->expirationDate = $expirationDate;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,10 +107,40 @@ class RemoveXPercent extends CouponAbstract
|
||||
);
|
||||
}
|
||||
|
||||
$basePrice =$adapter
|
||||
->getCartTotalPrice();
|
||||
$basePrice = $adapter->getCartTotalPrice();
|
||||
|
||||
return $basePrice * (( 100 - $this->percent ) / 100);
|
||||
return $basePrice * (( $this->percent ) / 100);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Remove X percent to total cart', null, 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
$toolTip = $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'This coupon will remove the entered percentage to the customer total checkout. If the discount is superior to the total checkout price the customer will only pay the postage. Unless if the coupon is set to remove postage too.',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
}
|
||||
142
core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php
Normal file
142
core/lib/Thelia/Tests/Constraint/ConstraintManagerTest.php
Normal file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
use Thelia\Tools\PhpUnitUtils;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test ConstraintManager Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate valid CouponRuleInterfaces
|
||||
*
|
||||
* @return array Array of CouponRuleInterface
|
||||
*/
|
||||
public static function generateValidRules()
|
||||
{
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$rule2 = new AvailableForTotalAmount(
|
||||
array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
, 400.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
$rules = new CouponRuleCollection(array($rule1, $rule2));
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
|
||||
@@ -37,7 +37,7 @@ use Thelia\Exception\InvalidRuleValueException;
|
||||
*
|
||||
* Unit Test AvailableForTotalAmount Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -86,8 +86,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -116,8 +115,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
'X',
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -176,8 +174,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -204,8 +201,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -232,8 +228,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -259,8 +254,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -286,8 +280,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -316,8 +309,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::EQUAL,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -343,8 +335,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::EQUAL,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -370,8 +361,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -397,8 +387,7 @@ class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
421.23,
|
||||
'EUR'
|
||||
, 421.23, 'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Rule\AvailableForXArticles;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticles;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -32,7 +32,7 @@ use Thelia\Coupon\Rule\AvailableForXArticles;
|
||||
*
|
||||
* Unit Test AvailableForXArticles Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\QuantityParam;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Rule\Operators;
|
||||
*
|
||||
* Unit Test Operators Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -58,7 +58,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -77,7 +77,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -96,7 +96,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -115,7 +115,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -134,7 +134,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 10;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -153,7 +153,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -172,7 +172,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -191,7 +191,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -210,7 +210,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -229,7 +229,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
$b = new QuantityParam(, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -248,7 +248,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 14;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
$b = new QuantityParam(, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -267,7 +267,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
$b = new QuantityParam(, 13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -286,7 +286,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -305,7 +305,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -324,7 +324,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
$b = new QuantityParam(, 12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -343,7 +343,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -362,7 +362,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -381,7 +381,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = 'X';
|
||||
$b = new QuantityParam(11);
|
||||
$b = new QuantityParam(, 11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValid($a, $operator, $b);
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Validator\DateParam;
|
||||
use Thelia\Constraint\Validator\DateParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\DateParam;
|
||||
*
|
||||
* Unit Test DateParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,10 +55,11 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
$dateParam = new DateParam($adapter, $dateValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -72,10 +73,11 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
$dateParam = new DateParam($adapter, $dateValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -89,10 +91,11 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-09");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
$dateParam = new DateParam($adapter, $dateValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -105,14 +108,36 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
$dateParam = new DateParam($adapter, $dateValidator);
|
||||
|
||||
$dateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
|
||||
$param = new DateParam($adapter, $dateValidator);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var DateParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getDateTime(), $unserialized->getDateTime());
|
||||
|
||||
$new = new DateParam($adapter, $unserialized->getDateTime());
|
||||
$this->assertEquals($param->getDateTime(), $new->getDateTime());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Validator\IntegerParam;
|
||||
use Thelia\Constraint\Validator\IntegerParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\IntegerParam;
|
||||
*
|
||||
* Unit Test IntegerParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,10 +55,11 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorInteger()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 41;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
$integerParam = new IntegerParam($adapter, $intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -72,10 +73,11 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsInteger()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 42;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
$integerParam = new IntegerParam($adapter, $intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -89,10 +91,11 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorInteger()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 43;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
$integerParam = new IntegerParam($adapter, $intValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -105,17 +108,38 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = '42';
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
$integerParam = new IntegerParam($adapter, $intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
|
||||
$param = new IntegerParam($adapter, $intValidator);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var IntegerParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
|
||||
$new = new IntegerParam($adapter, $unserialized->getInteger());
|
||||
$this->assertEquals($param->getInteger(), $new->getInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Validator\IntervalParam;
|
||||
use Thelia\Constraint\Validator\IntervalParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\IntervalParam;
|
||||
*
|
||||
* Unit Test IntervalParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,11 +55,12 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
$dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -73,6 +74,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
@@ -80,7 +82,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
echo '1 ' . date_format($dateValidatorStart, 'g:ia \o\n l jS F Y') . "\n";
|
||||
echo '2 ' . date_format($dateToValidate, 'g:ia \o\n l jS F Y') . "\n";
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
$dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -94,11 +96,12 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDate2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
$dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -112,11 +115,12 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-08-09");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
$dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
@@ -129,16 +133,38 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
$dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$dateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
|
||||
$param = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var IntervalParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
|
||||
$new = new IntervalParam($adapter, $unserialized->getStart(), $unserialized->getInterval());
|
||||
$this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\PriceParam;
|
||||
*
|
||||
* Unit Test PriceParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,10 +55,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorPrice()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 1.00;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -72,10 +74,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorPrice2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.49;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -89,10 +93,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsPrice()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.50;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -106,10 +112,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorPrice()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.51;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -122,10 +130,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = '42.50';
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -138,10 +148,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = -1;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -154,10 +166,12 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException3()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 0;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
@@ -170,17 +184,40 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException4()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 1;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
$integerParam = new PriceParam($adapter, $priceValidator, 'GBP');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$priceValidator = 42.50;
|
||||
|
||||
$param = new PriceParam($adapter, $priceValidator, 'GBP');
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var PriceParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getPrice(), $unserialized->getPrice());
|
||||
$this->assertEquals($param->getCurrency(), $unserialized->getCurrency());
|
||||
|
||||
$new = new PriceParam($adapter, $unserialized->getPrice(), $unserialized->getCurrency());
|
||||
$this->assertEquals($param->getPrice(), $new->getPrice());
|
||||
$this->assertEquals($param->getCurrency(), $new->getCurrency());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\QuantityParam;
|
||||
*
|
||||
* Unit Test QuantityParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,10 +55,11 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorQuantity()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 0;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -72,10 +73,11 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorQuantity2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 41;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -89,10 +91,11 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsQuantity()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 42;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -106,10 +109,11 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorQuantity()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = 43;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -122,10 +126,11 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = '42';
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
@@ -138,17 +143,39 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = -1;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
$integerParam = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$intValidator = 42;
|
||||
$intToValidate = -1;
|
||||
|
||||
$param = new QuantityParam($adapter, $intValidator);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var QuantityParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
|
||||
$new = new PriceParam($adapter, $unserialized->getInteger());
|
||||
$this->assertEquals($param->getInteger(), $new->getInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\Validator\RepeatedDateParam;
|
||||
use Thelia\Constraint\Validator\RepeatedDateParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -34,7 +34,7 @@ use Thelia\Coupon\Validator\RepeatedDateParam;
|
||||
*
|
||||
* Unit Test RepeatedDateParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -56,10 +56,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
|
||||
@@ -75,10 +76,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
|
||||
@@ -94,12 +96,13 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
$repeatedDateParam->repeatEveryMonth(1, 1);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
@@ -113,10 +116,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-09-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(1, 10);
|
||||
|
||||
@@ -132,10 +136,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-05-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(1, 10);
|
||||
|
||||
@@ -151,10 +156,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-11-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
@@ -170,10 +176,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-03-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
@@ -189,10 +196,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
@@ -208,10 +216,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-12-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
@@ -227,10 +236,11 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorDateRepeatEveryFourMonthTwoTimes()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-03-09");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
@@ -245,17 +255,42 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam = new RepeatedDateParam($adapter);
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$repeatedDateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
|
||||
$param = new RepeatedDateParam($adapter);
|
||||
$param->setFrom($startDateValidator);
|
||||
$param->repeatEveryMonth(4, 2);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var RepeatedDateParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
|
||||
$new = new RepeatedDateParam($adapter);
|
||||
$new->setFrom($unserialized->getFrom());
|
||||
$new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
|
||||
$this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\Validator\RepeatedIntervalParam;
|
||||
use Thelia\Constraint\Validator\RepeatedIntervalParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -33,7 +33,7 @@ use Thelia\Coupon\Validator\RepeatedIntervalParam;
|
||||
*
|
||||
* Unit Test RepeatedIntervalParam Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
@@ -55,11 +55,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
|
||||
@@ -77,11 +78,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -98,11 +100,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -119,11 +122,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -140,11 +144,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -161,11 +166,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -182,11 +188,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
@@ -201,13 +208,14 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBegining()
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -224,11 +232,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -245,11 +254,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -266,11 +276,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-07-19");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -287,11 +298,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-08-01");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -309,11 +321,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-08-07");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -332,11 +345,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorDateRepeatEveryMonthFourTime()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-10-19");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 0);
|
||||
@@ -352,11 +366,12 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
@@ -364,6 +379,36 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
$RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test is the object is serializable
|
||||
* If no data is lost during the process
|
||||
*/
|
||||
protected function isSerializableTest()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
$duration = 10;
|
||||
|
||||
$param = new RepeatedIntervalParam($adapter);
|
||||
$param->setFrom($startDateValidator);
|
||||
$param->setDurationInDays($duration);
|
||||
$param->repeatEveryMonth(1, 4);
|
||||
|
||||
$serialized = base64_encode(serialize($param));
|
||||
/** @var RepeatedIntervalParam $unserialized */
|
||||
$unserialized = base64_decode(serialize($serialized));
|
||||
|
||||
$this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
$this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
|
||||
$new = new RepeatedIntervalParam($adapter);
|
||||
$new->setFrom($unserialized->getFrom());
|
||||
$new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
|
||||
$new->setDurationInDays($unserialized->getDurationInDays());
|
||||
$this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Exception\CouponExpiredException;
|
||||
use Thelia\Model\Coupon;
|
||||
@@ -208,8 +208,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
40.00,
|
||||
'EUR'
|
||||
, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -219,8 +218,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
400.00,
|
||||
'EUR'
|
||||
, 400.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
use Thelia\Tools\PhpUnitUtils;
|
||||
@@ -103,6 +103,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
*/
|
||||
public function testGetDiscountTwoCoupon()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$cartTotalPrice = 100.00;
|
||||
$checkoutTotalPrice = 120.00;
|
||||
|
||||
@@ -113,8 +114,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
40.00,
|
||||
'EUR'
|
||||
$adapter, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -143,6 +143,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
*/
|
||||
public function testGetDiscountAlwaysInferiorToPrice()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$cartTotalPrice = 21.00;
|
||||
$checkoutTotalPrice = 26.00;
|
||||
|
||||
@@ -151,8 +152,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
20.00,
|
||||
'EUR'
|
||||
$adapter, 20.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -180,6 +180,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
*/
|
||||
public function testIsCouponRemovingPostage()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$cartTotalPrice = 21.00;
|
||||
$checkoutTotalPrice = 27.00;
|
||||
|
||||
@@ -188,8 +189,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
20.00,
|
||||
'EUR'
|
||||
$adapter, 20.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -640,13 +640,13 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
*/
|
||||
public static function generateValidRules()
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule1 = new AvailableForTotalAmount(
|
||||
array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
40.00,
|
||||
'EUR'
|
||||
$adapter, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -656,8 +656,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
400.00,
|
||||
'EUR'
|
||||
$adapter, 400.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -754,6 +753,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$isAvailableOnSpecialOffers = null,
|
||||
$maxUsage = null
|
||||
) {
|
||||
$adapter = new CouponBaseAdapter();
|
||||
if ($code === null) {
|
||||
$code = self::VALID_CODE;
|
||||
}
|
||||
@@ -790,7 +790,7 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
|
||||
$expirationDate->setTimestamp(strtotime("today + 2 months"));
|
||||
}
|
||||
|
||||
$coupon = new RemoveXAmount($code, $title, $shortDescription, $description, $amount, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate);
|
||||
$coupon = new RemoveXAmount($adapter, $code, $title, $shortDescription, $description, $amount, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate);
|
||||
|
||||
if ($rules === null) {
|
||||
$rules = self::generateValidRules();
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -51,8 +51,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::SUPERIOR,
|
||||
new PriceParam(
|
||||
40.00,
|
||||
'EUR'
|
||||
, 40.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -62,8 +61,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
Operators::INFERIOR,
|
||||
new PriceParam(
|
||||
400.00,
|
||||
'EUR'
|
||||
, 400.00, 'EUR'
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -23,10 +23,10 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Validator\PriceParam;
|
||||
use Thelia\Coupon\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
|
||||
require_once '../CouponManagerTest.php';
|
||||
@@ -54,6 +54,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon is well displayed
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getCode
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getTitle
|
||||
@@ -83,13 +84,13 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon can be Cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsCumulative()
|
||||
{
|
||||
|
||||
$coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
@@ -97,13 +98,13 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon can be non cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsNotCumulative()
|
||||
{
|
||||
|
||||
$coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
@@ -112,6 +113,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
/**
|
||||
* Test if a Coupon can remove postage
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
*
|
||||
@@ -125,13 +127,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon won't remove postage if not set to
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
*
|
||||
*/
|
||||
public function testIsNotRemovingPostage()
|
||||
{
|
||||
|
||||
$coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isRemovingPostage();
|
||||
@@ -140,25 +141,25 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
/**
|
||||
* Test if a Coupon has the effect expected (discount 10euros)
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffect()
|
||||
{
|
||||
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$expected = 10;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
*
|
||||
*/
|
||||
public function testSetRulesValid()
|
||||
{
|
||||
@@ -187,6 +188,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @expectedException \Thelia\Exception\InvalidRuleException
|
||||
@@ -212,6 +214,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount < 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
@@ -219,6 +222,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
400.00
|
||||
@@ -230,11 +234,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount <= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
@@ -242,6 +247,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
400.00
|
||||
@@ -253,11 +259,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount == 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
@@ -265,6 +272,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
400.00
|
||||
@@ -276,11 +284,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount >= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
@@ -288,6 +297,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
400.00
|
||||
@@ -299,11 +309,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount > 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
@@ -311,6 +322,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
400.00
|
||||
@@ -322,7 +334,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
// Then
|
||||
$expected = 10.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -347,10 +359,12 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount)
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
$operator,
|
||||
new PriceParam(
|
||||
$adapter,
|
||||
$amount,
|
||||
'EUR'
|
||||
)
|
||||
|
||||
@@ -24,8 +24,15 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Coupon\Type\RemoveXPercent;
|
||||
|
||||
require_once '../CouponManagerTest.php';
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
@@ -48,92 +55,29 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
protected function generateValidCumulativeRemovingPostageCoupon()
|
||||
{
|
||||
$coupon = new RemoveXPercent(
|
||||
self::VALID_COUPON_CODE,
|
||||
self::VALID_COUPON_TITLE,
|
||||
self::VALID_COUPON_SHORT_DESCRIPTION,
|
||||
self::VALID_COUPON_DESCRIPTION,
|
||||
30.00,
|
||||
true,
|
||||
true
|
||||
);
|
||||
|
||||
return $coupon;
|
||||
}
|
||||
|
||||
protected function generateValidNonCumulativeNonRemovingPostageCoupon()
|
||||
{
|
||||
$coupon = new RemoveXPercent(
|
||||
self::VALID_COUPON_CODE,
|
||||
self::VALID_COUPON_TITLE,
|
||||
self::VALID_COUPON_SHORT_DESCRIPTION,
|
||||
self::VALID_COUPON_DESCRIPTION,
|
||||
30.00,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
return $coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon can be Cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::getCode
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::getTitle
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::getShortDescription
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::getDescription
|
||||
*
|
||||
*/
|
||||
public function testDisplay()
|
||||
{
|
||||
|
||||
$coupon = $this->generateValidCumulativeRemovingPostageCoupon();
|
||||
|
||||
$expected = self::VALID_COUPON_CODE;
|
||||
$actual = $coupon->getCode();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$expected = self::VALID_COUPON_TITLE;
|
||||
$actual = $coupon->getTitle();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$expected = self::VALID_COUPON_SHORT_DESCRIPTION;
|
||||
$actual = $coupon->getShortDescription();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$expected = self::VALID_COUPON_DESCRIPTION;
|
||||
$actual = $coupon->getDescription();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsCumulative()
|
||||
{
|
||||
|
||||
$coupon = $this->generateValidCumulativeRemovingPostageCoupon();
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon can be non cumulative
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::isCumulative
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isCumulative
|
||||
*
|
||||
*/
|
||||
public function testIsNotCumulative()
|
||||
{
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isCumulative();
|
||||
$this->assertFalse($actual);
|
||||
@@ -141,28 +85,27 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
/**
|
||||
* Test if a Coupon can remove postage
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::isRemovingPostage
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
*
|
||||
*/
|
||||
public function testIsRemovingPostage()
|
||||
{
|
||||
|
||||
$coupon = $this->generateValidCumulativeRemovingPostageCoupon();
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, true, true);
|
||||
|
||||
$actual = $coupon->isRemovingPostage();
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test if a Coupon won't remove postage if not set to
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::isRemovingPostage
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::isRemovingPostage
|
||||
*/
|
||||
public function testIsNotRemovingPostage()
|
||||
{
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$actual = $coupon->isRemovingPostage();
|
||||
$this->assertFalse($actual);
|
||||
@@ -170,20 +113,337 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
|
||||
/**
|
||||
* Test if a Coupon has the effect expected (discount 10euros)
|
||||
*
|
||||
* @covers Thelia\Coupon\Type\RemoveXPercent::getDiscount
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*/
|
||||
public function testGetEffect()
|
||||
{
|
||||
$adapter = $this->generateFakeAdapter(245);
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getDiscount();
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
*/
|
||||
public function testSetRulesValid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
20.00
|
||||
);
|
||||
$rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
100.23
|
||||
);
|
||||
$rule2 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
421.23
|
||||
);
|
||||
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
|
||||
// Then
|
||||
$expected = 3;
|
||||
$this->assertCount($expected, $coupon->getRules()->getRules());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon rule setter
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @expectedException \Thelia\Exception\InvalidRuleException
|
||||
*
|
||||
*/
|
||||
public function testSetRulesInvalid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
20.00
|
||||
);
|
||||
$rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
100.23
|
||||
);
|
||||
$rule2 = $this;
|
||||
|
||||
$coupon = self::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount < 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount <= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount == 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount >= 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test Coupon effect for rule Total Amount > 400
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
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);
|
||||
|
||||
// When
|
||||
$coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
|
||||
// Then
|
||||
$expected = 24.50;
|
||||
$actual = $coupon->getDiscount($adapter);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate valid CouponInterface
|
||||
*
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon Title
|
||||
* @param string $shortDescription Coupon short
|
||||
* description
|
||||
* @param string $description Coupon description
|
||||
* @param float $amount Coupon discount
|
||||
* @param bool $isEnabled Is Coupon enabled
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
* @param CouponRuleCollection $rules Coupon rules
|
||||
* @param bool $isCumulative If is cumulative
|
||||
* @param bool $isRemovingPostage If is removing postage
|
||||
* @param bool $isAvailableOnSpecialOffers If is available on
|
||||
* special offers or not
|
||||
* @param int $maxUsage How many time a Coupon
|
||||
* can be used
|
||||
*
|
||||
* @return CouponInterface
|
||||
*/
|
||||
public static function generateValidCoupon(
|
||||
$code = null,
|
||||
$title = null,
|
||||
$shortDescription = null,
|
||||
$description = null,
|
||||
$percent = null,
|
||||
$isEnabled = null,
|
||||
$expirationDate = null,
|
||||
$rules = null,
|
||||
$isCumulative = null,
|
||||
$isRemovingPostage = null,
|
||||
$isAvailableOnSpecialOffers = null,
|
||||
$maxUsage = null
|
||||
) {
|
||||
$adapter = new CouponBaseAdapter();
|
||||
if ($code === null) {
|
||||
$code = CouponManagerTest::VALID_CODE;
|
||||
}
|
||||
if ($title === null) {
|
||||
$title = CouponManagerTest::VALID_TITLE;
|
||||
}
|
||||
if ($shortDescription === null) {
|
||||
$shortDescription = CouponManagerTest::VALID_SHORT_DESCRIPTION;
|
||||
}
|
||||
if ($description === null) {
|
||||
$description = CouponManagerTest::VALID_DESCRIPTION;
|
||||
}
|
||||
if ($percent === null) {
|
||||
$percent = 10.00;
|
||||
}
|
||||
if ($isEnabled === null) {
|
||||
$isEnabled = true;
|
||||
}
|
||||
if ($isCumulative === null) {
|
||||
$isCumulative = true;
|
||||
}
|
||||
if ($isRemovingPostage === null) {
|
||||
$isRemovingPostage = false;
|
||||
}
|
||||
if ($isAvailableOnSpecialOffers === null) {
|
||||
$isAvailableOnSpecialOffers = true;
|
||||
}
|
||||
if ($maxUsage === null) {
|
||||
$maxUsage = 40;
|
||||
}
|
||||
|
||||
if ($expirationDate === null) {
|
||||
$expirationDate = new \DateTime();
|
||||
$expirationDate->setTimestamp(strtotime("today + 2 months"));
|
||||
}
|
||||
|
||||
$coupon = new RemoveXPercent($adapter, $code, $title, $shortDescription, $description, $percent, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate);
|
||||
|
||||
if ($rules === null) {
|
||||
$rules = CouponManagerTest::generateValidRules();
|
||||
}
|
||||
|
||||
$coupon->setRules($rules);
|
||||
|
||||
return $coupon;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generate valid rule AvailableForTotalAmount
|
||||
* according to given operator and amount
|
||||
*
|
||||
* @param string $operator Operators::CONST
|
||||
* @param float $amount Amount with 2 decimals
|
||||
*
|
||||
* @return AvailableForTotalAmount
|
||||
*/
|
||||
protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount)
|
||||
{
|
||||
$adapter = new CouponBaseAdapter();
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
$operator,
|
||||
new PriceParam(
|
||||
$adapter,
|
||||
$amount,
|
||||
'EUR'
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
return new AvailableForTotalAmount($validators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a fake Adapter
|
||||
*
|
||||
* @param float $cartTotalPrice Cart total price
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateFakeAdapter($cartTotalPrice)
|
||||
{
|
||||
$stubCouponBaseAdapter = $this->getMock(
|
||||
'Thelia\Coupon\CouponBaseAdapter',
|
||||
array(
|
||||
'getCartTotalPrice'
|
||||
),
|
||||
array()
|
||||
);
|
||||
|
||||
$stubCouponBaseAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(($cartTotalPrice)));
|
||||
|
||||
return $stubCouponBaseAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
|
||||
Reference in New Issue
Block a user