WIP : Refactor contraint/rule becomes conditions (more generic)

This commit is contained in:
gmorel
2013-09-25 14:51:42 +02:00
parent cb389f126c
commit d6172f23cf
75 changed files with 582 additions and 2787 deletions

View File

@@ -23,16 +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\CouponRuleCollection;
use Thelia\Coupon\ConditionCollection;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Coupon as CouponModel;
@@ -78,11 +78,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface
*
* @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);
}
/**
@@ -139,15 +139,15 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$coupon->setDispatcher($this->getDispatcher());
// Set default rule if none found
$noConditionRule = $this->container->get('thelia.constraint.rule.available_for_everyone');
$constraintFactory = $this->container->get('thelia.constraint.factory');
$couponRuleCollection = new CouponRuleCollection();
/** @var ConditionManagerInterface $noConditionRule */
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
$constraintFactory = $this->container->get('thelia.condition.factory');
$couponRuleCollection = new ConditionCollection();
$couponRuleCollection->add($noConditionRule);
$defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection(
$couponRuleCollection
);
$coupon->createOrUpdate(
$event->getCode(),
$event->getTitle(),
@@ -165,8 +165,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface
$event->getLocale()
);
$event->setCoupon($coupon);
}
@@ -177,15 +175,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 $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
$coupon->createOrUpdateRules(
$constraintFactory->serializeCouponRuleCollection($event->getRules()),
$coupon->createOrUpdateConditions(
$constraintFactory->serializeConditionCollection($event->getConditions()),
$event->getLocale()
);
@@ -218,7 +216,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)
);
}
}

View File

