Merge branch 'master' into tax
Conflicts: local/config/schema.xml
This commit is contained in:
@@ -23,15 +23,16 @@
|
||||
|
||||
namespace Thelia\Action;
|
||||
|
||||
use Symfony\Component\Config\Definition\Exception\Exception;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Coupon\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon as CouponModel;
|
||||
|
||||
@@ -73,19 +74,19 @@ 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
|
||||
*/
|
||||
public function updateRule(CouponCreateOrUpdateEvent $event)
|
||||
public function updateCondition(CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon = $event->getCoupon();
|
||||
|
||||
$this->createOrUpdateRule($coupon, $event);
|
||||
$this->createOrUpdateCondition($coupon, $event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
@@ -137,11 +138,22 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
// Set default condition if none found
|
||||
/** @var ConditionManagerInterface $noConditionRule */
|
||||
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$couponRuleCollection = new ConditionCollection();
|
||||
$couponRuleCollection->add($noConditionRule);
|
||||
$defaultSerializedRule = $conditionFactory->serializeConditionCollection(
|
||||
$couponRuleCollection
|
||||
);
|
||||
|
||||
$coupon->createOrUpdate(
|
||||
$event->getCode(),
|
||||
$event->getTitle(),
|
||||
$event->getAmount(),
|
||||
$event->getEffect(),
|
||||
$event->getType(),
|
||||
$event->isRemovingPostage(),
|
||||
$event->getShortDescription(),
|
||||
$event->getDescription(),
|
||||
@@ -150,6 +162,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
$event->isAvailableOnSpecialOffers(),
|
||||
$event->isCumulative(),
|
||||
$event->getMaxUsage(),
|
||||
$defaultSerializedRule,
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
@@ -163,15 +176,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
* @param CouponModel $coupon Model to save
|
||||
* @param CouponCreateOrUpdateEvent $event Event containing data
|
||||
*/
|
||||
protected function createOrUpdateRule(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
protected function createOrUpdateCondition(CouponModel $coupon, CouponCreateOrUpdateEvent $event)
|
||||
{
|
||||
$coupon->setDispatcher($this->getDispatcher());
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
|
||||
$coupon->createOrUpdateRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($event->getRules()),
|
||||
$coupon->createOrUpdateConditions(
|
||||
$conditionFactory->serializeConditionCollection($event->getConditions()),
|
||||
$event->getLocale()
|
||||
);
|
||||
|
||||
@@ -204,7 +217,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
|
||||
TheliaEvents::COUPON_CREATE => array("create", 128),
|
||||
TheliaEvents::COUPON_UPDATE => array("update", 128),
|
||||
TheliaEvents::COUPON_CONSUME => array("consume", 128),
|
||||
TheliaEvents::COUPON_RULE_UPDATE => array("updateRule", 128)
|
||||
TheliaEvents::COUPON_CONDITION_UPDATE => array("updateCondition", 128)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,7 +241,7 @@ class Image extends BaseCachedFile implements EventSubscriberInterface
|
||||
// Compute the image URL
|
||||
$processed_image_url = $this->getCacheFileURL($subdir, basename($cacheFilePath));
|
||||
|
||||
// compute the full resulution image path in cache
|
||||
// compute the full resolution image path in cache
|
||||
$original_image_url = $this->getCacheFileURL($subdir, basename($originalImagePathInCache));
|
||||
|
||||
// Update the event with file path and file URL
|
||||
|
||||
144
core/lib/Thelia/Condition/ConditionEvaluator.php
Normal file
144
core/lib/Thelia/Condition/ConditionEvaluator.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Validate Conditions
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionEvaluator
|
||||
{
|
||||
/**
|
||||
* Check if an Event matches SerializableCondition
|
||||
*
|
||||
* @param ConditionCollection $conditions Conditions to check against the Event
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(ConditionCollection $conditions)
|
||||
{
|
||||
$isMatching = true;
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
if (!$condition->isMatching()) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do variable comparison
|
||||
*
|
||||
* @param mixed $v1 Variable 1
|
||||
* @param string $o Operator ex : Operators::DIFFERENT
|
||||
* @param mixed $v2 Variable 2
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function variableOpComparison($v1, $o, $v2)
|
||||
{
|
||||
if ($o == Operators::DIFFERENT) {
|
||||
return ($v1 != $v2);
|
||||
}
|
||||
|
||||
switch ($o) {
|
||||
case Operators::SUPERIOR :
|
||||
// >
|
||||
if ($v1 > $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::SUPERIOR_OR_EQUAL :
|
||||
// >=
|
||||
if ($v1 >= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::INFERIOR :
|
||||
// <
|
||||
if ($v1 < $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::INFERIOR_OR_EQUAL :
|
||||
// <=
|
||||
if ($v1 <= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::EQUAL :
|
||||
// ==
|
||||
if ($v1 == $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::IN:
|
||||
// in
|
||||
if (in_array($v1, $v2)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case Operators::OUT:
|
||||
// not in
|
||||
if (!in_array($v1, $v2)) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new \Exception('Unrecognized operator ' . $o);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
169
core/lib/Thelia/Condition/ConditionFactory.php
Normal file
169
core/lib/Thelia/Condition/ConditionFactory.php
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Condition could interact with the current application state (Thelia)
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var AdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter;
|
||||
|
||||
/** @var array ConditionCollection to process*/
|
||||
protected $conditions = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a collection of conditions
|
||||
*
|
||||
* @param ConditionCollection $collection A collection of conditions
|
||||
*
|
||||
* @return string A ready to be stored Condition collection
|
||||
*/
|
||||
public function serializeConditionCollection(ConditionCollection $collection)
|
||||
{
|
||||
if ($collection->isEmpty()) {
|
||||
/** @var ConditionManagerInterface $conditionNone */
|
||||
$conditionNone = $this->container->get(
|
||||
'thelia.condition.match_for_everyone'
|
||||
);
|
||||
$collection->add($conditionNone);
|
||||
}
|
||||
$serializableConditions = array();
|
||||
$conditions = $collection->getConditions();
|
||||
if ($conditions !== null) {
|
||||
/** @var $condition ConditionManagerInterface */
|
||||
foreach ($conditions as $condition) {
|
||||
// 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())));
|
||||
// }
|
||||
$serializableConditions[] = $condition->getSerializableCondition();
|
||||
}
|
||||
}
|
||||
|
||||
return base64_encode(json_encode($serializableConditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize a collection of conditions
|
||||
*
|
||||
* @param string $serializedConditions Serialized Conditions
|
||||
*
|
||||
* @return ConditionCollection Conditions ready to be processed
|
||||
*/
|
||||
public function unserializeConditionCollection($serializedConditions)
|
||||
{
|
||||
$unserializedConditions = json_decode(base64_decode($serializedConditions));
|
||||
|
||||
$collection = new ConditionCollection();
|
||||
|
||||
if (!empty($unserializedConditions) && !empty($unserializedConditions)) {
|
||||
/** @var SerializableCondition $condition */
|
||||
foreach ($unserializedConditions as $condition) {
|
||||
if ($this->container->has($condition->conditionServiceId)) {
|
||||
/** @var ConditionManagerInterface $conditionManager */
|
||||
$conditionManager = $this->build(
|
||||
$condition->conditionServiceId,
|
||||
(array) $condition->operators,
|
||||
(array) $condition->values
|
||||
);
|
||||
$collection->add(clone $conditionManager);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a Condition from form
|
||||
*
|
||||
* @param string $conditionServiceId Condition class name
|
||||
* @param array $operators Condition Operator (<, >, = )
|
||||
* @param array $values Values setting this Condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return ConditionManagerInterface Ready to use Condition or false
|
||||
*/
|
||||
public function build($conditionServiceId, array $operators, array $values)
|
||||
{
|
||||
if (!$this->container->has($conditionServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
$condition = $this->container->get($conditionServiceId);
|
||||
$condition->setValidatorsFromForm($operators, $values);
|
||||
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Condition inputs from serviceId
|
||||
*
|
||||
* @param string $conditionServiceId ConditionManager class name
|
||||
*
|
||||
* @return array Ready to be drawn condition inputs
|
||||
*/
|
||||
public function getInputs($conditionServiceId)
|
||||
{
|
||||
if (!$this->container->has($conditionServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
$condition = $this->container->get($conditionServiceId);
|
||||
|
||||
return $condition->getValidators();
|
||||
}
|
||||
}
|
||||
@@ -21,16 +21,14 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -43,7 +41,7 @@ use Thelia\Exception\InvalidRuleOperatorException;
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
abstract class ConditionManagerAbstract implements ConditionManagerInterface
|
||||
{
|
||||
// /** Operator key in $validators */
|
||||
// CONST OPERATOR = 'operator';
|
||||
@@ -62,7 +60,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// /** @var array Parameters to be validated */
|
||||
// protected $paramsToValidate = array();
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
/** @var AdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
@@ -74,19 +72,19 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
/** @var array Values set by Admin in BackOffice */
|
||||
protected $values = array();
|
||||
|
||||
/** @var ConstraintValidator Constaints validator */
|
||||
protected $constraintValidator = null;
|
||||
/** @var ConditionEvaluator Conditions validator */
|
||||
protected $conditionValidator = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
* @param AdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
public function __construct(AdapterInterface $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
$this->constraintValidator = $adapter->getConstraintValidator();
|
||||
$this->conditionValidator = $adapter->getConditionEvaluator();
|
||||
}
|
||||
|
||||
// /**
|
||||
@@ -96,16 +94,16 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// * 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 InvalidRuleOperatorException(
|
||||
// throw new InvalidConditionOperatorException(
|
||||
// get_class(),
|
||||
// $validator->getOperator()
|
||||
// );
|
||||
@@ -146,7 +144,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// }
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
* Return all available Operators for this Condition
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
@@ -158,7 +156,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// /**
|
||||
// * Check if Operators set for this Rule in the BackOffice are legit
|
||||
// *
|
||||
// * @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
// * @throws InvalidConditionOperatorException if Operator is not allowed
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function checkBackOfficeInputsOperators()
|
||||
@@ -169,7 +167,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
// if (!isset($operator)
|
||||
// ||!in_array($operator, $this->availableOperators)
|
||||
// ) {
|
||||
// throw new InvalidRuleOperatorException(get_class(), $key);
|
||||
// throw new InvalidConditionOperatorException(get_class(), $key);
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
@@ -230,7 +228,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
* Get ConditionManager Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
@@ -240,7 +238,7 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate if Operator given is available for this Coupon
|
||||
* Validate if Operator given is available for this Condition
|
||||
*
|
||||
* @param string $operator Operator to validate ex <
|
||||
* @param array $availableOperators Available operators
|
||||
@@ -253,19 +251,67 @@ abstract class CouponRuleAbstract implements CouponRuleInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a serializable Rule
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableRule
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableRule()
|
||||
public function getSerializableCondition()
|
||||
{
|
||||
$serializableRule = new SerializableRule();
|
||||
$serializableRule->ruleServiceId = $this->serviceId;
|
||||
$serializableRule->operators = $this->operators;
|
||||
$serializableCondition = new SerializableCondition();
|
||||
$serializableCondition->conditionServiceId = $this->serviceId;
|
||||
$serializableCondition->operators = $this->operators;
|
||||
|
||||
$serializableRule->values = $this->values;
|
||||
$serializableCondition->values = $this->values;
|
||||
|
||||
return $serializableRule;
|
||||
return $serializableCondition;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if currency if valid or not
|
||||
*
|
||||
* @param string $currencyValue Currency EUR|USD|..
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function IsCurrencyValid($currencyValue)
|
||||
{
|
||||
$availableCurrencies = $this->adapter->getAvailableCurrencies();
|
||||
/** @var Currency $currency */
|
||||
$currencyFound = false;
|
||||
foreach ($availableCurrencies as $currency) {
|
||||
if ($currencyValue == $currency->getCode()) {
|
||||
$currencyFound = true;
|
||||
}
|
||||
}
|
||||
if (!$currencyFound) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'currency'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if price is valid
|
||||
*
|
||||
* @param float $priceValue Price value to check
|
||||
*
|
||||
* @return bool
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
protected function isPriceValid($priceValue)
|
||||
{
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -21,30 +21,30 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represents a condition of whether the Rule is applied or not
|
||||
* Manage how the application checks its state in order to check if it matches the implemented condition
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface CouponRuleInterface
|
||||
interface ConditionManagerInterface
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
* @param AdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter);
|
||||
function __construct(AdapterInterface $adapter);
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
@@ -86,14 +86,14 @@ interface CouponRuleInterface
|
||||
// public function isMatching();
|
||||
|
||||
/**
|
||||
* Test if Customer meets conditions
|
||||
* Test if the current application state matches conditions
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching();
|
||||
|
||||
/**
|
||||
* Return all available Operators for this Rule
|
||||
* Return all available Operators for this condition
|
||||
*
|
||||
* @return array Operators::CONST
|
||||
*/
|
||||
@@ -122,10 +122,10 @@ interface CouponRuleInterface
|
||||
public function getValidators();
|
||||
|
||||
// /**
|
||||
// * Populate a Rule from a form admin
|
||||
// * Populate a Condition from a form admin
|
||||
// *
|
||||
// * @param array $operators Rule Operator set by the Admin
|
||||
// * @param array $values Rule Values set by the Admin
|
||||
// * @param array $operators Condition Operator set by the Admin
|
||||
// * @param array $values Condition Values set by the Admin
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
@@ -133,14 +133,10 @@ interface CouponRuleInterface
|
||||
|
||||
|
||||
/**
|
||||
* Return a serializable Rule
|
||||
* Return a serializable Condition
|
||||
*
|
||||
* @return SerializableRule
|
||||
* @return SerializableCondition
|
||||
*/
|
||||
public function getSerializableRule();
|
||||
|
||||
|
||||
|
||||
|
||||
public function getSerializableCondition();
|
||||
|
||||
}
|
||||
@@ -21,17 +21,10 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
use Thelia\Type\FloatType;
|
||||
use Thelia\Condition\ConditionManagerAbstract;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -40,14 +33,14 @@ use Thelia\Type\FloatType;
|
||||
*
|
||||
* Allow every one, perform no check
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
class MatchForEveryoneManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_everyone';
|
||||
protected $serviceId = 'thelia.condition.match_for_everyone';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array();
|
||||
@@ -102,7 +95,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Everybody can use it (no condition)',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -116,7 +109,7 @@ class AvailableForEveryoneManager extends CouponRuleAbstract
|
||||
$toolTip = $this->translator->trans(
|
||||
'Will return always true',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -21,42 +21,37 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
use Thelia\Condition\ConditionManagerAbstract;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
use Thelia\Model\Currency;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
use Thelia\Type\FloatType;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Rule AvailableForTotalAmount
|
||||
* Condition AvailableForTotalAmount
|
||||
* Check if a Checkout total amount match criteria
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
class MatchForTotalAmountManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** Rule 1st parameter : price */
|
||||
/** Condition 1st parameter : price */
|
||||
CONST INPUT1 = 'price';
|
||||
|
||||
/** Rule 1st parameter : currency */
|
||||
/** Condition 1st parameter : currency */
|
||||
CONST INPUT2 = 'currency';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_total_amount';
|
||||
protected $serviceId = 'thelia.condition.match_for_total_amount';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
@@ -101,7 +96,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
* @param string $currencyOperator Currency Operator ex =
|
||||
* @param string $currencyValue Currency set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Thelia\Exception\InvalidConditionOperatorException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($priceOperator, $priceValue, $currencyOperator, $currencyValue)
|
||||
@@ -111,8 +106,8 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for price field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,19 +116,16 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT2]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for currency field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'price'
|
||||
);
|
||||
}
|
||||
|
||||
$floatType = new FloatType();
|
||||
if (!$floatType->isValid($priceValue) || $priceValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for price field is not legit'
|
||||
);
|
||||
}
|
||||
$this->isPriceValid($priceValue);
|
||||
|
||||
|
||||
$this->IsCurrencyValid($currencyValue);
|
||||
|
||||
// @todo check currency is legit or not
|
||||
|
||||
$this->operators = array(
|
||||
self::INPUT1 => $priceOperator,
|
||||
@@ -167,19 +159,20 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
return false;
|
||||
}
|
||||
|
||||
$constraint1 = $this->constraintValidator->variableOpComparison(
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getCartTotalPrice(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
$constraint2 = $this->constraintValidator->variableOpComparison(
|
||||
$condition2 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getCheckoutCurrency(),
|
||||
$this->operators[self::INPUT2],
|
||||
$this->values[self::INPUT2]
|
||||
);
|
||||
if ($constraint1 && $constraint2) {
|
||||
if ($condition1 && $condition2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -193,7 +186,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Cart total amount',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -215,7 +208,7 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
'%amount%' => $this->values[self::INPUT1],
|
||||
'%currency%' => $this->values[self::INPUT2]
|
||||
),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -238,12 +231,12 @@ class AvailableForTotalAmountManager extends CouponRuleAbstract
|
||||
$name1 = $this->translator->trans(
|
||||
'Price',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
$name2 = $this->translator->trans(
|
||||
'Currency',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return array(
|
||||
@@ -21,17 +21,13 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
use Thelia\Type\FloatType;
|
||||
use Thelia\Condition\ConditionManagerAbstract;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Exception\InvalidConditionOperatorException;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -40,17 +36,17 @@ use Thelia\Type\FloatType;
|
||||
*
|
||||
* Check a Checkout against its Product number
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
class MatchForXArticlesManager extends ConditionManagerAbstract
|
||||
{
|
||||
/** Rule 1st parameter : quantity */
|
||||
/** Condition 1st parameter : quantity */
|
||||
CONST INPUT1 = 'quantity';
|
||||
|
||||
/** @var string Service Id from Resources/config.xml */
|
||||
protected $serviceId = 'thelia.constraint.rule.available_for_x_articles';
|
||||
protected $serviceId = 'thelia.condition.match_for_x_articles';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
@@ -88,7 +84,8 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
* @param string $quantityOperator Quantity Operator ex <
|
||||
* @param int $quantityValue Quantity set to meet condition
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @throws \Thelia\Exception\InvalidConditionValueException
|
||||
* @throws \Thelia\Exception\InvalidConditionOperatorException
|
||||
* @return $this
|
||||
*/
|
||||
protected function setValidators($quantityOperator, $quantityValue)
|
||||
@@ -98,14 +95,14 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
$this->availableOperators[self::INPUT1]
|
||||
);
|
||||
if (!$isOperator1Legit) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Operator for quantity field is not legit'
|
||||
throw new InvalidConditionOperatorException(
|
||||
get_class(), 'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
if ((int) $quantityValue <= 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'Value for quantity field is not legit'
|
||||
throw new InvalidConditionValueException(
|
||||
get_class(), 'quantity'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -126,15 +123,16 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
*/
|
||||
public function isMatching()
|
||||
{
|
||||
$constraint1 = $this->constraintValidator->variableOpComparison(
|
||||
$condition1 = $this->conditionValidator->variableOpComparison(
|
||||
$this->adapter->getNbArticlesInCart(),
|
||||
$this->operators[self::INPUT1],
|
||||
$this->values[self::INPUT1]
|
||||
);
|
||||
|
||||
if ($constraint1) {
|
||||
if ($condition1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -148,7 +146,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
return $this->translator->trans(
|
||||
'Number of articles in cart',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -169,7 +167,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
'%operator%' => $i18nOperator,
|
||||
'%quantity%' => $this->values[self::INPUT1]
|
||||
),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
@@ -185,7 +183,7 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
$name1 = $this->translator->trans(
|
||||
'Quantity',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
|
||||
return array(
|
||||
@@ -199,5 +197,4 @@ class AvailableForXArticlesManager extends CouponRuleAbstract
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -21,17 +21,16 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Thelia\Constraint\Validator\ComparableInterface;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent available Operations in rule checking
|
||||
* Represent available Operations in condition checking
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
@@ -56,62 +55,6 @@ abstract class Operators
|
||||
/** Param1 is not in Param2 */
|
||||
CONST OUT = 'out';
|
||||
|
||||
// /**
|
||||
// * Check if a parameter is valid against a ComparableInterface from its operator
|
||||
// *
|
||||
// * @param mixed $a Parameter to validate
|
||||
// * @param string $operator Operator to validate against
|
||||
// * @param ComparableInterface $b Comparable to validate against
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// public static function isValid($a, $operator, ComparableInterface $b)
|
||||
// {
|
||||
// $ret = false;
|
||||
//
|
||||
// try {
|
||||
// $comparison = $b->compareTo($a);
|
||||
// } catch (\Exception $e) {
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// switch ($operator) {
|
||||
// case self::INFERIOR:
|
||||
// if ($comparison == 1) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::INFERIOR_OR_EQUAL:
|
||||
// if ($comparison == 1 || $comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::EQUAL:
|
||||
// if ($comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::SUPERIOR_OR_EQUAL:
|
||||
// if ($comparison == -1 || $comparison == 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::SUPERIOR:
|
||||
// if ($comparison == -1) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// case self::DIFFERENT:
|
||||
// if ($comparison != 0) {
|
||||
// return true;
|
||||
// }
|
||||
// break;
|
||||
// default:
|
||||
// }
|
||||
//
|
||||
// return $ret;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Get operator translation
|
||||
*
|
||||
@@ -128,56 +71,56 @@ abstract class Operators
|
||||
$ret = $translator->trans(
|
||||
'inferior to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::INFERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'inferior or equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR_OR_EQUAL:
|
||||
$ret = $translator->trans(
|
||||
'superior or equal to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::SUPERIOR:
|
||||
$ret = $translator->trans(
|
||||
'superior to',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::DIFFERENT:
|
||||
$ret = $translator->trans(
|
||||
'different from',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::IN:
|
||||
$ret = $translator->trans(
|
||||
'in',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
case self::OUT:
|
||||
$ret = $translator->trans(
|
||||
'not in',
|
||||
array(),
|
||||
'constraint'
|
||||
'condition'
|
||||
);
|
||||
break;
|
||||
default:
|
||||
@@ -21,50 +21,57 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
namespace Thelia\Condition;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test RemoveXPercentForCategoryY Class
|
||||
* A condition set by an admin ready to be serialized and stored in DataBase
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
class SerializableCondition
|
||||
{
|
||||
public function testSomething()
|
||||
{
|
||||
// Stop here and mark this test as incomplete.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
/** @var string Condition Service id */
|
||||
public $conditionServiceId = null;
|
||||
|
||||
/** @var array Operators set by Admin for this Condition */
|
||||
public $operators = array();
|
||||
|
||||
/** @var array Values set by Admin for this Condition */
|
||||
public $values = array();
|
||||
|
||||
// /**
|
||||
// * Sets up the fixture, for example, opens a network connection.
|
||||
// * This method is called before a test is executed.
|
||||
// * Get Operators set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// protected function setUp()
|
||||
// public function getOperators()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public function incompleteTest()
|
||||
// {
|
||||
// $this->markTestIncomplete(
|
||||
// 'This test has not been implemented yet.'
|
||||
// );
|
||||
// return $this->operators;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// * Get Condition Service id
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// public function getConditionServiceId()
|
||||
// {
|
||||
// return $this->conditionServiceId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get Values set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getValues()
|
||||
// {
|
||||
// return $this->values;
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -275,7 +275,7 @@
|
||||
<service id="kernel" synthetic="true" />
|
||||
|
||||
<!-- Coupon module -->
|
||||
<service id="thelia.adapter" class="Thelia\Coupon\CouponBaseAdapter">
|
||||
<service id="thelia.adapter" class="Thelia\Coupon\BaseAdapter">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.coupon.manager" class="Thelia\Coupon\CouponManager">
|
||||
@@ -285,24 +285,6 @@
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
|
||||
<service id="thelia.constraint.factory" class="Thelia\Constraint\ConstraintFactory">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.constraint.validator" class="Thelia\Constraint\ConstraintValidator">
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_everyone" class="Thelia\Constraint\Rule\AvailableForEveryoneManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_x_articles" class="Thelia\Constraint\Rule\AvailableForXArticlesManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
<service id="thelia.constraint.rule.available_for_total_amount" class="Thelia\Constraint\Rule\AvailableForTotalAmountManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addRule"/>
|
||||
</service>
|
||||
|
||||
<service id="thelia.coupon.type.remove_x_amount" class="Thelia\Coupon\Type\RemoveXAmountManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
@@ -312,6 +294,26 @@
|
||||
<tag name="thelia.coupon.addCoupon"/>
|
||||
</service>
|
||||
|
||||
|
||||
<!-- Condition module -->
|
||||
<service id="thelia.condition.factory" class="Thelia\Condition\ConditionFactory">
|
||||
<argument type="service" id="service_container" />
|
||||
</service>
|
||||
<service id="thelia.condition.validator" class="Thelia\Condition\ConditionEvaluator">
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_everyone" class="Thelia\Condition\Implementation\MatchForEveryoneManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_x_articles" class="Thelia\Condition\Implementation\MatchForXArticlesManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
<service id="thelia.condition.match_for_total_amount" class="Thelia\Condition\Implementation\MatchForTotalAmountManager">
|
||||
<argument type="service" id="thelia.adapter" />
|
||||
<tag name="thelia.coupon.addCondition"/>
|
||||
</service>
|
||||
|
||||
<service id="mailer" class="Thelia\Mailer\MailerFactory">
|
||||
<argument type="service" id="event_dispatcher"/>
|
||||
</service>
|
||||
|
||||
@@ -398,26 +398,31 @@
|
||||
|
||||
<!-- Route to the Coupon controller (process Coupon browsing) -->
|
||||
|
||||
<route id="admin.coupon.list" path="/admin/coupon/">
|
||||
<route id="admin.coupon.list" path="/admin/coupon">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::browseAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.create" path="/admin/coupon/create/">
|
||||
<route id="admin.coupon.create" path="/admin/coupon/create">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::createAction</default>
|
||||
</route>
|
||||
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}/">
|
||||
<route id="admin.coupon.update" path="/admin/coupon/update/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}/">
|
||||
<route id="admin.coupon.read" path="/admin/coupon/read/{couponId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::readAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.input" path="/admin/coupon/rule/{ruleId}/">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getRuleInputAction</default>
|
||||
<route id="admin.coupon.condition.input" path="/admin/coupon/condition/{conditionId}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::getConditionInputAction</default>
|
||||
<requirement key="conditionId">.*</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.rule.update" path="/admin/coupon/{couponId}/rule/update/">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateRulesAction</default>
|
||||
<route id="admin.coupon.condition.update" path="/admin/coupon/{couponId}/condition/update">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::updateConditionsAction</default>
|
||||
<requirement key="couponId">\d+</requirement>
|
||||
</route>
|
||||
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}/">
|
||||
<route id="admin.coupon.consume" path="/admin/coupon/consume/{couponCode}">
|
||||
<default key="_controller">Thelia\Controller\Admin\CouponController::consumeAction</default>
|
||||
<requirement key="couponCode">.*</requirement>
|
||||
</route>
|
||||
|
||||
<!-- Routes to the Config (system variables) controller -->
|
||||
|
||||
@@ -1,174 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Thelia\Constraint\Rule\AvailableForEveryoneManager;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\SerializableRule;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage how Constraint could interact
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintFactory
|
||||
{
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/** @var array CouponRuleCollection to process*/
|
||||
protected $rules = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize a collection of rules
|
||||
*
|
||||
* @param CouponRuleCollection $collection A collection of rules
|
||||
*
|
||||
* @return string A ready to be stored Rule collection
|
||||
*/
|
||||
public function serializeCouponRuleCollection(CouponRuleCollection $collection)
|
||||
{
|
||||
if ($collection->isEmpty()) {
|
||||
/** @var CouponRuleInterface $ruleNoCondition */
|
||||
$ruleNoCondition = $this->container->get(
|
||||
'thelia.constraint.rule.available_for_everyone'
|
||||
);
|
||||
$collection->add($ruleNoCondition);
|
||||
}
|
||||
$serializableRules = array();
|
||||
$rules = $collection->getRules();
|
||||
if ($rules !== null) {
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules as $rule) {
|
||||
// Remove all rule if the "no condition" rule is found
|
||||
// if ($rule->getServiceId() == 'thelia.constraint.rule.available_for_everyone') {
|
||||
// return base64_encode(json_encode(array($rule->getSerializableRule())));
|
||||
// }
|
||||
$serializableRules[] = $rule->getSerializableRule();
|
||||
}
|
||||
}
|
||||
|
||||
return base64_encode(json_encode($serializableRules));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unserialize a collection of rules
|
||||
*
|
||||
* @param string $serializedRules Serialized Rules
|
||||
*
|
||||
* @return CouponRuleCollection Rules ready to be processed
|
||||
*/
|
||||
public function unserializeCouponRuleCollection($serializedRules)
|
||||
{
|
||||
$unserializedRules = json_decode(base64_decode($serializedRules));
|
||||
|
||||
$collection = new CouponRuleCollection();
|
||||
|
||||
if (!empty($serializedRules) && !empty($unserializedRules)) {
|
||||
/** @var SerializableRule $rule */
|
||||
foreach ($unserializedRules as $rule) {
|
||||
if ($this->container->has($rule->ruleServiceId)) {
|
||||
/** @var CouponRuleInterface $couponRule */
|
||||
$couponRule = $this->build(
|
||||
$rule->ruleServiceId,
|
||||
(array) $rule->operators,
|
||||
(array) $rule->values
|
||||
);
|
||||
$collection->add(clone $couponRule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $collection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Build a Coupon Rule from form
|
||||
*
|
||||
* @param string $ruleServiceId Rule class name
|
||||
* @param array $operators Rule Operator (<, >, = )
|
||||
* @param array $values Values setting this Rule
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return CouponRuleInterface Ready to use Rule or false
|
||||
*/
|
||||
public function build($ruleServiceId, array $operators, array $values)
|
||||
{
|
||||
if (!$this->container->has($ruleServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
$rule->setValidatorsFromForm($operators, $values);
|
||||
|
||||
return $rule;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon Rule inputs from serviceId
|
||||
*
|
||||
* @param string $ruleServiceId Rule class name
|
||||
*
|
||||
* @return array Ready to be drawn rule inputs
|
||||
*/
|
||||
public function getInputs($ruleServiceId)
|
||||
{
|
||||
if (!$this->container->has($ruleServiceId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
|
||||
return $rule->getValidators();
|
||||
}
|
||||
}
|
||||
@@ -1,133 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Serializer\Encoder\JsonEncoder;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Validate Constraints
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintValidator
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if a Customer meets SerializableRule
|
||||
*
|
||||
* @param CouponRuleCollection $rules Rules to check against the Customer
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isMatching(CouponRuleCollection $rules)
|
||||
{
|
||||
$isMatching = true;
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
if (!$rule->isMatching()) {
|
||||
$isMatching = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $isMatching;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Do variable comparison
|
||||
*
|
||||
* @param mixed $v1 Variable 1
|
||||
* @param string $o Operator
|
||||
* @param mixed $v2 Variable 2
|
||||
*
|
||||
* @throws \Exception
|
||||
* @return bool
|
||||
*/
|
||||
public function variableOpComparison($v1, $o, $v2) {
|
||||
if ($o == Operators::DIFFERENT) {
|
||||
return ($v1 != $v2);
|
||||
} // could put this elsewhere...
|
||||
// $operators = str_split($o);
|
||||
// foreach($o as $operator) {
|
||||
switch ($o) { // return will exit switch, foreach loop, function
|
||||
case Operators::SUPERIOR : // >
|
||||
if ($v1 > $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::SUPERIOR_OR_EQUAL : // >=
|
||||
if ($v1 >= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::INFERIOR : // <
|
||||
if ($v1 < $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::INFERIOR_OR_EQUAL : // <=
|
||||
if ($v1 <= $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::EQUAL : // ==
|
||||
if ($v1 == $v2) {
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::IN:
|
||||
if (in_array($v1, $v2)) { // in
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
case Operators::OUT:
|
||||
if (!in_array($v1, $v2)) { // not in
|
||||
return true;
|
||||
} else {
|
||||
continue;
|
||||
} break;
|
||||
default: throw new \Exception('Unrecognized operator ' . $o);
|
||||
}
|
||||
// }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,178 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Constraint\Validator\CustomerParam;
|
||||
use Thelia\Constraint\Validator\RuleValidator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForCustomer extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/** Rule 1st parameter : customer id */
|
||||
CONST PARAM1 = 'customerId';
|
||||
|
||||
/** @var array Available Operators (Operators::CONST) */
|
||||
protected $availableOperators = array(
|
||||
Operators::EQUAL,
|
||||
);
|
||||
|
||||
/** @var RuleValidator Customer Validator */
|
||||
protected $customerValidator = null;
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @throws InvalidRuleOperatorException if Operator is not allowed
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
if (!isset($this->validators)
|
||||
|| empty($this->validators)
|
||||
||!isset($this->validators[self::PARAM1])
|
||||
||!isset($this->validators[self::PARAM1])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
/** @var RuleValidator $ruleValidator */
|
||||
$ruleValidator = $this->validators[self::PARAM1];
|
||||
/** @var CustomerParam $customer */
|
||||
$customer = $ruleValidator->getParam();
|
||||
|
||||
if (!$customer instanceof CustomerParam) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
$this->checkBackOfficeInputsOperators();
|
||||
|
||||
return $this->isCustomerValid($customer->getInteger());
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function setParametersToValidate()
|
||||
{
|
||||
$this->paramsToValidate = array(
|
||||
self::PARAM1 => $this->adapter->getCustomer()->getId()
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @throws \Thelia\Exception\InvalidRuleValueException
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
if (!isset($this->paramsToValidate)
|
||||
|| empty($this->paramsToValidate)
|
||||
||!isset($this->paramsToValidate[self::PARAM1])
|
||||
) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
$customerId = $this->paramsToValidate[self::PARAM1];
|
||||
|
||||
return $this->isCustomerValid($customerId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a Customer is valid
|
||||
*
|
||||
* @param int $customerId Customer to check
|
||||
*
|
||||
* @throws InvalidRuleValueException if Value is not allowed
|
||||
* @return bool
|
||||
*/
|
||||
protected function isCustomerValid($customerId)
|
||||
{
|
||||
$customerValidator = $this->customerValidator;
|
||||
try {
|
||||
$customerValidator->getParam()->compareTo($customerId);
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
throw new InvalidRuleValueException(get_class(), self::PARAM1);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('Customer', null, 'constraint');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
/** @var CustomerParam $param */
|
||||
$param = $this->customerValidator->getParam();
|
||||
$toolTip = $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'If customer is %fistname% %lastname% (%email%)',
|
||||
array(
|
||||
'%fistname%' => $param->getFirstName(),
|
||||
'%lastname%' => $param->getLastName(),
|
||||
'%email%' => $param->getEmail(),
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
|
||||
return $toolTip;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForDate extends AvailableForPeriod
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForLocationX extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForPeriod extends CouponRuleAbstract
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForRepeatedDate extends AvailableForDate
|
||||
{
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForRepeatedPeriod extends AvailableForPeriod
|
||||
{
|
||||
|
||||
/**
|
||||
* Generate current Rule param to be validated from adapter
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter allowing to gather
|
||||
* all necessary Thelia variables
|
||||
*
|
||||
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
|
||||
* @return $this
|
||||
*/
|
||||
public function setParametersToValidate(CouponAdapterInterface $adapter)
|
||||
{
|
||||
// @todo implement
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if backoffice inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkBackOfficeInput()
|
||||
{
|
||||
// TODO: Implement checkBackOfficeInput() method.
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if Checkout inputs are relevant or not
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function checkCheckoutInput()
|
||||
{
|
||||
// TODO: Implement checkCheckoutInput() method.
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountForCategoryY extends AvailableForTotalAmount
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Rule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* A rule set by an admin ready to be serialized and stored in DataBase
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class SerializableRule
|
||||
{
|
||||
/** @var string Rule Service id */
|
||||
public $ruleServiceId = null;
|
||||
|
||||
/** @var array Operators set by Admin for this Rule */
|
||||
public $operators = array();
|
||||
|
||||
/** @var array Values set by Admin for this Rule */
|
||||
public $values = array();
|
||||
|
||||
/**
|
||||
* Get Operators set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOperators()
|
||||
{
|
||||
return $this->operators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rule Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRuleServiceId()
|
||||
{
|
||||
return $this->ruleServiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Values set by Admin for this Rule
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
/**
|
||||
* Comparable interface
|
||||
* Allows to compare two value objects to each other for similarity.
|
||||
*
|
||||
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||
*/
|
||||
interface ComparableInterface
|
||||
{
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other);
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Propel\Runtime\ActiveQuery\ModelCriteria;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Model\Customer;
|
||||
use Thelia\Model\CustomerQuery;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Customer
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CustomerParam extends IntegerParam
|
||||
{
|
||||
/** @var string Model Class name */
|
||||
protected $modelClass = '\Thelia\Model\Customer';
|
||||
|
||||
/** @var ModelCriteria */
|
||||
protected $queryBuilder = null;
|
||||
|
||||
/** @var string Customer firstname */
|
||||
protected $firstName = null;
|
||||
|
||||
/** @var string Customer lastname */
|
||||
protected $lastName = null;
|
||||
|
||||
/** @var string Customer email */
|
||||
protected $email = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->queryBuilder = CustomerQuery::create();
|
||||
/** @var Customer $customer */
|
||||
$customer = $this->queryBuilder->findById($integer);
|
||||
if ($customer !== null) {
|
||||
$this->firstName = $customer->getFirstname();
|
||||
$this->lastName = $customer->getLastname();
|
||||
$this->email = $customer->getEmail();
|
||||
} else {
|
||||
throw new \InvalidArgumentException(
|
||||
'CustomerParam can compare only existing Customers'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer email
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer first name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getFirstName()
|
||||
{
|
||||
return $this->firstName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Customer last name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastName()
|
||||
{
|
||||
return $this->lastName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A Customer',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,120 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a DateTime
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class DateParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var \DateTime Date */
|
||||
protected $dateTime = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $dateTime DateTime
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $dateTime)
|
||||
{
|
||||
$this->dateTime = $dateTime;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get DateTime
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getDateTime()
|
||||
{
|
||||
return clone $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('DateParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($this->dateTime == $other) {
|
||||
$ret = 0;
|
||||
} elseif ($this->dateTime > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \Datetime
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->dateTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent an Integer
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntegerParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var int Integer to compare with */
|
||||
protected $integer = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get integer
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getInteger()
|
||||
{
|
||||
return $this->integer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other)) {
|
||||
throw new \InvalidArgumentException('IntegerParam can compare only int');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($this->integer == $other) {
|
||||
$ret = 0;
|
||||
} elseif ($this->integer > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->integer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A number (ex: 42)', null, 'constraint');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent an DateTime period
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntervalParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var \DatePeriod Date period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var \DateTime Start date */
|
||||
protected $start = null;
|
||||
|
||||
/** @var \DateInterval Interval date */
|
||||
protected $interval = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param \DateTime $start Start interval
|
||||
* @param \DateInterval $interval Period
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, \DateTime $start, \DateInterval $interval)
|
||||
{
|
||||
$this->datePeriod = new \DatePeriod($start, $interval, 1);
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->start = $start;
|
||||
$this->interval = $interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start date
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getStart()
|
||||
{
|
||||
return $this->start;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get DatePeriod
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getDatePeriod()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('IntervalParam can compare only DateTime');
|
||||
}
|
||||
|
||||
/** @var \DateTime Start Date */
|
||||
$startDate = null;
|
||||
/** @var \DateTime End Date */
|
||||
$endDate = null;
|
||||
|
||||
foreach ($this->datePeriod as $key => $value) {
|
||||
if ($key == 0) {
|
||||
$startDate = $value;
|
||||
}
|
||||
if ($key == 1) {
|
||||
$endDate = $value;
|
||||
}
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
if ($startDate <= $other && $other <= $endDate) {
|
||||
$ret = 0;
|
||||
} elseif ($startDate > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('An interval between two dates', null, 'constraint');
|
||||
}
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Model
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ModelParam extends IntegerParam
|
||||
{
|
||||
/** @var string Model Class name */
|
||||
protected $modelClass = null;
|
||||
|
||||
/** @var ModelCriteria */
|
||||
protected $queryBuilder = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
* @param string $modelClass Model class name
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer, $modelClass)
|
||||
{
|
||||
if ($integer < 0) {
|
||||
$integer = 0;
|
||||
}
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
|
||||
$this->modelClass = $modelClass;
|
||||
$queryClassName = $modelClass . 'Query';
|
||||
try {
|
||||
$this->queryBuilder = $queryClassName::create();
|
||||
} catch (\Exception $e) {
|
||||
throw new InvalidArgumentException('ModelParam can only compare Models');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A Model',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent a Price
|
||||
* Positive value with currency
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class PriceParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var float Positive Float to compare with */
|
||||
protected $price = null;
|
||||
|
||||
/** @var string Currency Code ISO 4217 EUR|USD|GBP */
|
||||
protected $currency = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param Translator $translator Service translator
|
||||
* @param float $price Positive float
|
||||
* @param string $currency Currency Code ISO 4217 EUR|USD|GBP
|
||||
*/
|
||||
public function __construct(Translator $translator, $price, $currency)
|
||||
{
|
||||
$this->price = $price;
|
||||
$this->currency = $currency;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get currency code
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrency()
|
||||
{
|
||||
return $this->currency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get price
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getPrice()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!is_float($other)) {
|
||||
throw new \InvalidArgumentException(
|
||||
'PriceParam can compare only positive float'
|
||||
);
|
||||
}
|
||||
|
||||
$epsilon = 0.00001;
|
||||
|
||||
$ret = -1;
|
||||
if (abs($this->price - $other) < $epsilon) {
|
||||
$ret = 0;
|
||||
} elseif ($this->price > $other) {
|
||||
$ret = 1;
|
||||
} else {
|
||||
$ret = -1;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->translator
|
||||
->trans(
|
||||
'A price in %currency% (ex: 14.50)',
|
||||
array(
|
||||
'%currency%' => $this->currency
|
||||
),
|
||||
'constraint'
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,117 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent A repeated Date across the time
|
||||
* Ex :
|
||||
* A date repeated every 1 months 5 times
|
||||
* ---------*---*---*---*---*---*---------------------------> time
|
||||
* 1 2 3 4 5 6
|
||||
* 1 : $this->from Start date of the repetition
|
||||
* *--- : $this->interval Duration of a whole cycle
|
||||
* x5 : $this->recurrences How many repeated cycle, 1st excluded
|
||||
* x6 : How many occurrence
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedDateParam extends RepeatedParam
|
||||
{
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('RepeatedDateParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
$dates = array();
|
||||
/** @var $value \DateTime */
|
||||
foreach ($this->datePeriod as $value) {
|
||||
$dates[$value->getTimestamp()] = $value;
|
||||
}
|
||||
|
||||
foreach ($dates as $date) {
|
||||
if ($date == $other) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
@@ -1,151 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Represent A repeated DateInterval across the time
|
||||
* Ex :
|
||||
* A duration of 1 month repeated every 2 months 5 times
|
||||
* ---------****----****----****----****----****----****-----------------> time
|
||||
* 1 2 3 4 5 6
|
||||
* 1 : $this->from Start date of the repetition
|
||||
* ****---- : $this->interval Duration of a whole cycle
|
||||
* x5 : $this->recurrences How many repeated cycle, 1st excluded
|
||||
* x6 : How many occurrence
|
||||
* **** : $this->durationInDays Duration of a period
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedIntervalParam extends RepeatedParam
|
||||
{
|
||||
|
||||
/** @var int duration of the param */
|
||||
protected $durationInDays = 1;
|
||||
|
||||
/**
|
||||
* Get how many day a Param is lasting
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDurationInDays()
|
||||
{
|
||||
return $this->durationInDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set how many day a Param is lasting
|
||||
*
|
||||
* @param int $durationInDays How many day a Param is lasting
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDurationInDays($durationInDays = 1)
|
||||
{
|
||||
$this->durationInDays = $durationInDays;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter)
|
||||
{
|
||||
$this->defaultConstructor();
|
||||
$this->adapter = $adapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
*/
|
||||
public function compareTo($other)
|
||||
{
|
||||
if (!$other instanceof \DateTime) {
|
||||
throw new \InvalidArgumentException('RepeatedIntervalParam can compare only DateTime');
|
||||
}
|
||||
|
||||
$ret = -1;
|
||||
$dates = array();
|
||||
/** @var $value \DateTime */
|
||||
foreach ($this->datePeriod as $value) {
|
||||
$dates[$value->getTimestamp()]['startDate'] = $value;
|
||||
$endDate = new \DateTime();
|
||||
$dates[$value->getTimestamp()]['endDate'] = $endDate->setTimestamp(
|
||||
$value->getTimestamp() + ($this->durationInDays * 60 *60 *24)
|
||||
);
|
||||
}
|
||||
|
||||
foreach ($dates as $date) {
|
||||
if ($date['startDate'] <= $other && $other <= $date['endDate']) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans('A date (ex: YYYY-MM-DD HH:MM:SS)', null, 'constraint');
|
||||
}
|
||||
}
|
||||
@@ -1,297 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use DateInterval;
|
||||
use DatePeriod;
|
||||
use DateTime;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to set the way a parameter can be repeated across the time
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class RepeatedParam extends RuleParameterAbstract
|
||||
{
|
||||
/** @var DateTime The start date of the period. */
|
||||
protected $from = null;
|
||||
|
||||
/** @var DateInterval The interval between recurrences within the period. */
|
||||
protected $interval = null;
|
||||
|
||||
/** @var int Nb time the object will be repeated (1st occurrence excluded). */
|
||||
protected $recurrences = null;
|
||||
|
||||
/** @var DatePeriod dates recurring at regular intervals, over a given period */
|
||||
protected $datePeriod = null;
|
||||
|
||||
/** @var int Frequency the object will be repeated */
|
||||
protected $frequency = null;
|
||||
|
||||
/** @var int $nbRepetition Time the object will be repeated */
|
||||
protected $nbRepetition = null;
|
||||
|
||||
/**
|
||||
* Get frequency
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getFrequency()
|
||||
{
|
||||
return $this->frequency;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Interval
|
||||
*
|
||||
* @return \DateInterval
|
||||
*/
|
||||
public function getInterval()
|
||||
{
|
||||
return $this->interval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of time it will be repeated
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getNbRepetition()
|
||||
{
|
||||
return $this->nbRepetition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get number of recurrences
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getRecurrences()
|
||||
{
|
||||
return $this->recurrences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate default repetition
|
||||
* Every 1 week 100 times from now
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function defaultConstructor()
|
||||
{
|
||||
$this->from = new \DateTime();
|
||||
$this->interval = new \DateInterval('P1W'); // 1 week
|
||||
$this->recurrences = 100;
|
||||
$this->generateDatePeriod();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate DatePeriod from class attributes
|
||||
* Will repeat every DatePeriod
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
protected function generateDatePeriod()
|
||||
{
|
||||
$this->datePeriod = new DatePeriod(
|
||||
$this->from,
|
||||
$this->interval,
|
||||
$this->recurrences
|
||||
);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every days
|
||||
* Ex : $obj->repeatEveryDay() will occur once
|
||||
* $obj->repeatEveryDay(10) will occur once
|
||||
* $obj->repeatEveryDay(10, 0) will occur once
|
||||
* $obj->repeatEveryDay(10, 4) will occur every 10 days 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryDay($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'D', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every week
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 weeks (70days) 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryWeek($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every month
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 month (70days) 5times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryMonth($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every year
|
||||
* Ex : $obj->repeatEveryWeek() will occur once
|
||||
* $obj->repeatEveryWeek(10) will occur once
|
||||
* $obj->repeatEveryWeek(10, 0) will occur once
|
||||
* $obj->repeatEveryWeek(10, 4) will occur every 10 year 5 times
|
||||
*
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function repeatEveryYear($frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
$this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the Object to be repeated every Period
|
||||
* Ex : $obj->repeatEveryPeriod('D') will occur once
|
||||
* $obj->repeatEveryPeriod('W', 10) will occur once
|
||||
* $obj->repeatEveryPeriod('W', 10, 0) will occur once
|
||||
* $obj->repeatEveryPeriod('M', 10, 4) will occur every 10 month 5 times
|
||||
*
|
||||
* @param string $period Period Y|M||D|W
|
||||
* @param int $frequency Frequency the object will be repeated
|
||||
* @param int $nbRepetition Time the object will be repeated
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = 0)
|
||||
{
|
||||
if (is_numeric($frequency) && $frequency > 0) {
|
||||
$this->interval = new \DateInterval('P' . $frequency . $period);
|
||||
}
|
||||
|
||||
if (is_numeric($nbRepetition) && $nbRepetition >= 0) {
|
||||
$this->recurrences = $nbRepetition;
|
||||
}
|
||||
|
||||
$this->generateDatePeriod();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Set Start time
|
||||
*
|
||||
* @param \DateTime $from Start time
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setFrom($from)
|
||||
{
|
||||
$this->from = $from;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Start time
|
||||
*
|
||||
* @return \DateTime
|
||||
*/
|
||||
public function getFrom()
|
||||
{
|
||||
return clone $this->from;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DatePeriod
|
||||
*
|
||||
* @param DatePeriod $datePeriod DatePeriod
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setDatePeriod(DatePeriod $datePeriod)
|
||||
{
|
||||
$this->datePeriod = $datePeriod;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date DatePeriod
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getDatePeriod()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return \DatePeriod
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return clone $this->datePeriod;
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Exception\NotImplementedException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Get a Param value
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
abstract class RuleParameterAbstract implements ComparableInterface
|
||||
{
|
||||
/** @var Translator Service Translator */
|
||||
protected $translator = null;
|
||||
|
||||
/**
|
||||
* Get Parameter value to test against
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getValue()
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getToolTip()
|
||||
{
|
||||
return new NotImplementedException();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to validate parameters
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RuleValidator
|
||||
{
|
||||
/** @var string Operator ex: Operators::INFERIOR */
|
||||
protected $operator = null;
|
||||
|
||||
/** @var ComparableInterface Validator */
|
||||
protected $param = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $operator Operator ex: Operators::INFERIOR
|
||||
* @param ComparableInterface $param Validator ex: PriceParam
|
||||
*/
|
||||
function __construct($operator, ComparableInterface $param)
|
||||
{
|
||||
$this->operator = $operator;
|
||||
$this->param = $param;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Validator Operator
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getOperator()
|
||||
{
|
||||
return $this->operator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Validator Param
|
||||
*
|
||||
* @return ComparableInterface
|
||||
*/
|
||||
public function getParam()
|
||||
{
|
||||
return $this->param;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,24 +25,15 @@ namespace Thelia\Controller\Admin;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Router;
|
||||
use Thelia\Constraint\ConstraintFactory;
|
||||
use Thelia\Constraint\ConstraintFactoryTest;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Validator\PriceParam;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponConsumeEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent;
|
||||
use Thelia\Core\Event\Coupon\CouponEvent;
|
||||
use Thelia\Core\Event\TheliaEvents;
|
||||
use Thelia\Core\HttpFoundation\Session\Session;
|
||||
use Thelia\Core\Security\Exception\AuthenticationException;
|
||||
use Thelia\Core\Security\Exception\AuthorizationException;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponFactory;
|
||||
use Thelia\Coupon\CouponManager;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Form\CouponCreationForm;
|
||||
use Thelia\Form\Exception\FormValidationException;
|
||||
@@ -76,13 +67,13 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$args['urlReadCoupon'] = $this->getRoute(
|
||||
'admin.coupon.read',
|
||||
array('couponId' => 'couponId'),
|
||||
array('couponId' => 0),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlEditCoupon'] = $this->getRoute(
|
||||
'admin.coupon.update',
|
||||
array('couponId' => 'couponId'),
|
||||
array('couponId' => 0),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
@@ -162,7 +153,7 @@ class CouponController extends BaseAdminController
|
||||
|
||||
$args['dateFormat'] = $this->getSession()->getLang()->getDateFormat();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['formAction'] = 'admin/coupon/create/';
|
||||
$args['formAction'] = 'admin/coupon/create';
|
||||
|
||||
return $this->render(
|
||||
'coupon-create',
|
||||
@@ -187,8 +178,9 @@ class CouponController extends BaseAdminController
|
||||
|
||||
/** @var Coupon $coupon */
|
||||
$coupon = CouponQuery::create()->findPk($couponId);
|
||||
if (!$coupon) {
|
||||
$this->pageNotFound();
|
||||
if (null === $coupon) {
|
||||
return $this->pageNotFound();
|
||||
|
||||
}
|
||||
|
||||
// Parameters given to the template
|
||||
@@ -199,7 +191,7 @@ class CouponController extends BaseAdminController
|
||||
$lang = $this->getSession()->getLang();
|
||||
$eventToDispatch = TheliaEvents::COUPON_UPDATE;
|
||||
|
||||
// Create
|
||||
// Update
|
||||
if ($this->getRequest()->isMethod('POST')) {
|
||||
$this->validateCreateOrUpdateForm(
|
||||
$i18n,
|
||||
@@ -208,20 +200,23 @@ class CouponController extends BaseAdminController
|
||||
'updated',
|
||||
'update'
|
||||
);
|
||||
} else { // Update
|
||||
|
||||
} else {
|
||||
// Display
|
||||
// Prepare the data that will hydrate the form
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$conditions = $conditionFactory->unserializeConditionCollection(
|
||||
$coupon->getSerializedConditions()
|
||||
);
|
||||
|
||||
var_dump($coupon->getIsEnabled());;
|
||||
var_dump($coupon->getIsAvailableOnSpecialOffers());;
|
||||
var_dump($coupon->getIsCumulative());;
|
||||
var_dump($coupon->getIsRemovingPostage());;
|
||||
$data = array(
|
||||
'code' => $coupon->getCode(),
|
||||
'title' => $coupon->getTitle(),
|
||||
'amount' => $coupon->getAmount(),
|
||||
'effect' => $coupon->getType(),
|
||||
'type' => $coupon->getType(),
|
||||
'shortDescription' => $coupon->getShortDescription(),
|
||||
'description' => $coupon->getDescription(),
|
||||
'isEnabled' => ($coupon->getIsEnabled() == 1),
|
||||
@@ -230,23 +225,23 @@ class CouponController extends BaseAdminController
|
||||
'isCumulative' => ($coupon->getIsCumulative() == 1),
|
||||
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
|
||||
'maxUsage' => $coupon->getMaxUsage(),
|
||||
'rules' => $rules,
|
||||
'conditions' => $conditions,
|
||||
'locale' => $coupon->getLocale(),
|
||||
);
|
||||
|
||||
$args['rulesObject'] = array();
|
||||
$args['conditionsObject'] = array();
|
||||
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$args['rulesObject'][] = array(
|
||||
'serviceId' => $rule->getServiceId(),
|
||||
'name' => $rule->getName(),
|
||||
'tooltip' => $rule->getToolTip(),
|
||||
'validators' => $rule->getValidators()
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
$args['conditionsObject'][] = array(
|
||||
'serviceId' => $condition->getServiceId(),
|
||||
'name' => $condition->getName(),
|
||||
'tooltip' => $condition->getToolTip(),
|
||||
'validators' => $condition->getValidators()
|
||||
);
|
||||
}
|
||||
|
||||
$args['rules'] = $this->cleanRuleForTemplate($rules);
|
||||
$args['conditions'] = $this->cleanConditionForTemplate($conditions);
|
||||
|
||||
// Setup the object form
|
||||
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
|
||||
@@ -256,20 +251,20 @@ class CouponController extends BaseAdminController
|
||||
}
|
||||
$args['couponCode'] = $coupon->getCode();
|
||||
$args['availableCoupons'] = $this->getAvailableCoupons();
|
||||
$args['availableRules'] = $this->getAvailableRules();
|
||||
$args['urlAjaxGetRuleInput'] = $this->getRoute(
|
||||
'admin.coupon.rule.input',
|
||||
array('ruleId' => 'ruleId'),
|
||||
$args['availableConditions'] = $this->getAvailableConditions();
|
||||
$args['urlAjaxGetConditionInput'] = $this->getRoute(
|
||||
'admin.coupon.condition.input',
|
||||
array('conditionId' => 'conditionId'),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['urlAjaxUpdateRules'] = $this->getRoute(
|
||||
'admin.coupon.rule.update',
|
||||
$args['urlAjaxUpdateConditions'] = $this->getRoute(
|
||||
'admin.coupon.condition.update',
|
||||
array('couponId' => $couponId),
|
||||
Router::ABSOLUTE_URL
|
||||
);
|
||||
|
||||
$args['formAction'] = 'admin/coupon/update/' . $couponId;
|
||||
$args['formAction'] = 'admin/coupon/update' . $couponId;
|
||||
|
||||
return $this->render('coupon-update', $args);
|
||||
}
|
||||
@@ -277,28 +272,28 @@ class CouponController extends BaseAdminController
|
||||
/**
|
||||
* Manage Coupons read display
|
||||
*
|
||||
* @param string $ruleId Rule service id
|
||||
* @param string $conditionId Condition service id
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function getRuleInputAction($ruleId)
|
||||
public function getConditionInputAction($conditionId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
$this->checkXmlHttpRequest();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$inputs = $constraintFactory->getInputs($ruleId);
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$inputs = $conditionFactory->getInputs($conditionId);
|
||||
|
||||
if ($inputs === null) {
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
return $this->render(
|
||||
'coupon/rule-input-ajax',
|
||||
'coupon/condition-input-ajax',
|
||||
array(
|
||||
'ruleId' => $ruleId,
|
||||
'conditionId' => $conditionId,
|
||||
'inputs' => $inputs
|
||||
)
|
||||
);
|
||||
@@ -312,7 +307,7 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @return \Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function updateRulesAction($couponId)
|
||||
public function updateConditionsAction($couponId)
|
||||
{
|
||||
$this->checkAuth('ADMIN', 'admin.coupon.read');
|
||||
|
||||
@@ -326,64 +321,51 @@ class CouponController extends BaseAdminController
|
||||
return $this->pageNotFound();
|
||||
}
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$conditions = new ConditionCollection();
|
||||
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
$rulesReceived = json_decode($this->getRequest()->get('rules'));
|
||||
foreach ($rulesReceived as $ruleReceived) {
|
||||
$rule = $constraintFactory->build(
|
||||
$ruleReceived->serviceId,
|
||||
(array) $ruleReceived->operators,
|
||||
(array) $ruleReceived->values
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$conditionsReceived = json_decode($this->getRequest()->get('conditions'));
|
||||
foreach ($conditionsReceived as $conditionReceived) {
|
||||
$condition = $conditionFactory->build(
|
||||
$conditionReceived->serviceId,
|
||||
(array) $conditionReceived->operators,
|
||||
(array) $conditionReceived->values
|
||||
);
|
||||
$rules->add(clone $rule);
|
||||
$conditions->add(clone $condition);
|
||||
}
|
||||
|
||||
$coupon->setSerializedRules(
|
||||
$constraintFactory->serializeCouponRuleCollection($rules)
|
||||
);
|
||||
// $coupon->setSerializedConditions(
|
||||
// $conditionFactory->serializeCouponConditionCollection($conditions)
|
||||
// );
|
||||
|
||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||
$coupon->getCode(),
|
||||
$coupon->getTitle(),
|
||||
$coupon->getAmount(),
|
||||
$coupon->getType(),
|
||||
$coupon->getShortDescription(),
|
||||
$coupon->getDescription(),
|
||||
$coupon->getIsEnabled(),
|
||||
$coupon->getExpirationDate(),
|
||||
$coupon->getIsAvailableOnSpecialOffers(),
|
||||
$coupon->getIsCumulative(),
|
||||
$coupon->getIsRemovingPostage(),
|
||||
$coupon->getMaxUsage(),
|
||||
$rules,
|
||||
$coupon->getLocale()
|
||||
$conditionEvent = new ConditionCreateOrUpdateEvent(
|
||||
$conditions
|
||||
);
|
||||
$couponEvent->setCoupon($coupon);
|
||||
$conditionEvent->setCouponModel($coupon);
|
||||
|
||||
$eventToDispatch = TheliaEvents::COUPON_RULE_UPDATE;
|
||||
$eventToDispatch = TheliaEvents::COUPON_CONDITION_UPDATE;
|
||||
// Dispatch Event to the Action
|
||||
$this->dispatch(
|
||||
$eventToDispatch,
|
||||
$couponEvent
|
||||
$conditionEvent
|
||||
);
|
||||
|
||||
$this->adminLogAppend(
|
||||
sprintf(
|
||||
'Coupon %s (ID %s) rules updated',
|
||||
$couponEvent->getTitle(),
|
||||
$couponEvent->getCoupon()->getId()
|
||||
'Coupon %s (ID %s) conditions updated',
|
||||
$conditionEvent->getCouponModel()->getTitle(),
|
||||
$conditionEvent->getCouponModel()->getServiceId()
|
||||
)
|
||||
);
|
||||
|
||||
$cleanedRules = $this->cleanRuleForTemplate($rules);
|
||||
$cleanedConditions = $this->cleanConditionForTemplate($conditions);
|
||||
|
||||
return $this->render(
|
||||
'coupon/rules',
|
||||
'coupon/conditions',
|
||||
array(
|
||||
'couponId' => $couponId,
|
||||
'rules' => $cleanedRules,
|
||||
'conditions' => $cleanedConditions,
|
||||
'urlEdit' => $couponId,
|
||||
'urlDelete' => $couponId
|
||||
)
|
||||
@@ -395,6 +377,8 @@ class CouponController extends BaseAdminController
|
||||
*
|
||||
* @param string $couponCode Coupon code
|
||||
*
|
||||
* @todo remove (event dispatcher testing purpose)
|
||||
*
|
||||
*/
|
||||
public function consumeAction($couponCode)
|
||||
{
|
||||
@@ -431,8 +415,8 @@ class CouponController extends BaseAdminController
|
||||
$couponBeingCreated->setAmount($data['amount']);
|
||||
$couponBeingCreated->setIsEnabled($data['isEnabled']);
|
||||
$couponBeingCreated->setExpirationDate($data['expirationDate']);
|
||||
$couponBeingCreated->setSerializedRules(
|
||||
new CouponRuleCollection(
|
||||
$couponBeingCreated->setSerializedConditions(
|
||||
new ConditionCollection(
|
||||
array()
|
||||
)
|
||||
);
|
||||
@@ -488,26 +472,14 @@ 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
|
||||
$data = $form->getData();
|
||||
|
||||
$couponEvent = new CouponCreateOrUpdateEvent(
|
||||
$data['code'],
|
||||
$data['title'],
|
||||
$data['amount'],
|
||||
$data['effect'],
|
||||
$data['shortDescription'],
|
||||
$data['description'],
|
||||
$data['isEnabled'],
|
||||
\DateTime::createFromFormat('Y-m-d', $data['expirationDate']),
|
||||
$data['isAvailableOnSpecialOffers'],
|
||||
$data['isCumulative'],
|
||||
$data['isRemovingPostage'],
|
||||
$data['maxUsage'],
|
||||
new CouponRuleCollection(array()),
|
||||
$data['locale']
|
||||
$data['code'], $data['title'], $data['amount'], $data['type'], $data['shortDescription'], $data['description'], $data['isEnabled'], \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], $data['maxUsage'], $data['locale']
|
||||
);
|
||||
|
||||
// Dispatch Event to the Action
|
||||
@@ -535,7 +507,6 @@ class CouponController extends BaseAdminController
|
||||
} catch (FormValidationException $e) {
|
||||
// Invalid data entered
|
||||
$message = 'Please check your input:';
|
||||
$this->logError($action, $message, $e);
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// Any other error
|
||||
@@ -557,26 +528,26 @@ class CouponController extends BaseAdminController
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all available rules
|
||||
* Get all available conditions
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getAvailableRules()
|
||||
protected function getAvailableConditions()
|
||||
{
|
||||
/** @var CouponManager $couponManager */
|
||||
$couponManager = $this->container->get('thelia.coupon.manager');
|
||||
$availableRules = $couponManager->getAvailableRules();
|
||||
$cleanedRules = array();
|
||||
/** @var CouponRuleInterface $availableRule */
|
||||
foreach ($availableRules as $availableRule) {
|
||||
$rule = array();
|
||||
$rule['serviceId'] = $availableRule->getServiceId();
|
||||
$rule['name'] = $availableRule->getName();
|
||||
$rule['toolTip'] = $availableRule->getToolTip();
|
||||
$cleanedRules[] = $rule;
|
||||
$availableConditions = $couponManager->getAvailableConditions();
|
||||
$cleanedConditions = array();
|
||||
/** @var ConditionManagerInterface $availableCondition */
|
||||
foreach ($availableConditions as $availableCondition) {
|
||||
$condition = array();
|
||||
$condition['serviceId'] = $availableCondition->getServiceId();
|
||||
$condition['name'] = $availableCondition->getName();
|
||||
$condition['toolTip'] = $availableCondition->getToolTip();
|
||||
$cleanedConditions[] = $condition;
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
return $cleanedConditions;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -592,48 +563,51 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $rules
|
||||
* Clean condition for template
|
||||
*
|
||||
* @param ConditionCollection $conditions Condition collection
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function cleanRuleForTemplate($rules)
|
||||
protected function cleanConditionForTemplate(ConditionCollection $conditions)
|
||||
{
|
||||
$cleanedRules = array();
|
||||
/** @var $rule CouponRuleInterface */
|
||||
foreach ($rules->getRules() as $rule) {
|
||||
$cleanedRules[] = $rule->getToolTip();
|
||||
$cleanedConditions = array();
|
||||
/** @var $condition ConditionManagerInterface */
|
||||
foreach ($conditions->getConditions() as $condition) {
|
||||
$cleanedConditions[] = $condition->getToolTip();
|
||||
}
|
||||
|
||||
return $cleanedRules;
|
||||
return $cleanedConditions;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Validation Rule creation
|
||||
// * Validation Condition creation
|
||||
// *
|
||||
// * @param string $type Rule class type
|
||||
// * @param string $operator Rule operator (<, >, =, etc)
|
||||
// * @param array $values Rules values
|
||||
// * @param string $type Condition class type
|
||||
// * @param string $operator Condition operator (<, >, =, etc)
|
||||
// * @param array $values Condition values
|
||||
// *
|
||||
// * @return bool
|
||||
// */
|
||||
// protected function validateRulesCreation($type, $operator, $values)
|
||||
// protected function validateConditionsCreation($type, $operator, $values)
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $adapter */
|
||||
// /** @var AdapterInterface $adapter */
|
||||
// $adapter = $this->container->get('thelia.adapter');
|
||||
// $validator = new PriceParam()
|
||||
// try {
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
// $rule = new $type($adapter, $validators);
|
||||
// $condition = new AvailableForTotalAmount($adapter, $validators);
|
||||
// $condition = new $type($adapter, $validators);
|
||||
// } catch (\Exception $e) {
|
||||
// return false;
|
||||
// }
|
||||
|
||||
@@ -21,76 +21,86 @@
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint\Validator;
|
||||
namespace Thelia\Core\Event\Condition;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
* Date: 8/29/13
|
||||
* Time: 3:45 PM
|
||||
*
|
||||
* Represent a Quantity
|
||||
* Occurring when a Condition is created or updated
|
||||
*
|
||||
* @package Constraint
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class QuantityParam extends IntegerParam
|
||||
class ConditionCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
/** @var ConditionCollection Array of ConditionManagerInterface */
|
||||
protected $conditions = null;
|
||||
|
||||
/** @var CouponInterface Coupon model associated with this conditions */
|
||||
protected $couponModel = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
|
||||
* @param int $integer Integer
|
||||
* @param ConditionCollection $conditions Array of ConditionManagerInterface
|
||||
*/
|
||||
public function __construct(CouponAdapterInterface $adapter, $integer)
|
||||
public function __construct(ConditionCollection $conditions)
|
||||
{
|
||||
$this->integer = $integer;
|
||||
$this->adapter = $adapter;
|
||||
$this->conditions = $conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare the current object to the passed $other.
|
||||
* Get Conditions
|
||||
*
|
||||
* Returns 0 if they are semantically equal, 1 if the other object
|
||||
* is less than the current one, or -1 if its more than the current one.
|
||||
*
|
||||
* This method should not check for identity using ===, only for semantically equality for example
|
||||
* when two different DateTime instances point to the exact same Date + TZ.
|
||||
*
|
||||
* @param mixed $other Object
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
* @return int
|
||||
* @return null|ConditionCollection Array of ConditionManagerInterface
|
||||
*/
|
||||
public function compareTo($other)
|
||||
public function getConditions()
|
||||
{
|
||||
if (!is_integer($other) || $other < 0) {
|
||||
throw new \InvalidArgumentException(
|
||||
'IntegerParam can compare only positive int'
|
||||
);
|
||||
}
|
||||
|
||||
return parent::compareTo($other);
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get I18n tooltip
|
||||
* Set Conditions
|
||||
*
|
||||
* @return string
|
||||
* @param ConditionCollection $conditions Array of ConditionManagerInterface
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function getToolTip()
|
||||
public function setConditions(ConditionCollection $conditions)
|
||||
{
|
||||
return $this->adapter
|
||||
->getTranslator()
|
||||
->trans(
|
||||
'A positive quantity (ex: 42)',
|
||||
null,
|
||||
'constraint'
|
||||
);
|
||||
$this->conditions = $conditions;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Coupon Model associated to this condition
|
||||
*
|
||||
* @param CouponInterface $couponModel Coupon Model
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setCouponModel($couponModel)
|
||||
{
|
||||
$this->couponModel = $couponModel;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon Model associated to this condition
|
||||
*
|
||||
* @return null|CouponInterface
|
||||
*/
|
||||
public function getCouponModel()
|
||||
{
|
||||
return $this->couponModel;
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,6 @@
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -56,7 +54,7 @@ class CouponConsumeEvent extends ActionEvent
|
||||
* @param bool $isValid If Coupon is valid or
|
||||
* if Customer meets coupon conditions
|
||||
*/
|
||||
function __construct($code, $discount = null, $isValid = null)
|
||||
public function __construct($code, $discount = null, $isValid = null)
|
||||
{
|
||||
$this->code = $code;
|
||||
$this->discount = $discount;
|
||||
@@ -136,7 +134,4 @@ class CouponConsumeEvent extends ActionEvent
|
||||
return $this->isValid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
namespace Thelia\Core\Event\Coupon;
|
||||
use Thelia\Core\Event\ActionEvent;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
/**
|
||||
@@ -39,8 +39,8 @@ use Thelia\Model\Coupon;
|
||||
*/
|
||||
class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
{
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
/** @var ConditionCollection Array of ConditionManagerInterface */
|
||||
protected $conditions = null;
|
||||
|
||||
/** @var string Coupon code (ex: XMAS) */
|
||||
protected $code = null;
|
||||
@@ -78,8 +78,8 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
/** @var Coupon Coupon model */
|
||||
protected $coupon = null;
|
||||
|
||||
/** @var string Coupon effect */
|
||||
protected $effect;
|
||||
/** @var string Coupon type */
|
||||
protected $type;
|
||||
|
||||
/** @var string Language code ISO (ex: fr_FR) */
|
||||
protected $locale = null;
|
||||
@@ -87,37 +87,24 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon title
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
* @param string $effect Coupon effect
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param boolean $isEnabled Enable/Disable
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||
* @param boolean $isCumulative Is cumulative
|
||||
* @param boolean $isRemovingPostage Is removing Postage
|
||||
* @param int $maxUsage Coupon quantity
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon title
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
* @param string $type Coupon type
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
* @param bool $isEnabled Enable/Disable
|
||||
* @param \DateTime $expirationDate Coupon expiration date
|
||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||
* @param boolean $isCumulative Is cumulative
|
||||
* @param boolean $isRemovingPostage Is removing Postage
|
||||
* @param int $maxUsage Coupon quantity
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
*/
|
||||
public function __construct(
|
||||
$code,
|
||||
$title,
|
||||
$amount,
|
||||
$effect,
|
||||
$shortDescription,
|
||||
$description,
|
||||
$isEnabled,
|
||||
\DateTime $expirationDate,
|
||||
$isAvailableOnSpecialOffers,
|
||||
$isCumulative,
|
||||
$isRemovingPostage,
|
||||
$maxUsage,
|
||||
$rules,
|
||||
$locale
|
||||
) {
|
||||
$code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
|
||||
)
|
||||
{
|
||||
$this->amount = $amount;
|
||||
$this->code = $code;
|
||||
$this->description = $description;
|
||||
@@ -127,10 +114,9 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
$this->isEnabled = $isEnabled;
|
||||
$this->isRemovingPostage = $isRemovingPostage;
|
||||
$this->maxUsage = $maxUsage;
|
||||
$this->rules = $rules;
|
||||
$this->shortDescription = $shortDescription;
|
||||
$this->title = $title;
|
||||
$this->effect = $effect;
|
||||
$this->type = $type;
|
||||
$this->locale = $locale;
|
||||
}
|
||||
|
||||
@@ -206,22 +192,6 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection
|
||||
*/
|
||||
public function getRules()
|
||||
{
|
||||
if ($this->rules === null || !is_object($this->rules)) {
|
||||
$rules = $this->rules;
|
||||
} else {
|
||||
$rules = clone $this->rules;
|
||||
}
|
||||
|
||||
return $rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
*
|
||||
@@ -264,13 +234,13 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Coupon effect
|
||||
* Get Coupon type (effect)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getEffect()
|
||||
public function getType()
|
||||
{
|
||||
return $this->effect;
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -307,4 +277,28 @@ class CouponCreateOrUpdateEvent extends ActionEvent
|
||||
return $this->coupon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rules
|
||||
*
|
||||
* @return null|ConditionCollection Array of ConditionManagerInterface
|
||||
*/
|
||||
public function getConditions()
|
||||
{
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* set Rules
|
||||
*
|
||||
* @param ConditionCollection $rules Array of ConditionManagerInterface
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConditions(ConditionCollection $rules)
|
||||
{
|
||||
$this->conditions = $rules;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -428,19 +428,19 @@ final class TheliaEvents
|
||||
const AFTER_CONSUME_COUPON = "action.after_consume_coupon";
|
||||
|
||||
/**
|
||||
* Sent when attempting to update Coupon Rule
|
||||
* Sent when attempting to update Coupon Condition
|
||||
*/
|
||||
const COUPON_RULE_UPDATE = "action.update_coupon_rule";
|
||||
const COUPON_CONDITION_UPDATE = "action.update_coupon_condition";
|
||||
|
||||
/**
|
||||
* Sent just before an attempt to update a Coupon Rule
|
||||
* Sent just before an attempt to update a Coupon Condition
|
||||
*/
|
||||
const BEFORE_COUPON_RULE_UPDATE = "action.before_update_coupon_rule";
|
||||
const BEFORE_COUPON_CONDITION_UPDATE = "action.before_update_coupon_condition";
|
||||
|
||||
/**
|
||||
* Sent just after an attempt to update a Coupon Rule
|
||||
* Sent just after an attempt to update a Coupon Condition
|
||||
*/
|
||||
const AFTER_COUPON_RULE_UPDATE = "action.after_update_coupon_rule";
|
||||
const AFTER_COUPON_CONDITION_UPDATE = "action.after_update_coupon_condition";
|
||||
|
||||
// -- Configuration management ---------------------------------------------
|
||||
|
||||
|
||||
@@ -25,19 +25,17 @@ 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;
|
||||
use Thelia\Core\Template\Element\LoopResultRow;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Core\Template\Loop\Argument\Argument;
|
||||
|
||||
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Model\Coupon as MCoupon;
|
||||
use Thelia\Model\CouponQuery;
|
||||
use Thelia\Type;
|
||||
use Thelia\Type\BooleanOrBothType;
|
||||
|
||||
@@ -63,14 +61,14 @@ class Coupon extends BaseI18nLoop
|
||||
{
|
||||
return new ArgumentCollection(
|
||||
Argument::createIntListTypeArgument('id'),
|
||||
Argument::createBooleanOrBothTypeArgument('is_enabled', 1)
|
||||
Argument::createBooleanOrBothTypeArgument('is_enabled')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute Loop
|
||||
*
|
||||
* @param PropelModelPager $pagination
|
||||
* @param PropelModelPager $pagination Pagination manager
|
||||
*
|
||||
* @return \Thelia\Core\Template\Element\LoopResult
|
||||
*/
|
||||
@@ -88,16 +86,16 @@ class Coupon extends BaseI18nLoop
|
||||
$search->filterById($id, Criteria::IN);
|
||||
}
|
||||
|
||||
if ($isEnabled != BooleanOrBothType::ANY) {
|
||||
$search->filterByIsEnabled($isEnabled ? 1 : 0);
|
||||
if (isset($isEnabled)) {
|
||||
$search->filterByIsEnabled($isEnabled ? true : false);
|
||||
}
|
||||
|
||||
// Perform search
|
||||
$coupons = $this->search($search, $pagination);
|
||||
|
||||
$loopResult = new LoopResult();
|
||||
/** @var ConstraintFactory $constraintFactory */
|
||||
$constraintFactory = $this->container->get('thelia.constraint.factory');
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
|
||||
/** @var Request $request */
|
||||
$request = $this->container->get('request');
|
||||
@@ -107,8 +105,8 @@ class Coupon extends BaseI18nLoop
|
||||
/** @var MCoupon $coupon */
|
||||
foreach ($coupons as $coupon) {
|
||||
$loopResultRow = new LoopResultRow();
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$coupon->getSerializedRules()
|
||||
$conditions = $conditionFactory->unserializeConditionCollection(
|
||||
$coupon->getSerializedConditions()
|
||||
);
|
||||
|
||||
/** @var CouponInterface $couponManager */
|
||||
@@ -132,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'))
|
||||
@@ -151,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());
|
||||
|
||||
@@ -27,6 +27,8 @@ use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
use Thelia\Model\Coupon;
|
||||
|
||||
@@ -35,13 +37,13 @@ use Thelia\Model\Coupon;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow a CouponManager class to be fed with relevant Thelia data
|
||||
* Allow to assist in getting relevant data on the current application state
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface CouponAdapterInterface
|
||||
interface AdapterInterface
|
||||
{
|
||||
|
||||
/**
|
||||
@@ -163,10 +165,17 @@ interface CouponAdapterInterface
|
||||
public function getRequest();
|
||||
|
||||
/**
|
||||
* Return Constraint Validator
|
||||
* Return Condition Evaluator
|
||||
*
|
||||
* @return ConstraintValidator
|
||||
* @return ConditionEvaluator
|
||||
*/
|
||||
public function getConstraintValidator();
|
||||
public function getConditionEvaluator();
|
||||
|
||||
/**
|
||||
* Return all available currencies
|
||||
*
|
||||
* @return array of Currency
|
||||
*/
|
||||
public function getAvailableCurrencies();
|
||||
|
||||
}
|
||||
@@ -27,26 +27,27 @@ use Symfony\Component\DependencyInjection\Container;
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Symfony\Component\Translation\Translator;
|
||||
use Symfony\Component\Translation\TranslatorInterface;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
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;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Allow to assist in getting relevant data on the current application state
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
* @todo implements
|
||||
*
|
||||
*/
|
||||
class CouponBaseAdapter implements CouponAdapterInterface
|
||||
class BaseAdapter implements AdapterInterface
|
||||
{
|
||||
use CartTrait {
|
||||
CartTrait::getCart as getCartFromTrait;
|
||||
@@ -260,11 +261,24 @@ class CouponBaseAdapter implements CouponAdapterInterface
|
||||
/**
|
||||
* Return Constraint Validator
|
||||
*
|
||||
* @return ConstraintValidator
|
||||
* @return ConditionValidator
|
||||
*/
|
||||
public function getConstraintValidator()
|
||||
public function getConditionEvaluator()
|
||||
{
|
||||
return $this->container->get('thelia.constraint.validator');
|
||||
return $this->container->get('thelia.condition.validator');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return all available currencies
|
||||
*
|
||||
* @return array of Currency
|
||||
*/
|
||||
public function getAvailableCurrencies()
|
||||
{
|
||||
$currencies = CurrencyQuery::create();
|
||||
|
||||
return $currencies->find();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -24,6 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Constraint\Rule\SerializableRule;
|
||||
|
||||
@@ -32,70 +33,62 @@ use Thelia\Constraint\Rule\SerializableRule;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Manage a set of CouponRuleInterface
|
||||
* Manage a set of ConditionManagerInterface
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponRuleCollection
|
||||
class ConditionCollection
|
||||
{
|
||||
/** @var array Array of CouponRuleInterface */
|
||||
protected $rules = array();
|
||||
/** @var array Array of ConditionManagerInterface */
|
||||
protected $conditions = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* Get Conditions
|
||||
*
|
||||
* @return array Array of ConditionManagerInterface
|
||||
*/
|
||||
function __construct()
|
||||
public function getConditions()
|
||||
{
|
||||
|
||||
return $this->conditions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rules
|
||||
* Add a ConditionManagerInterface to the Collection
|
||||
*
|
||||
* @return array Array of CouponRuleInterface
|
||||
*/
|
||||
public function getRules()
|
||||
{
|
||||
return $this->rules;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a CouponRuleInterface to the Collection
|
||||
*
|
||||
* @param CouponRuleInterface $rule Rule
|
||||
* @param ConditionManagerInterface $condition Condition
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function add(CouponRuleInterface $rule)
|
||||
public function add(ConditionManagerInterface $condition)
|
||||
{
|
||||
$this->rules[] = $rule;
|
||||
$this->conditions[] = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if there is at least one rule in the collection
|
||||
* Check if there is at least one condition in the collection
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
{
|
||||
return (empty($this->rules));
|
||||
return (empty($this->conditions));
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow to compare 2 set of rules
|
||||
* Allow to compare 2 set of conditions
|
||||
*
|
||||
* @return string Jsoned data
|
||||
*/
|
||||
public function __toString()
|
||||
{
|
||||
$arrayToSerialize = array();
|
||||
/** @var CouponRuleInterface $rule */
|
||||
foreach ($this->getRules() as $rule) {
|
||||
$arrayToSerialize[] = $rule->getSerializableRule();
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
foreach ($this->getConditions() as $condition) {
|
||||
$arrayToSerialize[] = $condition->getSerializableCondition();
|
||||
}
|
||||
|
||||
return json_encode($arrayToSerialize);
|
||||
@@ -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.
|
||||
@@ -49,7 +47,7 @@ class CouponFactory
|
||||
/** @var ContainerInterface Service Container */
|
||||
protected $container = null;
|
||||
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia*/
|
||||
/** @var AdapterInterface Provide necessary value from Thelia*/
|
||||
protected $adapter;
|
||||
|
||||
/**
|
||||
@@ -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.constraint.factory');
|
||||
$rules = $constraintFactory->unserializeCouponRuleCollection(
|
||||
$model->getSerializedRules()
|
||||
/** @var ConditionFactory $conditionFactory */
|
||||
$conditionFactory = $this->container->get('thelia.condition.factory');
|
||||
$conditions = $conditionFactory->unserializeConditionCollection(
|
||||
$model->getSerializedConditions()
|
||||
);
|
||||
|
||||
$couponManager->setRules($rules);
|
||||
$couponManager->setConditions($conditions);
|
||||
|
||||
return $couponManager;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Condition\ConditionManagerInterface;
|
||||
use Thelia\Coupon\Type\CouponInterface;
|
||||
|
||||
/**
|
||||
@@ -40,7 +40,7 @@ use Thelia\Coupon\Type\CouponInterface;
|
||||
*/
|
||||
class CouponManager
|
||||
{
|
||||
/** @var CouponAdapterInterface Provides necessary value from Thelia */
|
||||
/** @var AdapterInterface Provides necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var ContainerInterface Service Container */
|
||||
@@ -52,15 +52,15 @@ class CouponManager
|
||||
/** @var array Available Coupons (Services) */
|
||||
protected $availableCoupons = array();
|
||||
|
||||
/** @var array Available Rules (Services) */
|
||||
protected $availableRules = array();
|
||||
/** @var array Available Conditions (Services) */
|
||||
protected $availableConditions = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param ContainerInterface $container Service container
|
||||
*/
|
||||
function __construct(ContainerInterface $container)
|
||||
public function __construct(ContainerInterface $container)
|
||||
{
|
||||
$this->container = $container;
|
||||
$this->adapter = $container->get('thelia.adapter');
|
||||
@@ -191,29 +191,29 @@ class CouponManager
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a CouponRuleInterface from data coming from a form
|
||||
* Build a ConditionManagerInterface from data coming from a form
|
||||
*
|
||||
* @param string $ruleServiceId Rule service id you want to instantiate
|
||||
* @param array $operators Rule Operator set by the Admin
|
||||
* @param array $values Rule Values set by the Admin
|
||||
* @param string $conditionServiceId Condition service id you want to instantiate
|
||||
* @param array $operators Condition Operator set by the Admin
|
||||
* @param array $values Condition Values set by the Admin
|
||||
*
|
||||
* @return CouponRuleInterface
|
||||
* @return ConditionManagerInterface
|
||||
*/
|
||||
public function buildRuleFromForm($ruleServiceId, array $operators, array $values)
|
||||
public function buildRuleFromForm($conditionServiceId, array $operators, array $values)
|
||||
{
|
||||
$rule = false;
|
||||
$condition = false;
|
||||
try {
|
||||
|
||||
if ($this->container->has($ruleServiceId)) {
|
||||
/** @var CouponRuleInterface $rule */
|
||||
$rule = $this->container->get($ruleServiceId);
|
||||
$rule->populateFromForm($operators, $values);
|
||||
if ($this->container->has($conditionServiceId)) {
|
||||
/** @var ConditionManagerInterface $condition */
|
||||
$condition = $this->container->get($conditionServiceId);
|
||||
$condition->populateFromForm($operators, $values);
|
||||
}
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
|
||||
}
|
||||
|
||||
return $rule;
|
||||
return $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -239,11 +239,11 @@ class CouponManager
|
||||
/**
|
||||
* Add an available ConstraintManager (Services)
|
||||
*
|
||||
* @param CouponRuleInterface $rule CouponRuleInterface
|
||||
* @param ConditionManagerInterface $condition ConditionManagerInterface
|
||||
*/
|
||||
public function addAvailableRule(CouponRuleInterface $rule)
|
||||
public function addAvailableRule(ConditionManagerInterface $condition)
|
||||
{
|
||||
$this->availableRules[] = $rule;
|
||||
$this->availableConditions[] = $condition;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -251,8 +251,8 @@ class CouponManager
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAvailableRules()
|
||||
public function getAvailableConditions()
|
||||
{
|
||||
return $this->availableRules;
|
||||
return $this->availableConditions;
|
||||
}
|
||||
}
|
||||
@@ -30,20 +30,20 @@ namespace Thelia\Coupon;
|
||||
*
|
||||
* Manage how Coupons could interact with a Checkout
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RuleOrganizer implements RuleOrganizerInterface
|
||||
{
|
||||
/**
|
||||
* Organize CouponRuleInterface
|
||||
* Organize ConditionManagerInterface
|
||||
*
|
||||
* @param array $rules Array of CouponRuleInterface
|
||||
* @param array $conditions Array of ConditionManagerInterface
|
||||
*
|
||||
* @return array Array of CouponRuleInterface sorted
|
||||
* @return array Array of ConditionManagerInterface sorted
|
||||
*/
|
||||
public function organize(array $rules)
|
||||
public function organize(array $conditions)
|
||||
{
|
||||
// TODO: Implement organize() method.
|
||||
}
|
||||
|
||||
@@ -28,20 +28,20 @@ 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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
interface RuleOrganizerInterface
|
||||
{
|
||||
/**
|
||||
* Organize CouponRuleInterface
|
||||
* Organize ConditionManagerInterface
|
||||
*
|
||||
* @param array $rules Array of CouponRuleInterface
|
||||
* @param array $conditions Array of ConditionManagerInterface
|
||||
*
|
||||
* @return array Array of CouponRuleInterface sorted
|
||||
* @return array Array of ConditionManagerInterface sorted
|
||||
*/
|
||||
public function organize(array $rules);
|
||||
public function organize(array $conditions);
|
||||
}
|
||||
@@ -24,13 +24,12 @@
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Core\Translation\Translator;
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Coupon\RuleOrganizerInterface;
|
||||
use Thelia\Exception\InvalidRuleException;
|
||||
use Thelia\Exception\InvalidConditionException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -45,7 +44,7 @@ use Thelia\Exception\InvalidRuleException;
|
||||
*/
|
||||
abstract class CouponAbstract implements CouponInterface
|
||||
{
|
||||
/** @var CouponAdapterInterface Provide necessary value from Thelia */
|
||||
/** @var AdapterInterface Provide necessary value from Thelia */
|
||||
protected $adapter = null;
|
||||
|
||||
/** @var Translator Service Translator */
|
||||
@@ -54,12 +53,11 @@ abstract class CouponAbstract implements CouponInterface
|
||||
/** @var RuleOrganizerInterface */
|
||||
protected $organizer = null;
|
||||
|
||||
/** @var CouponRuleCollection Array of CouponRuleInterface */
|
||||
protected $rules = null;
|
||||
|
||||
/** @var ConstraintValidator Constraint validator */
|
||||
protected $constraintValidator = null;
|
||||
/** @var ConditionCollection Array of ConditionManagerInterface */
|
||||
protected $conditions = null;
|
||||
|
||||
/** @var ConditionEvaluator Condition validator */
|
||||
protected $conditionEvaluator = null;
|
||||
|
||||
|
||||
/** @var string Service Id */
|
||||
@@ -106,19 +104,19 @@ abstract class CouponAbstract implements CouponInterface
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param CouponAdapterInterface $adapter Service adapter
|
||||
* @param AdapterInterface $adapter Service adapter
|
||||
*/
|
||||
function __construct(CouponAdapterInterface $adapter)
|
||||
public function __construct(AdapterInterface $adapter)
|
||||
{
|
||||
$this->adapter = $adapter;
|
||||
$this->translator = $adapter->getTranslator();
|
||||
$this->constraintValidator = $adapter->getConstraintValidator();
|
||||
$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
|
||||
*/
|
||||
@@ -205,25 +203,25 @@ abstract class CouponAbstract implements CouponInterface
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection
|
||||
* @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 CouponRuleCollection $rules CouponRuleInterface to add
|
||||
* @param ConditionCollection $conditions ConditionManagerInterface to add
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
* @throws \Thelia\Exception\InvalidConditionException
|
||||
*/
|
||||
public function setRules(CouponRuleCollection $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)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
@@ -140,20 +140,20 @@ interface CouponInterface
|
||||
/**
|
||||
* Return condition to validate the Coupon or not
|
||||
*
|
||||
* @return CouponRuleCollection A set of CouponRuleInterface
|
||||
* @return ConditionCollection A set of ConditionManagerInterface
|
||||
*/
|
||||
public function getRules();
|
||||
public function getConditions();
|
||||
|
||||
/**
|
||||
* Replace the existing Rules by those given in parameter
|
||||
* If one Rule is badly implemented, no Rule will be added
|
||||
*
|
||||
* @param CouponRuleCollection $rules CouponRuleInterface to add
|
||||
* @param ConditionCollection $rules ConditionManagerInterface to add
|
||||
*
|
||||
* @return $this
|
||||
* @throws \Thelia\Exception\InvalidRuleException
|
||||
* @throws \Thelia\Exception\InvalidConditionException
|
||||
*/
|
||||
public function setRules(CouponRuleCollection $rules);
|
||||
public function setConditions(ConditionCollection $rules);
|
||||
|
||||
/**
|
||||
* Return Coupon expiration date
|
||||
@@ -209,7 +209,7 @@ interface CouponInterface
|
||||
|
||||
/**
|
||||
* Check if the current Coupon is matching its conditions (Rules)
|
||||
* Thelia variables are given by the CouponAdapterInterface
|
||||
* Thelia variables are given by the AdapterInterface
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Thelia\Constraint\ConstraintManager;
|
||||
use Thelia\Coupon\Type\CouponAbstract;
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,6 @@
|
||||
|
||||
namespace Thelia\Coupon\Type;
|
||||
|
||||
use Thelia\Coupon\CouponAdapterInterface;
|
||||
use Thelia\Coupon\Type\CouponAbstract;
|
||||
use Thelia\Exception\MissingAdapterException;
|
||||
|
||||
|
||||
@@ -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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleException extends \RuntimeException
|
||||
class InvalidConditionException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleOperatorException 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);
|
||||
@@ -30,24 +30,23 @@ use Thelia\Log\Tlog;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
* Thrown when a Condition receive an invalid Operator
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleValueException extends \RuntimeException
|
||||
class InvalidConditionOperatorException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleValueException thrown when a Rule is given a bad Parameter
|
||||
* InvalidConditionOperatorException thrown when a Condition is given a bad Operator
|
||||
*
|
||||
* @param string $className Class name
|
||||
* @param string $parameter array key parameter
|
||||
*/
|
||||
public function __construct($className, $parameter)
|
||||
{
|
||||
|
||||
$message = 'Invalid Parameter for Rule ' . $className . ' on parameter ' . $parameter;
|
||||
$message = 'Invalid Operator for Condition ' . $className . ' on parameter ' . $parameter;
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message);
|
||||
@@ -30,16 +30,16 @@ use Thelia\Log\Tlog;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Operator
|
||||
* Thrown when a Condition receives an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class InvalidRuleOperatorException extends \RuntimeException
|
||||
class InvalidConditionValueException extends \RuntimeException
|
||||
{
|
||||
/**
|
||||
* InvalidRuleOperatorException thrown when a Rule is given a bad Operator
|
||||
* InvalidConditionValueException thrown when a Condition is given a bad Parameter
|
||||
*
|
||||
* @param string $className Class name
|
||||
* @param string $parameter array key parameter
|
||||
@@ -47,7 +47,7 @@ class InvalidRuleOperatorException extends \RuntimeException
|
||||
public function __construct($className, $parameter)
|
||||
{
|
||||
|
||||
$message = 'Invalid Operator for Rule ' . $className . ' on parameter ' . $parameter;
|
||||
$message = 'Invalid Parameter for Condition ' . $className . ' on parameter ' . $parameter;
|
||||
Tlog::getInstance()->addError($message);
|
||||
|
||||
parent::__construct($message);
|
||||
@@ -87,7 +87,7 @@ class CouponCreationForm extends BaseForm
|
||||
)
|
||||
)
|
||||
->add(
|
||||
'effect',
|
||||
'type',
|
||||
'text',
|
||||
array(
|
||||
'constraints' => array(
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Thelia\Model;
|
||||
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Constraint\Rule\CouponRuleInterface;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Model\Base\Coupon as BaseCoupon;
|
||||
use Thelia\Model\Map\CouponTableMap;
|
||||
|
||||
@@ -54,7 +54,7 @@ class Coupon extends BaseCoupon
|
||||
* @param string $code Coupon Code
|
||||
* @param string $title Coupon title
|
||||
* @param float $amount Amount removed from the Total Checkout
|
||||
* @param string $effect Coupon effect
|
||||
* @param string $type Coupon type
|
||||
* @param bool $isRemovingPostage Is removing Postage
|
||||
* @param string $shortDescription Coupon short description
|
||||
* @param string $description Coupon description
|
||||
@@ -63,17 +63,18 @@ class Coupon extends BaseCoupon
|
||||
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
|
||||
* @param boolean $isCumulative Is cumulative
|
||||
* @param int $maxUsage Coupon quantity
|
||||
* @param string $defaultSerializedRule Serialized default rule added if none found
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
function createOrUpdate($code, $title, $amount, $effect, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $locale = null)
|
||||
function createOrUpdate($code, $title, $amount, $type, $isRemovingPostage, $shortDescription, $description, $isEnabled, $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $maxUsage, $defaultSerializedRule, $locale = null)
|
||||
{
|
||||
$this->setCode($code)
|
||||
->setTitle($title)
|
||||
->setShortDescription($shortDescription)
|
||||
->setDescription($description)
|
||||
->setType($effect)
|
||||
->setType($type)
|
||||
->setAmount($amount)
|
||||
->setIsRemovingPostage($isRemovingPostage)
|
||||
->setIsEnabled($isEnabled)
|
||||
@@ -82,6 +83,11 @@ class Coupon extends BaseCoupon
|
||||
->setIsCumulative($isCumulative)
|
||||
->setMaxUsage($maxUsage);
|
||||
|
||||
// If no rule given, set default rule
|
||||
if (null === $this->getSerializedConditions()) {
|
||||
$this->setSerializedConditions($defaultSerializedRule);
|
||||
}
|
||||
|
||||
// Set object language (i18n)
|
||||
if (!is_null($locale)) {
|
||||
$this->setLocale($locale);
|
||||
@@ -100,16 +106,16 @@ class Coupon extends BaseCoupon
|
||||
}
|
||||
|
||||
/**
|
||||
* Create or Update this coupon rule
|
||||
* Create or Update this coupon condition
|
||||
*
|
||||
* @param string $serializableRules Serialized rules ready to be saved
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
* @param string $serializableConditions Serialized conditions ready to be saved
|
||||
* @param string $locale Coupon Language code ISO (ex: fr_FR)
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
function createOrUpdateRules($serializableRules, $locale)
|
||||
public function createOrUpdateConditions($serializableConditions, $locale)
|
||||
{
|
||||
$this->setSerializedRules($serializableRules);
|
||||
$this->setSerializedConditions($serializableConditions);
|
||||
|
||||
// Set object language (i18n)
|
||||
if (!is_null($locale)) {
|
||||
@@ -121,13 +127,9 @@ class Coupon extends BaseCoupon
|
||||
try {
|
||||
$this->save($con);
|
||||
$con->commit();
|
||||
|
||||
} catch(\Exception $e) {
|
||||
$con->rollback();
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
461
core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php
Normal file
461
core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php
Normal file
@@ -0,0 +1,461 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test ConditionEvaluator Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConditionEvaluatorTest 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()
|
||||
{
|
||||
}
|
||||
|
||||
public function testTestSuccess1Rules()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubMatchForTotalAmountManager->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($stubMatchForTotalAmountManager));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401.00));
|
||||
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => '>',
|
||||
MatchForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$isValid = $conditionEvaluator->isMatching($conditions);
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testTestFail1Rules()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubMatchForTotalAmountManager->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($stubMatchForTotalAmountManager));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400.00));
|
||||
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => '>',
|
||||
MatchForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$isValid = $conditionEvaluator->isMatching($conditions);
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions');
|
||||
}
|
||||
|
||||
public function testTestSuccess2Rules()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubMatchForTotalAmountManager->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($stubMatchForTotalAmountManager));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(5));
|
||||
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => '>',
|
||||
MatchForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$condition2 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => '>'
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$condition2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
$conditions->add($condition2);
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$isValid = $conditionEvaluator->isMatching($conditions);
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testTestFail2Rules()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubMatchForTotalAmountManager = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForTotalAmountManager')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubMatchForTotalAmountManager->expects($this->any())
|
||||
->method('isMatching')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($stubMatchForTotalAmountManager));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(5));
|
||||
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => '>',
|
||||
MatchForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 400.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$condition2 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => '>'
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$condition2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
$conditions->add($condition2);
|
||||
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$isValid = $conditionEvaluator->isMatching($conditions);
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions');
|
||||
}
|
||||
|
||||
public function testVariableOpComparisonSuccess()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = true;
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
public function testVariableOpComparisonFail()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = false;
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testVariableOpComparisonException()
|
||||
{
|
||||
$conditionEvaluator = new ConditionEvaluator();
|
||||
$expected = true;
|
||||
$actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1);
|
||||
$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()
|
||||
{
|
||||
}
|
||||
}
|
||||
403
core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php
Normal file
403
core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php
Normal file
@@ -0,0 +1,403 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\ConditionFactory;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Coupon\ConditionCollection;
|
||||
use Thelia\Model\CurrencyQuery;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test ConditionFactory Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
|
||||
$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($stubContainer);
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValueMap(array('unset.service', false)));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$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($stubContainer);
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue(new MatchForTotalAmountManager($stubAdapter)));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
$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($stubContainer);
|
||||
|
||||
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
|
||||
$unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
|
||||
|
||||
$expected = (string) $conditions;
|
||||
$actual = (string) $unserializedConditions;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputs()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = $condition1->getValidators();
|
||||
$actual = $conditionFactory->getInputs('thelia.condition.match_for_x_articles');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputsFalse()
|
||||
{
|
||||
$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));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = false;
|
||||
$actual = $conditionFactory->getInputs('thelia.condition.unknown');
|
||||
|
||||
$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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 MatchForEveryoneManager Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForEveryoneManagerTest 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::setValidators
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInputOperator()
|
||||
{
|
||||
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$condition1 = new MatchForEveryoneManager($stubAdapter);
|
||||
$operators = array();
|
||||
$values = array();
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if condition is always matching
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testIsMatching()
|
||||
{
|
||||
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$condition1 = new MatchForEveryoneManager($stubAdapter);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual = $isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,610 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,670 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Condition\SerializableCondition;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test MatchForXArticlesManager Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForXArticlesManagerTest 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()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @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('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::IN
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\MatchForXArticlesManager::setValidators
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 'X'
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferior()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferior()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4,
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 5,
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals2()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferiorEquals()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleEqual()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals2()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperiorEquals()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\MatchForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperior()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $condition1->getSerializableCondition();
|
||||
|
||||
$expected = new SerializableCondition();
|
||||
$expected->conditionServiceId = $condition1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
public function testGetAvailableOperators()
|
||||
{
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
MatchForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$expected = array(
|
||||
MatchForXArticlesManager::INPUT1 => array(
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
)
|
||||
);
|
||||
$actual = $condition1->getAvailableOperators();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
// public function testGetValidators()
|
||||
// {
|
||||
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
// ->disableOriginalConstructor()
|
||||
// ->getMock();
|
||||
//
|
||||
// $stubAdapter->expects($this->any())
|
||||
// ->method('getNbArticlesInCart')
|
||||
// ->will($this->returnValue(4));
|
||||
//
|
||||
// $condition1 = new MatchForXArticlesManager($stubAdapter);
|
||||
// $operators = array(
|
||||
// MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
// );
|
||||
// $values = array(
|
||||
// MatchForXArticlesManager::INPUT1 => 4
|
||||
// );
|
||||
// $condition1->setValidatorsFromForm($operators, $values);
|
||||
//
|
||||
// $expected = array(
|
||||
// $operators,
|
||||
// $values
|
||||
// );
|
||||
// $actual = $condition1->getValidators();
|
||||
//
|
||||
// $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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
114
core/lib/Thelia/Tests/Condition/OperatorsTest.php
Normal file
114
core/lib/Thelia/Tests/Condition/OperatorsTest.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,228 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponBaseAdapter;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test ConstraintManager Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class 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 CouponRuleCollection();
|
||||
$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 CouponBaseAdapter($container);
|
||||
|
||||
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
|
||||
$container->set('thelia.constraint.rule.available_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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,346 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Constraint;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Coupon\CouponBaseAdapter;
|
||||
use Thelia\Coupon\CouponRuleCollection;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test ConstraintValidator Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class ConstraintValidatorTest 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()
|
||||
{
|
||||
}
|
||||
|
||||
public function testTestSuccess1Rules()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue($ConstraintValidator));
|
||||
|
||||
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => '>',
|
||||
AvailableForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
|
||||
$isValid = $ConstraintValidator->isMatching($rules);
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testTestFail1Rules()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue($ConstraintValidator));
|
||||
|
||||
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => '>',
|
||||
AvailableForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
|
||||
$isValid = $ConstraintValidator->isMatching($rules);
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules');
|
||||
}
|
||||
|
||||
public function testTestSuccess2Rules()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(5));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue($ConstraintValidator));
|
||||
|
||||
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => '>',
|
||||
AvailableForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rule2 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => '>'
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$rule2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
$rules->add($rule2);
|
||||
|
||||
$isValid = $ConstraintValidator->isMatching($rules);
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testTestFail2Rules()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(5));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue($ConstraintValidator));
|
||||
|
||||
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => '>',
|
||||
AvailableForTotalAmountManager::INPUT2 => '=='
|
||||
);
|
||||
$values = array(
|
||||
AvailableForTotalAmountManager::INPUT1 => 400.00,
|
||||
AvailableForTotalAmountManager::INPUT2 => 'EUR');
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rule2 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => '>'
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$rule2->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$rules = new CouponRuleCollection();
|
||||
$rules->add($rule1);
|
||||
$rules->add($rule2);
|
||||
|
||||
$isValid = $ConstraintValidator->isMatching($rules);
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules');
|
||||
}
|
||||
|
||||
public function testVariableOpComparisonSuccess()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$expected = true;
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
public function testVariableOpComparisonFail()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$expected = false;
|
||||
$actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(2, Operators::DIFFERENT, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(0, Operators::SUPERIOR, 0);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(3, Operators::INFERIOR, 2);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$actual = $ConstraintValidator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Exception
|
||||
*/
|
||||
public function testVariableOpComparisonException()
|
||||
{
|
||||
$ConstraintValidator = new ConstraintValidator();
|
||||
$expected = true;
|
||||
$actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1);
|
||||
$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 CouponBaseAdapter($container);
|
||||
|
||||
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
|
||||
$container->set('thelia.constraint.rule.available_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()
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,709 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test AvailableForTotalAmount Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var CouponAdapterInterface $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 CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Generate valid CouponBaseAdapter
|
||||
// *
|
||||
// * @param float $cartTotalPrice Total amount of the current Cart
|
||||
// *
|
||||
// * @return CouponAdapterInterface
|
||||
// */
|
||||
// protected function generateValidCouponBaseAdapterMock($cartTotalPrice = 421.23)
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $stubTheliaAdapter = $this->getMock(
|
||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
||||
// array('getCartTotalPrice'),
|
||||
// array()
|
||||
// );
|
||||
// $stubTheliaAdapter->expects($this->any())
|
||||
// ->method('getCartTotalPrice')
|
||||
// ->will($this->returnValue($cartTotalPrice));
|
||||
//
|
||||
// return $stubTheliaAdapter;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
// *
|
||||
// */
|
||||
// public function testValidBackOfficeInput()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
// Operators::SUPERIOR,
|
||||
// new PriceParam(
|
||||
// $adapter, 421.23, 'EUR'
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
//
|
||||
// $expected = true;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
// * @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
||||
// *
|
||||
// */
|
||||
// public function testInValidBackOfficeInputOperator()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
// 'X',
|
||||
// new PriceParam(
|
||||
// $adapter, 421.23, 'EUR'
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
//
|
||||
// $expected = false;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
// * @expectedException \ErrorException
|
||||
// *
|
||||
// */
|
||||
// public function testInValidBackOfficeInputValue()
|
||||
// {
|
||||
// $adapter = $this->generateValidCouponBaseAdapterMock();
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
// Operators::SUPERIOR,
|
||||
// 421
|
||||
// )
|
||||
// );
|
||||
//
|
||||
// $rule = new AvailableForTotalAmount($adapter, $validators);
|
||||
//
|
||||
// $expected = false;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferior()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(399));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(399));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(399));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(399.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(401));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(399.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue(400.00));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue('EUR'));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,710 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Constraint\ConstraintValidator;
|
||||
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
|
||||
use Thelia\Constraint\Rule\Operators;
|
||||
use Thelia\Constraint\Rule\SerializableRule;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test AvailableForXArticles Class
|
||||
*
|
||||
* @package Constraint
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
// /** @var CouponAdapterInterface $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 CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Generate valid CouponBaseAdapter
|
||||
// *
|
||||
// * @param int $nbArticlesInCart Total articles in the current Cart
|
||||
// *
|
||||
// * @return CouponAdapterInterface
|
||||
// */
|
||||
// protected function generateValidCouponBaseAdapterMock($nbArticlesInCart = 4)
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $stubTheliaAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
// ->disableOriginalConstructor()
|
||||
// ->setMethods(array('getNbArticlesInCart'))
|
||||
// ->getMock();
|
||||
// $stubTheliaAdapter->expects($this->any())
|
||||
// ->method('getNbArticlesInCart')
|
||||
// ->will($this->returnValue($nbArticlesInCart));
|
||||
//
|
||||
// return $stubTheliaAdapter;
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
// *
|
||||
// */
|
||||
// public function testValidBackOfficeInput()
|
||||
// {
|
||||
// $translator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
// ->disableOriginalConstructor()
|
||||
// ->getMock();
|
||||
//
|
||||
// $rule = new AvailableForXArticles($translator);
|
||||
// $operators = array(AvailableForXArticles::PARAM1_QUANTITY => Operators::SUPERIOR);
|
||||
// $values = array(
|
||||
// AvailableForXArticles::PARAM1_QUANTITY => 4
|
||||
// );
|
||||
// $rule->populateFromForm($operators, $values);
|
||||
//
|
||||
// $expected = true;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
// * @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
// */
|
||||
// public function testInValidBackOfficeInputFloat()
|
||||
// {
|
||||
// $adapter = $this->stubTheliaAdapter;
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
|
||||
// Operators::SUPERIOR,
|
||||
// new QuantityParam(
|
||||
// $adapter,
|
||||
// 4.5
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rule = new AvailableForXArticles($adapter, $validators);
|
||||
//
|
||||
// $expected = false;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
// * @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
// */
|
||||
// public function testInValidBackOfficeInputNegative()
|
||||
// {
|
||||
// $adapter = $this->stubTheliaAdapter;
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
|
||||
// Operators::SUPERIOR,
|
||||
// new QuantityParam(
|
||||
// $adapter,
|
||||
// -1
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rule = new AvailableForXArticles($adapter, $validators);
|
||||
//
|
||||
// $expected = false;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * Check if validity test on BackOffice inputs are working
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
// * @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
// */
|
||||
// public function testInValidBackOfficeInputString()
|
||||
// {
|
||||
// $adapter = $this->stubTheliaAdapter;
|
||||
//
|
||||
// $validators = array(
|
||||
// AvailableForXArticles::PARAM1_QUANTITY => new RuleValidator(
|
||||
// Operators::SUPERIOR,
|
||||
// new QuantityParam(
|
||||
// $adapter,
|
||||
// 'bad'
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rule = new AvailableForXArticles($adapter, $validators);
|
||||
//
|
||||
// $expected = false;
|
||||
// $actual = $rule->checkBackOfficeInput();
|
||||
// $this->assertEquals($expected, $actual);
|
||||
// }
|
||||
|
||||
/**
|
||||
* Check if test inferior operator is working
|
||||
*
|
||||
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferior()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferior()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4,
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 5,
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleInferiorEquals2()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleInferiorEquals()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleEqual()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperiorEquals2()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperiorEquals()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 5
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 3
|
||||
);
|
||||
$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\AvailableForXArticlesManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperior()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $rule1->isMatching();
|
||||
|
||||
$expected = false;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
public function testGetSerializableRule()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$serializableRule = $rule1->getSerializableRule();
|
||||
|
||||
$expected = new SerializableRule();
|
||||
$expected->ruleServiceId = $rule1->getServiceId();
|
||||
$expected->operators = $operators;
|
||||
$expected->values = $values;
|
||||
|
||||
$actual = $serializableRule;
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
public function testGetAvailableOperators()
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getNbArticlesInCart')
|
||||
->will($this->returnValue(4));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConstraintValidator')
|
||||
->will($this->returnValue(new ConstraintValidator()));
|
||||
|
||||
$rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
$operators = array(
|
||||
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
);
|
||||
$values = array(
|
||||
AvailableForXArticlesManager::INPUT1 => 4
|
||||
);
|
||||
$rule1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$expected = array(
|
||||
AvailableForXArticlesManager::INPUT1 => array(
|
||||
Operators::INFERIOR,
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
Operators::EQUAL,
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
Operators::SUPERIOR
|
||||
)
|
||||
);
|
||||
$actual = $rule1->getAvailableOperators();
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
// public function testGetValidators()
|
||||
// {
|
||||
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
|
||||
// ->disableOriginalConstructor()
|
||||
// ->getMock();
|
||||
//
|
||||
// $stubAdapter->expects($this->any())
|
||||
// ->method('getNbArticlesInCart')
|
||||
// ->will($this->returnValue(4));
|
||||
//
|
||||
// $rule1 = new AvailableForXArticlesManager($stubAdapter);
|
||||
// $operators = array(
|
||||
// AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
|
||||
// );
|
||||
// $values = array(
|
||||
// AvailableForXArticlesManager::INPUT1 => 4
|
||||
// );
|
||||
// $rule1->setValidatorsFromForm($operators, $values);
|
||||
//
|
||||
// $expected = array(
|
||||
// $operators,
|
||||
// $values
|
||||
// );
|
||||
// $actual = $rule1->getValidators();
|
||||
//
|
||||
// $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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,427 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Constraint\Validator\QuantityParam;
|
||||
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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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.'
|
||||
);
|
||||
}
|
||||
|
||||
// /**
|
||||
// *
|
||||
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
// *
|
||||
// */
|
||||
// public function testOperatorInferiorValidBefore()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// // 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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,168 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponAdapterInterface $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 CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Generate valid CouponBaseAdapter
|
||||
// *
|
||||
// * @param int $customerId Customer id
|
||||
// *
|
||||
// * @return CouponAdapterInterface
|
||||
// */
|
||||
// protected function generateValidCouponBaseAdapterMock($customerId = 4521)
|
||||
// {
|
||||
// $customer = new Customer();
|
||||
// $customer->setId($customerId);
|
||||
// $customer->setFirstname('Firstname');
|
||||
// $customer->setLastname('Lastname');
|
||||
// $customer->setEmail('em@il.com');
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
// $stubTheliaAdapter = $this->getMock(
|
||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
||||
// 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 CouponBaseAdapter();
|
||||
//// $intValidator = 42;
|
||||
//// $intToValidate = -1;
|
||||
////
|
||||
//// $param = new QuantityParam($adapter, $intValidator);
|
||||
////
|
||||
//// $serialized = base64_encode(serialize($param));
|
||||
//// /** @var QuantityParam $unserialized */
|
||||
//// $unserialized = base64_decode(serialize($serialized));
|
||||
////
|
||||
//// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
//// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
////
|
||||
//// $new = new 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()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,158 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $dateValidator = new \DateTime("2012-07-08");
|
||||
//
|
||||
// $param = new DateParam($adapter, $dateValidator);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var DateParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getDateTime(), $unserialized->getDateTime());
|
||||
//
|
||||
// $new = new DateParam($adapter, $unserialized->getDateTime());
|
||||
// $this->assertEquals($param->getDateTime(), $new->getDateTime());
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,159 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $intValidator = 42;
|
||||
//
|
||||
// $param = new IntegerParam($adapter, $intValidator);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var IntegerParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
//
|
||||
// $new = new IntegerParam($adapter, $unserialized->getInteger());
|
||||
// $this->assertEquals($param->getInteger(), $new->getInteger());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,184 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $dateValidatorStart = new \DateTime("2012-07-08");
|
||||
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
//
|
||||
// $param = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var IntervalParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
//
|
||||
// $new = new IntervalParam($adapter, $unserialized->getStart(), $unserialized->getInterval());
|
||||
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,237 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
//
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $priceValidator = 42.50;
|
||||
//
|
||||
// $param = new PriceParam($adapter, $priceValidator, 'GBP');
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var PriceParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getPrice(), $unserialized->getPrice());
|
||||
// $this->assertEquals($param->getCurrency(), $unserialized->getCurrency());
|
||||
//
|
||||
// $new = new PriceParam($adapter, $unserialized->getPrice(), $unserialized->getCurrency());
|
||||
// $this->assertEquals($param->getPrice(), $new->getPrice());
|
||||
// $this->assertEquals($param->getCurrency(), $new->getCurrency());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,195 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $intValidator = 42;
|
||||
// $intToValidate = -1;
|
||||
//
|
||||
// $param = new QuantityParam($adapter, $intValidator);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var QuantityParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
|
||||
//
|
||||
// $new = new 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()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $startDateValidator = new \DateTime("2012-07-08");
|
||||
//
|
||||
// $param = new RepeatedDateParam($adapter);
|
||||
// $param->setFrom($startDateValidator);
|
||||
// $param->repeatEveryMonth(4, 2);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var RepeatedDateParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
//
|
||||
// $new = new RepeatedDateParam($adapter);
|
||||
// $new->setFrom($unserialized->getFrom());
|
||||
// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
|
||||
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -1,426 +0,0 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\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 <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $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 CouponBaseAdapter();
|
||||
// $startDateValidator = new \DateTime("2012-07-08");
|
||||
// $dateToValidate = 1377012588;
|
||||
// $duration = 10;
|
||||
//
|
||||
// $param = new RepeatedIntervalParam($adapter);
|
||||
// $param->setFrom($startDateValidator);
|
||||
// $param->setDurationInDays($duration);
|
||||
// $param->repeatEveryMonth(1, 4);
|
||||
//
|
||||
// $serialized = base64_encode(serialize($param));
|
||||
// /** @var RepeatedIntervalParam $unserialized */
|
||||
// $unserialized = base64_decode(serialize($serialized));
|
||||
//
|
||||
// $this->assertEquals($param->getValue(), $unserialized->getValue());
|
||||
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
|
||||
//
|
||||
// $new = new RepeatedIntervalParam($adapter);
|
||||
// $new->setFrom($unserialized->getFrom());
|
||||
// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
|
||||
// $new->setDurationInDays($unserialized->getDurationInDays());
|
||||
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Tears down the fixture, for example, closes a network connection.
|
||||
// * This method is called after a test is executed.
|
||||
// */
|
||||
// protected function tearDown()
|
||||
// {
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -28,7 +28,7 @@ namespace Thelia\Coupon;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test CouponBaseAdapter Class
|
||||
* Unit Test BaseAdapter Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
@@ -44,7 +44,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
);
|
||||
}
|
||||
// /**
|
||||
// * @var CouponBaseAdapter
|
||||
// * @var BaseAdapter
|
||||
// */
|
||||
// protected $object;
|
||||
//
|
||||
@@ -54,7 +54,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// protected function setUp()
|
||||
// {
|
||||
// $this->object = new CouponBaseAdapter;
|
||||
// $this->object = new BaseAdapter;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@@ -66,7 +66,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @covers Thelia\Coupon\CouponBaseAdapter::getCart
|
||||
// * @covers Thelia\Coupon\BaseAdapter::getCart
|
||||
// * @todo Implement testGetCart().
|
||||
// */
|
||||
// public function testGetCart()
|
||||
@@ -78,7 +78,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @covers Thelia\Coupon\CouponBaseAdapter::getDeliveryAddress
|
||||
// * @covers Thelia\Coupon\BaseAdapter::getDeliveryAddress
|
||||
// * @todo Implement testGetDeliveryAddress().
|
||||
// */
|
||||
// public function testGetDeliveryAddress()
|
||||
@@ -90,7 +90,7 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * @covers Thelia\Coupon\CouponBaseAdapter::getCustomer
|
||||
// * @covers Thelia\Coupon\BaseAdapter::getCustomer
|
||||
// * @todo Implement testGetCustomer().
|
||||
// */
|
||||
// public function testGetCustomer()
|
||||
|
||||
@@ -74,7 +74,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// * @param bool $isUsed If Coupon has been used yet
|
||||
// * @param bool $isEnabled If Coupon is enabled
|
||||
// * @param \DateTime $expirationDate When Coupon expires
|
||||
// * @param CouponRuleCollection $rules Coupon rules
|
||||
// * @param ConditionCollection $rules Coupon rules
|
||||
// * @param bool $isCumulative If Coupon is cumulative
|
||||
// * @param bool $isRemovingPostage If Coupon is removing postage
|
||||
// *
|
||||
@@ -109,9 +109,9 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// $isRemovingPostage
|
||||
// );
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->getMock(
|
||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
||||
// 'Thelia\Coupon\BaseAdapter',
|
||||
// array('findOneCouponByCode'),
|
||||
// array()
|
||||
// );
|
||||
@@ -135,7 +135,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// $date = new \DateTime();
|
||||
// $date->setTimestamp(strtotime("today - 2 months"));
|
||||
//
|
||||
// /** @var CouponAdapterInterface $mockAdapter */
|
||||
// /** @var AdapterInterface $mockAdapter */
|
||||
// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date);
|
||||
// $couponFactory = new CouponFactory($mockAdapter);
|
||||
// $coupon = $couponFactory->buildCouponFromCode('XMAS1');
|
||||
@@ -151,7 +151,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// {
|
||||
// $date = new \DateTime();
|
||||
//
|
||||
// /** @var CouponAdapterInterface $mockAdapter */
|
||||
// /** @var AdapterInterface $mockAdapter */
|
||||
// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date);
|
||||
// $couponFactory = new CouponFactory($mockAdapter);
|
||||
// $coupon = $couponFactory->buildCouponFromCode('XMAS1');
|
||||
@@ -161,12 +161,12 @@ 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()
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $mockAdapter */
|
||||
// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, null, new CouponRuleCollection(array()));
|
||||
// /** @var AdapterInterface $mockAdapter */
|
||||
// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, null, new ConditionCollection(array()));
|
||||
// $couponFactory = new CouponFactory($mockAdapter);
|
||||
// $coupon = $couponFactory->buildCouponFromCode('XMAS1');
|
||||
// }
|
||||
@@ -178,7 +178,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// public function testBuildCouponFromCode()
|
||||
// {
|
||||
// /** @var CouponAdapterInterface $mockAdapter */
|
||||
// /** @var AdapterInterface $mockAdapter */
|
||||
// $mockAdapter = $this->generateCouponModelMock();
|
||||
// $couponFactory = new CouponFactory($mockAdapter);
|
||||
// /** @var CouponInterface $coupon */
|
||||
@@ -206,7 +206,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// /**
|
||||
// * Generate valid CouponRuleInterfaces
|
||||
// *
|
||||
// * @return CouponRuleCollection Set of CouponRuleInterface
|
||||
// * @return ConditionCollection Set of ConditionManagerInterface
|
||||
// */
|
||||
// protected function generateValidRules()
|
||||
// {
|
||||
@@ -230,7 +230,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
//// )
|
||||
//// )
|
||||
//// );
|
||||
//// $rules = new CouponRuleCollection(array($rule1, $rule2));
|
||||
//// $rules = new ConditionCollection(array($rule1, $rule2));
|
||||
////
|
||||
//// return $rules;
|
||||
// }
|
||||
@@ -247,7 +247,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// * @param bool $isUsed If Coupon has been used yet
|
||||
// * @param bool $isEnabled If Coupon is enabled
|
||||
// * @param \DateTime $expirationDate When Coupon expires
|
||||
// * @param CouponRuleCollection $rules Coupon rules
|
||||
// * @param ConditionCollection $rules Coupon rules
|
||||
// * @param bool $isCumulative If Coupon is cumulative
|
||||
// * @param bool $isRemovingPostage If Coupon is removing postage
|
||||
// *
|
||||
@@ -327,7 +327,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
// $rules = $this->generateValidRules();
|
||||
// }
|
||||
//
|
||||
// $coupon->setSerializedRules(base64_encode(serialize($rules)));
|
||||
// $coupon->setSerializedConditions(base64_encode(serialize($rules)));
|
||||
//
|
||||
// $coupon->setIsCumulative($isCumulative);
|
||||
// $coupon->setIsRemovingPostage($isRemovingPostage);
|
||||
|
||||
@@ -88,7 +88,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// /** @var CouponInterface $coupon */
|
||||
// $coupon = self::generateValidCoupon();
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// $couponManager = new CouponManager($stubCouponBaseAdapter);
|
||||
@@ -108,7 +108,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// public function testGetDiscountTwoCoupon()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $cartTotalPrice = 100.00;
|
||||
// $checkoutTotalPrice = 120.00;
|
||||
//
|
||||
@@ -124,11 +124,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rules = new CouponRuleCollection(array($rule1));
|
||||
// $rules = new ConditionCollection(array($rule1));
|
||||
// /** @var CouponInterface $coupon2 */
|
||||
// $coupon2 = $this->generateValidCoupon('XMAS2', null, null, null, 15.00, null, null, $rules);
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon1, $coupon2), $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// $couponManager = new CouponManager($stubCouponBaseAdapter);
|
||||
@@ -148,7 +148,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// public function testGetDiscountAlwaysInferiorToPrice()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $cartTotalPrice = 21.00;
|
||||
// $checkoutTotalPrice = 26.00;
|
||||
//
|
||||
@@ -162,11 +162,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rules = new CouponRuleCollection(array($rule1));
|
||||
// $rules = new ConditionCollection(array($rule1));
|
||||
// /** @var CouponInterface $coupon */
|
||||
// $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules);
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// $couponManager = new CouponManager($stubCouponBaseAdapter);
|
||||
@@ -185,7 +185,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// public function testIsCouponRemovingPostage()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $cartTotalPrice = 21.00;
|
||||
// $checkoutTotalPrice = 27.00;
|
||||
//
|
||||
@@ -199,11 +199,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rules = new CouponRuleCollection(array($rule1));
|
||||
// $rules = new ConditionCollection(array($rule1));
|
||||
// /** @var CouponInterface $coupon */
|
||||
// $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules, null, true);
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// $couponManager = new CouponManager($stubCouponBaseAdapter);
|
||||
@@ -231,7 +231,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
//
|
||||
// $coupons = array($couponCumulative1);
|
||||
//
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -264,7 +264,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative1 = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -299,7 +299,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -334,7 +334,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -369,7 +369,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -404,7 +404,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -437,7 +437,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, new \DateTime(), null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -472,7 +472,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -507,7 +507,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -542,7 +542,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -581,7 +581,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, true);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -620,7 +620,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, false);
|
||||
//
|
||||
// $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4);
|
||||
// /** @var CouponAdapterInterface $stubCouponBaseAdapter */
|
||||
// /** @var AdapterInterface $stubCouponBaseAdapter */
|
||||
// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice);
|
||||
//
|
||||
// // When
|
||||
@@ -641,11 +641,11 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// /**
|
||||
// * Generate valid CouponRuleInterfaces
|
||||
// *
|
||||
// * @return array Array of CouponRuleInterface
|
||||
// * @return array Array of ConditionManagerInterface
|
||||
// */
|
||||
// public static function generateValidRules()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule1 = new AvailableForTotalAmount(
|
||||
// $adapter, array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
@@ -666,7 +666,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// )
|
||||
// )
|
||||
// );
|
||||
// $rules = new CouponRuleCollection(array($rule1, $rule2));
|
||||
// $rules = new ConditionCollection(array($rule1, $rule2));
|
||||
//
|
||||
// return $rules;
|
||||
// }
|
||||
@@ -692,7 +692,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// public function generateFakeAdapter(array $coupons, $cartTotalPrice, $checkoutTotalPrice, $postagePrice = 6.00)
|
||||
// {
|
||||
// $stubCouponBaseAdapter = $this->getMock(
|
||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
||||
// 'Thelia\Coupon\BaseAdapter',
|
||||
// array(
|
||||
// 'getCurrentCoupons',
|
||||
// 'getCartTotalPrice',
|
||||
@@ -734,7 +734,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// * @param float $amount Coupon discount
|
||||
// * @param bool $isEnabled Is Coupon enabled
|
||||
// * @param \DateTime $expirationDate Coupon expiration date
|
||||
// * @param CouponRuleCollection $rules Coupon rules
|
||||
// * @param ConditionCollection $rules Coupon rules
|
||||
// * @param bool $isCumulative If is cumulative
|
||||
// * @param bool $isRemovingPostage If is removing postage
|
||||
// * @param bool $isAvailableOnSpecialOffers If is available on
|
||||
@@ -758,7 +758,7 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
// $isAvailableOnSpecialOffers = null,
|
||||
// $maxUsage = null
|
||||
// ) {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// if ($code === null) {
|
||||
// $code = self::VALID_CODE;
|
||||
// }
|
||||
|
||||
@@ -33,7 +33,7 @@ use Thelia\Constraint\Rule\Operators;
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test CouponRuleCollection Class
|
||||
* Unit Test ConditionCollection Class
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
@@ -73,7 +73,7 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase
|
||||
//// )
|
||||
//// )
|
||||
//// );
|
||||
//// $rules = new CouponRuleCollection(array($rule1, $rule2));
|
||||
//// $rules = new ConditionCollection(array($rule1, $rule2));
|
||||
////
|
||||
//// $serializedRules = base64_encode(serialize($rules));
|
||||
//// $unserializedRules = unserialize(base64_decode($serializedRules));
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\RuleOrganizer;
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
@@ -47,7 +48,7 @@ class RuleOrganizerTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
$this->object = new RuleOrganizer;
|
||||
$this->object = new RuleOrganizer();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -153,7 +153,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// public function testGetEffect()
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// $expected = 10;
|
||||
@@ -186,7 +186,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 3;
|
||||
@@ -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()
|
||||
@@ -216,7 +216,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2)));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@@ -228,7 +228,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
// {
|
||||
// // Given
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
// Operators::INFERIOR,
|
||||
// 400.00
|
||||
@@ -236,7 +236,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 10.00;
|
||||
@@ -253,7 +253,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
// {
|
||||
// // Given
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
// Operators::INFERIOR_OR_EQUAL,
|
||||
// 400.00
|
||||
@@ -261,7 +261,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 10.00;
|
||||
@@ -278,7 +278,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
// {
|
||||
// // Given
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
// Operators::EQUAL,
|
||||
// 400.00
|
||||
@@ -286,7 +286,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 10.00;
|
||||
@@ -303,7 +303,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
// {
|
||||
// // Given
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
// Operators::SUPERIOR_OR_EQUAL,
|
||||
// 400.00
|
||||
@@ -311,7 +311,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 10.00;
|
||||
@@ -328,7 +328,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
// {
|
||||
// // Given
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo(
|
||||
// Operators::SUPERIOR,
|
||||
// 400.00
|
||||
@@ -336,7 +336,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 10.00;
|
||||
@@ -365,7 +365,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount)
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $validators = array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
// $operator,
|
||||
|
||||
@@ -158,7 +158,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 3;
|
||||
@@ -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()
|
||||
@@ -188,7 +188,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0, $rule1, $rule2)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2)));
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
@@ -207,7 +207,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 24.50;
|
||||
@@ -231,7 +231,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 24.50;
|
||||
@@ -255,7 +255,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 24.50;
|
||||
@@ -279,7 +279,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 24.50;
|
||||
@@ -303,7 +303,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false);
|
||||
//
|
||||
// // When
|
||||
// $coupon->setRules(new CouponRuleCollection(array($rule0)));
|
||||
// $coupon->setRules(new ConditionCollection(array($rule0)));
|
||||
//
|
||||
// // Then
|
||||
// $expected = 24.50;
|
||||
@@ -322,7 +322,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// * @param float $amount Coupon discount
|
||||
// * @param bool $isEnabled Is Coupon enabled
|
||||
// * @param \DateTime $expirationDate Coupon expiration date
|
||||
// * @param CouponRuleCollection $rules Coupon rules
|
||||
// * @param ConditionCollection $rules Coupon rules
|
||||
// * @param bool $isCumulative If is cumulative
|
||||
// * @param bool $isRemovingPostage If is removing postage
|
||||
// * @param bool $isAvailableOnSpecialOffers If is available on
|
||||
@@ -407,7 +407,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// */
|
||||
// protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount)
|
||||
// {
|
||||
// $adapter = new CouponBaseAdapter();
|
||||
// $adapter = new BaseAdapter();
|
||||
// $validators = array(
|
||||
// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator(
|
||||
// $operator,
|
||||
@@ -432,7 +432,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
// public function generateFakeAdapter($cartTotalPrice)
|
||||
// {
|
||||
// $stubCouponBaseAdapter = $this->getMock(
|
||||
// 'Thelia\Coupon\CouponBaseAdapter',
|
||||
// 'Thelia\Coupon\BaseAdapter',
|
||||
// array(
|
||||
// 'getCartTotalPrice'
|
||||
// ),
|
||||
|
||||
Reference in New Issue
Block a user