diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 335a36340..b3086c266 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -74,7 +74,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface } /** - * Occurring when a Coupon rule is about to be updated + * Occurring when a Coupon condition is about to be updated * * @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule */ @@ -86,7 +86,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface } /** - * Occurring when a Coupon rule is about to be consumed + * Occurring when a Coupon condition is about to be consumed * * @param CouponConsumeEvent $event Event consuming Coupon */ @@ -138,13 +138,14 @@ class Coupon extends BaseAction implements EventSubscriberInterface { $coupon->setDispatcher($this->getDispatcher()); - // Set default rule if none found + // Set default condition if none found /** @var ConditionManagerInterface $noConditionRule */ $noConditionRule = $this->container->get('thelia.condition.match_for_everyone'); - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); $couponRuleCollection = new ConditionCollection(); $couponRuleCollection->add($noConditionRule); - $defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection( + $defaultSerializedRule = $conditionFactory->serializeConditionCollection( $couponRuleCollection ); @@ -179,11 +180,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface { $coupon->setDispatcher($this->getDispatcher()); - /** @var ConditionFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); $coupon->createOrUpdateConditions( - $constraintFactory->serializeConditionCollection($event->getConditions()), + $conditionFactory->serializeConditionCollection($event->getConditions()), $event->getLocale() ); diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index 642b474e0..ff024ecae 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -82,7 +82,7 @@ class ConditionFactory if ($conditions !== null) { /** @var $condition ConditionManagerInterface */ foreach ($conditions as $condition) { - // Remove all rule if the "no condition" condition is found + // Remove all condition if the "no condition" condition is found // if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') { // return base64_encode(json_encode(array($condition->getSerializableRule()))); // } @@ -153,7 +153,7 @@ class ConditionFactory * * @param string $conditionServiceId ConditionManager class name * - * @return array Ready to be drawn rule inputs + * @return array Ready to be drawn condition inputs */ public function getInputs($conditionServiceId) { diff --git a/core/lib/Thelia/Condition/ConditionManagerAbstract.php b/core/lib/Thelia/Condition/ConditionManagerAbstract.php index 16ef2c044..e5c8aed1a 100644 --- a/core/lib/Thelia/Condition/ConditionManagerAbstract.php +++ b/core/lib/Thelia/Condition/ConditionManagerAbstract.php @@ -84,7 +84,7 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->conditionValidator = $adapter->getConditionValidator(); + $this->conditionValidator = $adapter->getConditionEvaluator(); } // /** @@ -94,13 +94,13 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface // * validating $paramsToValidate against // * // * @return $this -// * @throws InvalidRuleException +// * @throws InvalidConditionException // */ // protected function setValidators(array $validators) // { // foreach ($validators as $validator) { // if (!$validator instanceof RuleValidator) { -// throw new InvalidRuleException(get_class()); +// throw new InvalidConditionException(get_class()); // } // if (!in_array($validator->getOperator(), $this->availableOperators)) { // throw new InvalidConditionOperatorException( diff --git a/core/lib/Thelia/Condition/ConditionManagerInterface.php b/core/lib/Thelia/Condition/ConditionManagerInterface.php index bf7f439b3..0e7fc99b1 100644 --- a/core/lib/Thelia/Condition/ConditionManagerInterface.php +++ b/core/lib/Thelia/Condition/ConditionManagerInterface.php @@ -121,15 +121,15 @@ interface ConditionManagerInterface */ public function getValidators(); - /** - * Populate a Condition from a form admin - * - * @param array $operators Condition Operator set by the Admin - * @param array $values Condition Values set by the Admin - * - * @return bool - */ - public function populateFromForm(array$operators, array $values); +// /** +// * Populate a Condition from a form admin +// * +// * @param array $operators Condition Operator set by the Admin +// * @param array $values Condition Values set by the Admin +// * +// * @return bool +// */ +// public function populateFromForm(array$operators, array $values); /** diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php index e56d58d6b..bc158c878 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php @@ -159,17 +159,17 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract return false; } - $constraint1 = $this->conditionValidator->variableOpComparison( + $condition1 = $this->conditionValidator->variableOpComparison( $this->adapter->getCartTotalPrice(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); - $constraint2 = $this->conditionValidator->variableOpComparison( + $condition2 = $this->conditionValidator->variableOpComparison( $this->adapter->getCheckoutCurrency(), $this->operators[self::INPUT2], $this->values[self::INPUT2] ); - if ($constraint1 && $constraint2) { + if ($condition1 && $condition2) { return true; } diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f1882920e..6bebe103e 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -203,9 +203,9 @@ class CouponController extends BaseAdminController } else { // Display // Prepare the data that will hydrate the form - /** @var ConditionFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); - $conditions = $constraintFactory->unserializeConditionCollection( + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); @@ -318,26 +318,26 @@ class CouponController extends BaseAdminController return $this->pageNotFound(); } - $rules = new ConditionCollection(); + $conditions = new ConditionCollection(); /** @var ConditionFactory $conditionFactory */ $conditionFactory = $this->container->get('thelia.condition.factory'); $conditionsReceived = json_decode($this->getRequest()->get('rules')); foreach ($conditionsReceived as $conditionReceived) { - $rule = $conditionFactory->build( + $condition = $conditionFactory->build( $conditionReceived->serviceId, (array) $conditionReceived->operators, (array) $conditionReceived->values ); - $rules->add(clone $rule); + $conditions->add(clone $condition); } // $coupon->setSerializedRules( -// $constraintFactory->serializeCouponRuleCollection($rules) +// $conditionFactory->serializeCouponRuleCollection($rules) // ); $conditionEvent = new ConditionCreateOrUpdateEvent( - $rules + $conditions ); $conditionEvent->setCouponModel($coupon); @@ -350,19 +350,19 @@ class CouponController extends BaseAdminController $this->adminLogAppend( sprintf( - 'Coupon %s (ID %s) rules updated', + 'Coupon %s (ID %s) conditions updated', $conditionEvent->getCouponModel()->getTitle(), $conditionEvent->getCouponModel()->getServiceId() ) ); - $cleanedRules = $this->cleanConditionForTemplate($rules); + $cleanedConditions = $this->cleanConditionForTemplate($conditions); return $this->render( - 'coupon/rules', + 'coupon/conditions', array( 'couponId' => $couponId, - 'rules' => $cleanedRules, + 'rules' => $cleanedConditions, 'urlEdit' => $couponId, 'urlDelete' => $couponId ) @@ -469,7 +469,7 @@ class CouponController extends BaseAdminController $message = false; try { - // Check the form against constraints violations + // Check the form against conditions violations $form = $this->validateForm($creationForm, 'POST'); // Get the form field values @@ -525,7 +525,7 @@ class CouponController extends BaseAdminController } /** - * Get all available rules + * Get all available conditions * * @return array */ @@ -560,18 +560,18 @@ class CouponController extends BaseAdminController $cleanedCoupons = array(); /** @var CouponInterface $availableCoupon */ foreach ($availableCoupons as $availableCoupon) { - $rule = array(); - $rule['serviceId'] = $availableCoupon->getServiceId(); - $rule['name'] = $availableCoupon->getName(); - $rule['toolTip'] = $availableCoupon->getToolTip(); - $cleanedCoupons[] = $rule; + $condition = array(); + $condition['serviceId'] = $availableCoupon->getServiceId(); + $condition['name'] = $availableCoupon->getName(); + $condition['toolTip'] = $availableCoupon->getToolTip(); + $cleanedCoupons[] = $condition; } return $cleanedCoupons; } /** - * Clean rule for template + * Clean condition for template * * @param ConditionCollection $conditions Condition collection * diff --git a/core/lib/Thelia/Core/Template/Loop/Coupon.php b/core/lib/Thelia/Core/Template/Loop/Coupon.php index 16c20c4e8..ea8473192 100755 --- a/core/lib/Thelia/Core/Template/Loop/Coupon.php +++ b/core/lib/Thelia/Core/Template/Loop/Coupon.php @@ -25,8 +25,8 @@ namespace Thelia\Core\Template\Loop; use Propel\Runtime\ActiveQuery\Criteria; use Propel\Runtime\Util\PropelModelPager; -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\ConditionManagerInterface; use Thelia\Core\HttpFoundation\Request; use Thelia\Core\Template\Element\BaseI18nLoop; use Thelia\Core\Template\Element\LoopResult; @@ -68,7 +68,7 @@ class Coupon extends BaseI18nLoop /** * Execute Loop * - * @param PropelModelPager $pagination + * @param PropelModelPager $pagination Pagination manager * * @return \Thelia\Core\Template\Element\LoopResult */ @@ -94,8 +94,8 @@ class Coupon extends BaseI18nLoop $coupons = $this->search($search, $pagination); $loopResult = new LoopResult(); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); /** @var Request $request */ $request = $this->container->get('request'); @@ -105,7 +105,7 @@ class Coupon extends BaseI18nLoop /** @var MCoupon $coupon */ foreach ($coupons as $coupon) { $loopResultRow = new LoopResultRow(); - $rules = $constraintFactory->unserializeCouponRuleCollection( + $conditions = $conditionFactory->unserializeConditionCollection( $coupon->getSerializedRules() ); @@ -130,10 +130,10 @@ class Coupon extends BaseI18nLoop $datediff = $coupon->getExpirationDate()->getTimestamp() - $now; $daysLeftBeforeExpiration = floor($datediff/(60*60*24)); - $cleanedRules = array(); - /** @var CouponRuleInterface $rule */ - foreach ($rules->getRules() as $rule) { - $cleanedRules[] = $rule->getToolTip(); + $cleanedConditions = array(); + /** @var ConditionManagerInterface $condition */ + foreach ($conditions->getConditions() as $condition) { + $cleanedConditions[] = $condition->getToolTip(); } $loopResultRow->set("ID", $coupon->getId()) ->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED')) @@ -149,7 +149,7 @@ class Coupon extends BaseI18nLoop ->set("IS_AVAILABLE_ON_SPECIAL_OFFERS", $coupon->getIsAvailableOnSpecialOffers()) ->set("IS_ENABLED", $coupon->getIsEnabled()) ->set("AMOUNT", $coupon->getAmount()) - ->set("APPLICATION_CONDITIONS", $cleanedRules) + ->set("APPLICATION_CONDITIONS", $cleanedConditions) ->set("TOOLTIP", $couponManager->getToolTip()) ->set("DAY_LEFT_BEFORE_EXPIRATION", $daysLeftBeforeExpiration) ->set("SERVICE_ID", $couponManager->getServiceId()); diff --git a/core/lib/Thelia/Coupon/AdapterInterface.php b/core/lib/Thelia/Coupon/AdapterInterface.php index 4ca2b67aa..37979b44f 100644 --- a/core/lib/Thelia/Coupon/AdapterInterface.php +++ b/core/lib/Thelia/Coupon/AdapterInterface.php @@ -165,11 +165,11 @@ interface AdapterInterface public function getRequest(); /** - * Return Condition Validator + * Return Condition Evaluator * * @return ConditionEvaluator */ - public function getConditionValidator(); + public function getConditionEvaluator(); /** * Return all available currencies diff --git a/core/lib/Thelia/Coupon/BaseAdapter.php b/core/lib/Thelia/Coupon/BaseAdapter.php index 6963ef0d6..883758ce1 100644 --- a/core/lib/Thelia/Coupon/BaseAdapter.php +++ b/core/lib/Thelia/Coupon/BaseAdapter.php @@ -27,16 +27,13 @@ use Symfony\Component\DependencyInjection\Container; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; -use Thelia\Constraint\ConditionValidator; use Thelia\Core\HttpFoundation\Request; -use Thelia\Core\Security\SecurityContext; use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; use Thelia\Cart\CartTrait; use Thelia\Model\Currency; use Thelia\Model\CurrencyQuery; -use Thelia\Model\LangQuery; /** * Created by JetBrains PhpStorm. @@ -266,7 +263,7 @@ class BaseAdapter implements AdapterInterface * * @return ConditionValidator */ - public function getConditionValidator() + public function getConditionEvaluator() { return $this->container->get('thelia.condition.validator'); } diff --git a/core/lib/Thelia/Coupon/CouponFactory.php b/core/lib/Thelia/Coupon/CouponFactory.php index 64c0058b4..e5752a762 100644 --- a/core/lib/Thelia/Coupon/CouponFactory.php +++ b/core/lib/Thelia/Coupon/CouponFactory.php @@ -25,13 +25,11 @@ namespace Thelia\Coupon; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\Exception\NotFoundResourceException; -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\CouponRuleInterface; +use Thelia\Condition\ConditionFactory; use Thelia\Coupon\Type\CouponInterface; use Thelia\Exception\CouponExpiredException; -use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidConditionException; use Thelia\Model\Coupon; -use Symfony\Component\Serializer\Encoder\JsonEncoder; /** * Created by JetBrains PhpStorm. @@ -57,7 +55,7 @@ class CouponFactory * * @param ContainerInterface $container Service container */ - function __construct(ContainerInterface $container) + public function __construct(ContainerInterface $container) { $this->container = $container; $this->adapter = $container->get('thelia.adapter'); @@ -69,6 +67,7 @@ class CouponFactory * @param string $couponCode Coupon code ex: XMAS * * @throws \Thelia\Exception\CouponExpiredException + * @throws \Thelia\Exception\InvalidConditionException * @throws \Symfony\Component\Translation\Exception\NotFoundResourceException * @return CouponInterface ready to be processed */ @@ -87,9 +86,9 @@ class CouponFactory } /** @var CouponInterface $couponInterface */ - $couponInterface = $this->buildCouponInterfacFromModel($couponModel); - if ($couponInterface->getRules()->isEmpty()) { - throw new InvalidRuleException( + $couponInterface = $this->buildCouponInterfaceFromModel($couponModel); + if ($couponInterface->getConditions()->isEmpty()) { + throw new InvalidConditionException( get_class($couponInterface) ); } @@ -104,7 +103,7 @@ class CouponFactory * * @return CouponInterface ready to use CouponInterface object instance */ - protected function buildCouponInterfacFromModel(Coupon $model) + protected function buildCouponInterfaceFromModel(Coupon $model) { $isCumulative = ($model->getIsCumulative() == 1 ? true : false); $isRemovingPostage = ($model->getIsRemovingPostage() == 1 ? true : false); @@ -130,13 +129,13 @@ class CouponFactory $model->getExpirationDate() ); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $this->container->get('thelia.condition.factory'); - $rules = $constraintFactory->unserializeCouponRuleCollection( + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $this->container->get('thelia.condition.factory'); + $conditions = $conditionFactory->unserializeConditionCollection( $model->getSerializedRules() ); - $couponManager->setRules($rules); + $couponManager->setConditions($conditions); return $couponManager; } diff --git a/core/lib/Thelia/Coupon/RuleOrganizer.php b/core/lib/Thelia/Coupon/RuleOrganizer.php index 4c95fb7c4..ee840bfbc 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizer.php +++ b/core/lib/Thelia/Coupon/RuleOrganizer.php @@ -30,7 +30,7 @@ namespace Thelia\Coupon; * * Manage how Coupons could interact with a Checkout * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ @@ -39,11 +39,11 @@ class RuleOrganizer implements RuleOrganizerInterface /** * Organize ConditionManagerInterface * - * @param array $rules Array of ConditionManagerInterface + * @param array $conditions Array of ConditionManagerInterface * * @return array Array of ConditionManagerInterface sorted */ - public function organize(array $rules) + public function organize(array $conditions) { // TODO: Implement organize() method. } diff --git a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php index 37a3334f3..93dd12ee9 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php +++ b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php @@ -28,9 +28,9 @@ namespace Thelia\Coupon; * Date: 8/19/13 * Time: 3:24 PM * - * Manage how Coupons could interact with a Checkout + * Manage how Condition could interact with a Checkout * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ @@ -39,9 +39,9 @@ interface RuleOrganizerInterface /** * Organize ConditionManagerInterface * - * @param array $rules Array of ConditionManagerInterface + * @param array $conditions Array of ConditionManagerInterface * * @return array Array of ConditionManagerInterface sorted */ - public function organize(array $rules); + public function organize(array $conditions); } \ No newline at end of file diff --git a/core/lib/Thelia/Coupon/Type/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php index ef5e17a27..f3aa392bc 100644 --- a/core/lib/Thelia/Coupon/Type/CouponAbstract.php +++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php @@ -24,13 +24,12 @@ namespace Thelia\Coupon\Type; use Symfony\Component\Intl\Exception\NotImplementedException; -use Thelia\Constraint\ConstraintManager; -use Thelia\Constraint\ConditionValidator; +use Thelia\Condition\ConditionEvaluator; use Thelia\Core\Translation\Translator; use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\RuleOrganizerInterface; -use Thelia\Exception\InvalidRuleException; +use Thelia\Exception\InvalidConditionException; /** * Created by JetBrains PhpStorm. @@ -55,11 +54,10 @@ abstract class CouponAbstract implements CouponInterface protected $organizer = null; /** @var ConditionCollection Array of ConditionManagerInterface */ - protected $rules = null; - - /** @var ConditionValidator Constraint validator */ - protected $constraintValidator = null; + protected $conditions = null; + /** @var ConditionEvaluator Condition validator */ + protected $conditionEvaluator = null; /** @var string Service Id */ @@ -108,17 +106,17 @@ abstract class CouponAbstract implements CouponInterface * * @param AdapterInterface $adapter Service adapter */ - function __construct(AdapterInterface $adapter) + public function __construct(AdapterInterface $adapter) { $this->adapter = $adapter; $this->translator = $adapter->getTranslator(); - $this->constraintValidator = $adapter->getConditionValidator(); + $this->conditionEvaluator = $adapter->getConditionEvaluator(); } /** - * Set Rule Organizer + * Set Condition Organizer * - * @param RuleOrganizerInterface $organizer Manage Rule groups (&& and ||) + * @param RuleOrganizerInterface $organizer Manage Condition groups (&& and ||) * * @return $this */ @@ -207,23 +205,23 @@ abstract class CouponAbstract implements CouponInterface * * @return ConditionCollection */ - public function getRules() + public function getConditions() { - return clone $this->rules; + return clone $this->conditions; } /** - * Replace the existing Rules by those given in parameter - * If one Rule is badly implemented, no Rule will be added + * Replace the existing Conditions by those given in parameter + * If one Condition is badly implemented, no Condition will be added * - * @param ConditionCollection $rules ConditionManagerInterface to add + * @param ConditionCollection $conditions ConditionManagerInterface to add * * @return $this - * @throws \Thelia\Exception\InvalidRuleException + * @throws \Thelia\Exception\InvalidConditionException */ - public function setRules(ConditionCollection $rules) + public function setConditions(ConditionCollection $conditions) { - $this->rules = $rules; + $this->conditions = $conditions; return $this; } @@ -249,7 +247,6 @@ abstract class CouponAbstract implements CouponInterface return $this->isAvailableOnSpecialOffers; } - /** * Check if Coupon has been disabled by admin * @@ -300,14 +297,14 @@ abstract class CouponAbstract implements CouponInterface /** - * Check if the current Coupon is matching its conditions (Rules) + * Check if the current state of the application is matching this Coupon conditions * Thelia variables are given by the AdapterInterface * * @return bool */ public function isMatching() { - return $this->constraintValidator->isMatching($this->rules); + return $this->conditionEvaluator->isMatching($this->conditions); } diff --git a/core/lib/Thelia/Coupon/Type/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php index d8ef41f43..192a608e8 100644 --- a/core/lib/Thelia/Coupon/Type/CouponInterface.php +++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php @@ -142,7 +142,7 @@ interface CouponInterface * * @return ConditionCollection A set of ConditionManagerInterface */ - public function getRules(); + public function getConditions(); /** * Replace the existing Rules by those given in parameter @@ -151,9 +151,9 @@ interface CouponInterface * @param ConditionCollection $rules ConditionManagerInterface to add * * @return $this - * @throws \Thelia\Exception\InvalidRuleException + * @throws \Thelia\Exception\InvalidConditionException */ - public function setRules(ConditionCollection $rules); + public function setConditions(ConditionCollection $rules); /** * Return Coupon expiration date diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php b/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php index eb5dc4548..1f9e12420 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXAmountManager.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon\Type; -use Thelia\Constraint\ConstraintManager; use Thelia\Coupon\Type\CouponAbstract; /** diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php index be6b65aea..d5c45b4d3 100644 --- a/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php +++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentManager.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon\Type; -use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\Type\CouponAbstract; use Thelia\Exception\MissingAdapterException; diff --git a/core/lib/Thelia/Exception/InvalidRuleException.php b/core/lib/Thelia/Exception/InvalidConditionException.php similarity index 88% rename from core/lib/Thelia/Exception/InvalidRuleException.php rename to core/lib/Thelia/Exception/InvalidConditionException.php index f2eb48a84..dbc3315c8 100644 --- a/core/lib/Thelia/Exception/InvalidRuleException.php +++ b/core/lib/Thelia/Exception/InvalidConditionException.php @@ -30,23 +30,23 @@ use Thelia\Log\Tlog; * Date: 8/19/13 * Time: 3:24 PM * - * Thrown when a Rule is badly implemented + * Thrown when a Condition is badly implemented * - * @package Coupon + * @package Condition * @author Guillaume MOREL * */ -class InvalidRuleException extends \RuntimeException +class InvalidConditionException extends \RuntimeException { /** - * InvalidConditionOperatorException thrown when a Rule is badly implemented + * InvalidConditionOperatorException thrown when a Condition is badly implemented * * @param string $className Class name */ public function __construct($className) { - $message = 'Invalid Rule given to ' . $className; + $message = 'Invalid Condition given to ' . $className; Tlog::getInstance()->addError($message); parent::__construct($message); diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php new file mode 100644 index 000000000..8efc4d38f --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php @@ -0,0 +1,227 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Symfony\Component\DependencyInjection\ContainerBuilder; +use Thelia\Condition\ConditionFactory; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test ConditionFactory Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class ConditionFactoryTest extends \PHPUnit_Framework_TestCase +{ + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + public function setUp() + { + } + + /** + * Check the Rules serialization module + */ + public function testBuild() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $conditionFactory = new ConditionFactory($this->getContainer()); + $ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values); + + $expected = $condition1; + $actual = $ruleManager1; + + $this->assertEquals($expected, $actual); + $this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId()); + $this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators()); + } + +// /** +// * Check the Rules serialization module +// */ +// public function testBuildFail() +// { +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 40.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition1->setValidatorsFromForm($operators, $values); +// +// $conditionFactory = new ConditionFactory($this->getContainer()); +// $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values); +// +// $expected = false; +// $actual = $conditionManager1; +// +// $this->assertEquals($expected, $actual); +// } +// +// /** +// * Check the Rules serialization module +// */ +// public function testRuleSerialisation() +// { +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 40.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition1->setValidatorsFromForm($operators, $values); +// +// $condition2 = new MatchForTotalAmountManager($stubAdapter); +// $operators = array( +// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, +// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL +// ); +// $values = array( +// MatchForTotalAmountManager::INPUT1 => 400.00, +// MatchForTotalAmountManager::INPUT2 => 'EUR' +// ); +// $condition2->setValidatorsFromForm($operators, $values); +// +// $conditions = new ConditionCollection(); +// $conditions->add($condition1); +// $conditions->add($condition2); +// +// $conditionFactory = new ConditionFactory($this->getContainer()); +// +// $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); +// $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions); +// +// $expected = (string) $conditions; +// $actual = (string) $unserializedConditions; +// +// $this->assertEquals($expected, $actual); +// } +// +// /** +// * Get Mocked Container with 2 Rules +// * +// * @return ContainerBuilder +// */ +// public function getContainer() +// { +// $container = new ContainerBuilder(); +// +// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') +// ->disableOriginalConstructor() +// ->getMock(); +// +// /** @var AdapterInterface $stubAdapter */ +// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') +// ->disableOriginalConstructor() +// ->getMock(); +// +// $stubAdapter->expects($this->any()) +// ->method('getTranslator') +// ->will($this->returnValue($stubTranslator)); +// +// $condition1 = new MatchForTotalAmountManager($stubAdapter); +// $condition2 = new MatchForXArticlesManager($stubAdapter); +// +// $adapter = new BaseAdapter($container); +// +// $container->set('thelia.condition.match_for_total_amount', $condition1); +// $container->set('thelia.condition.match_for_x_articles', $condition2); +// $container->set('thelia.adapter', $adapter); +// +// return $container; +// } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } +} diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php b/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php similarity index 53% rename from core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php rename to core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php index e3e83eb2b..5d7ae29d7 100644 --- a/core/lib/Thelia/Tests/Constraint/ConstraintValidatorTest.php +++ b/core/lib/Thelia/Tests/Condition/ConstraintValidatorTest.php @@ -21,12 +21,12 @@ /* */ /**********************************************************************************/ -namespace Thelia\Constraint; +namespace Thelia\Condition\Implementation; use Symfony\Component\DependencyInjection\ContainerBuilder; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; use Thelia\Coupon\BaseAdapter; use Thelia\Coupon\ConditionCollection; @@ -41,7 +41,7 @@ use Thelia\Coupon\ConditionCollection; * @author Guillaume MOREL * */ -class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase +class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase { /** @@ -54,8 +54,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestSuccess1Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -66,23 +68,23 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; $actual =$isValid; @@ -91,8 +93,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail1Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -103,33 +107,35 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getCheckoutCurrency') ->will($this->returnValue('EUR')); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; $actual =$isValid; - $this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules'); + $this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions'); } public function testTestSuccess2Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -143,33 +149,33 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(5)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => '>' + MatchForXArticlesManager::INPUT1 => '>' ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = true; $actual =$isValid; @@ -178,8 +184,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase public function testTestFail2Rules() { - $ConstraintValidator = new ConditionValidator(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + $conditionEvaluator = new ConditionEvaluator(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -193,101 +201,101 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(5)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue($ConstraintValidator)); + ->method('getConditionEvaluator') + ->will($this->returnValue($conditionEvaluator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => '>', - AvailableForTotalAmountManager::INPUT2 => '==' + MatchForTotalAmountManager::INPUT1 => '>', + MatchForTotalAmountManager::INPUT2 => '==' ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => '>' + MatchForXArticlesManager::INPUT1 => '>' ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); - $isValid = $ConstraintValidator->isMatching($rules); + $isValid = $conditionEvaluator->isMatching($conditions); $expected = false; $actual =$isValid; - $this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules'); + $this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions'); } public function testVariableOpComparisonSuccess() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = true; - $actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::DIFFERENT, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR, 0); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::IN, array(1, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3)); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(1, Operators::OUT, array(0, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3)); $this->assertEquals($expected, $actual); } public function testVariableOpComparisonFail() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = false; - $actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::DIFFERENT, 2); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(0, Operators::SUPERIOR, 0); + $actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(3, Operators::INFERIOR, 2); + $actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4); + $actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(0, Operators::IN, array(1, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3)); $this->assertEquals($expected, $actual); - $actual = $ConstraintValidator->variableOpComparison(2, Operators::OUT, array(0, 2, 3)); + $actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3)); $this->assertEquals($expected, $actual); } @@ -297,9 +305,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase */ public function testVariableOpComparisonException() { - $ConstraintValidator = new ConditionValidator(); + $conditionEvaluator = new ConditionEvaluator(); $expected = true; - $actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1); + $actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1); $this->assertEquals($expected, $actual); } @@ -316,7 +324,8 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->disableOriginalConstructor() ->getMock(); - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -324,13 +333,13 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase ->method('getTranslator') ->will($this->returnValue($stubTranslator)); - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $rule2 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $condition2 = new MatchForXArticlesManager($stubAdapter); $adapter = new BaseAdapter($container); - $container->set('thelia.condition.match_for_total_amount', $rule1); - $container->set('thelia.condition.match_for_x_articles', $rule2); + $container->set('thelia.condition.match_for_total_amount', $condition1); + $container->set('thelia.condition.match_for_x_articles', $condition2); $container->set('thelia.adapter', $adapter); return $container; diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php new file mode 100644 index 000000000..cc142ac38 --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php @@ -0,0 +1,610 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; +use Thelia\Exception\InvalidConditionValueException; +use Thelia\Model\Currency; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test MatchForTotalAmountManager Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase +{ + /** @var AdapterInterface $stubTheliaAdapter */ + protected $stubTheliaAdapter = null; + + /** + * Generate adapter stub + * + * @param int $cartTotalPrice Cart total price + * @param string $checkoutCurrency Checkout currency + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue($cartTotalPrice)); + + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue($checkoutCurrency)); + + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currency1 = new Currency(); + $currency1->setCode('EUR'); + $currency2 = new Currency(); + $currency2->setCode('USD'); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue(array($currency1, $currency2))); + + return $stubAdapter; + } + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionOperatorException + * + */ + public function testInValidBackOfficeInputOperator() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::IN, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => '400', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionOperatorException + * + */ + public function testInValidBackOfficeInputOperator2() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::INFERIOR + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => '400', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionValueException + * + */ + public function testInValidBackOfficeInputValue() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 'X', + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators + * @expectedException \Thelia\Exception\InvalidConditionValueException + * + */ + public function testInValidBackOfficeInputValue2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400, + MatchForTotalAmountManager::INPUT2 => 'FLA'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionInferior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionInferiorEquals2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test inferior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionInferiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test equals operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionEqual() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test equals operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionEqual() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperiorEquals2() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionSuperiorEquals() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionSuperior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(401, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check if test superior operator is working + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionSuperior() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check currency is checked + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testMatchingConditionCurrency() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Check currency is checked + * + * @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching + * + */ + public function testNotMatchingConditionCurrency() + { + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->generateAdapterStub(400.00, 'EUR'); + + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'USD'); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = false; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php similarity index 54% rename from core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php index 468a813c2..4243b1082 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php @@ -21,12 +21,12 @@ /* */ /**********************************************************************************/ -namespace Thelia\Coupon; +namespace Thelia\Condition\Implementation; -use Thelia\Constraint\ConditionValidator; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Constraint\Rule\SerializableRule; +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Condition\SerializableCondition; +use Thelia\Coupon\AdapterInterface; /** * Created by JetBrains PhpStorm. @@ -39,12 +39,9 @@ use Thelia\Constraint\Rule\SerializableRule; * @author Guillaume MOREL * */ -class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase +class MatchForXArticlesManagerTest extends \PHPUnit_Framework_TestCase { -// /** @var AdapterInterface $stubTheliaAdapter */ -// protected $stubTheliaAdapter = null; - /** * Sets up the fixture, for example, opens a network connection. * This method is called before a test is executed. @@ -57,32 +54,34 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidConditionOperatorException */ public function testInValidBackOfficeInputOperator() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); + /** @var AdapterInterface $stubAdapter */ $stubAdapter->expects($this->any()) ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::IN + MatchForXArticlesManager::INPUT1 => Operators::IN ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -92,12 +91,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if validity test on BackOffice inputs are working * - * @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators * @expectedException \Thelia\Exception\InvalidConditionValueException */ public function testInValidBackOfficeInputValue() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -105,19 +105,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 'X' + MatchForXArticlesManager::INPUT1 => 'X' ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -127,12 +127,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -140,19 +141,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -162,12 +163,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleInferior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -175,19 +177,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4, + MatchForXArticlesManager::INPUT1 => 4, ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -197,12 +199,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -210,19 +213,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5, + MatchForXArticlesManager::INPUT1 => 5, ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -232,12 +235,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleInferiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -245,19 +249,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -267,12 +271,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test inferior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleInferiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -280,19 +285,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -302,12 +307,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test equals operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -315,19 +321,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::EQUAL + MatchForXArticlesManager::INPUT1 => Operators::EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -337,12 +343,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test equals operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleEqual() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -350,19 +357,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::EQUAL + MatchForXArticlesManager::INPUT1 => Operators::EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -372,12 +379,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -385,19 +393,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -407,12 +415,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperiorEquals2() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -420,19 +429,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -442,12 +451,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleSuperiorEquals() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -455,19 +465,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL ); $values = array( - AvailableForXArticlesManager::INPUT1 => 5 + MatchForXArticlesManager::INPUT1 => 5 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -477,12 +487,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -490,19 +501,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 3 + MatchForXArticlesManager::INPUT1 => 3 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = true; $actual =$isValid; @@ -512,12 +523,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase /** * Check if test superior operator is working * - * @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching + * @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching * */ public function testNotMatchingRuleSuperior() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -525,19 +537,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $isValid = $rule1->isMatching(); + $isValid = $condition1->isMatching(); $expected = false; $actual =$isValid; @@ -546,7 +558,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase public function testGetSerializableRule() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -554,22 +567,22 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $serializableRule = $rule1->getSerializableRule(); + $serializableRule = $condition1->getSerializableCondition(); - $expected = new SerializableRule(); - $expected->ruleServiceId = $rule1->getServiceId(); + $expected = new SerializableCondition(); + $expected->conditionServiceId = $condition1->getServiceId(); $expected->operators = $operators; $expected->values = $values; @@ -581,7 +594,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase public function testGetAvailableOperators() { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') ->disableOriginalConstructor() ->getMock(); @@ -589,20 +603,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase ->method('getNbArticlesInCart') ->will($this->returnValue(4)); $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); - $rule1 = new AvailableForXArticlesManager($stubAdapter); + $condition1 = new MatchForXArticlesManager($stubAdapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4 + MatchForXArticlesManager::INPUT1 => 4 ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); $expected = array( - AvailableForXArticlesManager::INPUT1 => array( + MatchForXArticlesManager::INPUT1 => array( Operators::INFERIOR, Operators::INFERIOR_OR_EQUAL, Operators::EQUAL, @@ -610,7 +624,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase Operators::SUPERIOR ) ); - $actual = $rule1->getAvailableOperators(); + $actual = $condition1->getAvailableOperators(); $this->assertEquals($expected, $actual); @@ -626,20 +640,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase // ->method('getNbArticlesInCart') // ->will($this->returnValue(4)); // -// $rule1 = new MatchForXArticlesManager($stubAdapter); +// $condition1 = new MatchForXArticlesManager($stubAdapter); // $operators = array( // MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR // ); // $values = array( // MatchForXArticlesManager::INPUT1 => 4 // ); -// $rule1->setValidatorsFromForm($operators, $values); +// $condition1->setValidatorsFromForm($operators, $values); // // $expected = array( // $operators, // $values // ); -// $actual = $rule1->getValidators(); +// $actual = $condition1->getValidators(); // // $this->assertEquals($expected, $actual); // diff --git a/core/lib/Thelia/Tests/Condition/OperatorsTest.php b/core/lib/Thelia/Tests/Condition/OperatorsTest.php new file mode 100644 index 000000000..667714189 --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/OperatorsTest.php @@ -0,0 +1,114 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition; + +use Thelia\Core\Translation\Translator; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test Operators Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class OperatorsTest 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() + { + } + + public function testOperatorI18n() + { + /** @var Translator $stubTranslator */ + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnCallback((array($this, 'callbackI18n')))); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); + $expected = 'inferior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); + $expected = 'inferior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::EQUAL); + $expected = 'equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL); + $expected = 'superior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); + $expected = 'superior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); + $expected = 'different from'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::IN); + $expected = 'in'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::OUT); + $expected = 'not in'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, 'unexpected operator'); + $expected = 'unexpected operator'; + $this->assertEquals($expected, $actual); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + + function callbackI18n() + { + $args = func_get_args(); + + return $args[0]; + } +} + + diff --git a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php deleted file mode 100644 index f7f2b131a..000000000 --- a/core/lib/Thelia/Tests/Constraint/ConstraintFactoryTest.php +++ /dev/null @@ -1,228 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Constraint; - -use Symfony\Component\DependencyInjection\ContainerBuilder; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\BaseAdapter; -use Thelia\Coupon\ConditionCollection; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test ConstraintManager Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase -{ - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - public function setUp() - { - } - - /** - * Check the Rules serialization module - */ - public function testBuild() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - $ruleManager1 = $constraintFactory->build($rule1->getServiceId(), $operators, $values); - - $expected = $rule1; - $actual = $ruleManager1; - - $this->assertEquals($expected, $actual); - $this->assertEquals($rule1->getServiceId(), $ruleManager1->getServiceId()); - $this->assertEquals($rule1->getValidators(), $ruleManager1->getValidators()); - } - - /** - * Check the Rules serialization module - */ - public function testBuildFail() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - $ruleManager1 = $constraintFactory->build('unset.service', $operators, $values); - - $expected = false; - $actual = $ruleManager1; - - $this->assertEquals($expected, $actual); - } - - /** - * Check the Rules serialization module - */ - public function testRuleSerialisation() - { - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule1->setValidatorsFromForm($operators, $values); - - $rule2 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' - ); - $rule2->setValidatorsFromForm($operators, $values); - - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); - - /** @var ConstraintManager $constraintManager */ - $constraintFactory = new ConstraintFactory($this->getContainer()); - - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $unserializedRules = $constraintFactory->unserializeCouponRuleCollection($serializedRules); - - $expected = (string) $rules; - $actual = (string) $unserializedRules; - - $this->assertEquals($expected, $actual); - } - - /** - * Get Mocked Container with 2 Rules - * - * @return ContainerBuilder - */ - public function getContainer() - { - $container = new ContainerBuilder(); - - $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getTranslator') - ->will($this->returnValue($stubTranslator)); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $rule2 = new AvailableForXArticlesManager($stubAdapter); - - $adapter = new BaseAdapter($container); - - $container->set('thelia.condition.match_for_total_amount', $rule1); - $container->set('thelia.condition.match_for_x_articles', $rule2); - $container->set('thelia.adapter', $adapter); - - return $container; - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } -} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php deleted file mode 100644 index 53cf39a9b..000000000 --- a/core/lib/Thelia/Tests/Constraint/Rule/AvailableForTotalAmountManagerTest.php +++ /dev/null @@ -1,592 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\ConditionValidator; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Exception\InvalidConditionValueException; -use Thelia\Model\Currency; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test MatchForTotalAmountManager Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase -{ - /** @var AdapterInterface $stubTheliaAdapter */ - protected $stubTheliaAdapter = null; - - /** - * Generate adapter stub - * - * @param int $cartTotalPrice Cart total price - * @param string $checkoutCurrency Checkout currency - * - * @return \PHPUnit_Framework_MockObject_MockObject - */ - public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') - { - $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter') - ->disableOriginalConstructor() - ->getMock(); - - $stubAdapter->expects($this->any()) - ->method('getCartTotalPrice') - ->will($this->returnValue($cartTotalPrice)); - - $stubAdapter->expects($this->any()) - ->method('getCheckoutCurrency') - ->will($this->returnValue($checkoutCurrency)); - - $stubAdapter->expects($this->any()) - ->method('getConstraintValidator') - ->will($this->returnValue(new ConditionValidator())); - - $currency1 = new Currency(); - $currency1->setCode('EUR'); - $currency2 = new Currency(); - $currency2->setCode('USD'); - $stubAdapter->expects($this->any()) - ->method('getAvailableCurrencies') - ->will($this->returnValue(array($currency1, $currency2))); - - return $stubAdapter; - } - - /** - * Sets up the fixture, for example, opens a network connection. - * This method is called before a test is executed. - */ - protected function setUp() - { - - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionOperatorException - * - */ - public function testInValidBackOfficeInputOperator() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::IN, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => '400', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionOperatorException - * - */ - public function testInValidBackOfficeInputOperator2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::INFERIOR - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => '400', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionValueException - * - */ - public function testInValidBackOfficeInputValue() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 'X', - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if validity test on BackOffice inputs are working - * - * @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators - * @expectedException \Thelia\Exception\InvalidConditionValueException - * - */ - public function testInValidBackOfficeInputValue2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400, - AvailableForTotalAmountManager::INPUT2 => 'FLA'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferior() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleInferior() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferiorEquals() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleInferiorEquals2() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test inferior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleInferiorEquals() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test equals operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleEqual() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test equals operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleEqual() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperiorEquals() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperiorEquals2() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleSuperiorEquals() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleSuperior() - { - $stubAdapter = $this->generateAdapterStub(401, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check if test superior operator is working - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleSuperior() - { - $stubAdapter = $this->generateAdapterStub(399, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check currency is checked - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testMatchingRuleCurrency() - { - $stubAdapter = $this->generateAdapterStub(400, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = true; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Check currency is checked - * - * @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching - * - */ - public function testNotMatchingRuleCurrency() - { - $stubAdapter = $this->generateAdapterStub(400.00, 'EUR'); - - $rule1 = new AvailableForTotalAmountManager($stubAdapter); - $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL - ); - $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'USD'); - $rule1->setValidatorsFromForm($operators, $values); - - $isValid = $rule1->isMatching(); - - $expected = false; - $actual =$isValid; - $this->assertEquals($expected, $actual); - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php deleted file mode 100644 index ef9340dac..000000000 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ /dev/null @@ -1,481 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\Rule\Operators; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test Operators Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class OperatorsTest 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() - { - } - -// public function testSomething() -// { -// // Stop here and mark this test as incomplete. -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } - - public function testOperatorI18n() - { - $stubTranslator = $this->getMockBuilder('\Symfony\Component\Translation\Translator') - ->disableOriginalConstructor() - ->getMock(); - - $stubTranslator->expects($this->any()) - ->method('trans') - ->will($this->returnCallback((array($this, 'callbackI18n')))); - - $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); - $expected = 'inferior to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); - $expected = 'inferior or equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::EQUAL); - $expected = 'equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL); - $expected = 'superior or equal to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); - $expected = 'superior to'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); - $expected = 'different from'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::IN); - $expected = 'in'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, Operators::OUT); - $expected = 'not in'; - $this->assertEquals($expected, $actual); - - $actual = Operators::getI18n($stubTranslator, 'unexpected operator'); - $expected = 'unexpected operator'; - $this->assertEquals($expected, $actual); - } - - -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorValidBefore() -// { -// $adapter = new BaseAdapter(); -// // Given -// $a = 11; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorInvalidEquals() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorInvalidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::INFERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualValidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 10; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInferiorOrEqualInValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::INFERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualInValidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorEqualInValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::EQUAL; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualValidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 14; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorOrEqualInvalidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::SUPERIOR_OR_EQUAL; -// $b = new QuantityParam($adapter, 13); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorValidAfter() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 13; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorInvalidEqual() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorSuperiorInvalidBefore() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::SUPERIOR; -// $b = new QuantityParam($adapter, 12); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorDifferentValid() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = Operators::DIFFERENT; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertTrue($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorDifferentInvalidEquals() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 11; -// $operator = Operators::DIFFERENT; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator -// * -// */ -// public function testOperatorInValid() -// { -// // Given -// $adapter = new BaseAdapter(); -// $a = 12; -// $operator = 'X'; -// $b = new QuantityParam($adapter, 11); -// -// // When -// $actual = Operators::isValid($a, $operator, $b); -// -// // Then -// $this->assertFalse($actual); -// } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - } - - function callbackI18n() { - $args = func_get_args(); - - return $args[0]; - } -} - - diff --git a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php deleted file mode 100644 index d78faacd0..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php +++ /dev/null @@ -1,168 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\CustomerParam; -use Thelia\Constraint\Validator\QuantityParam; -use Thelia\Model\Customer; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test CustomerParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class CustomerParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** @var AdapterInterface $stubTheliaAdapter */ -// protected $stubTheliaAdapter = null; -// -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// /** @var AdapterInterface $stubTheliaAdapter */ -// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); -// } -// -// /** -// * Generate valid BaseAdapter -// * -// * @param int $customerId Customer id -// * -// * @return AdapterInterface -// */ -// protected function generateValidCouponBaseAdapterMock($customerId = 4521) -// { -// $customer = new Customer(); -// $customer->setId($customerId); -// $customer->setFirstname('Firstname'); -// $customer->setLastname('Lastname'); -// $customer->setEmail('em@il.com'); -// -// /** @var AdapterInterface $stubTheliaAdapter */ -// $stubTheliaAdapter = $this->getMock( -// 'Thelia\Coupon\BaseAdapter', -// array('getCustomer'), -// array() -// ); -// $stubTheliaAdapter->expects($this->any()) -// ->method('getCustomer') -// ->will($this->returnValue($customer)); -// -// return $stubTheliaAdapter; -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testCanUseCoupon() -// { -// $customerId = 4521; -// $couponValidForCustomerId = 4521; -// -// $adapter = $this->generateValidCouponBaseAdapterMock($customerId); -// -// $customerParam = new CustomerParam($adapter, $couponValidForCustomerId); -// -// $expected = 0; -// $actual = $customerParam->compareTo($customerId); -// $this->assertEquals($expected, $actual); -// } -// -//// /** -//// * -//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -//// * -//// */ -//// public function testCanNotUseCouponTest() -//// { -//// -//// } -//// -//// /** -//// * -//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -//// * @expectedException InvalidArgumentException -//// * -//// */ -//// public function testCanNotUseCouponCustomerNotFoundTest() -//// { -//// -//// } -// -// -// -// -//// /** -//// * Test is the object is serializable -//// * If no data is lost during the process -//// */ -//// public function isSerializableTest() -//// { -//// $adapter = new BaseAdapter(); -//// $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 QuantityParam($adapter, $unserialized->getInteger()); -//// $this->assertEquals($param->getInteger(), $new->getInteger()); -//// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php deleted file mode 100644 index 9fa382317..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/DateParamTest.php +++ /dev/null @@ -1,158 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\DateParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test DateParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class DateParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = 1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testEqualsDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * -// */ -// public function testSuperiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-09"); -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $expected = -1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $dateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// -// $dateParam = new DateParam($adapter, $dateValidator); -// -// $dateParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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()); -// } -// -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php deleted file mode 100644 index 3761a2a11..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntegerParamTest.php +++ /dev/null @@ -1,159 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\IntegerParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test IntegerParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntegerParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testInferiorInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 41; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testEqualsInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 42; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * -// */ -// public function testSuperiorInteger() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 43; -// -// $integerParam = new IntegerParam($adapter, $intValidator); -// -// $expected = -1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = '42'; -// -// $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 -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php deleted file mode 100644 index ce59875cc..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/IntervalParamTest.php +++ /dev/null @@ -1,184 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\IntervalParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test IntervalParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class IntervalParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testEqualsDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-07-08"); -// -// 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($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testEqualsDate2() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = 0; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo -// * -// */ -// public function testSuperiorDate() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = new \DateTime("2012-08-09"); -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $expected = -1; -// $actual = $dateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $dateValidatorStart = new \DateTime("2012-07-08"); -// $dateValidatorInterval = new \DateInterval("P1M"); //1month -// $dateToValidate = 1377012588; -// -// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval); -// -// $dateParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php deleted file mode 100644 index 892800f50..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/PriceParamTest.php +++ /dev/null @@ -1,237 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\PriceParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test PriceParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class PriceParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testInferiorPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 1.00; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testInferiorPrice2() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.49; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testEqualsPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.50; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * -// */ -// public function testSuperiorPrice() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 42.51; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = -1; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = '42.50'; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException2() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = -1; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException3() -// { -// $adapter = new BaseAdapter(); -// -// $priceValidator = 42.50; -// $priceToValidate = 0; -// -// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR'); -// -// $expected = 0; -// $actual = $integerParam->compareTo($priceToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException4() -// { -// $adapter = new BaseAdapter(); -// $priceValidator = 42.50; -// $priceToValidate = 1; -// -// $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 -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php deleted file mode 100644 index 4c2155ee8..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/QuantityParamTest.php +++ /dev/null @@ -1,195 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\QuantityParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test QuantityParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class QuantityParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testInferiorQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 0; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testInferiorQuantity2() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 41; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testEqualsQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 42; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * -// */ -// public function testSuperiorQuantity() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = 43; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = -1; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = '42'; -// -// $integerParam = new QuantityParam($adapter, $intValidator); -// -// $expected = 0; -// $actual = $integerParam->compareTo($intToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException2() -// { -// $adapter = new BaseAdapter(); -// $intValidator = 42; -// $intToValidate = -1; -// -// $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 -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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 QuantityParam($adapter, $unserialized->getInteger()); -// $this->assertEquals($param->getInteger(), $new->getInteger()); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php deleted file mode 100644 index 8e2d344b8..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedDateParamTest.php +++ /dev/null @@ -1,309 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use InvalidArgumentException; -use Thelia\Constraint\Validator\RepeatedDateParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RepeatedDateParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 1); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-09-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 10); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-05-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(1, 10); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-11-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-03-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = 0; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-12-08"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo -// * -// */ -// public function testSuperiorDateRepeatEveryFourMonthTwoTimes() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2013-03-09"); -// -// $repeatedDateParam = new RepeatedDateParam($adapter); -// $repeatedDateParam->setFrom($startDateValidator); -// $repeatedDateParam->repeatEveryMonth(4, 2); -// -// $expected = -1; -// $actual = $repeatedDateParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// -// $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 -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php deleted file mode 100644 index bf138da93..000000000 --- a/core/lib/Thelia/Tests/Constraint/Validator/RepeatedIntervalParamTest.php +++ /dev/null @@ -1,426 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -use Thelia\Constraint\Validator\RepeatedIntervalParam; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RepeatedIntervalParam Class - * - * @package Constraint - * @author Guillaume MOREL - * - */ -class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase -{ - - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testInferiorDate() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-07"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-07-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-08-08"); -// $dateToValidate = new \DateTime("2012-08-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-08"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-13"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-10-18"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = 0; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-07-19"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-08-01"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-10-08"); -// $dateToValidate = new \DateTime("2012-08-07"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// -// -// /** -// * -// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo -// * -// */ -// public function testSuperiorDateRepeatEveryMonthFourTime() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = new \DateTime("2012-10-19"); -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 0); -// -// $expected = -1; -// $actual = $RepeatedIntervalParam->compareTo($dateToValidate); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * @covers Thelia\Coupon\Parameter\DateParam::compareTo -// * @expectedException \InvalidArgumentException -// */ -// public function testInvalidArgumentException() -// { -// $adapter = new BaseAdapter(); -// $startDateValidator = new \DateTime("2012-07-08"); -// $dateToValidate = 1377012588; -// $duration = 10; -// -// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter); -// $RepeatedIntervalParam->setFrom($startDateValidator); -// $RepeatedIntervalParam->setDurationInDays($duration); -// $RepeatedIntervalParam->repeatEveryMonth(1, 4); -// -// $RepeatedIntervalParam->compareTo($dateToValidate); -// } -// -// /** -// * Test is the object is serializable -// * If no data is lost during the process -// */ -// public function isSerializableTest() -// { -// $adapter = new BaseAdapter(); -// $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. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index 3d609c497..6341a199e 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -161,7 +161,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase // * Test if an expired Coupon is build or not (equal) // * // * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // */ // public function testBuildCouponFromCodeWithoutRule() // { diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index f3a4ff620..de739bf90 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -197,7 +197,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase // * Test Coupon rule setter // * // * @covers Thelia\Coupon\type\RemoveXAmountManager::setRules -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // * // */ // public function testSetRulesInvalid() diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php deleted file mode 100644 index ac13d4ea0..000000000 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php +++ /dev/null @@ -1,70 +0,0 @@ -. */ -/* */ -/**********************************************************************************/ - -namespace Thelia\Coupon; - -/** - * Created by JetBrains PhpStorm. - * Date: 8/19/13 - * Time: 3:24 PM - * - * Unit Test RemoveXPercentForCategoryY Class - * - * @package Coupon - * @author Guillaume MOREL - * - */ -class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase -{ - public function testSomething() - { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); - } - -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// public function incompleteTest() -// { -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } - -} diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index 4d60604f5..b1b012fb3 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -169,7 +169,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase // * Test Coupon rule setter // * // * @covers Thelia\Coupon\type\RemoveXPercentManager::setRules -// * @expectedException \Thelia\Exception\InvalidRuleException +// * @expectedException \Thelia\Exception\InvalidConditionException // * // */ // public function testSetRulesInvalid() diff --git a/install/faker.php b/install/faker.php index 7e2b6e84d..68673394b 100755 --- a/install/faker.php +++ b/install/faker.php @@ -1,9 +1,11 @@ 20, 'Description' /** * Generate Coupon fixtures */ -function generateCouponFixtures($thelia) +function generateCouponFixtures(\Thelia\Core\Thelia $thelia) { + /** @var $container ContainerInterface Service Container */ $container = $thelia->getContainer(); + /** @var AdapterInterface $adapter */ $adapter = $container->get('thelia.adapter'); // Coupons @@ -663,36 +667,36 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon1->setExpirationDate($date->setTimestamp(strtotime("today + 3 months"))); - $rule1 = new AvailableForTotalAmountManager($adapter); + $condition1 = new MatchForTotalAmountManager($adapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 40.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' ); - $rule1->setValidatorsFromForm($operators, $values); + $condition1->setValidatorsFromForm($operators, $values); - $rule2 = new AvailableForTotalAmountManager($adapter); + $condition2 = new MatchForTotalAmountManager($adapter); $operators = array( - AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR, - AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL + MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL ); $values = array( - AvailableForTotalAmountManager::INPUT1 => 400.00, - AvailableForTotalAmountManager::INPUT2 => 'EUR' + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' ); - $rule2->setValidatorsFromForm($operators, $values); + $condition2->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); - $rules->add($rule2); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon1->setSerializedRules($serializedRules); + $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); + $coupon1->setSerializedRules($serializedConditions); $coupon1->setMaxUsage(40); $coupon1->setIsCumulative(1); $coupon1->setIsRemovingPostage(0); @@ -721,22 +725,22 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon2->setExpirationDate($date->setTimestamp(strtotime("today + 1 months"))); - $rule1 = new AvailableForXArticlesManager($adapter); + $condition1 = new MatchForXArticlesManager($adapter); $operators = array( - AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR, + MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR, ); $values = array( - AvailableForXArticlesManager::INPUT1 => 4, + MatchForXArticlesManager::INPUT1 => 4, ); - $rule1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $condition1->setValidatorsFromForm($operators, $values); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + /** @var ConditionFactory $conditionFactory */ + $conditionFactory = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon2->setSerializedRules($serializedRules); + $serializedConditions = $conditionFactory->serializeConditionCollection($conditions); + $coupon2->setSerializedRules($serializedConditions); $coupon2->setMaxUsage(-1); $coupon2->setIsCumulative(0); $coupon2->setIsRemovingPostage(1); @@ -765,18 +769,18 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $date = new \DateTime(); $coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months"))); - $rule1 = new MatchForEveryoneManager($adapter); + $condition1 = new MatchForEveryoneManager($adapter); $operators = array(); $values = array(); - $rule1->setValidatorsFromForm($operators, $values); - $rules = new ConditionCollection(); - $rules->add($rule1); + $condition1->setValidatorsFromForm($operators, $values); + $conditions = new ConditionCollection(); + $conditions->add($condition1); - /** @var ConstraintFactory $constraintFactory */ - $constraintFactory = $container->get('thelia.condition.factory'); + /** @var ConditionFactory $constraintCondition */ + $constraintCondition = $container->get('thelia.condition.factory'); - $serializedRules = $constraintFactory->serializeCouponRuleCollection($rules); - $coupon3->setSerializedRules($serializedRules); + $serializedConditions = $constraintCondition->serializeConditionCollection($conditions); + $coupon3->setSerializedRules($serializedConditions); $coupon3->setMaxUsage(-1); $coupon3->setIsCumulative(1); $coupon3->setIsRemovingPostage(0); diff --git a/install/import.php b/install/import.php index 47313df6e..d0910eede 100644 --- a/install/import.php +++ b/install/import.php @@ -21,11 +21,8 @@ /* */ /*************************************************************************************/ -use Thelia\Constraint\ConstraintFactory; -use Thelia\Constraint\Rule\AvailableForTotalAmountManager; -use Thelia\Constraint\Rule\AvailableForXArticlesManager; -use Thelia\Constraint\Rule\Operators; -use Thelia\Coupon\ConditionCollection; +use Thelia\Condition\Implementation\MatchForTotalAmountManager; +use Thelia\Condition\Implementation\MatchForXArticlesManager; require __DIR__ . '/../core/bootstrap.php'; diff --git a/install/tax_faker.php b/install/tax_faker.php index f967ca7a4..85e274c98 100755 --- a/install/tax_faker.php +++ b/install/tax_faker.php @@ -1,16 +1,6 @@