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

This commit is contained in:
gmorel
2013-09-25 16:36:14 +02:00
parent d6172f23cf
commit b7851b2d54
41 changed files with 1387 additions and 3637 deletions

View File

@@ -74,7 +74,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
}
/**
* Occurring when a Coupon rule is about to be updated
* Occurring when a Coupon condition is about to be updated
*
* @param CouponCreateOrUpdateEvent $event Event creation or update Coupon Rule
*/
@@ -86,7 +86,7 @@ class Coupon extends BaseAction implements EventSubscriberInterface
}
/**
* Occurring when a Coupon rule is about to be consumed
* Occurring when a Coupon condition is about to be consumed
*
* @param CouponConsumeEvent $event Event consuming Coupon
*/
@@ -138,13 +138,14 @@ class Coupon extends BaseAction implements EventSubscriberInterface
{
$coupon->setDispatcher($this->getDispatcher());
// Set default rule if none found
// Set default condition if none found
/** @var ConditionManagerInterface $noConditionRule */
$noConditionRule = $this->container->get('thelia.condition.match_for_everyone');
$constraintFactory = $this->container->get('thelia.condition.factory');
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
$couponRuleCollection = new ConditionCollection();
$couponRuleCollection->add($noConditionRule);
$defaultSerializedRule = $constraintFactory->serializeCouponRuleCollection(
$defaultSerializedRule = $conditionFactory->serializeConditionCollection(
$couponRuleCollection
);
@@ -179,11 +180,11 @@ class Coupon extends BaseAction implements EventSubscriberInterface
{
$coupon->setDispatcher($this->getDispatcher());
/** @var ConditionFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
$coupon->createOrUpdateConditions(
$constraintFactory->serializeConditionCollection($event->getConditions()),
$conditionFactory->serializeConditionCollection($event->getConditions()),
$event->getLocale()
);

View File

@@ -82,7 +82,7 @@ class ConditionFactory
if ($conditions !== null) {
/** @var $condition ConditionManagerInterface */
foreach ($conditions as $condition) {
// Remove all rule if the "no condition" condition is found
// Remove all condition if the "no condition" condition is found
// if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') {
// return base64_encode(json_encode(array($condition->getSerializableRule())));
// }
@@ -153,7 +153,7 @@ class ConditionFactory
*
* @param string $conditionServiceId ConditionManager class name
*
* @return array Ready to be drawn rule inputs
* @return array Ready to be drawn condition inputs
*/
public function getInputs($conditionServiceId)
{

View File

@@ -84,7 +84,7 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface
{
$this->adapter = $adapter;
$this->translator = $adapter->getTranslator();
$this->conditionValidator = $adapter->getConditionValidator();
$this->conditionValidator = $adapter->getConditionEvaluator();
}
// /**
@@ -94,13 +94,13 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface
// * validating $paramsToValidate against
// *
// * @return $this
// * @throws InvalidRuleException
// * @throws InvalidConditionException
// */
// protected function setValidators(array $validators)
// {
// foreach ($validators as $validator) {
// if (!$validator instanceof RuleValidator) {
// throw new InvalidRuleException(get_class());
// throw new InvalidConditionException(get_class());
// }
// if (!in_array($validator->getOperator(), $this->availableOperators)) {
// throw new InvalidConditionOperatorException(

View File

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

View File

@@ -159,17 +159,17 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract
return false;
}
$constraint1 = $this->conditionValidator->variableOpComparison(
$condition1 = $this->conditionValidator->variableOpComparison(
$this->adapter->getCartTotalPrice(),
$this->operators[self::INPUT1],
$this->values[self::INPUT1]
);
$constraint2 = $this->conditionValidator->variableOpComparison(
$condition2 = $this->conditionValidator->variableOpComparison(
$this->adapter->getCheckoutCurrency(),
$this->operators[self::INPUT2],
$this->values[self::INPUT2]
);
if ($constraint1 && $constraint2) {
if ($condition1 && $condition2) {
return true;
}

View File

@@ -203,9 +203,9 @@ class CouponController extends BaseAdminController
} else {
// Display
// Prepare the data that will hydrate the form
/** @var ConditionFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
$conditions = $constraintFactory->unserializeConditionCollection(
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
$conditions = $conditionFactory->unserializeConditionCollection(
$coupon->getSerializedRules()
);
@@ -318,26 +318,26 @@ class CouponController extends BaseAdminController
return $this->pageNotFound();
}
$rules = new ConditionCollection();
$conditions = new ConditionCollection();
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
$conditionsReceived = json_decode($this->getRequest()->get('rules'));
foreach ($conditionsReceived as $conditionReceived) {
$rule = $conditionFactory->build(
$condition = $conditionFactory->build(
$conditionReceived->serviceId,
(array) $conditionReceived->operators,
(array) $conditionReceived->values
);
$rules->add(clone $rule);
$conditions->add(clone $condition);
}
// $coupon->setSerializedRules(
// $constraintFactory->serializeCouponRuleCollection($rules)
// $conditionFactory->serializeCouponRuleCollection($rules)
// );
$conditionEvent = new ConditionCreateOrUpdateEvent(
$rules
$conditions
);
$conditionEvent->setCouponModel($coupon);
@@ -350,19 +350,19 @@ class CouponController extends BaseAdminController
$this->adminLogAppend(
sprintf(
'Coupon %s (ID %s) rules updated',
'Coupon %s (ID %s) conditions updated',
$conditionEvent->getCouponModel()->getTitle(),
$conditionEvent->getCouponModel()->getServiceId()
)
);
$cleanedRules = $this->cleanConditionForTemplate($rules);
$cleanedConditions = $this->cleanConditionForTemplate($conditions);
return $this->render(
'coupon/rules',
'coupon/conditions',
array(
'couponId' => $couponId,
'rules' => $cleanedRules,
'rules' => $cleanedConditions,
'urlEdit' => $couponId,
'urlDelete' => $couponId
)
@@ -469,7 +469,7 @@ class CouponController extends BaseAdminController
$message = false;
try {
// Check the form against constraints violations
// Check the form against conditions violations
$form = $this->validateForm($creationForm, 'POST');
// Get the form field values
@@ -525,7 +525,7 @@ class CouponController extends BaseAdminController
}
/**
* Get all available rules
* Get all available conditions
*
* @return array
*/
@@ -560,18 +560,18 @@ class CouponController extends BaseAdminController
$cleanedCoupons = array();
/** @var CouponInterface $availableCoupon */
foreach ($availableCoupons as $availableCoupon) {
$rule = array();
$rule['serviceId'] = $availableCoupon->getServiceId();
$rule['name'] = $availableCoupon->getName();
$rule['toolTip'] = $availableCoupon->getToolTip();
$cleanedCoupons[] = $rule;
$condition = array();
$condition['serviceId'] = $availableCoupon->getServiceId();
$condition['name'] = $availableCoupon->getName();
$condition['toolTip'] = $availableCoupon->getToolTip();
$cleanedCoupons[] = $condition;
}
return $cleanedCoupons;
}
/**
* Clean rule for template
* Clean condition for template
*
* @param ConditionCollection $conditions Condition collection
*

View File

@@ -25,8 +25,8 @@ namespace Thelia\Core\Template\Loop;
use Propel\Runtime\ActiveQuery\Criteria;
use Propel\Runtime\Util\PropelModelPager;
use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\ConditionManagerInterface;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Template\Element\BaseI18nLoop;
use Thelia\Core\Template\Element\LoopResult;
@@ -68,7 +68,7 @@ class Coupon extends BaseI18nLoop
/**
* Execute Loop
*
* @param PropelModelPager $pagination
* @param PropelModelPager $pagination Pagination manager
*
* @return \Thelia\Core\Template\Element\LoopResult
*/
@@ -94,8 +94,8 @@ class Coupon extends BaseI18nLoop
$coupons = $this->search($search, $pagination);
$loopResult = new LoopResult();
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
/** @var Request $request */
$request = $this->container->get('request');
@@ -105,7 +105,7 @@ class Coupon extends BaseI18nLoop
/** @var MCoupon $coupon */
foreach ($coupons as $coupon) {
$loopResultRow = new LoopResultRow();
$rules = $constraintFactory->unserializeCouponRuleCollection(
$conditions = $conditionFactory->unserializeConditionCollection(
$coupon->getSerializedRules()
);
@@ -130,10 +130,10 @@ class Coupon extends BaseI18nLoop
$datediff = $coupon->getExpirationDate()->getTimestamp() - $now;
$daysLeftBeforeExpiration = floor($datediff/(60*60*24));
$cleanedRules = array();
/** @var CouponRuleInterface $rule */
foreach ($rules->getRules() as $rule) {
$cleanedRules[] = $rule->getToolTip();
$cleanedConditions = array();
/** @var ConditionManagerInterface $condition */
foreach ($conditions->getConditions() as $condition) {
$cleanedConditions[] = $condition->getToolTip();
}
$loopResultRow->set("ID", $coupon->getId())
->set("IS_TRANSLATED", $coupon->getVirtualColumn('IS_TRANSLATED'))
@@ -149,7 +149,7 @@ class Coupon extends BaseI18nLoop
->set("IS_AVAILABLE_ON_SPECIAL_OFFERS", $coupon->getIsAvailableOnSpecialOffers())
->set("IS_ENABLED", $coupon->getIsEnabled())
->set("AMOUNT", $coupon->getAmount())
->set("APPLICATION_CONDITIONS", $cleanedRules)
->set("APPLICATION_CONDITIONS", $cleanedConditions)
->set("TOOLTIP", $couponManager->getToolTip())
->set("DAY_LEFT_BEFORE_EXPIRATION", $daysLeftBeforeExpiration)
->set("SERVICE_ID", $couponManager->getServiceId());

View File

@@ -165,11 +165,11 @@ interface AdapterInterface
public function getRequest();
/**
* Return Condition Validator
* Return Condition Evaluator
*
* @return ConditionEvaluator
*/
public function getConditionValidator();
public function getConditionEvaluator();
/**
* Return all available currencies

View File

@@ -27,16 +27,13 @@ use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Translator;
use Symfony\Component\Translation\TranslatorInterface;
use Thelia\Constraint\ConditionValidator;
use Thelia\Core\HttpFoundation\Request;
use Thelia\Core\Security\SecurityContext;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Model\Coupon;
use Thelia\Model\CouponQuery;
use Thelia\Cart\CartTrait;
use Thelia\Model\Currency;
use Thelia\Model\CurrencyQuery;
use Thelia\Model\LangQuery;
/**
* Created by JetBrains PhpStorm.
@@ -266,7 +263,7 @@ class BaseAdapter implements AdapterInterface
*
* @return ConditionValidator
*/
public function getConditionValidator()
public function getConditionEvaluator()
{
return $this->container->get('thelia.condition.validator');
}

View File

@@ -25,13 +25,11 @@ namespace Thelia\Coupon;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Translation\Exception\NotFoundResourceException;
use Thelia\Constraint\ConstraintFactory;
use Thelia\Constraint\Rule\CouponRuleInterface;
use Thelia\Condition\ConditionFactory;
use Thelia\Coupon\Type\CouponInterface;
use Thelia\Exception\CouponExpiredException;
use Thelia\Exception\InvalidRuleException;
use Thelia\Exception\InvalidConditionException;
use Thelia\Model\Coupon;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
/**
* Created by JetBrains PhpStorm.
@@ -57,7 +55,7 @@ class CouponFactory
*
* @param ContainerInterface $container Service container
*/
function __construct(ContainerInterface $container)
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->adapter = $container->get('thelia.adapter');
@@ -69,6 +67,7 @@ class CouponFactory
* @param string $couponCode Coupon code ex: XMAS
*
* @throws \Thelia\Exception\CouponExpiredException
* @throws \Thelia\Exception\InvalidConditionException
* @throws \Symfony\Component\Translation\Exception\NotFoundResourceException
* @return CouponInterface ready to be processed
*/
@@ -87,9 +86,9 @@ class CouponFactory
}
/** @var CouponInterface $couponInterface */
$couponInterface = $this->buildCouponInterfacFromModel($couponModel);
if ($couponInterface->getRules()->isEmpty()) {
throw new InvalidRuleException(
$couponInterface = $this->buildCouponInterfaceFromModel($couponModel);
if ($couponInterface->getConditions()->isEmpty()) {
throw new InvalidConditionException(
get_class($couponInterface)
);
}
@@ -104,7 +103,7 @@ class CouponFactory
*
* @return CouponInterface ready to use CouponInterface object instance
*/
protected function buildCouponInterfacFromModel(Coupon $model)
protected function buildCouponInterfaceFromModel(Coupon $model)
{
$isCumulative = ($model->getIsCumulative() == 1 ? true : false);
$isRemovingPostage = ($model->getIsRemovingPostage() == 1 ? true : false);
@@ -130,13 +129,13 @@ class CouponFactory
$model->getExpirationDate()
);
/** @var ConstraintFactory $constraintFactory */
$constraintFactory = $this->container->get('thelia.condition.factory');
$rules = $constraintFactory->unserializeCouponRuleCollection(
/** @var ConditionFactory $conditionFactory */
$conditionFactory = $this->container->get('thelia.condition.factory');
$conditions = $conditionFactory->unserializeConditionCollection(
$model->getSerializedRules()
);
$couponManager->setRules($rules);
$couponManager->setConditions($conditions);
return $couponManager;
}

View File

@@ -30,7 +30,7 @@ namespace Thelia\Coupon;
*
* Manage how Coupons could interact with a Checkout
*
* @package Coupon
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
@@ -39,11 +39,11 @@ class RuleOrganizer implements RuleOrganizerInterface
/**
* Organize ConditionManagerInterface
*
* @param array $rules Array of ConditionManagerInterface
* @param array $conditions Array of ConditionManagerInterface
*
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $rules)
public function organize(array $conditions)
{
// TODO: Implement organize() method.
}

View File

@@ -28,9 +28,9 @@ namespace Thelia\Coupon;
* Date: 8/19/13
* Time: 3:24 PM
*
* Manage how Coupons could interact with a Checkout
* Manage how Condition could interact with a Checkout
*
* @package Coupon
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
@@ -39,9 +39,9 @@ interface RuleOrganizerInterface
/**
* Organize ConditionManagerInterface
*
* @param array $rules Array of ConditionManagerInterface
* @param array $conditions Array of ConditionManagerInterface
*
* @return array Array of ConditionManagerInterface sorted
*/
public function organize(array $rules);
public function organize(array $conditions);
}

View File

@@ -24,13 +24,12 @@
namespace Thelia\Coupon\Type;
use Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Constraint\ConstraintManager;
use Thelia\Constraint\ConditionValidator;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Core\Translation\Translator;
use Thelia\Coupon\AdapterInterface;
use Thelia\Coupon\ConditionCollection;
use Thelia\Coupon\RuleOrganizerInterface;
use Thelia\Exception\InvalidRuleException;
use Thelia\Exception\InvalidConditionException;
/**
* Created by JetBrains PhpStorm.
@@ -55,11 +54,10 @@ abstract class CouponAbstract implements CouponInterface
protected $organizer = null;
/** @var ConditionCollection Array of ConditionManagerInterface */
protected $rules = null;
/** @var ConditionValidator Constraint validator */
protected $constraintValidator = null;
protected $conditions = null;
/** @var ConditionEvaluator Condition validator */
protected $conditionEvaluator = null;
/** @var string Service Id */
@@ -108,17 +106,17 @@ abstract class CouponAbstract implements CouponInterface
*
* @param AdapterInterface $adapter Service adapter
*/
function __construct(AdapterInterface $adapter)
public function __construct(AdapterInterface $adapter)
{
$this->adapter = $adapter;
$this->translator = $adapter->getTranslator();
$this->constraintValidator = $adapter->getConditionValidator();
$this->conditionEvaluator = $adapter->getConditionEvaluator();
}
/**
* Set Rule Organizer
* Set Condition Organizer
*
* @param RuleOrganizerInterface $organizer Manage Rule groups (&& and ||)
* @param RuleOrganizerInterface $organizer Manage Condition groups (&& and ||)
*
* @return $this
*/
@@ -207,23 +205,23 @@ abstract class CouponAbstract implements CouponInterface
*
* @return ConditionCollection
*/
public function getRules()
public function getConditions()
{
return clone $this->rules;
return clone $this->conditions;
}
/**
* Replace the existing Rules by those given in parameter
* If one Rule is badly implemented, no Rule will be added
* Replace the existing Conditions by those given in parameter
* If one Condition is badly implemented, no Condition will be added
*
* @param ConditionCollection $rules ConditionManagerInterface to add
* @param ConditionCollection $conditions ConditionManagerInterface to add
*
* @return $this
* @throws \Thelia\Exception\InvalidRuleException
* @throws \Thelia\Exception\InvalidConditionException
*/
public function setRules(ConditionCollection $rules)
public function setConditions(ConditionCollection $conditions)
{
$this->rules = $rules;
$this->conditions = $conditions;
return $this;
}
@@ -249,7 +247,6 @@ abstract class CouponAbstract implements CouponInterface
return $this->isAvailableOnSpecialOffers;
}
/**
* Check if Coupon has been disabled by admin
*
@@ -300,14 +297,14 @@ abstract class CouponAbstract implements CouponInterface
/**
* Check if the current Coupon is matching its conditions (Rules)
* Check if the current state of the application is matching this Coupon conditions
* Thelia variables are given by the AdapterInterface
*
* @return bool
*/
public function isMatching()
{
return $this->constraintValidator->isMatching($this->rules);
return $this->conditionEvaluator->isMatching($this->conditions);
}

View File

@@ -142,7 +142,7 @@ interface CouponInterface
*
* @return ConditionCollection A set of ConditionManagerInterface
*/
public function getRules();
public function getConditions();
/**
* Replace the existing Rules by those given in parameter
@@ -151,9 +151,9 @@ interface CouponInterface
* @param ConditionCollection $rules ConditionManagerInterface to add
*
* @return $this
* @throws \Thelia\Exception\InvalidRuleException
* @throws \Thelia\Exception\InvalidConditionException
*/
public function setRules(ConditionCollection $rules);
public function setConditions(ConditionCollection $rules);
/**
* Return Coupon expiration date

View File

@@ -23,7 +23,6 @@
namespace Thelia\Coupon\Type;
use Thelia\Constraint\ConstraintManager;
use Thelia\Coupon\Type\CouponAbstract;
/**

View File

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

View File

@@ -30,23 +30,23 @@ use Thelia\Log\Tlog;
* Date: 8/19/13
* Time: 3:24 PM
*
* Thrown when a Rule is badly implemented
* Thrown when a Condition is badly implemented
*
* @package Coupon
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class InvalidRuleException extends \RuntimeException
class InvalidConditionException extends \RuntimeException
{
/**
* InvalidConditionOperatorException thrown when a Rule is badly implemented
* InvalidConditionOperatorException thrown when a Condition is badly implemented
*
* @param string $className Class name
*/
public function __construct($className)
{
$message = 'Invalid Rule given to ' . $className;
$message = 'Invalid Condition given to ' . $className;
Tlog::getInstance()->addError($message);
parent::__construct($message);

View File

@@ -0,0 +1,227 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition\Implementation;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Operators;
use Thelia\Coupon\AdapterInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test ConditionFactory Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
}
/**
* Check the Rules serialization module
*/
public function testBuild()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 40.00,
MatchForTotalAmountManager::INPUT2 => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$conditionFactory = new ConditionFactory($this->getContainer());
$ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
$expected = $condition1;
$actual = $ruleManager1;
$this->assertEquals($expected, $actual);
$this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId());
$this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
}
// /**
// * Check the Rules serialization module
// */
// public function testBuildFail()
// {
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
// ->disableOriginalConstructor()
// ->getMock();
//
// /** @var AdapterInterface $stubAdapter */
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
// ->disableOriginalConstructor()
// ->getMock();
//
// $stubAdapter->expects($this->any())
// ->method('getTranslator')
// ->will($this->returnValue($stubTranslator));
//
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
// $operators = array(
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
// );
// $values = array(
// MatchForTotalAmountManager::INPUT1 => 40.00,
// MatchForTotalAmountManager::INPUT2 => 'EUR'
// );
// $condition1->setValidatorsFromForm($operators, $values);
//
// $conditionFactory = new ConditionFactory($this->getContainer());
// $conditionManager1 = $conditionFactory->build('unset.service', $operators, $values);
//
// $expected = false;
// $actual = $conditionManager1;
//
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Check the Rules serialization module
// */
// public function testRuleSerialisation()
// {
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
// ->disableOriginalConstructor()
// ->getMock();
//
// /** @var AdapterInterface $stubAdapter */
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
// ->disableOriginalConstructor()
// ->getMock();
//
// $stubAdapter->expects($this->any())
// ->method('getTranslator')
// ->will($this->returnValue($stubTranslator));
//
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
// $operators = array(
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
// );
// $values = array(
// MatchForTotalAmountManager::INPUT1 => 40.00,
// MatchForTotalAmountManager::INPUT2 => 'EUR'
// );
// $condition1->setValidatorsFromForm($operators, $values);
//
// $condition2 = new MatchForTotalAmountManager($stubAdapter);
// $operators = array(
// MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
// MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
// );
// $values = array(
// MatchForTotalAmountManager::INPUT1 => 400.00,
// MatchForTotalAmountManager::INPUT2 => 'EUR'
// );
// $condition2->setValidatorsFromForm($operators, $values);
//
// $conditions = new ConditionCollection();
// $conditions->add($condition1);
// $conditions->add($condition2);
//
// $conditionFactory = new ConditionFactory($this->getContainer());
//
// $serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
// $unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
//
// $expected = (string) $conditions;
// $actual = (string) $unserializedConditions;
//
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Get Mocked Container with 2 Rules
// *
// * @return ContainerBuilder
// */
// public function getContainer()
// {
// $container = new ContainerBuilder();
//
// $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
// ->disableOriginalConstructor()
// ->getMock();
//
// /** @var AdapterInterface $stubAdapter */
// $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
// ->disableOriginalConstructor()
// ->getMock();
//
// $stubAdapter->expects($this->any())
// ->method('getTranslator')
// ->will($this->returnValue($stubTranslator));
//
// $condition1 = new MatchForTotalAmountManager($stubAdapter);
// $condition2 = new MatchForXArticlesManager($stubAdapter);
//
// $adapter = new BaseAdapter($container);
//
// $container->set('thelia.condition.match_for_total_amount', $condition1);
// $container->set('thelia.condition.match_for_x_articles', $condition2);
// $container->set('thelia.adapter', $adapter);
//
// return $container;
// }
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -21,12 +21,12 @@
/* */
/**********************************************************************************/
namespace Thelia\Constraint;
namespace Thelia\Condition\Implementation;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Coupon\AdapterInterface;
use Thelia\Coupon\BaseAdapter;
use Thelia\Coupon\ConditionCollection;
@@ -41,7 +41,7 @@ use Thelia\Coupon\ConditionCollection;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase
{
/**
@@ -54,8 +54,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestSuccess1Rules()
{
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
$conditionEvaluator = new ConditionEvaluator();
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -66,23 +68,23 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
->method('getConditionEvaluator')
->will($this->returnValue($conditionEvaluator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => '>',
AvailableForTotalAmountManager::INPUT2 => '=='
MatchForTotalAmountManager::INPUT1 => '>',
MatchForTotalAmountManager::INPUT2 => '=='
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$rules = new ConditionCollection();
$rules->add($rule1);
$conditions = new ConditionCollection();
$conditions->add($condition1);
$isValid = $ConstraintValidator->isMatching($rules);
$isValid = $conditionEvaluator->isMatching($conditions);
$expected = true;
$actual =$isValid;
@@ -91,8 +93,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestFail1Rules()
{
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
$conditionEvaluator = new ConditionEvaluator();
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -103,33 +107,35 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->method('getCheckoutCurrency')
->will($this->returnValue('EUR'));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
->method('getConditionEvaluator')
->will($this->returnValue($conditionEvaluator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => '>',
AvailableForTotalAmountManager::INPUT2 => '=='
MatchForTotalAmountManager::INPUT1 => '>',
MatchForTotalAmountManager::INPUT2 => '=='
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$rules = new ConditionCollection();
$rules->add($rule1);
$conditions = new ConditionCollection();
$conditions->add($condition1);
$isValid = $ConstraintValidator->isMatching($rules);
$isValid = $conditionEvaluator->isMatching($conditions);
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules');
$this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions');
}
public function testTestSuccess2Rules()
{
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
$conditionEvaluator = new ConditionEvaluator();
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -143,33 +149,33 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(5));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
->method('getConditionEvaluator')
->will($this->returnValue($conditionEvaluator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => '>',
AvailableForTotalAmountManager::INPUT2 => '=='
MatchForTotalAmountManager::INPUT1 => '>',
MatchForTotalAmountManager::INPUT2 => '=='
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$condition2 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => '>'
MatchForXArticlesManager::INPUT1 => '>'
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule2->setValidatorsFromForm($operators, $values);
$condition2->setValidatorsFromForm($operators, $values);
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
$conditions = new ConditionCollection();
$conditions->add($condition1);
$conditions->add($condition2);
$isValid = $ConstraintValidator->isMatching($rules);
$isValid = $conditionEvaluator->isMatching($conditions);
$expected = true;
$actual =$isValid;
@@ -178,8 +184,10 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
public function testTestFail2Rules()
{
$ConstraintValidator = new ConditionValidator();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
$conditionEvaluator = new ConditionEvaluator();
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -193,101 +201,101 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(5));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue($ConstraintValidator));
->method('getConditionEvaluator')
->will($this->returnValue($conditionEvaluator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => '>',
AvailableForTotalAmountManager::INPUT2 => '=='
MatchForTotalAmountManager::INPUT1 => '>',
MatchForTotalAmountManager::INPUT2 => '=='
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$condition2 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => '>'
MatchForXArticlesManager::INPUT1 => '>'
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule2->setValidatorsFromForm($operators, $values);
$condition2->setValidatorsFromForm($operators, $values);
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
$conditions = new ConditionCollection();
$conditions->add($condition1);
$conditions->add($condition2);
$isValid = $ConstraintValidator->isMatching($rules);
$isValid = $conditionEvaluator->isMatching($conditions);
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual, 'Constraints validator always think Customer is matching rules');
$this->assertEquals($expected, $actual, 'Conditions evaluator always think Customer is matching conditions');
}
public function testVariableOpComparisonSuccess()
{
$ConstraintValidator = new ConditionValidator();
$conditionEvaluator = new ConditionEvaluator();
$expected = true;
$actual = $ConstraintValidator->variableOpComparison(1, Operators::EQUAL, 1);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::DIFFERENT, 2);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR, 0);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR, 2);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
$actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
$actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
$this->assertEquals($expected, $actual);
}
public function testVariableOpComparisonFail()
{
$ConstraintValidator = new ConditionValidator();
$conditionEvaluator = new ConditionEvaluator();
$expected = false;
$actual = $ConstraintValidator->variableOpComparison(2, Operators::EQUAL, 1);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(2, Operators::DIFFERENT, 2);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(0, Operators::SUPERIOR, 0);
$actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(3, Operators::INFERIOR, 2);
$actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
$actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
$actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
$this->assertEquals($expected, $actual);
$actual = $ConstraintValidator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
$actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
$this->assertEquals($expected, $actual);
}
@@ -297,9 +305,9 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
*/
public function testVariableOpComparisonException()
{
$ConstraintValidator = new ConditionValidator();
$conditionEvaluator = new ConditionEvaluator();
$expected = true;
$actual = $ConstraintValidator->variableOpComparison(1, 'bad', 1);
$actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1);
$this->assertEquals($expected, $actual);
}
@@ -316,7 +324,8 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -324,13 +333,13 @@ class ConstraintValidatorTest extends \PHPUnit_Framework_TestCase
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$condition2 = new MatchForXArticlesManager($stubAdapter);
$adapter = new BaseAdapter($container);
$container->set('thelia.condition.match_for_total_amount', $rule1);
$container->set('thelia.condition.match_for_x_articles', $rule2);
$container->set('thelia.condition.match_for_total_amount', $condition1);
$container->set('thelia.condition.match_for_x_articles', $condition2);
$container->set('thelia.adapter', $adapter);
return $container;

View File

@@ -0,0 +1,610 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Coupon\AdapterInterface;
use Thelia\Exception\InvalidConditionValueException;
use Thelia\Model\Currency;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test MatchForTotalAmountManager Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
{
/** @var AdapterInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR')
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubAdapter->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$currency1 = new Currency();
$currency1->setCode('EUR');
$currency2 = new Currency();
$currency2->setCode('USD');
$stubAdapter->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue(array($currency1, $currency2)));
return $stubAdapter;
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
/** @var AdapterInterface $stubAdapter */
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::IN,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => '400',
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator2()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
/** @var AdapterInterface $stubAdapter */
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::INFERIOR
);
$values = array(
MatchForTotalAmountManager::INPUT1 => '400',
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 'X',
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue2()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400,
MatchForTotalAmountManager::INPUT2 => 'FLA');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionInferior()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionInferior()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionInferiorEquals()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionInferiorEquals2()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionInferiorEquals()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionEqual()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionEqual()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionSuperiorEquals()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionSuperiorEquals2()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionSuperiorEquals()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionSuperior()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionSuperior()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testMatchingConditionCurrency()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmountManager::isMatching
*
*/
public function testNotMatchingConditionCurrency()
{
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->generateAdapterStub(400.00, 'EUR');
$condition1 = new MatchForTotalAmountManager($stubAdapter);
$operators = array(
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
MatchForTotalAmountManager::INPUT1 => 400.00,
MatchForTotalAmountManager::INPUT2 => 'USD');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -21,12 +21,12 @@
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
namespace Thelia\Condition\Implementation;
use Thelia\Constraint\ConditionValidator;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Constraint\Rule\SerializableRule;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\AdapterInterface;
/**
* Created by JetBrains PhpStorm.
@@ -39,12 +39,9 @@ use Thelia\Constraint\Rule\SerializableRule;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
class MatchForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
{
// /** @var AdapterInterface $stubTheliaAdapter */
// protected $stubTheliaAdapter = null;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
@@ -57,32 +54,34 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
/** @var AdapterInterface $stubAdapter */
$stubAdapter->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::IN
MatchForXArticlesManager::INPUT1 => Operators::IN
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 5
MatchForXArticlesManager::INPUT1 => 5
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -92,12 +91,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForXArticlesManager::setValidators
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -105,19 +105,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 'X'
MatchForXArticlesManager::INPUT1 => 'X'
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -127,12 +127,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleInferior()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -140,19 +141,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 5
MatchForXArticlesManager::INPUT1 => 5
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -162,12 +163,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testNotMatchingRuleInferior()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -175,19 +177,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4,
MatchForXArticlesManager::INPUT1 => 4,
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
@@ -197,12 +199,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleInferiorEquals()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -210,19 +213,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 5,
MatchForXArticlesManager::INPUT1 => 5,
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -232,12 +235,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleInferiorEquals2()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -245,19 +249,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -267,12 +271,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testNotMatchingRuleInferiorEquals()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -280,19 +285,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
MatchForXArticlesManager::INPUT1 => Operators::INFERIOR_OR_EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 3
MatchForXArticlesManager::INPUT1 => 3
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
@@ -302,12 +307,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test equals operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleEqual()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -315,19 +321,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::EQUAL
MatchForXArticlesManager::INPUT1 => Operators::EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -337,12 +343,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test equals operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testNotMatchingRuleEqual()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -350,19 +357,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::EQUAL
MatchForXArticlesManager::INPUT1 => Operators::EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 5
MatchForXArticlesManager::INPUT1 => 5
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
@@ -372,12 +379,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleSuperiorEquals()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -385,19 +393,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -407,12 +415,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleSuperiorEquals2()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -420,19 +429,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 3
MatchForXArticlesManager::INPUT1 => 3
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -442,12 +451,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testNotMatchingRuleSuperiorEquals()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -455,19 +465,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 5
MatchForXArticlesManager::INPUT1 => 5
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
@@ -477,12 +487,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testMatchingRuleSuperior()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -490,19 +501,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 3
MatchForXArticlesManager::INPUT1 => 3
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
@@ -512,12 +523,13 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForXArticlesManager::isMatching
* @covers Thelia\Condition\Implementation\MatchForXArticlesManager::isMatching
*
*/
public function testNotMatchingRuleSuperior()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -525,19 +537,19 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
@@ -546,7 +558,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
public function testGetSerializableRule()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -554,22 +567,22 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $rule1->getSerializableRule();
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableRule();
$expected->ruleServiceId = $rule1->getServiceId();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
@@ -581,7 +594,8 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
public function testGetAvailableOperators()
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
/** @var AdapterInterface $stubAdapter */
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
->disableOriginalConstructor()
->getMock();
@@ -589,20 +603,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$rule1 = new AvailableForXArticlesManager($stubAdapter);
$condition1 = new MatchForXArticlesManager($stubAdapter);
$operators = array(
AvailableForXArticlesManager::INPUT1 => Operators::SUPERIOR
MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
);
$values = array(
AvailableForXArticlesManager::INPUT1 => 4
MatchForXArticlesManager::INPUT1 => 4
);
$rule1->setValidatorsFromForm($operators, $values);
$condition1->setValidatorsFromForm($operators, $values);
$expected = array(
AvailableForXArticlesManager::INPUT1 => array(
MatchForXArticlesManager::INPUT1 => array(
Operators::INFERIOR,
Operators::INFERIOR_OR_EQUAL,
Operators::EQUAL,
@@ -610,7 +624,7 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
Operators::SUPERIOR
)
);
$actual = $rule1->getAvailableOperators();
$actual = $condition1->getAvailableOperators();
$this->assertEquals($expected, $actual);
@@ -626,20 +640,20 @@ class AvailableForXArticlesManagerTest extends \PHPUnit_Framework_TestCase
// ->method('getNbArticlesInCart')
// ->will($this->returnValue(4));
//
// $rule1 = new MatchForXArticlesManager($stubAdapter);
// $condition1 = new MatchForXArticlesManager($stubAdapter);
// $operators = array(
// MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR
// );
// $values = array(
// MatchForXArticlesManager::INPUT1 => 4
// );
// $rule1->setValidatorsFromForm($operators, $values);
// $condition1->setValidatorsFromForm($operators, $values);
//
// $expected = array(
// $operators,
// $values
// );
// $actual = $rule1->getValidators();
// $actual = $condition1->getValidators();
//
// $this->assertEquals($expected, $actual);
//

View File

@@ -0,0 +1,114 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Condition;
use Thelia\Core\Translation\Translator;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test Operators Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class OperatorsTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
public function testOperatorI18n()
{
/** @var Translator $stubTranslator */
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnCallback((array($this, 'callbackI18n'))));
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR);
$expected = 'inferior to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL);
$expected = 'inferior or equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::EQUAL);
$expected = 'equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL);
$expected = 'superior or equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR);
$expected = 'superior to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT);
$expected = 'different from';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::IN);
$expected = 'in';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
$expected = 'not in';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, 'unexpected operator');
$expected = 'unexpected operator';
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
function callbackI18n()
{
$args = func_get_args();
return $args[0];
}
}

View File

@@ -1,228 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Constraint;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\AvailableForXArticlesManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Coupon\BaseAdapter;
use Thelia\Coupon\ConditionCollection;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test ConstraintManager Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConstraintFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
}
/**
* Check the Rules serialization module
*/
public function testBuild()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 40.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR'
);
$rule1->setValidatorsFromForm($operators, $values);
/** @var ConstraintManager $constraintManager */
$constraintFactory = new ConstraintFactory($this->getContainer());
$ruleManager1 = $constraintFactory->build($rule1->getServiceId(), $operators, $values);
$expected = $rule1;
$actual = $ruleManager1;
$this->assertEquals($expected, $actual);
$this->assertEquals($rule1->getServiceId(), $ruleManager1->getServiceId());
$this->assertEquals($rule1->getValidators(), $ruleManager1->getValidators());
}
/**
* Check the Rules serialization module
*/
public function testBuildFail()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 40.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR'
);
$rule1->setValidatorsFromForm($operators, $values);
/** @var ConstraintManager $constraintManager */
$constraintFactory = new ConstraintFactory($this->getContainer());
$ruleManager1 = $constraintFactory->build('unset.service', $operators, $values);
$expected = false;
$actual = $ruleManager1;
$this->assertEquals($expected, $actual);
}
/**
* Check the Rules serialization module
*/
public function testRuleSerialisation()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 40.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR'
);
$rule1->setValidatorsFromForm($operators, $values);
$rule2 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR'
);
$rule2->setValidatorsFromForm($operators, $values);
$rules = new ConditionCollection();
$rules->add($rule1);
$rules->add($rule2);
/** @var ConstraintManager $constraintManager */
$constraintFactory = new ConstraintFactory($this->getContainer());
$serializedRules = $constraintFactory->serializeCouponRuleCollection($rules);
$unserializedRules = $constraintFactory->unserializeCouponRuleCollection($serializedRules);
$expected = (string) $rules;
$actual = (string) $unserializedRules;
$this->assertEquals($expected, $actual);
}
/**
* Get Mocked Container with 2 Rules
*
* @return ContainerBuilder
*/
public function getContainer()
{
$container = new ContainerBuilder();
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$rule2 = new AvailableForXArticlesManager($stubAdapter);
$adapter = new BaseAdapter($container);
$container->set('thelia.condition.match_for_total_amount', $rule1);
$container->set('thelia.condition.match_for_x_articles', $rule2);
$container->set('thelia.adapter', $adapter);
return $container;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -1,592 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use Thelia\Constraint\ConditionValidator;
use Thelia\Constraint\Rule\AvailableForTotalAmountManager;
use Thelia\Constraint\Rule\Operators;
use Thelia\Exception\InvalidConditionValueException;
use Thelia\Model\Currency;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test MatchForTotalAmountManager Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class AvailableForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
{
/** @var AdapterInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR')
{
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\CouponBaseAdapter')
->disableOriginalConstructor()
->getMock();
$stubAdapter->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubAdapter->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubAdapter->expects($this->any())
->method('getConstraintValidator')
->will($this->returnValue(new ConditionValidator()));
$currency1 = new Currency();
$currency1->setCode('EUR');
$currency2 = new Currency();
$currency2->setCode('USD');
$stubAdapter->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue(array($currency1, $currency2)));
return $stubAdapter;
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::IN,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => '400',
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator2()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::INFERIOR
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => '400',
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 'X',
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Coupon\Rule\AvailableForTotalAmountManager::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue2()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400,
AvailableForTotalAmountManager::INPUT2 => 'FLA');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleInferior()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleInferior()
{
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleInferiorEquals()
{
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleInferiorEquals2()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleInferiorEquals()
{
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::INFERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleEqual()
{
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleEqual()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleSuperiorEquals()
{
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleSuperiorEquals2()
{
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleSuperiorEquals()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR_OR_EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleSuperior()
{
$stubAdapter = $this->generateAdapterStub(401, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleSuperior()
{
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testMatchingRuleCurrency()
{
$stubAdapter = $this->generateAdapterStub(400, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'EUR');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Constraint\Rule\AvailableForTotalAmountManager::isMatching
*
*/
public function testNotMatchingRuleCurrency()
{
$stubAdapter = $this->generateAdapterStub(400.00, 'EUR');
$rule1 = new AvailableForTotalAmountManager($stubAdapter);
$operators = array(
AvailableForTotalAmountManager::INPUT1 => Operators::EQUAL,
AvailableForTotalAmountManager::INPUT2 => Operators::EQUAL
);
$values = array(
AvailableForTotalAmountManager::INPUT1 => 400.00,
AvailableForTotalAmountManager::INPUT2 => 'USD');
$rule1->setValidatorsFromForm($operators, $values);
$isValid = $rule1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -1,481 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use Thelia\Constraint\Rule\Operators;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test Operators Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class OperatorsTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
// public function testSomething()
// {
// // Stop here and mark this test as incomplete.
// $this->markTestIncomplete(
// 'This test has not been implemented yet.'
// );
// }
public function testOperatorI18n()
{
$stubTranslator = $this->getMockBuilder('\Symfony\Component\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnCallback((array($this, 'callbackI18n'))));
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR);
$expected = 'inferior to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL);
$expected = 'inferior or equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::EQUAL);
$expected = 'equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL);
$expected = 'superior or equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR);
$expected = 'superior to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT);
$expected = 'different from';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::IN);
$expected = 'in';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
$expected = 'not in';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, 'unexpected operator');
$expected = 'unexpected operator';
$this->assertEquals($expected, $actual);
}
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorValidBefore()
// {
// $adapter = new BaseAdapter();
// // Given
// $a = 11;
// $operator = Operators::INFERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorInvalidEquals()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::INFERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorInvalidAfter()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::INFERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorOrEqualValidEqual()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorOrEqualValidBefore()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 10;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInferiorOrEqualInValidAfter()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::INFERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorEqualValidEqual()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorEqualInValidBefore()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorEqualInValidAfter()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::EQUAL;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorOrEqualValidEqual()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorOrEqualAfter()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 14;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorOrEqualInvalidBefore()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::SUPERIOR_OR_EQUAL;
// $b = new QuantityParam($adapter, 13);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorValidAfter()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 13;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorInvalidEqual()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorSuperiorInvalidBefore()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::SUPERIOR;
// $b = new QuantityParam($adapter, 12);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorDifferentValid()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = Operators::DIFFERENT;
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertTrue($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorDifferentInvalidEquals()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 11;
// $operator = Operators::DIFFERENT;
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
// *
// */
// public function testOperatorInValid()
// {
// // Given
// $adapter = new BaseAdapter();
// $a = 12;
// $operator = 'X';
// $b = new QuantityParam($adapter, 11);
//
// // When
// $actual = Operators::isValid($a, $operator, $b);
//
// // Then
// $this->assertFalse($actual);
// }
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
function callbackI18n() {
$args = func_get_args();
return $args[0];
}
}

View File

@@ -1,168 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\CustomerParam;
use Thelia\Constraint\Validator\QuantityParam;
use Thelia\Model\Customer;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test CustomerParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CustomerParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /** @var AdapterInterface $stubTheliaAdapter */
// protected $stubTheliaAdapter = null;
//
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// /** @var AdapterInterface $stubTheliaAdapter */
// $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
// }
//
// /**
// * Generate valid BaseAdapter
// *
// * @param int $customerId Customer id
// *
// * @return AdapterInterface
// */
// protected function generateValidCouponBaseAdapterMock($customerId = 4521)
// {
// $customer = new Customer();
// $customer->setId($customerId);
// $customer->setFirstname('Firstname');
// $customer->setLastname('Lastname');
// $customer->setEmail('em@il.com');
//
// /** @var AdapterInterface $stubTheliaAdapter */
// $stubTheliaAdapter = $this->getMock(
// 'Thelia\Coupon\BaseAdapter',
// array('getCustomer'),
// array()
// );
// $stubTheliaAdapter->expects($this->any())
// ->method('getCustomer')
// ->will($this->returnValue($customer));
//
// return $stubTheliaAdapter;
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// *
// */
// public function testCanUseCoupon()
// {
// $customerId = 4521;
// $couponValidForCustomerId = 4521;
//
// $adapter = $this->generateValidCouponBaseAdapterMock($customerId);
//
// $customerParam = new CustomerParam($adapter, $couponValidForCustomerId);
//
// $expected = 0;
// $actual = $customerParam->compareTo($customerId);
// $this->assertEquals($expected, $actual);
// }
//
//// /**
//// *
//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
//// *
//// */
//// public function testCanNotUseCouponTest()
//// {
////
//// }
////
//// /**
//// *
//// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
//// * @expectedException InvalidArgumentException
//// *
//// */
//// public function testCanNotUseCouponCustomerNotFoundTest()
//// {
////
//// }
//
//
//
//
//// /**
//// * Test is the object is serializable
//// * If no data is lost during the process
//// */
//// public function isSerializableTest()
//// {
//// $adapter = new BaseAdapter();
//// $intValidator = 42;
//// $intToValidate = -1;
////
//// $param = new QuantityParam($adapter, $intValidator);
////
//// $serialized = base64_encode(serialize($param));
//// /** @var QuantityParam $unserialized */
//// $unserialized = base64_decode(serialize($serialized));
////
//// $this->assertEquals($param->getValue(), $unserialized->getValue());
//// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
////
//// $new = new QuantityParam($adapter, $unserialized->getInteger());
//// $this->assertEquals($param->getInteger(), $new->getInteger());
//// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

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\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\DateParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test DateParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class DateParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// *
// */
// public function testInferiorDate()
// {
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
//
// $dateParam = new DateParam($adapter, $dateValidator);
//
// $expected = 1;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// *
// */
// public function testEqualsDate()
// {
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
//
// $dateParam = new DateParam($adapter, $dateValidator);
//
// $expected = 0;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// *
// */
// public function testSuperiorDate()
// {
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-09");
//
// $dateParam = new DateParam($adapter, $dateValidator);
//
// $expected = -1;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
//
// $dateParam = new DateParam($adapter, $dateValidator);
//
// $dateParam->compareTo($dateToValidate);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $dateValidator = new \DateTime("2012-07-08");
//
// $param = new DateParam($adapter, $dateValidator);
//
// $serialized = base64_encode(serialize($param));
// /** @var DateParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getDateTime(), $unserialized->getDateTime());
//
// $new = new DateParam($adapter, $unserialized->getDateTime());
// $this->assertEquals($param->getDateTime(), $new->getDateTime());
// }
//
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,159 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\IntegerParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test IntegerParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class IntegerParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
// *
// */
// public function testInferiorInteger()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 41;
//
// $integerParam = new IntegerParam($adapter, $intValidator);
//
// $expected = 1;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
// *
// */
// public function testEqualsInteger()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 42;
//
// $integerParam = new IntegerParam($adapter, $intValidator);
//
// $expected = 0;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
// *
// */
// public function testSuperiorInteger()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 43;
//
// $integerParam = new IntegerParam($adapter, $intValidator);
//
// $expected = -1;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = '42';
//
// $integerParam = new IntegerParam($adapter, $intValidator);
//
// $expected = 0;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
//
// $param = new IntegerParam($adapter, $intValidator);
//
// $serialized = base64_encode(serialize($param));
// /** @var IntegerParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
//
// $new = new IntegerParam($adapter, $unserialized->getInteger());
// $this->assertEquals($param->getInteger(), $new->getInteger());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,184 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\IntervalParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test IntervalParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class IntervalParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
// *
// */
// public function testInferiorDate()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-07-07");
//
// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $expected = 1;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
// *
// */
// public function testEqualsDate()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-07-08");
//
// echo '1 ' . date_format($dateValidatorStart, 'g:ia \o\n l jS F Y') . "\n";
// echo '2 ' . date_format($dateToValidate, 'g:ia \o\n l jS F Y') . "\n";
//
// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $expected = 0;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
// *
// */
// public function testEqualsDate2()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-08-08");
//
// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $expected = 0;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
// *
// */
// public function testSuperiorDate()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = new \DateTime("2012-08-09");
//
// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $expected = -1;
// $actual = $dateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
// $dateToValidate = 1377012588;
//
// $dateParam = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $dateParam->compareTo($dateToValidate);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $dateValidatorStart = new \DateTime("2012-07-08");
// $dateValidatorInterval = new \DateInterval("P1M"); //1month
//
// $param = new IntervalParam($adapter, $dateValidatorStart, $dateValidatorInterval);
//
// $serialized = base64_encode(serialize($param));
// /** @var IntervalParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
//
// $new = new IntervalParam($adapter, $unserialized->getStart(), $unserialized->getInterval());
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,237 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\PriceParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test PriceParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class PriceParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// *
// */
// public function testInferiorPrice()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 1.00;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 1;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// *
// */
// public function testInferiorPrice2()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.49;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 1;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// *
// */
// public function testEqualsPrice()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.50;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 0;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// *
// */
// public function testSuperiorPrice()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 42.51;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = -1;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = '42.50';
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 0;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException2()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = -1;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 0;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException3()
// {
// $adapter = new BaseAdapter();
//
// $priceValidator = 42.50;
// $priceToValidate = 0;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'EUR');
//
// $expected = 0;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\PriceParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException4()
// {
// $adapter = new BaseAdapter();
// $priceValidator = 42.50;
// $priceToValidate = 1;
//
// $integerParam = new PriceParam($adapter, $priceValidator, 'GBP');
//
// $expected = 0;
// $actual = $integerParam->compareTo($priceToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $priceValidator = 42.50;
//
// $param = new PriceParam($adapter, $priceValidator, 'GBP');
//
// $serialized = base64_encode(serialize($param));
// /** @var PriceParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getPrice(), $unserialized->getPrice());
// $this->assertEquals($param->getCurrency(), $unserialized->getCurrency());
//
// $new = new PriceParam($adapter, $unserialized->getPrice(), $unserialized->getCurrency());
// $this->assertEquals($param->getPrice(), $new->getPrice());
// $this->assertEquals($param->getCurrency(), $new->getCurrency());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,195 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\QuantityParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test QuantityParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class QuantityParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// *
// */
// public function testInferiorQuantity()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 0;
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = 1;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// *
// */
// public function testInferiorQuantity2()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 41;
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = 1;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// *
// */
// public function testEqualsQuantity()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 42;
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = 0;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// *
// */
// public function testSuperiorQuantity()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = 43;
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = -1;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = '42';
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = 0;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException2()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = -1;
//
// $integerParam = new QuantityParam($adapter, $intValidator);
//
// $expected = 0;
// $actual = $integerParam->compareTo($intToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $intValidator = 42;
// $intToValidate = -1;
//
// $param = new QuantityParam($adapter, $intValidator);
//
// $serialized = base64_encode(serialize($param));
// /** @var QuantityParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getInteger(), $unserialized->getInteger());
//
// $new = new QuantityParam($adapter, $unserialized->getInteger());
// $this->assertEquals($param->getInteger(), $new->getInteger());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,309 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use InvalidArgumentException;
use Thelia\Constraint\Validator\RepeatedDateParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test RepeatedDateParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testInferiorDate()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth();
//
// $expected = -1;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-08-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(1, 1);
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-09-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(1, 10);
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-05-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(1, 10);
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-11-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-03-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $expected = 0;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-08-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $expected = -1;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-12-08");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $expected = -1;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
// *
// */
// public function testSuperiorDateRepeatEveryFourMonthTwoTimes()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2013-03-09");
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $expected = -1;
// $actual = $repeatedDateParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// * @expectedException InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
//
// $repeatedDateParam = new RepeatedDateParam($adapter);
// $repeatedDateParam->setFrom($startDateValidator);
// $repeatedDateParam->repeatEveryMonth(4, 2);
//
// $repeatedDateParam->compareTo($dateToValidate);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
//
// $param = new RepeatedDateParam($adapter);
// $param->setFrom($startDateValidator);
// $param->repeatEveryMonth(4, 2);
//
// $serialized = base64_encode(serialize($param));
// /** @var RepeatedDateParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
//
// $new = new RepeatedDateParam($adapter);
// $new->setFrom($unserialized->getFrom());
// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -1,426 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
use Thelia\Constraint\Validator\RepeatedIntervalParam;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test RepeatedIntervalParam Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testInferiorDate()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-07");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
//
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = -1;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBeginning()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-08");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-13");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-07-18");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBeginning()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-08");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-13");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-08-08");
// $dateToValidate = new \DateTime("2012-08-18");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth();
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBeginning()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-08");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-13");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-10-18");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = 0;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBeginning()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-07-19");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = -1;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-08-01");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = -1;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-10-08");
// $dateToValidate = new \DateTime("2012-08-07");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $expected = -1;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
//
//
// /**
// *
// * @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
// *
// */
// public function testSuperiorDateRepeatEveryMonthFourTime()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = new \DateTime("2012-10-19");
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 0);
//
// $expected = -1;
// $actual = $RepeatedIntervalParam->compareTo($dateToValidate);
// $this->assertEquals($expected, $actual);
// }
//
// /**
// * @covers Thelia\Coupon\Parameter\DateParam::compareTo
// * @expectedException \InvalidArgumentException
// */
// public function testInvalidArgumentException()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
// $duration = 10;
//
// $RepeatedIntervalParam = new RepeatedIntervalParam($adapter);
// $RepeatedIntervalParam->setFrom($startDateValidator);
// $RepeatedIntervalParam->setDurationInDays($duration);
// $RepeatedIntervalParam->repeatEveryMonth(1, 4);
//
// $RepeatedIntervalParam->compareTo($dateToValidate);
// }
//
// /**
// * Test is the object is serializable
// * If no data is lost during the process
// */
// public function isSerializableTest()
// {
// $adapter = new BaseAdapter();
// $startDateValidator = new \DateTime("2012-07-08");
// $dateToValidate = 1377012588;
// $duration = 10;
//
// $param = new RepeatedIntervalParam($adapter);
// $param->setFrom($startDateValidator);
// $param->setDurationInDays($duration);
// $param->repeatEveryMonth(1, 4);
//
// $serialized = base64_encode(serialize($param));
// /** @var RepeatedIntervalParam $unserialized */
// $unserialized = base64_decode(serialize($serialized));
//
// $this->assertEquals($param->getValue(), $unserialized->getValue());
// $this->assertEquals($param->getDatePeriod(), $unserialized->getDatePeriod());
//
// $new = new RepeatedIntervalParam($adapter);
// $new->setFrom($unserialized->getFrom());
// $new->repeatEveryMonth($unserialized->getFrequency(), $unserialized->getNbRepetition());
// $new->setDurationInDays($unserialized->getDurationInDays());
// $this->assertEquals($param->getDatePeriod(), $new->getDatePeriod());
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -161,7 +161,7 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase
// * Test if an expired Coupon is build or not (equal)
// *
// * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode
// * @expectedException \Thelia\Exception\InvalidRuleException
// * @expectedException \Thelia\Exception\InvalidConditionException
// */
// public function testBuildCouponFromCodeWithoutRule()
// {

View File

@@ -197,7 +197,7 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
// * Test Coupon rule setter
// *
// * @covers Thelia\Coupon\type\RemoveXAmountManager::setRules
// * @expectedException \Thelia\Exception\InvalidRuleException
// * @expectedException \Thelia\Exception\InvalidConditionException
// *
// */
// public function testSetRulesInvalid()

View File

@@ -1,70 +0,0 @@
<?php
/**********************************************************************************/
/* */
/* Thelia */
/* */
/* Copyright (c) OpenStudio */
/* email : info@thelia.net */
/* web : http://www.thelia.net */
/* */
/* This program is free software; you can redistribute it and/or modify */
/* it under the terms of the GNU General Public License as published by */
/* the Free Software Foundation; either version 3 of the License */
/* */
/* This program is distributed in the hope that it will be useful, */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
/* GNU General Public License for more details. */
/* */
/* You should have received a copy of the GNU General Public License */
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* */
/**********************************************************************************/
namespace Thelia\Coupon;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Unit Test RemoveXPercentForCategoryY Class
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class RemoveXPercentForCategoryYTest extends \PHPUnit_Framework_TestCase
{
public function testSomething()
{
// Stop here and mark this test as incomplete.
$this->markTestIncomplete(
'This test has not been implemented yet.'
);
}
// /**
// * Sets up the fixture, for example, opens a network connection.
// * This method is called before a test is executed.
// */
// protected function setUp()
// {
// }
//
// public function incompleteTest()
// {
// $this->markTestIncomplete(
// 'This test has not been implemented yet.'
// );
// }
//
// /**
// * Tears down the fixture, for example, closes a network connection.
// * This method is called after a test is executed.
// */
// protected function tearDown()
// {
// }
}

View File

@@ -169,7 +169,7 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
// * Test Coupon rule setter
// *
// * @covers Thelia\Coupon\type\RemoveXPercentManager::setRules
// * @expectedException \Thelia\Exception\InvalidRuleException
// * @expectedException \Thelia\Exception\InvalidConditionException
// *
// */
// public function testSetRulesInvalid()