@@ -68,12 +68,12 @@ class ConditionFactory
*
* @return string A ready to be stored Condition collection
*/
public function serializeCouponRuleCollection(ConditionCollection $collection)
public function serializeConditionCollection(ConditionCollection $collection)
{
if ($collection->isEmpty()) {
/** @var ConditionManagerInterface $conditionNone */
$conditionNone = $this->container->get(
'thelia.constraint.rule.available_for_everyone'
'thelia.condition.match_for_everyone'
);
$collection->add($conditionNone);
}
@@ -83,7 +83,7 @@ class ConditionFactory
/** @var $condition ConditionManagerInterface */
foreach ($conditions as $condition) {
// Remove all rule if the "no condition" condition is found
// if ($condition->getServiceId() == 'thelia.constraint.rule.available_for_everyone') {
// if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') {
// return base64_encode(json_encode(array($condition->getSerializableRule())));
// }
$serializableConditions[] = $condition->getSerializableCondition();
@@ -100,7 +100,7 @@ class ConditionFactory
*
* @return ConditionCollection Conditions ready to be processed
*/
public function unserializeCouponRuleCollection($serializedConditions)
public function unserializeConditionCollection($serializedConditions)
{
$unserializedConditions = json_decode(base64_decode($serializedConditions));

View File

@@ -121,15 +121,15 @@ interface ConditionManagerInterface
*/
public function getValidators();
// /**
// * Populate a Rule from a form admin
// *
// * @param array $operators Rule Operator set by the Admin
// * @param array $values Rule Values set by the Admin
// *
// * @return bool
// */
// public function populateFromForm(array$operators, array $values);
/**
* Populate a Condition from a form admin
*
* @param array $operators Condition Operator set by the Admin
* @param array $values Condition Values set by the Admin
*
* @return bool
*/
public function populateFromForm(array$operators, array $values);
/**

View File

@@ -40,7 +40,7 @@ use Thelia\Condition\ConditionManagerAbstract;
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();

View File

@@ -51,7 +51,7 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract
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(

View File

@@ -46,7 +46,7 @@ class MatchForXArticlesManager extends ConditionManagerAbstract
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(

View File

@@ -253,7 +253,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">
@@ -263,24 +263,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"/>
@@ -290,6 +272,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.addRule"/>
</service>
<service id="thelia.condition.match_for_x_articles" class="Thelia\Condition\Implementation\MatchForXArticlesManager">
<argument type="service" id="thelia.adapter" />
<tag name="thelia.coupon.addRule"/>
</service>
<service id="thelia.condition.match_for_total_amount" class="Thelia\Condition\Implementation\MatchForTotalAmountManager">
<argument type="service" id="thelia.adapter" />
<tag name="thelia.coupon.addRule"/>
</service>
<service id="mailer" class="Thelia\Mailer\MailerFactory">
<argument type="service" id="event_dispatcher"/>
</service>

View File

@@ -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;
}
}

View File

@@ -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;
}
}

View File

@@ -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.
}
}

View File

@@ -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.
}
}

View File

@@ -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.
}
}

View File

@@ -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.
}
}

View File

@@ -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.
}
}

View File

@@ -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
{
}

View File

@@ -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);
}

View File

@@ -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'
);
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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'
);
}
}

View File

@@ -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'
);
}
}

View File

@@ -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');
}
}

View File

@@ -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');
}
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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;
}
}

View File

@@ -25,33 +25,22 @@ 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;
use Thelia\Log\Tlog;
use Thelia\Model\Coupon;
use Thelia\Model\CouponQuery;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
use Thelia\Tools\I18n;
/**
@@ -189,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
@@ -210,12 +200,12 @@ class CouponController extends BaseAdminController
'updated',
'update'
);
} else { // Display
} else {
// Display
// Prepare the data that will hydrate the form
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$rules = $constraintFactory->unserializeCouponRuleCollection(
/** @var ConditionFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
$conditions = $constraintFactory->unserializeConditionCollection(
$coupon->getSerializedRules()
);
@@ -232,23 +222,23 @@ class CouponController extends BaseAdminController
'isCumulative' => ($coupon->getIsCumulative() == 1),
'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1),
'maxUsage' => $coupon->getMaxUsage(),
'rules' => $rules,
'rules' => $conditions,
'locale' => $coupon->getLocale(),
);
$args['rulesObject'] = array();
/** @var CouponRuleInterface $rule */
foreach ($rules->getRules() as $rule) {
/** @var ConditionManagerInterface $condition */
foreach ($conditions->getConditions() as $condition) {
$args['rulesObject'][] = array(
'serviceId' => $rule->getServiceId(),
'name' => $rule->getName(),
'tooltip' => $rule->getToolTip(),
'validators' => $rule->getValidators()
'serviceId' => $condition->getServiceId(),
'name' => $condition->getName(),
'tooltip' => $condition->getToolTip(),
'validators' => $condition->getValidators()
);
}
$args['rules'] = $this->cleanRuleForTemplate($rules);
$args['rules'] = $this->cleanConditionForTemplate($conditions);
// Setup the object form
$changeForm = new CouponCreationForm($this->getRequest(), 'form', $data);
@@ -258,7 +248,7 @@ class CouponController extends BaseAdminController
}
$args['couponCode'] = $coupon->getCode();
$args['availableCoupons'] = $this->getAvailableCoupons();
$args['availableRules'] = $this->getAvailableRules();
$args['availableConditions'] = $this->getAvailableConditions();
$args['urlAjaxGetRuleInput'] = $this->getRoute(
'admin.coupon.rule.input',
array('ruleId' => 'ruleId'),
@@ -289,16 +279,16 @@ class CouponController extends BaseAdminController
$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($ruleId);
if ($inputs === null) {
return $this->pageNotFound();
}
return $this->render(
'coupon/rule-input-ajax',
'coupon/condition-input-ajax',
array(
'ruleId' => $ruleId,
'inputs' => $inputs
@@ -328,45 +318,45 @@ class CouponController extends BaseAdminController
return $this->pageNotFound();
}
$rules = new CouponRuleCollection();
$rules = 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('rules'));
foreach ($conditionsReceived as $conditionReceived) {
$rule = $conditionFactory->build(
$conditionReceived->serviceId,
(array) $conditionReceived->operators,
(array) $conditionReceived->values
);
$rules->add(clone $rule);
}
$coupon->setSerializedRules(
$constraintFactory->serializeCouponRuleCollection($rules)
);
// $coupon->setSerializedRules(
// $constraintFactory->serializeCouponRuleCollection($rules)
// );
$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(), $coupon->getLocale()
$conditionEvent = new ConditionCreateOrUpdateEvent(
$rules
);
$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()
$conditionEvent->getCouponModel()->getTitle(),
$conditionEvent->getCouponModel()->getServiceId()
)
);
$cleanedRules = $this->cleanRuleForTemplate($rules);
$cleanedRules = $this->cleanConditionForTemplate($rules);
return $this->render(
'coupon/rules',
@@ -384,6 +374,8 @@ class CouponController extends BaseAdminController
*
* @param string $couponCode Coupon code
*
* @todo remove (event dispatcher testing purpose)
*
*/
public function consumeAction($couponCode)
{
@@ -421,7 +413,7 @@ class CouponController extends BaseAdminController
$couponBeingCreated->setIsEnabled($data['isEnabled']);
$couponBeingCreated->setExpirationDate($data['expirationDate']);
$couponBeingCreated->setSerializedRules(
new CouponRuleCollection(
new ConditionCollection(
array()
)
);
@@ -537,22 +529,22 @@ class CouponController extends BaseAdminController
*
* @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;
}
/**
@@ -579,18 +571,21 @@ class CouponController extends BaseAdminController
}
/**
* @param $rules
* Clean rule 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;
}
// /**
@@ -604,7 +599,7 @@ class CouponController extends BaseAdminController
// */
// protected function validateRulesCreation($type, $operator, $values)
// {
// /** @var CouponAdapterInterface $adapter */
// /** @var AdapterInterface $adapter */
// $adapter = $this->container->get('thelia.adapter');
// $validator = new PriceParam()
// try {

View File

@@ -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 $this->conditions;
}
return parent::compareTo($other);
}
/**
* 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;
}
}

View File

@@ -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;
}
}

View File

@@ -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;
@@ -93,7 +93,7 @@ class CouponCreateOrUpdateEvent extends ActionEvent
* @param string $type Coupon type
* @param string $shortDescription Coupon short description
* @param string $description Coupon description
* @param boolean $isEnabled Enable/Disable
* @param bool $isEnabled Enable/Disable
* @param \DateTime $expirationDate Coupon expiration date
* @param boolean $isAvailableOnSpecialOffers Is available on special offers
* @param boolean $isCumulative Is cumulative
@@ -103,7 +103,8 @@ class CouponCreateOrUpdateEvent extends ActionEvent
*/
public function __construct(
$code, $title, $amount, $type, $shortDescription, $description, $isEnabled, \DateTime $expirationDate, $isAvailableOnSpecialOffers, $isCumulative, $isRemovingPostage, $maxUsage, $locale
) {
)
{
$this->amount = $amount;
$this->code = $code;
$this->description = $description;
@@ -276,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;
}
}

View File

@@ -365,19 +365,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 ---------------------------------------------

View File

@@ -95,7 +95,7 @@ class Coupon extends BaseI18nLoop
$loopResult = new LoopResult();
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$constraintFactory = $this->container->get('thelia.condition.factory');
/** @var Request $request */
$request = $this->container->get('request');

View File

@@ -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,11 +165,11 @@ interface CouponAdapterInterface
public function getRequest();
/**
* Return Constraint Validator
* Return Condition Validator
*
* @return ConstraintValidator
* @return ConditionEvaluator
*/
public function getConstraintValidator();
public function getConditionValidator();
/**
* Return all available currencies

View File

@@ -27,7 +27,7 @@ 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\Constraint\ConditionValidator;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
use Thelia\Coupon\Type\CouponInterface;
@@ -43,12 +43,14 @@ use Thelia\Model\LangQuery;
* 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;
@@ -262,11 +264,11 @@ class CouponBaseAdapter implements CouponAdapterInterface
/**
* Return Constraint Validator
*
* @return ConstraintValidator
* @return ConditionValidator
*/
public function getConstraintValidator()
public function getConditionValidator()
{
return $this->container->get('thelia.constraint.validator');
return $this->container->get('thelia.condition.validator');
}

View File

@@ -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);

View File

@@ -49,7 +49,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;
/**
@@ -131,7 +131,7 @@ class CouponFactory
);
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.constraint.factory');
$constraintFactory = $this->container->get('thelia.condition.factory');
$rules = $constraintFactory->unserializeCouponRuleCollection(
$model->getSerializedRules()
);

View File

@@ -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;
}
}

View File

@@ -37,11 +37,11 @@ namespace Thelia\Coupon;
class RuleOrganizer implements RuleOrganizerInterface
{
/**
* Organize CouponRuleInterface
* Organize ConditionManagerInterface
*
* @param array $rules Array of CouponRuleInterface
* @param array $rules Array of ConditionManagerInterface
*
* @return array Array of CouponRuleInterface sorted
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $rules)
{

View File

@@ -37,11 +37,11 @@ namespace Thelia\Coupon;
interface RuleOrganizerInterface
{
/**
* Organize CouponRuleInterface
* Organize ConditionManagerInterface
*
* @param array $rules Array of CouponRuleInterface
* @param array $rules Array of ConditionManagerInterface
*
* @return array Array of CouponRuleInterface sorted
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $rules);
}

View File

@@ -25,10 +25,10 @@ namespace Thelia\Coupon\Type;
use Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Constraint\ConstraintManager;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Constraint\ConditionValidator;
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;
@@ -45,7 +45,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,10 +54,10 @@ abstract class CouponAbstract implements CouponInterface
/** @var RuleOrganizerInterface */
protected $organizer = null;
/** @var CouponRuleCollection Array of CouponRuleInterface */
/** @var ConditionCollection Array of ConditionManagerInterface */
protected $rules = null;
/** @var ConstraintValidator Constraint validator */
/** @var ConditionValidator Constraint validator */
protected $constraintValidator = null;
@@ -106,13 +106,13 @@ abstract class CouponAbstract implements CouponInterface
/**
* Constructor
*
* @param CouponAdapterInterface $adapter Service adapter
* @param AdapterInterface $adapter Service adapter
*/
function __construct(CouponAdapterInterface $adapter)
function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
$this->translator = $adapter->getTranslator();
$this->constraintValidator = $adapter->getConstraintValidator();
$this->constraintValidator = $adapter->getConditionValidator();
}
/**
@@ -205,7 +205,7 @@ abstract class CouponAbstract implements CouponInterface
/**
* Return condition to validate the Coupon or not
*
* @return CouponRuleCollection
* @return ConditionCollection
*/
public function getRules()
{
@@ -216,12 +216,12 @@ abstract class CouponAbstract implements CouponInterface
* 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
*/
public function setRules(CouponRuleCollection $rules)
public function setRules(ConditionCollection $rules)
{
$this->rules = $rules;
@@ -301,7 +301,7 @@ abstract class CouponAbstract implements 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
*/

View File

@@ -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,7 +140,7 @@ 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();
@@ -148,12 +148,12 @@ interface CouponInterface
* 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
*/
public function setRules(CouponRuleCollection $rules);
public function setRules(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
*/

View File

@@ -23,7 +23,7 @@
namespace Thelia\Coupon\Type;
use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Coupon\AdapterInterface;
use Thelia\Coupon\Type\CouponAbstract;
use Thelia\Exception\MissingAdapterException;

View File

@@ -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);

View File

@@ -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);

View File

@@ -39,7 +39,7 @@ use Thelia\Log\Tlog;
class InvalidRuleException extends \RuntimeException
{
/**
* InvalidRuleOperatorException thrown when a Rule is badly implemented
* InvalidConditionOperatorException thrown when a Rule is badly implemented
*
* @param string $className Class name
*/

View File

@@ -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;
@@ -106,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 $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->setSerializedRules($serializableConditions);
// Set object language (i18n)
if (!is_null($locale)) {
@@ -127,13 +127,9 @@ class Coupon extends BaseCoupon
try {
$this->save($con);
$con->commit();
} catch(\Exception $e) {
$con->rollback();
throw $e;
}
}
}

View File

@@ -27,8 +27,8 @@ 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;
use Thelia\Coupon\BaseAdapter;
use Thelia\Coupon\ConditionCollection;
/**
* Created by JetBrains PhpStorm.
@@ -169,7 +169,7 @@ class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase
);
$rule2->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
@@ -209,10 +209,10 @@ class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$adapter = new CouponBaseAdapter($container);
$adapter = new BaseAdapter($container);
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
$container->set('thelia.constraint.rule.available_for_x_articles', $rule2);
$container->set('thelia.condition.match_for_total_amount', $rule1);
$container->set('thelia.condition.match_for_x_articles', $rule2);
$container->set('thelia.adapter', $adapter);
return $container;

View File

@@ -27,15 +27,15 @@ 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;
use Thelia\Coupon\BaseAdapter;
use Thelia\Coupon\ConditionCollection;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test ConstraintValidator Class
* Unit Test ConditionEvaluator Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
@@ -54,7 +54,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestSuccess1Rules()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -79,7 +79,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$isValid = $ConstraintValidator->isMatching($rules);
@@ -91,7 +91,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestFail1Rules()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -116,7 +116,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$isValid = $ConstraintValidator->isMatching($rules);
@@ -128,7 +128,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestSuccess2Rules()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -165,7 +165,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
);
$rule2->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
@@ -178,7 +178,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestFail2Rules()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -215,7 +215,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
);
$rule2->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
@@ -228,7 +228,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testVariableOpComparisonSuccess()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$expected = true;
$actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
@@ -264,7 +264,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testVariableOpComparisonFail()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$expected = false;
$actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
@@ -297,7 +297,7 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testVariableOpComparisonException()
{
$ConstraintValidator = new ConstraintValidator();
$ConstraintValidator = new ConditionValidator();
$expected = true;
$actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1);
$this->assertEquals($expected, $actual);
@@ -327,10 +327,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$adapter = new CouponBaseAdapter($container);
$adapter = new BaseAdapter($container);
$container->set('thelia.constraint.rule.available_for_total_amount', $rule1);
$container->set('thelia.constraint.rule.available_for_x_articles', $rule2);
$container->set('thelia.condition.match_for_total_amount', $rule1);
$container->set('thelia.condition.match_for_x_articles', $rule2);
$container->set('thelia.adapter', $adapter);
return $container;

View File

@@ -23,10 +23,10 @@
namespace Thelia\Coupon;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Constraint\ConditionValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Exception\InvalidRuleValueException;
use Thelia\Exception\InvalidConditionValueException;
use Thelia\Model\Currency;
/**
@@ -34,7 +34,7 @@ use Thelia\Model\Currency;
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test AvailableForTotalAmountManager Class
* Unit Test MatchForTotalAmountManager Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
@@ -42,7 +42,7 @@ use Thelia\Model\Currency;
*/
class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
{
/** @var CouponAdapterInterface $stubTheliaAdapter */
/** @var AdapterInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/**
@@ -69,7 +69,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$currency1 = new Currency();
$currency1->setCode('EUR');
@@ -95,7 +95,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator()
@@ -123,7 +123,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator2()
@@ -151,7 +151,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleValueException
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue()
@@ -179,7 +179,7 @@ class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleValueException
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue2()

View File

@@ -23,7 +23,7 @@
namespace Thelia\Coupon;
use Thelia\Constraint\ConstraintValidator;
use Thelia\Constraint\ConditionValidator;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Constraint\Rule\SerializableRule;
@@ -33,7 +33,7 @@ use Thelia\Constraint\Rule\SerializableRule;
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test AvailableForXArticlesManager Class
* Unit Test MatchForXArticlesManager Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
@@ -42,7 +42,7 @@ use Thelia\Constraint\Rule\SerializableRule;
class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
{
// /** @var CouponAdapterInterface $stubTheliaAdapter */
// /** @var AdapterInterface $stubTheliaAdapter */
// protected $stubTheliaAdapter = null;
/**
@@ -58,7 +58,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
@@ -71,7 +71,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -93,7 +93,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators
* @expectedException \Thelia\Exception\InvalidRuleValueException
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
@@ -106,7 +106,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -141,7 +141,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -176,7 +176,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -211,7 +211,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -246,7 +246,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -281,7 +281,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -316,7 +316,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -351,7 +351,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -386,7 +386,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -421,7 +421,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -456,7 +456,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -491,7 +491,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -526,7 +526,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -555,7 +555,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -590,7 +590,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConstraintValidator()));
->will($this->returnValue(new ConditionValidator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$operators = array(
@@ -618,7 +618,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
// public function testGetValidators()
// {
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
// ->disableOriginalConstructor()
// ->getMock();
//
@@ -626,12 +626,12 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
// ->method('getNbArticlesInCart')
// ->will($this->returnValue(4));
//
// $rule1 = new AvailableForXArticlesManager($stubAdapter);
// $rule1 = new MatchForXArticlesManager($stubAdapter);
// $operators = array(
// AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
// MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
// );
// $values = array(
// AvailableForXArticlesManager::INPUT1 => 4
// MatchForXArticlesManager::INPUT1 => 4
// );
// $rule1->setValidatorsFromForm($operators, $values);
//

View File

@@ -110,7 +110,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// */
// public function testOperatorInferiorValidBefore()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// // Given
// $a = 11;
// $operator = Operators::INFERIOR;
@@ -131,7 +131,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInferiorInvalidEquals()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::INFERIOR;
// $b = new QuantityParam($adapter, 12);
@@ -151,7 +151,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInferiorInvalidAfter()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::INFERIOR;
// $b = new QuantityParam($adapter, 12);
@@ -171,7 +171,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInferiorOrEqualValidEqual()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
@@ -191,7 +191,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInferiorOrEqualValidBefore()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 10;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
@@ -211,7 +211,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInferiorOrEqualInValidAfter()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
@@ -231,7 +231,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorEqualValidEqual()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
@@ -251,7 +251,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorEqualInValidBefore()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
@@ -271,7 +271,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorEqualInValidAfter()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
@@ -291,7 +291,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorOrEqualValidEqual()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
@@ -311,7 +311,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorOrEqualAfter()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 14;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
@@ -331,7 +331,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorOrEqualInvalidBefore()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
@@ -351,7 +351,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorValidAfter()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
@@ -371,7 +371,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorInvalidEqual()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
@@ -391,7 +391,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorSuperiorInvalidBefore()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
@@ -411,7 +411,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorDifferentValid()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::DIFFERENT;
// $b = new QuantityParam($adapter, 11);
@@ -431,7 +431,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorDifferentInvalidEquals()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::DIFFERENT;
// $b = new QuantityParam($adapter, 11);
@@ -451,7 +451,7 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase
// public function testOperatorInValid()
// {
// // Given
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = 'X';
// $b = new QuantityParam($adapter, 11);

View File

@@ -50,7 +50,7 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase
);
}
// /** @var CouponAdapterInterface $stubTheliaAdapter */
// /** @var AdapterInterface $stubTheliaAdapter */
// protected $stubTheliaAdapter = null;
//
// /**
@@ -59,16 +59,16 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase
// */
// protected function setUp()
// {
// /** @var CouponAdapterInterface $stubTheliaAdapter */
// /** @var AdapterInterface $stubTheliaAdapter */
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
// }
//
// /**
// * Generate valid CouponBaseAdapter
// * Generate valid BaseAdapter
// *
// * @param int $customerId Customer id
// *
// * @return CouponAdapterInterface
// * @return AdapterInterface
// */
// protected function generateValidCouponBaseAdapterMock($customerId = 4521)
// {
@@ -78,9 +78,9 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase
// $customer->setLastname('Lastname');
// $customer->setEmail('em@il.com');
//
// /** @var CouponAdapterInterface $stubTheliaAdapter */
// /** @var AdapterInterface $stubTheliaAdapter */
// $stubTheliaAdapter = $this->getMock(
// 'Thelia\Coupon\CouponBaseAdapter',
// 'Thelia\Coupon\BaseAdapter',
// array('getCustomer'),
// array()
// );
@@ -140,7 +140,7 @@ class CustomerParamTest extends \PHPUnit_Framework_TestCase
//// */
//// public function isSerializableTest()
//// {
//// $adapter = new CouponBaseAdapter();
//// $adapter = new BaseAdapter();
//// $intValidator = 42;
//// $intToValidate = -1;
////

View File

@@ -62,7 +62,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
//
@@ -80,7 +80,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
//
@@ -98,7 +98,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-09");
//
@@ -115,7 +115,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
//
@@ -130,7 +130,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
//
// $param = new DateParam($adapter, $dateValidator);

View File

@@ -62,7 +62,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorInteger()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 41;
//
@@ -80,7 +80,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsInteger()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 42;
//
@@ -98,7 +98,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorInteger()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 43;
//
@@ -115,7 +115,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = '42';
//
@@ -132,7 +132,7 @@ class IntegerParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
//
// $param = new IntegerParam($adapter, $intValidator);

View File

@@ -62,7 +62,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-07-07");
@@ -81,7 +81,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-07-08");
@@ -103,7 +103,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDate2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-08-08");
@@ -122,7 +122,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-08-09");
@@ -140,7 +140,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = 1377012588;
@@ -156,7 +156,7 @@ class IntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
//

View File

@@ -62,7 +62,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorPrice()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 1.00;
@@ -81,7 +81,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorPrice2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.49;
@@ -100,7 +100,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsPrice()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.50;
@@ -119,7 +119,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorPrice()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.51;
@@ -137,7 +137,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = '42.50';
@@ -155,7 +155,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = -1;
@@ -173,7 +173,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException3()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 0;
@@ -191,7 +191,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException4()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $priceValidator = 42.50;
// $priceToValidate = 1;
//
@@ -208,7 +208,7 @@ class PriceParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $priceValidator = 42.50;
//
// $param = new PriceParam($adapter, $priceValidator, 'GBP');

