From 9c7c4e851ed5e120260e5ea51ecfd444c7fd2472 Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 21 Oct 2013 23:09:04 +0200 Subject: [PATCH] Working cleaning --- core/lib/Thelia/Action/Coupon.php | 2 - .../lib/Thelia/Condition/ConditionFactory.php | 4 - .../Condition/ConditionManagerAbstract.php | 94 --- .../Condition/ConditionManagerInterface.php | 32 - .../Condition/SerializableCondition.php | 29 - .../Controller/Admin/CouponController.php | 52 -- core/lib/Thelia/Coupon/BaseFacade.php | 33 +- core/lib/Thelia/Coupon/CouponManager.php | 27 - core/lib/Thelia/Coupon/FacadeInterface.php | 10 - core/lib/Thelia/Coupon/RuleOrganizer.php | 2 +- .../MatchForXArticlesManagerTest.php | 29 - .../Tests/Coupon/CouponBaseAdapterTest.php | 58 +- .../Thelia/Tests/Coupon/CouponFactoryTest.php | 289 ------- .../Thelia/Tests/Coupon/CouponManagerTest.php | 756 ------------------ .../Tests/Coupon/CouponRuleCollectionTest.php | 40 - .../Tests/Coupon/Type/RemoveXAmountTest.php | 346 +------- .../Tests/Coupon/Type/RemoveXPercentTest.php | 419 +--------- 17 files changed, 37 insertions(+), 2185 deletions(-) diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 2517c575d..b476af6b4 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -26,7 +26,6 @@ namespace Thelia\Action; use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Thelia\Condition\ConditionFactory; use Thelia\Condition\ConditionManagerInterface; -use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; @@ -124,7 +123,6 @@ class Coupon extends BaseAction implements EventSubscriberInterface // @todo decrement coupon quantity - // @todo modify Cart total discount $request->getSession()->getCart()->setDiscount($totalDiscount); } diff --git a/core/lib/Thelia/Condition/ConditionFactory.php b/core/lib/Thelia/Condition/ConditionFactory.php index 64a5afb45..3e1c771ee 100644 --- a/core/lib/Thelia/Condition/ConditionFactory.php +++ b/core/lib/Thelia/Condition/ConditionFactory.php @@ -82,10 +82,6 @@ class ConditionFactory if ($conditions !== null) { /** @var $condition ConditionManagerInterface */ foreach ($conditions as $condition) { - // Remove all condition if the "no condition" condition is found -// if ($condition->getServiceId() == 'thelia.condition.match_for_everyone') { -// return base64_encode(json_encode(array($condition->getSerializableRule()))); -// } $serializableConditions[] = $condition->getSerializableCondition(); } } diff --git a/core/lib/Thelia/Condition/ConditionManagerAbstract.php b/core/lib/Thelia/Condition/ConditionManagerAbstract.php index 7b190428b..bf38ef387 100644 --- a/core/lib/Thelia/Condition/ConditionManagerAbstract.php +++ b/core/lib/Thelia/Condition/ConditionManagerAbstract.php @@ -43,10 +43,6 @@ use Thelia\Type\FloatType; */ abstract class ConditionManagerAbstract implements ConditionManagerInterface { -// /** Operator key in $validators */ -// CONST OPERATOR = 'operator'; -// /** Value key in $validators */ -// CONST VALUE = 'value'; /** @var string Service Id from Resources/config.xml */ protected $serviceId = null; @@ -57,9 +53,6 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface /** @var array Parameters validating parameters against */ protected $validators = array(); -// /** @var array Parameters to be validated */ -// protected $paramsToValidate = array(); - /** @var FacadeInterface Provide necessary value from Thelia */ protected $adapter = null; @@ -87,62 +80,6 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface $this->conditionValidator = $adapter->getConditionEvaluator(); } -// /** -// * Check validator relevancy and store them -// * -// * @param array $validators Array of RuleValidator -// * validating $paramsToValidate against -// * -// * @return $this -// * @throws InvalidConditionException -// */ -// protected function setValidators(array $validators) -// { -// foreach ($validators as $validator) { -// if (!$validator instanceof RuleValidator) { -// throw new InvalidConditionException(get_class()); -// } -// if (!in_array($validator->getOperator(), $this->availableOperators)) { -// throw new InvalidConditionOperatorException( -// get_class(), -// $validator->getOperator() -// ); -// } -// } -// $this->validators = $validators; -// -// return $this; -// } - - - -// /** -// * Check if the current Checkout matches this condition -// * -// * @return bool -// */ -// public function isMatching() -// { -// $this->checkBackOfficeInput(); -// $this->checkCheckoutInput(); -// -// $isMatching = true; -// /** @var $validator RuleValidator*/ -// foreach ($this->validators as $param => $validator) { -// $a = $this->paramsToValidate[$param]; -// $operator = $validator->getOperator(); -// /** @var ComparableInterface, RuleParameterAbstract $b */ -// $b = $validator->getParam(); -// -// if (!Operators::isValid($a, $operator, $b)) { -// $isMatching = false; -// } -// } -// -// return $isMatching; -// -// } - /** * Return all available Operators for this Condition * @@ -153,37 +90,6 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface return $this->availableOperators; } -// /** -// * Check if Operators set for this Rule in the BackOffice are legit -// * -// * @throws InvalidConditionOperatorException if Operator is not allowed -// * @return bool -// */ -// protected function checkBackOfficeInputsOperators() -// { -// /** @var RuleValidator $param */ -// foreach ($this->validators as $key => $param) { -// $operator = $param->getOperator(); -// if (!isset($operator) -// ||!in_array($operator, $this->availableOperators) -// ) { -// throw new InvalidConditionOperatorException(get_class(), $key); -// } -// } -// return true; -// } - -// /** -// * Generate current Rule param to be validated from adapter -// * -// * @throws \Thelia\Exception\NotImplementedException -// * @return $this -// */ -// protected function setParametersToValidate() -// { -// throw new \Thelia\Exception\NotImplementedException(); -// } - /** * Return all validators * diff --git a/core/lib/Thelia/Condition/ConditionManagerInterface.php b/core/lib/Thelia/Condition/ConditionManagerInterface.php index acf0490ed..ceda090bf 100644 --- a/core/lib/Thelia/Condition/ConditionManagerInterface.php +++ b/core/lib/Thelia/Condition/ConditionManagerInterface.php @@ -53,20 +53,6 @@ interface ConditionManagerInterface */ public function getServiceId(); -// /** -// * Check if backoffice inputs are relevant or not -// * -// * @return bool -// */ -// public function checkBackOfficeInput(); - -// /** -// * Check if Checkout inputs are relevant or not -// * -// * @return bool -// */ -// public function checkCheckoutInput(); - /** * Check validators relevancy and store them * @@ -78,13 +64,6 @@ interface ConditionManagerInterface */ public function setValidatorsFromForm(array $operators, array $values); -// /** -// * Check if the current Checkout matches this condition -// * -// * @return bool -// */ -// public function isMatching(); - /** * Test if the current application state matches conditions * @@ -121,17 +100,6 @@ 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); - - /** * Return a serializable Condition * diff --git a/core/lib/Thelia/Condition/SerializableCondition.php b/core/lib/Thelia/Condition/SerializableCondition.php index 426052506..31163cdda 100644 --- a/core/lib/Thelia/Condition/SerializableCondition.php +++ b/core/lib/Thelia/Condition/SerializableCondition.php @@ -45,33 +45,4 @@ class SerializableCondition /** @var array Values set by Admin for this Condition */ public $values = array(); -// /** -// * Get Operators set by Admin for this Condition -// * -// * @return array -// */ -// public function getOperators() -// { -// return $this->operators; -// } -// -// /** -// * Get Condition Service id -// * -// * @return string -// */ -// public function getConditionServiceId() -// { -// return $this->conditionServiceId; -// } -// -// /** -// * Get Values set by Admin for this Condition -// * -// * @return array -// */ -// public function getValues() -// { -// return $this->values; -// } } diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index f1642ec06..b443e2769 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -28,7 +28,6 @@ use Symfony\Component\Routing\Router; use Thelia\Condition\ConditionFactory; use Thelia\Condition\ConditionManagerInterface; use Thelia\Core\Event\AdminResources; -use Thelia\Core\Event\Condition\ConditionCreateOrUpdateEvent; use Thelia\Core\Event\Coupon\CouponConsumeEvent; use Thelia\Core\Event\Coupon\CouponCreateOrUpdateEvent; use Thelia\Core\Event\TheliaEvents; @@ -331,10 +330,6 @@ class CouponController extends BaseAdminController $conditions->add(clone $condition); } -// $coupon->setSerializedConditions( -// $conditionFactory->serializeCouponConditionCollection($conditions) -// ); - $couponEvent = new CouponCreateOrUpdateEvent( $coupon->getCode(), $coupon->getTitle(), @@ -381,31 +376,6 @@ class CouponController extends BaseAdminController ); } - /** - * Test Coupon consuming - * - * @param string $couponCode Coupon code - * - * @todo remove (event dispatcher testing purpose) - * - */ - public function consumeAction($couponCode) - { - // @todo remove (event dispatcher testing purpose) - $couponConsumeEvent = new CouponConsumeEvent($couponCode); - $eventToDispatch = TheliaEvents::COUPON_CONSUME; - - // Dispatch Event to the Action - $this->dispatch( - $eventToDispatch, - $couponConsumeEvent - ); - - var_dump('test', $couponConsumeEvent->getCode(), $couponConsumeEvent->getDiscount(), $couponConsumeEvent->getIsValid()); - - exit(); - } - /** * Build a Coupon from its form * @@ -600,26 +570,4 @@ class CouponController extends BaseAdminController return $cleanedConditions; } -// /** -// * Validation Condition creation -// * -// * @param string $type Condition class type -// * @param string $operator Condition operator (<, >, =, etc) -// * @param array $values Condition values -// * -// * @return bool -// */ -// protected function validateConditionsCreation($type, $operator, $values) -// { -// /** @var FacadeInterface $adapter */ -// $adapter = $this->container->get('thelia.adapter'); -// $validator = new PriceParam() -// try { -// $condition = new AvailableForTotalAmount($adapter, $validators); -// $condition = new $type($adapter, $validators); -// } catch (\Exception $e) { -// return false; -// } -// } - } diff --git a/core/lib/Thelia/Coupon/BaseFacade.php b/core/lib/Thelia/Coupon/BaseFacade.php index 6c8a1f27d..9d28be69f 100644 --- a/core/lib/Thelia/Coupon/BaseFacade.php +++ b/core/lib/Thelia/Coupon/BaseFacade.php @@ -29,7 +29,6 @@ use Symfony\Component\Translation\Translator; use Symfony\Component\Translation\TranslatorInterface; use Thelia\Condition\ConditionEvaluator; use Thelia\Core\HttpFoundation\Request; -use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; use Thelia\Model\CouponQuery; use Thelia\Cart\CartTrait; @@ -45,7 +44,6 @@ use Thelia\Model\CurrencyQuery; * * @package Coupon * @author Guillaume MOREL - * @todo implements * */ class BaseFacade implements FacadeInterface @@ -87,7 +85,7 @@ class BaseFacade implements FacadeInterface */ public function getDeliveryAddress() { - // TODO: Implement getDeliveryAddress() method. + // @todo: Implement getDeliveryAddress() method. } /** @@ -189,34 +187,7 @@ class BaseFacade implements FacadeInterface } /** - * Save a Coupon in the database - * - * @param CouponInterface $coupon Coupon - * - * @return $this - */ - public function saveCoupon(CouponInterface $coupon) - { -// $couponModel = new Coupon(); -// $couponModel->setCode($coupon->getCode()); -// $couponModel->setType(get_class($coupon)); -// $couponModel->setTitle($coupon->getTitle()); -// $couponModel->setShortDescription($coupon->getShortDescription()); -// $couponModel->setDescription($coupon->getDescription()); -// $couponModel->setAmount($coupon->getDiscount()); -// $couponModel->setIsUsed(0); -// $couponModel->setIsEnabled(1); -// $couponModel->set -// $couponModel->set -// $couponModel->set -// $couponModel->set -// $couponModel->set -// $couponModel->set -// $couponModel->set - } - - /** - * Return plateform Container + * Return platform Container * * @return Container */ diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php index d831d92d6..0b4a9e9e8 100644 --- a/core/lib/Thelia/Coupon/CouponManager.php +++ b/core/lib/Thelia/Coupon/CouponManager.php @@ -183,39 +183,12 @@ class CouponManager $discount = 0.00; /** @var CouponInterface $coupon */ foreach ($coupons as $coupon) { - // @todo modify Cart with discount for each cart item $discount += $coupon->exec($this->adapter); } return $discount; } - /** - * Build a ConditionManagerInterface from data coming from a form - * - * @param string $conditionServiceId Condition service id you want to instantiate - * @param array $operators Condition Operator set by the Admin - * @param array $values Condition Values set by the Admin - * - * @return ConditionManagerInterface - */ - public function buildRuleFromForm($conditionServiceId, array $operators, array $values) - { - $condition = false; - try { - - if ($this->container->has($conditionServiceId)) { - /** @var ConditionManagerInterface $condition */ - $condition = $this->container->get($conditionServiceId); - $condition->populateFromForm($operators, $values); - } - } catch (\InvalidArgumentException $e) { - - } - - return $condition; - } - /** * Add an available CouponManager (Services) * diff --git a/core/lib/Thelia/Coupon/FacadeInterface.php b/core/lib/Thelia/Coupon/FacadeInterface.php index e464436da..4c264430c 100644 --- a/core/lib/Thelia/Coupon/FacadeInterface.php +++ b/core/lib/Thelia/Coupon/FacadeInterface.php @@ -28,7 +28,6 @@ use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\Translation\TranslatorInterface; use Thelia\Condition\ConditionEvaluator; use Thelia\Core\HttpFoundation\Request; -use Thelia\Coupon\Type\CouponInterface; use Thelia\Model\Coupon; /** @@ -125,15 +124,6 @@ interface FacadeInterface */ public function findOneCouponByCode($code); - /** - * Save a Coupon in the database - * - * @param CouponInterface $coupon Coupon - * - * @return $this - */ - public function saveCoupon(CouponInterface $coupon); - /** * Return platform Container * diff --git a/core/lib/Thelia/Coupon/RuleOrganizer.php b/core/lib/Thelia/Coupon/RuleOrganizer.php index ee840bfbc..673f27404 100644 --- a/core/lib/Thelia/Coupon/RuleOrganizer.php +++ b/core/lib/Thelia/Coupon/RuleOrganizer.php @@ -45,7 +45,7 @@ class RuleOrganizer implements RuleOrganizerInterface */ public function organize(array $conditions) { - // TODO: Implement organize() method. + // @todo: Implement organize() method. } } \ No newline at end of file diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php index a9e300f67..a618d3dcd 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php @@ -630,35 +630,6 @@ class MatchForXArticlesManagerTest extends \PHPUnit_Framework_TestCase } -// public function testGetValidators() -// { -// $stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade') -// ->disableOriginalConstructor() -// ->getMock(); -// -// $stubFacade->expects($this->any()) -// ->method('getNbArticlesInCart') -// ->will($this->returnValue(4)); -// -// $condition1 = new MatchForXArticlesManager($stubFacade); -// $operators = array( -// MatchForXArticlesManager::INPUT1 => Operators::SUPERIOR -// ); -// $values = array( -// MatchForXArticlesManager::INPUT1 => 4 -// ); -// $condition1->setValidatorsFromForm($operators, $values); -// -// $expected = array( -// $operators, -// $values -// ); -// $actual = $condition1->getValidators(); -// -// $this->assertEquals($expected, $actual); -// -// } - /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php index 69f4019bd..8e2d0addb 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php @@ -43,61 +43,5 @@ class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase 'This test has not been implemented yet.' ); } -// /** -// * @var BaseFacade -// */ -// protected $object; -// -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// $this->object = new BaseFacade; -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } -// -// /** -// * @covers Thelia\Coupon\BaseFacade::getCart -// * @todo Implement testGetCart(). -// */ -// public function testGetCart() -// { -// // Remove the following lines when you implement this test. -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } -// -// /** -// * @covers Thelia\Coupon\BaseFacade::getDeliveryAddress -// * @todo Implement testGetDeliveryAddress(). -// */ -// public function testGetDeliveryAddress() -// { -// // Remove the following lines when you implement this test. -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } -// -// /** -// * @covers Thelia\Coupon\BaseFacade::getCustomer -// * @todo Implement testGetCustomer(). -// */ -// public function testGetCustomer() -// { -// // Remove the following lines when you implement this test. -// $this->markTestIncomplete( -// 'This test has not been implemented yet.' -// ); -// } + } diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index 2f22de74a..648dbcd19 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -45,293 +45,4 @@ class CouponFactoryTest extends \PHPUnit_Framework_TestCase '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() -// { -// } -// -// /** -// * Fake CouponQuery->findByCode -// * -// * @param string $code Coupon code -// * @param string $type Coupon type (object) -// * @param string $title Coupon title -// * @param string $shortDescription Coupon short description -// * @param string $description Coupon description -// * @param float $amount Coupon amount -// * @param bool $isUsed If Coupon has been used yet -// * @param bool $isEnabled If Coupon is enabled -// * @param \DateTime $expirationDate When Coupon expires -// * @param ConditionCollection $rules Coupon rules -// * @param bool $isCumulative If Coupon is cumulative -// * @param bool $isRemovingPostage If Coupon is removing postage -// * -// * @return Coupon -// */ -// public function generateCouponModelMock( -// $code = null, -// $type = null, -// $title = null, -// $shortDescription = null, -// $description = null, -// $amount = null, -// $isUsed = null, -// $isEnabled = null, -// $expirationDate = null, -// $rules = null, -// $isCumulative = null, -// $isRemovingPostage = null -// ) { -// $coupon = $this->generateValidCoupon( -// $code, -// $type, -// $title, -// $shortDescription, -// $description, -// $amount, -// $isUsed, -// $isEnabled, -// $expirationDate, -// $rules, -// $isCumulative, -// $isRemovingPostage -// ); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\BaseFacade', -// array('findOneCouponByCode'), -// array() -// ); -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('findOneCouponByCode') -// ->will($this->returnValue($coupon)); -// -// return $stubCouponBaseAdapter; -// } -// -// -// -// /** -// * Test if an expired Coupon is build or not (superior) -// * -// * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// * @expectedException \Thelia\Exception\CouponExpiredException -// */ -// public function testBuildCouponFromCodeExpiredDateBefore() -// { -// $date = new \DateTime(); -// $date->setTimestamp(strtotime("today - 2 months")); -// -// /** @var FacadeInterface $mockAdapter */ -// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date); -// $couponFactory = new CouponFactory($mockAdapter); -// $coupon = $couponFactory->buildCouponFromCode('XMAS1'); -// } -// -// /** -// * Test if an expired Coupon is build or not (equal) -// * -// * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// * @expectedException \Thelia\Exception\CouponExpiredException -// */ -// public function testBuildCouponFromCodeExpiredDateEquals() -// { -// $date = new \DateTime(); -// -// /** @var FacadeInterface $mockAdapter */ -// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, $date); -// $couponFactory = new CouponFactory($mockAdapter); -// $coupon = $couponFactory->buildCouponFromCode('XMAS1'); -// } -// -// /** -// * Test if an expired Coupon is build or not (equal) -// * -// * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// * @expectedException \Thelia\Exception\InvalidConditionException -// */ -// public function testBuildCouponFromCodeWithoutRule() -// { -// /** @var FacadeInterface $mockAdapter */ -// $mockAdapter = $this->generateCouponModelMock(null, null, null, null, null, null, null, null, null, new ConditionCollection(array())); -// $couponFactory = new CouponFactory($mockAdapter); -// $coupon = $couponFactory->buildCouponFromCode('XMAS1'); -// } -// -// /** -// * Test if a CouponInterface can be built from database -// * -// * @covers Thelia\Coupon\CouponFactory::buildCouponFromCode -// */ -// public function testBuildCouponFromCode() -// { -// /** @var FacadeInterface $mockAdapter */ -// $mockAdapter = $this->generateCouponModelMock(); -// $couponFactory = new CouponFactory($mockAdapter); -// /** @var CouponInterface $coupon */ -// $coupon = $couponFactory->buildCouponFromCode('XMAS1'); -// -// $this->assertEquals('XMAS1', $coupon->getCode()); -// $this->assertEquals('Thelia\Coupon\Type\RemoveXAmount', get_class($coupon)); -// $this->assertEquals(CouponManagerTest::VALID_TITLE, $coupon->getTitle()); -// $this->assertEquals(CouponManagerTest::VALID_SHORT_DESCRIPTION, $coupon->getShortDescription()); -// $this->assertEquals(CouponManagerTest::VALID_DESCRIPTION, $coupon->getDescription()); -// $this->assertEquals(10.00, $coupon->getDiscount()); -// $this->assertEquals(1, $coupon->isEnabled()); -// -// $date = new \DateTime(); -// $date->setTimestamp(strtotime("today + 2 months")); -// $this->assertEquals($date, $coupon->getExpirationDate()); -// -// $rules = $this->generateValidRules(); -// $this->assertEquals($rules, $coupon->getRules()); -// -// $this->assertEquals(1, $coupon->isCumulative()); -// $this->assertEquals(0, $coupon->isRemovingPostage()); -// } -// -// /** -// * Generate valid CouponRuleInterfaces -// * -// * @return ConditionCollection Set of ConditionManagerInterface -// */ -// protected function generateValidRules() -// { -//// $rule1 = new AvailableForTotalAmount( -//// , array( -//// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -//// Operators::SUPERIOR, -//// new PriceParam( -//// , 40.00, 'EUR' -//// ) -//// ) -//// ) -//// ); -//// $rule2 = new AvailableForTotalAmount( -//// , array( -//// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -//// Operators::INFERIOR, -//// new PriceParam( -//// , 400.00, 'EUR' -//// ) -//// ) -//// ) -//// ); -//// $rules = new ConditionCollection(array($rule1, $rule2)); -//// -//// return $rules; -// } -// -// /** -// * Generate valid CouponInterface -// * -// * @param string $code Coupon code -// * @param string $type Coupon type (object) -// * @param string $title Coupon title -// * @param string $shortDescription Coupon short description -// * @param string $description Coupon description -// * @param float $amount Coupon amount -// * @param bool $isUsed If Coupon has been used yet -// * @param bool $isEnabled If Coupon is enabled -// * @param \DateTime $expirationDate When Coupon expires -// * @param ConditionCollection $rules Coupon rules -// * @param bool $isCumulative If Coupon is cumulative -// * @param bool $isRemovingPostage If Coupon is removing postage -// * -// * @return Coupon -// */ -// public function generateValidCoupon( -// $code = null, -// $type = null, -// $title = null, -// $shortDescription = null, -// $description = null, -// $amount = null, -// $isUsed = null, -// $isEnabled = null, -// $expirationDate = null, -// $rules = null, -// $isCumulative = null, -// $isRemovingPostage = null -// ) { -// $coupon = new Coupon(); -// -// if ($code === null) { -// $code = 'XMAS1'; -// } -// $coupon->setCode($code); -// -// if ($type === null) { -// $type = 'Thelia\Coupon\Type\RemoveXAmount'; -// } -// $coupon->setType($type); -// -// if ($title === null) { -// $title = CouponManagerTest::VALID_TITLE; -// } -// $coupon->setTitle($title); -// -// if ($shortDescription === null) { -// $shortDescription = CouponManagerTest::VALID_SHORT_DESCRIPTION; -// } -// $coupon->setShortDescription($shortDescription); -// -// if ($description === null) { -// $description = CouponManagerTest::VALID_DESCRIPTION; -// } -// $coupon->setDescription($description); -// -// if ($amount === null) { -// $amount = 10.00; -// } -// $coupon->setAmount($amount); -// -// if ($isUsed === null) { -// $isUsed = 1; -// } -// $coupon->setIsUsed($isUsed); -// -// if ($isEnabled === null) { -// $isEnabled = 1; -// } -// $coupon->setIsEnabled($isEnabled); -// -// if ($isCumulative === null) { -// $isCumulative = 1; -// } -// if ($isRemovingPostage === null) { -// $isRemovingPostage = 0; -// } -// -// if ($expirationDate === null) { -// $date = new \DateTime(); -// $coupon->setExpirationDate( -// $date->setTimestamp(strtotime("today + 2 months")) -// ); -// } -// -// if ($rules === null) { -// $rules = $this->generateValidRules(); -// } -// -// $coupon->setSerializedConditions(base64_encode(serialize($rules))); -// -// $coupon->setIsCumulative($isCumulative); -// $coupon->setIsRemovingPostage($isRemovingPostage); -// -// return $coupon; -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } } diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php index e56c44ed6..751a1ba33 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php @@ -44,761 +44,5 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase 'This test has not been implemented yet.' ); } -// CONST VALID_CODE = 'XMAS'; -// CONST VALID_TITLE = 'XMAS coupon'; -// CONST VALID_SHORT_DESCRIPTION = 'Coupon for Christmas removing 10€ if your total checkout is more than 40€'; -// CONST VALID_DESCRIPTION = '