View File

@@ -62,7 +62,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorQuantity()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 0;
//
@@ -80,7 +80,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorQuantity2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 41;
//
@@ -98,7 +98,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsQuantity()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 42;
//
@@ -116,7 +116,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorQuantity()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 43;
//
@@ -133,7 +133,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = '42';
//
@@ -150,7 +150,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = -1;
//
@@ -167,7 +167,7 @@ class QuantityParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = -1;
//

View File

@@ -62,7 +62,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
//
@@ -82,7 +82,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
//
@@ -102,7 +102,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-08-08");
//
@@ -122,7 +122,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-09-08");
//
@@ -142,7 +142,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-05-08");
//
@@ -162,7 +162,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-11-08");
//
@@ -182,7 +182,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-03-08");
//
@@ -202,7 +202,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-08-08");
//
@@ -222,7 +222,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-12-08");
//
@@ -242,7 +242,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorDateRepeatEveryFourMonthTwoTimes()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-03-09");
//
@@ -261,7 +261,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
//
@@ -278,7 +278,7 @@ class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
//
// $param = new RepeatedDateParam($adapter);

View File

@@ -61,7 +61,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInferiorDate()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
// $duration = 10;
@@ -84,7 +84,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
// $duration = 10;
@@ -106,7 +106,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-13");
// $duration = 10;
@@ -128,7 +128,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-18");
// $duration = 10;
@@ -150,7 +150,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-08");
// $duration = 10;
@@ -172,7 +172,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-13");
// $duration = 10;
@@ -194,7 +194,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-18");
// $duration = 10;
@@ -216,7 +216,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-08");
// $duration = 10;
@@ -238,7 +238,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-13");
// $duration = 10;
@@ -260,7 +260,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-18");
// $duration = 10;
@@ -282,7 +282,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-07-19");
// $duration = 10;
@@ -304,7 +304,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-08-01");
// $duration = 10;
@@ -327,7 +327,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-08-07");
// $duration = 10;
@@ -351,7 +351,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testSuperiorDateRepeatEveryMonthFourTime()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-10-19");
// $duration = 10;
@@ -372,7 +372,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function testInvalidArgumentException()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
// $duration = 10;
@@ -391,7 +391,7 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
// */
// public function isSerializableTest()
// {
// $adapter = new CouponBaseAdapter();
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
// $duration = 10;

View File

@@ -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()

View File

@@ -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');
@@ -165,8 +165,8 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
// */
// 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
// *

View File

@@ -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;
// }

View File

@@ -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));

View File

@@ -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;
@@ -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,

View File

@@ -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;
@@ -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'
// ),

View File

@@ -1,10 +1,10 @@
<?php
use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\Rule\AvailableForEveryoneManager;
use Thelia\Constraint\Rule\MatchForEveryoneManager;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\ConditionCollection;
require __DIR__ . '/../core/bootstrap.php';
@@ -685,11 +685,11 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
);
$rule2->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $container->get('thelia.constraint.factory');
$constraintFactory = $container->get('thelia.condition.factory');
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
$coupon1->setSerializedRules($serializedRules);
@@ -729,11 +729,11 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
AvailableForXArticlesManager::INPUT1 => 4,
);
$rule1->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $container->get('thelia.constraint.factory');
$constraintFactory = $container->get('thelia.condition.factory');
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
$coupon2->setSerializedRules($serializedRules);
@@ -765,15 +765,15 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua
$date = new \DateTime();
$coupon3->setExpirationDate($date->setTimestamp(strtotime("today + 2 months")));
$rule1 = new AvailableForEveryoneManager($adapter);
$rule1 = new MatchForEveryoneManager($adapter);
$operators = array();
$values = array();
$rule1->setValidatorsFromForm($operators, $values);
$rules = new CouponRuleCollection();
$rules = new ConditionCollection();
$rules->add($rule1);
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $container->get('thelia.constraint.factory');
$constraintFactory = $container->get('thelia.condition.factory');
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
$coupon3->setSerializedRules($serializedRules);

View File

@@ -25,7 +25,7 @@ use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\ConditionCollection;
require __DIR__ . '/../core/bootstrap.php';

View File

@@ -5,7 +5,7 @@ use Thelia\Constraint\Rule\AvailableForTotalAmount;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\CouponRuleCollection;
use Thelia\Coupon\ConditionCollection;
use Thelia\Model\ProductImage;
use Thelia\Model\CategoryImage;
use Thelia\Model\FolderImage;

View File

@@ -90,12 +90,15 @@ $(function($){
// Save rules on click
$.couponManager.onClickSaveRule = function() {
$('#constraint-save-btn').on('click', function () {
if($('#category-rule').val() == 'thelia.constraint.rule.available_for_everyone') {
// @todo translate + modal
var r= confirm("Do you really want to set this coupon available to everyone ?");
console.log('constraint-save-btn');
if($('#category-rule').val() == 'thelia.condition.match_for_everyone') {
// // @todo translate + modal
var r = confirm("Do you really want to set this coupon available to everyone ?");
if (r == true) {
$.couponManager.createOrUpdateRuleAjax();
}
} else {
$.couponManager.createOrUpdateRuleAjax();
}
});

View File

@@ -56,16 +56,29 @@
if($('[data-toggle="confirm"]').length){
$('[data-toggle="confirm"]').click(function(e){
var $link = $(this);
var modal = $(this).data('target');
var $this = $(this);
var $modal = $($this.data('target'));
$(modal).modal('show');
$modal.modal('show');
$(modal).on('shown', function () {
$('[data-confirm]').attr('href', $link.attr('href'));
$modal.on('shown', function () {
if($this.data('script')){
$('[data-confirm]').click(function(){
eval($this.data('script'));
$modal.modal('hide');
return false;
});
if($(modal).is(':hidden')){
}
else{
$('[data-confirm]').attr('href', $this.attr('href'));
}
});
if($modal.is(':hidden')){
e.preventDefault();
}

View File

@@ -24,8 +24,6 @@
</section> <!-- #wrapper -->
{/block}
{include file='includes/confirmation-modal.html'}
{block name="javascript-initialization"}
{javascripts file='assets/bootstrap-datepicker/js/bootstrap-datepicker.js'}
<script src="{$asset_url}"></script>
@@ -89,7 +87,7 @@
$('#constraint-add-operators-values').html('');
// Set the rule selector
$("#category-rule option").filter(function() {
return $(this).val() == 'thelia.constraint.rule.available_for_everyone';
return $(this).val() == 'thelia.condition.match_for_everyone';
}).prop('selected', true);
$.couponManager.onClickUpdateRule();

View File

@@ -190,7 +190,7 @@
<section class="row">
<div class="col-md-12 general-block-decorator clearfix">
<a id="constraint-save-btn" title="{intl l='Save this rule'}" class="btn btn-default btn-primary pull-right">
<a id="constraint-save-btn" title="{intl l='Save this rule'}" class="btn btn-default btn-primary pull-right" data-toggle="confirm" data-script="">
<span class="glyphicon glyphicon-plus-sign"></span> {intl l='Save this rule'}
</a>

View File

@@ -23,7 +23,7 @@ casper.start(thelia2_login_coupon_update_url, function() {
// Create rule
this.evaluate(function() {
$('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change();
$('#category-rule').val('thelia.condition.match_for_x_articles').change();
return true;
});
this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected.png');
@@ -133,7 +133,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() {
casper.then(function(){
// Create rule
this.evaluate(function() {
$('#category-rule').val('thelia.constraint.rule.available_for_total_amount').change();
$('#category-rule').val('thelia.condition.match_for_total_amount').change();
return true;
});
this.capture('tests/functionnal/casperjs/screenshot/coupons/rule-selected2.png');
@@ -234,7 +234,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() {
// Test add no condition rule
casper.then(function(){
this.evaluate(function() {
$('#category-rule').val('thelia.constraint.rule.available_for_x_articles').change();
$('#category-rule').val('thelia.condition.match_for_x_articles').change();
return true;
});
});
@@ -274,7 +274,7 @@ casper.thenOpen(thelia2_login_coupon_update_url, function() {
casper.then(function(){
this.evaluate(function() {
$('#category-rule').val('thelia.constraint.rule.available_for_everyone').change();
$('#category-rule').val('thelia.condition.match_for_everyone').change();
return true;
});
});