Lorem ipsum dolor sit amet

Consectetur adipiscing elit. Cras at luctus tellus. Integer turpis mauris, aliquet vitae risus tristique, pellentesque vestibulum urna. Vestibulum sodales laoreet lectus dictum suscipit. Praesent vulputate, sem id varius condimentum, quam magna tempor elit, quis venenatis ligula nulla eget libero. Cras egestas euismod tellus, id pharetra leo suscipit quis. Donec lacinia ac lacus et ultricies. Nunc in porttitor neque. Proin at quam congue, consectetur orci sed, congue nulla. Nulla eleifend nunc ligula, nec pharetra elit tempus quis. Vivamus vel mauris sed est dictum blandit. Maecenas blandit dapibus velit ut sollicitudin. In in euismod mauris, consequat viverra magna. Cras velit velit, sollicitudin commodo tortor gravida, tempus varius nulla. -// -//Donec rhoncus leo mauris, id porttitor ante luctus tempus. -// -//Curabitur quis augue feugiat, ullamcorper mauris ac, interdum mi. Quisque aliquam lorem vitae felis lobortis, id interdum turpis mattis. Vestibulum diam massa, ornare congue blandit quis, facilisis at nisl. In tortor metus, venenatis non arcu nec, sollicitudin ornare nisl. Nunc erat risus, varius nec urna at, iaculis lacinia elit. Aenean ut felis tempus, tincidunt odio non, sagittis nisl. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Donec vitae hendrerit elit. Nunc sit amet gravida risus, euismod lobortis massa. Nam a erat mauris. Nam a malesuada lorem. Nulla id accumsan dolor, sed rhoncus tellus. Quisque dictum felis sed leo auctor, at volutpat lectus viverra. Morbi rutrum, est ac aliquam imperdiet, nibh sem sagittis justo, ac mattis magna lacus eu nulla. -// -//Duis interdum lectus nulla, nec pellentesque sapien condimentum at. Suspendisse potenti. Sed eu purus tellus. Nunc quis rhoncus metus. Fusce vitae tellus enim. Interdum et malesuada fames ac ante ipsum primis in faucibus. Etiam tempor porttitor erat vitae iaculis. Sed est elit, consequat non ornare vitae, vehicula eget lectus. Etiam consequat sapien mauris, eget consectetur magna imperdiet eget. Nunc sollicitudin luctus velit, in commodo nulla adipiscing fermentum. Fusce nisi sapien, posuere vitae metus sit amet, facilisis sollicitudin dui. Fusce ultricies auctor enim sit amet iaculis. Morbi at vestibulum enim, eget adipiscing eros. -// -//Praesent ligula lorem, faucibus ut metus quis, fermentum iaculis erat. Pellentesque elit erat, lacinia sed semper ac, sagittis vel elit. Nam eu convallis est. Curabitur rhoncus odio vitae consectetur pellentesque. Nam vitae arcu nec ante scelerisque dignissim vel nec neque. Suspendisse augue nulla, mollis eget dui et, tempor facilisis erat. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi ac diam ipsum. Donec convallis dui ultricies velit auctor, non lobortis nulla ultrices. Morbi vitae dignissim ante, sit amet lobortis tortor. Nunc dapibus condimentum augue, in molestie neque congue non. -// -//Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesuada tortor vel erat volutpat tincidunt. In vehicula diam est, a convallis eros scelerisque ut. Donec aliquet venenatis iaculis. Ut a arcu gravida, placerat dui eu, iaculis nisl. Quisque adipiscing orci sit amet dui dignissim lacinia. Sed vulputate lorem non dolor adipiscing ornare. Morbi ornare id nisl id aliquam. Ut fringilla elit ante, nec lacinia enim fermentum sit amet. Aenean rutrum lorem eu convallis pharetra. Cras malesuada varius metus, vitae gravida velit. Nam a varius ipsum, ac commodo dolor. Phasellus nec elementum elit. Etiam vel adipiscing leo.'; -// -// /** -// * Sets up the fixture, for example, opens a network connection. -// * This method is called before a test is executed. -// */ -// protected function setUp() -// { -// } -// -// /** -// * Test getDiscount() behaviour -// * Entering : 1 valid Coupon (If 40 < total amount 400) - 10euros -// * -// * @covers Thelia\Coupon\CouponManager::getDiscount -// */ -// public function testGetDiscountOneCoupon() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// /** @var CouponInterface $coupon */ -// $coupon = self::generateValidCoupon(); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); -// -// $couponManager = new CouponManager($stubCouponBaseAdapter); -// $discount = $couponManager->getDiscount(); -// -// $expected = 10.00; -// $actual = $discount; -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test getDiscount() behaviour -// * Entering : 1 valid Coupon (If 40 < total amount 400) - 10euros -// * 1 valid Coupon (If total amount > 20) - 15euros -// * -// * @covers Thelia\Coupon\CouponManager::getDiscount -// */ -// public function testGetDiscountTwoCoupon() -// { -// $adapter = new BaseFacade(); -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// /** @var CouponInterface $coupon1 */ -// $coupon1 = self::generateValidCoupon(); -// $rule1 = new AvailableForTotalAmount( -// $adapter, array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// new PriceParam( -// $adapter, 40.00, 'EUR' -// ) -// ) -// ) -// ); -// $rules = new ConditionCollection(array($rule1)); -// /** @var CouponInterface $coupon2 */ -// $coupon2 = $this->generateValidCoupon('XMAS2', null, null, null, 15.00, null, null, $rules); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon1, $coupon2), $cartTotalPrice, $checkoutTotalPrice); -// -// $couponManager = new CouponManager($stubCouponBaseAdapter); -// $discount = $couponManager->getDiscount(); -// -// $expected = 25.00; -// $actual = $discount; -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test getDiscount() behaviour -// * For a Cart of 21euros -// * Entering : 1 valid Coupon (If total amount > 20) - 30euros -// * -// * @covers Thelia\Coupon\CouponManager::getDiscount -// */ -// public function testGetDiscountAlwaysInferiorToPrice() -// { -// $adapter = new BaseFacade(); -// $cartTotalPrice = 21.00; -// $checkoutTotalPrice = 26.00; -// -// $rule1 = new AvailableForTotalAmount( -// $adapter, array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// new PriceParam( -// $adapter, 20.00, 'EUR' -// ) -// ) -// ) -// ); -// $rules = new ConditionCollection(array($rule1)); -// /** @var CouponInterface $coupon */ -// $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); -// -// $couponManager = new CouponManager($stubCouponBaseAdapter); -// $discount = $couponManager->getDiscount(); -// -// $expected = 21.00; -// $actual = $discount; -// $this->assertEquals($expected, $actual); -// } -// -// -// /** -// * Check if removing postage on discout is working -// * @covers Thelia\Coupon\CouponManager::isCouponRemovingPostage -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testIsCouponRemovingPostage() -// { -// $adapter = new BaseFacade(); -// $cartTotalPrice = 21.00; -// $checkoutTotalPrice = 27.00; -// -// $rule1 = new AvailableForTotalAmount( -// $adapter, array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// new PriceParam( -// $adapter, 20.00, 'EUR' -// ) -// ) -// ) -// ); -// $rules = new ConditionCollection(array($rule1)); -// /** @var CouponInterface $coupon */ -// $coupon = $this->generateValidCoupon('XMAS2', null, null, null, 30.00, null, null, $rules, null, true); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter(array($coupon), $cartTotalPrice, $checkoutTotalPrice); -// -// $couponManager = new CouponManager($stubCouponBaseAdapter); -// $discount = $couponManager->getDiscount(); -// -// $expected = 21.00; -// $actual = $discount; -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon not cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponNotCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false); -// -// $coupons = array($couponCumulative1); -// -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = $coupons; -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite there is only once'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true); -// -// $coupons = array($couponCumulative1); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = $coupons; -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite there is only once'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative -// * 1 Coupon cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationTwoCouponCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = $coupons; -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite both Coupon can be accumulated'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative -// * 1 Coupon non cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponCumulativeOneNonCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative2); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite both Coupon can be accumulated'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon non cumulative -// * 1 Coupon cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponNonCumulativeOneCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, false); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative2); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite both Coupon can be accumulated'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon non cumulative -// * 1 Coupon non cumulative -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationTwoCouponNonCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, false); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, false); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative2); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Array Sorted despite both Coupon can be accumulated'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative expired -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponCumulativeExpired() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, new \DateTime(), null, true); -// -// $coupons = array($couponCumulative1); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array(); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon expired ignored'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative expired -// * 1 Coupon cumulative expired -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationTwoCouponCumulativeExpired() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, new \DateTime(), null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array(); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon expired ignored'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative expired -// * 1 Coupon cumulative valid -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponCumulativeExpiredOneNonExpired() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, new \DateTime(), null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative2); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon expired ignored'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative valid -// * 1 Coupon cumulative expired -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationOneCouponCumulativeNonExpiredOneExpired() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, new \DateTime(), null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative1); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon expired ignored'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative valid -// * 1 Coupon cumulative valid -// * 1 Coupon cumulative valid -// * 1 Coupon cumulative valid -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationFourCouponCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); -// $couponCumulative3 = $this->generateValidCoupon('XMAS3', null, null, null, null, null, null, null, true); -// $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, true); -// -// $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = $coupons; -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon cumulative ignored'); -// } -// -// /** -// * Testing how multiple Coupon behaviour -// * Entering 1 Coupon cumulative valid -// * 1 Coupon cumulative valid -// * 1 Coupon cumulative valid -// * 1 Coupon non cumulative valid -// * -// * @covers Thelia\Coupon\CouponManager::sortCoupons -// */ -// public function testCouponCumulationThreeCouponCumulativeOneNonCumulative() -// { -// $cartTotalPrice = 100.00; -// $checkoutTotalPrice = 120.00; -// -// // Given -// /** @var CouponInterface $coupon */ -// $couponCumulative1 = $this->generateValidCoupon('XMAS1', null, null, null, null, null, null, null, true); -// $couponCumulative2 = $this->generateValidCoupon('XMAS2', null, null, null, null, null, null, null, true); -// $couponCumulative3 = $this->generateValidCoupon('XMAS3', null, null, null, null, null, null, null, true); -// $couponCumulative4 = $this->generateValidCoupon('XMAS4', null, null, null, null, null, null, null, false); -// -// $coupons = array($couponCumulative1, $couponCumulative2, $couponCumulative3, $couponCumulative4); -// /** @var FacadeInterface $stubCouponBaseAdapter */ -// $stubCouponBaseAdapter = $this->generateFakeAdapter($coupons, $cartTotalPrice, $checkoutTotalPrice); -// -// // When -// $sortedCoupons = PhpUnitUtils::callMethod( -// new CouponManager($stubCouponBaseAdapter), -// 'sortCoupons', -// array($coupons) -// ); -// -// // Then -// $expected = array($couponCumulative4); -// $actual = $sortedCoupons; -// -// $this->assertSame($expected, $actual, 'Coupon cumulative ignored'); -// } -// -// -// /** -// * Generate valid CouponRuleInterfaces -// * -// * @return array Array of ConditionManagerInterface -// */ -// public static function generateValidRules() -// { -// $adapter = new BaseFacade(); -// $rule1 = new AvailableForTotalAmount( -// $adapter, array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::SUPERIOR, -// new PriceParam( -// $adapter, 40.00, 'EUR' -// ) -// ) -// ) -// ); -// $rule2 = new AvailableForTotalAmount( -// $adapter, array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// Operators::INFERIOR, -// new PriceParam( -// $adapter, 400.00, 'EUR' -// ) -// ) -// ) -// ); -// $rules = new ConditionCollection(array($rule1, $rule2)); -// -// return $rules; -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } -// -// /** -// * Generate a fake Adapter -// * -// * @param array $coupons Coupons -// * @param float $cartTotalPrice Cart total price -// * @param float $checkoutTotalPrice Checkout total price -// * @param float $postagePrice Checkout postage price -// * -// * @return \PHPUnit_Framework_MockObject_MockObject -// */ -// public function generateFakeAdapter(array $coupons, $cartTotalPrice, $checkoutTotalPrice, $postagePrice = 6.00) -// { -// $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\BaseFacade', -// array( -// 'getCurrentCoupons', -// 'getCartTotalPrice', -// 'getCheckoutTotalPrice', -// 'getCheckoutPostagePrice' -// ), -// array() -// ); -// -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('getCurrentCoupons') -// ->will($this->returnValue(($coupons))); -// -// // Return Cart product amount = $cartTotalPrice euros -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('getCartTotalPrice') -// ->will($this->returnValue($cartTotalPrice)); -// -// // Return Checkout amount = $checkoutTotalPrice euros -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('getCheckoutTotalPrice') -// ->will($this->returnValue($checkoutTotalPrice)); -// -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('getCheckoutPostagePrice') -// ->will($this->returnValue($postagePrice)); -// -// return $stubCouponBaseAdapter; -// } -// -// /** -// * Generate valid CouponInterface -// * -// * @param string $code Coupon Code -// * @param string $title Coupon Title -// * @param string $shortDescription Coupon short -// * description -// * @param string $description Coupon description -// * @param float $amount Coupon discount -// * @param bool $isEnabled Is Coupon enabled -// * @param \DateTime $expirationDate Coupon expiration date -// * @param ConditionCollection $rules Coupon rules -// * @param bool $isCumulative If is cumulative -// * @param bool $isRemovingPostage If is removing postage -// * @param bool $isAvailableOnSpecialOffers If is available on -// * special offers or not -// * @param int $maxUsage How many time a Coupon -// * can be used -// * -// * @return CouponInterface -// */ -// public static function generateValidCoupon( -// $code = null, -// $title = null, -// $shortDescription = null, -// $description = null, -// $amount = null, -// $isEnabled = null, -// $expirationDate = null, -// $rules = null, -// $isCumulative = null, -// $isRemovingPostage = null, -// $isAvailableOnSpecialOffers = null, -// $maxUsage = null -// ) { -// $adapter = new BaseFacade(); -// if ($code === null) { -// $code = self::VALID_CODE; -// } -// if ($title === null) { -// $title = self::VALID_TITLE; -// } -// if ($shortDescription === null) { -// $shortDescription = self::VALID_SHORT_DESCRIPTION; -// } -// if ($description === null) { -// $description = self::VALID_DESCRIPTION; -// } -// if ($amount === null) { -// $amount = 10.00; -// } -// if ($isEnabled === null) { -// $isEnabled = true; -// } -// if ($isCumulative === null) { -// $isCumulative = true; -// } -// if ($isRemovingPostage === null) { -// $isRemovingPostage = false; -// } -// if ($isAvailableOnSpecialOffers === null) { -// $isAvailableOnSpecialOffers = true; -// } -// if ($maxUsage === null) { -// $maxUsage = 40; -// } -// -// if ($expirationDate === null) { -// $expirationDate = new \DateTime(); -// $expirationDate->setTimestamp(strtotime("today + 2 months")); -// } -// -// $coupon = new RemoveXAmount($adapter, $code, $title, $shortDescription, $description, $amount, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate); -// -// if ($rules === null) { -// $rules = self::generateValidRules(); -// } -// -// $coupon->setRules($rules); -// -// return $coupon; -// } } diff --git a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php index 2b19ba130..0745e9b98 100644 --- a/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponRuleCollectionTest.php @@ -23,11 +23,6 @@ namespace Thelia\Coupon; -use Thelia\Constraint\Validator\PriceParam; -use Thelia\Constraint\Validator\RuleValidator; -use Thelia\Constraint\Rule\AvailableForTotalAmount; -use Thelia\Constraint\Rule\Operators; - /** * Created by JetBrains PhpStorm. * Date: 8/19/13 @@ -48,39 +43,4 @@ class CouponRuleCollectionTest extends \PHPUnit_Framework_TestCase 'This test has not been implemented yet.' ); } -// /** -// * -// */ -// public function testRuleSerialisation() -// { -//// $rule1 = new AvailableForTotalAmount( -//// , array( -//// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -//// Operators::SUPERIOR, -//// new PriceParam( -//// , 40.00, 'EUR' -//// ) -//// ) -//// ) -//// ); -//// $rule2 = new AvailableForTotalAmount( -//// , array( -//// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -//// Operators::INFERIOR, -//// new PriceParam( -//// , 400.00, 'EUR' -//// ) -//// ) -//// ) -//// ); -//// $rules = new ConditionCollection(array($rule1, $rule2)); -//// -//// $serializedRules = base64_encode(serialize($rules)); -//// $unserializedRules = unserialize(base64_decode($serializedRules)); -//// -//// $expected = $rules; -//// $actual = $unserializedRules; -//// -//// $this->assertEquals($expected, $actual); -// } } diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index 80d6d459e..ee8ed3068 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -39,341 +39,27 @@ namespace Thelia\Coupon; */ class RemoveXAmountTest 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.' + 'This coupon 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() -// { -// -// } -// -// /** -// * Test if a Coupon is well displayed -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getCode -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getTitle -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getShortDescription -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getDescription -// * -// */ -// public function testDisplay() -// { -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, true, true); -// -// $expected = CouponManagerTest::VALID_CODE; -// $actual = $coupon->getCode(); -// $this->assertEquals($expected, $actual); -// -// $expected = CouponManagerTest::VALID_TITLE; -// $actual = $coupon->getTitle(); -// $this->assertEquals($expected, $actual); -// -// $expected = CouponManagerTest::VALID_SHORT_DESCRIPTION; -// $actual = $coupon->getShortDescription(); -// $this->assertEquals($expected, $actual); -// -// $expected = CouponManagerTest::VALID_DESCRIPTION; -// $actual = $coupon->getDescription(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test if a Coupon can be Cumulative -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::isCumulative -// * -// */ -// public function testIsCumulative() -// { -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, true, true); -// -// $actual = $coupon->isCumulative(); -// $this->assertTrue($actual); -// } -// -// /** -// * Test if a Coupon can be non cumulative -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::isCumulative -// * -// */ -// public function testIsNotCumulative() -// { -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $actual = $coupon->isCumulative(); -// $this->assertFalse($actual); -// } -// -// -// /** -// * Test if a Coupon can remove postage -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::isRemovingPostage -// * -// */ -// public function testIsRemovingPostage() -// { -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, true, true); -// -// $actual = $coupon->isRemovingPostage(); -// $this->assertTrue($actual); -// } -// -// /** -// * Test if a Coupon won't remove postage if not set to -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::isRemovingPostage -// */ -// public function testIsNotRemovingPostage() -// { -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $actual = $coupon->isRemovingPostage(); -// $this->assertFalse($actual); -// } -// -// -// /** -// * Test if a Coupon has the effect expected (discount 10euros) -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// */ -// public function testGetEffect() -// { -// $adapter = new BaseFacade(); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $expected = 10; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon rule setter -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::setRules -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getRules -// */ -// public function testSetRulesValid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 20.00 -// ); -// $rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 100.23 -// ); -// $rule2 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR, -// 421.23 -// ); -// -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); -// -// // Then -// $expected = 3; -// $this->assertCount($expected, $coupon->getRules()->getRules()); -// } -// -// /** -// * Test Coupon rule setter -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::setRules -// * @expectedException \Thelia\Exception\InvalidConditionException -// * -// */ -// public function testSetRulesInvalid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 20.00 -// ); -// $rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 100.23 -// ); -// $rule2 = $this; -// -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); -// } -// -// /** -// * Test Coupon effect for rule Total Amount < 400 -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountInferiorTo400Valid() -// { -// // Given -// $adapter = new BaseFacade(); -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 400.00 -// ); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 10.00; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount <= 400 -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid() -// { -// // Given -// $adapter = new BaseFacade(); -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR_OR_EQUAL, -// 400.00 -// ); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 10.00; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount == 400 -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountEqualTo400Valid() -// { -// // Given -// $adapter = new BaseFacade(); -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 400.00 -// ); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 10.00; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount >= 400 -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid() -// { -// // Given -// $adapter = new BaseFacade(); -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR_OR_EQUAL, -// 400.00 -// ); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 10.00; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount > 400 -// * -// * @covers Thelia\Coupon\type\RemoveXAmountManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountSuperiorTo400Valid() -// { -// // Given -// $adapter = new BaseFacade(); -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR, -// 400.00 -// ); -// $coupon = CouponManagerTest::generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 10.00; -// $actual = $coupon->getDiscount(); -// $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() -// { -// } -// -// /** -// * Generate valid rule AvailableForTotalAmount -// * according to given operator and amount -// * -// * @param string $operator Operators::CONST -// * @param float $amount Amount with 2 decimals -// * -// * @return AvailableForTotalAmount -// */ -// protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount) -// { -// $adapter = new BaseFacade(); -// $validators = array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// $operator, -// new PriceParam( -// $adapter, -// $amount, -// 'EUR' -// ) -// ) -// ); -// -// return new AvailableForTotalAmount($adapter, $validators); -// } + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } } diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index c217326ed..bbb0c24a3 100644 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -41,412 +41,27 @@ use PHPUnit_Framework_TestCase; class RemoveXPercentTest 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.' + 'This coupon 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() -// { -// } -// -// /** -// * Test if a Coupon can be Cumulative -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::isCumulative -// * -// */ -// public function testIsCumulative() -// { -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true); -// -// $actual = $coupon->isCumulative(); -// $this->assertTrue($actual); -// } -// -// /** -// * Test if a Coupon can be non cumulative -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::isCumulative -// * -// */ -// public function testIsNotCumulative() -// { -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $actual = $coupon->isCumulative(); -// $this->assertFalse($actual); -// } -// -// -// /** -// * Test if a Coupon can remove postage -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::isRemovingPostage -// * -// */ -// public function testIsRemovingPostage() -// { -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, true, true); -// -// $actual = $coupon->isRemovingPostage(); -// $this->assertTrue($actual); -// } -// -// /** -// * Test if a Coupon won't remove postage if not set to -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::isRemovingPostage -// */ -// public function testIsNotRemovingPostage() -// { -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $actual = $coupon->isRemovingPostage(); -// $this->assertFalse($actual); -// } -// -// -// /** -// * Test if a Coupon has the effect expected (discount 10euros) -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// */ -// public function testGetEffect() -// { -// $adapter = $this->generateFakeAdapter(245); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// $expected = 24.50; -// $actual = $coupon->getDiscount($adapter); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon rule setter -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::setRules -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getRules -// */ -// public function testSetRulesValid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 20.00 -// ); -// $rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 100.23 -// ); -// $rule2 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR, -// 421.23 -// ); -// -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); -// -// // Then -// $expected = 3; -// $this->assertCount($expected, $coupon->getRules()->getRules()); -// } -// -// /** -// * Test Coupon rule setter -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::setRules -// * @expectedException \Thelia\Exception\InvalidConditionException -// * -// */ -// public function testSetRulesInvalid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 20.00 -// ); -// $rule1 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 100.23 -// ); -// $rule2 = $this; -// -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0, $rule1, $rule2))); -// } -// -// /** -// * Test Coupon effect for rule Total Amount < 400 -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountInferiorTo400Valid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR, -// 400.00 -// ); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 24.50; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount <= 400 -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::INFERIOR_OR_EQUAL, -// 400.00 -// ); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 24.50; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount == 400 -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountEqualTo400Valid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::EQUAL, -// 400.00 -// ); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 24.50; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount >= 400 -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR_OR_EQUAL, -// 400.00 -// ); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 24.50; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Test Coupon effect for rule Total Amount > 400 -// * -// * @covers Thelia\Coupon\type\RemoveXPercentManager::getEffect -// * -// */ -// public function testGetEffectIfTotalAmountSuperiorTo400Valid() -// { -// // Given -// $rule0 = $this->generateValidRuleAvailableForTotalAmountOperatorTo( -// Operators::SUPERIOR, -// 400.00 -// ); -// $coupon = $this->generateValidCoupon(null, null, null, null, null, null, null, null, false, false); -// -// // When -// $coupon->setRules(new ConditionCollection(array($rule0))); -// -// // Then -// $expected = 24.50; -// $actual = $coupon->getDiscount(); -// $this->assertEquals($expected, $actual); -// } -// -// /** -// * Generate valid CouponInterface -// * -// * @param string $code Coupon Code -// * @param string $title Coupon Title -// * @param string $shortDescription Coupon short -// * description -// * @param string $description Coupon description -// * @param float $amount Coupon discount -// * @param bool $isEnabled Is Coupon enabled -// * @param \DateTime $expirationDate Coupon expiration date -// * @param ConditionCollection $rules Coupon rules -// * @param bool $isCumulative If is cumulative -// * @param bool $isRemovingPostage If is removing postage -// * @param bool $isAvailableOnSpecialOffers If is available on -// * special offers or not -// * @param int $maxUsage How many time a Coupon -// * can be used -// * -// * @return CouponInterface -// */ -// public function generateValidCoupon( -// $code = null, -// $title = null, -// $shortDescription = null, -// $description = null, -// $percent = null, -// $isEnabled = null, -// $expirationDate = null, -// $rules = null, -// $isCumulative = null, -// $isRemovingPostage = null, -// $isAvailableOnSpecialOffers = null, -// $maxUsage = null -// ) { -// $adapter = $this->generateFakeAdapter(245); -// -// if ($code === null) { -// $code = CouponManagerTest::VALID_CODE; -// } -// if ($title === null) { -// $title = CouponManagerTest::VALID_TITLE; -// } -// if ($shortDescription === null) { -// $shortDescription = CouponManagerTest::VALID_SHORT_DESCRIPTION; -// } -// if ($description === null) { -// $description = CouponManagerTest::VALID_DESCRIPTION; -// } -// if ($percent === null) { -// $percent = 10.00; -// } -// if ($isEnabled === null) { -// $isEnabled = true; -// } -// if ($isCumulative === null) { -// $isCumulative = true; -// } -// if ($isRemovingPostage === null) { -// $isRemovingPostage = false; -// } -// if ($isAvailableOnSpecialOffers === null) { -// $isAvailableOnSpecialOffers = true; -// } -// if ($maxUsage === null) { -// $maxUsage = 40; -// } -// -// if ($expirationDate === null) { -// $expirationDate = new \DateTime(); -// $expirationDate->setTimestamp(strtotime("today + 2 months")); -// } -// -// $coupon = new RemoveXPercent($adapter, $code, $title, $shortDescription, $description, $percent, $isCumulative, $isRemovingPostage, $isAvailableOnSpecialOffers, $isEnabled, $maxUsage, $expirationDate); -// -// if ($rules === null) { -// $rules = CouponManagerTest::generateValidRules(); -// } -// -// $coupon->setRules($rules); -// -// return $coupon; -// } -// -// -// /** -// * Generate valid rule AvailableForTotalAmount -// * according to given operator and amount -// * -// * @param string $operator Operators::CONST -// * @param float $amount Amount with 2 decimals -// * -// * @return AvailableForTotalAmount -// */ -// protected function generateValidRuleAvailableForTotalAmountOperatorTo($operator, $amount) -// { -// $adapter = new BaseFacade(); -// $validators = array( -// AvailableForTotalAmount::PARAM1_PRICE => new RuleValidator( -// $operator, -// new PriceParam( -// $adapter, -// $amount, -// 'EUR' -// ) -// ) -// ); -// -// return new AvailableForTotalAmount($adapter, $validators); -// } -// -// /** -// * Generate a fake Adapter -// * -// * @param float $cartTotalPrice Cart total price -// * -// * @return \PHPUnit_Framework_MockObject_MockObject -// */ -// public function generateFakeAdapter($cartTotalPrice) -// { -// $stubCouponBaseAdapter = $this->getMock( -// 'Thelia\Coupon\BaseFacade', -// array( -// 'getCartTotalPrice' -// ), -// array() -// ); -// -// $stubCouponBaseAdapter->expects($this->any()) -// ->method('getCartTotalPrice') -// ->will($this->returnValue(($cartTotalPrice))); -// -// return $stubCouponBaseAdapter; -// } -// -// /** -// * Tears down the fixture, for example, closes a network connection. -// * This method is called after a test is executed. -// */ -// protected function tearDown() -// { -// } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } }