diff --git a/core/lib/Thelia/Condition/ConditionManagerAbstract.php b/core/lib/Thelia/Condition/ConditionManagerAbstract.php index bf38ef387..97418178f 100644 --- a/core/lib/Thelia/Condition/ConditionManagerAbstract.php +++ b/core/lib/Thelia/Condition/ConditionManagerAbstract.php @@ -54,7 +54,7 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface protected $validators = array(); /** @var FacadeInterface Provide necessary value from Thelia */ - protected $adapter = null; + protected $facade = null; /** @var Translator Service Translator */ protected $translator = null; @@ -71,13 +71,13 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface /** * Constructor * - * @param FacadeInterface $adapter Service adapter + * @param FacadeInterface $facade Service Facade */ - public function __construct(FacadeInterface $adapter) + public function __construct(FacadeInterface $facade) { - $this->adapter = $adapter; - $this->translator = $adapter->getTranslator(); - $this->conditionValidator = $adapter->getConditionEvaluator(); + $this->facade = $facade; + $this->translator = $facade->getTranslator(); + $this->conditionValidator = $facade->getConditionEvaluator(); } /** @@ -181,9 +181,9 @@ abstract class ConditionManagerAbstract implements ConditionManagerInterface * @return bool * @throws \Thelia\Exception\InvalidConditionValueException */ - protected function IsCurrencyValid($currencyValue) + protected function isCurrencyValid($currencyValue) { - $availableCurrencies = $this->adapter->getAvailableCurrencies(); + $availableCurrencies = $this->facade->getAvailableCurrencies(); /** @var Currency $currency */ $currencyFound = false; foreach ($availableCurrencies as $currency) { diff --git a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php index bc158c878..874ad508e 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForTotalAmountManager.php @@ -124,7 +124,7 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract $this->isPriceValid($priceValue); - $this->IsCurrencyValid($currencyValue); + $this->isCurrencyValid($currencyValue); $this->operators = array( @@ -160,12 +160,12 @@ class MatchForTotalAmountManager extends ConditionManagerAbstract } $condition1 = $this->conditionValidator->variableOpComparison( - $this->adapter->getCartTotalPrice(), + $this->facade->getCartTotalPrice(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); $condition2 = $this->conditionValidator->variableOpComparison( - $this->adapter->getCheckoutCurrency(), + $this->facade->getCheckoutCurrency(), $this->operators[self::INPUT2], $this->values[self::INPUT2] ); diff --git a/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php index 05de953d0..d8721cb07 100644 --- a/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php +++ b/core/lib/Thelia/Condition/Implementation/MatchForXArticlesManager.php @@ -124,7 +124,7 @@ class MatchForXArticlesManager extends ConditionManagerAbstract public function isMatching() { $condition1 = $this->conditionValidator->variableOpComparison( - $this->adapter->getNbArticlesInCart(), + $this->facade->getNbArticlesInCart(), $this->operators[self::INPUT1], $this->values[self::INPUT1] ); diff --git a/core/lib/Thelia/Config/Resources/coupon.xml b/core/lib/Thelia/Config/Resources/coupon.xml index fc327911c..8be9ea59f 100644 --- a/core/lib/Thelia/Config/Resources/coupon.xml +++ b/core/lib/Thelia/Config/Resources/coupon.xml @@ -9,7 +9,7 @@ - + @@ -20,11 +20,11 @@ - + - + @@ -36,17 +36,18 @@ - - - - - + - + + + + + + diff --git a/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php index 28e81ee77..b211c4ddf 100644 --- a/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php @@ -387,6 +387,66 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase } + /** + * Test condition serialization if collection is empty + * + * @covers Thelia\Condition\ConditionFactory::serializeConditionCollection + */ + public function testSerializeConditionCollectionEmpty() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var FacadeInterface $stubFacade */ + $stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade') + ->disableOriginalConstructor() + ->getMock(); + + $stubFacade->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubFacade->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubFacade->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue(new MatchForEveryoneManager($stubFacade))); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubFacade->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + + $conditions = new ConditionCollection(); + + $conditionFactory = new ConditionFactory($stubContainer); + + + $conditionNone = new MatchForEveryoneManager($stubFacade); + $expectedCollection = new ConditionCollection(); + $expectedCollection->add($conditionNone); + + $expected = $conditionFactory->serializeConditionCollection($expectedCollection); + $actual = $conditionFactory->serializeConditionCollection($conditions); + + $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/Condition/Implementation/MatchForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php index 465f27225..2881c4e42 100644 --- a/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php @@ -24,10 +24,13 @@ namespace Thelia\Condition\Implementation; use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\ConditionFactory; use Thelia\Condition\Operators; +use Thelia\Coupon\ConditionCollection; use Thelia\Coupon\FacadeInterface; use Thelia\Exception\InvalidConditionValueException; use Thelia\Model\Currency; +use Thelia\Model\CurrencyQuery; /** * Created by JetBrains PhpStorm. @@ -599,6 +602,73 @@ class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * Check unknown currency + * + * @covers Thelia\Condition\ConditionManagerAbstract::isCurrencyValid + * @expectedException \Thelia\Exception\InvalidConditionValueException + * + */ + public function testUnknownCurrency() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var FacadeInterface $stubFacade */ + $stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade') + ->disableOriginalConstructor() + ->getMock(); + + $stubFacade->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubFacade->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubFacade->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + + $condition1 = new MatchForTotalAmountManager($stubFacade); + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::EQUAL, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 400.00, + MatchForTotalAmountManager::INPUT2 => 'UNK'); + $condition1->setValidatorsFromForm($operators, $values); + + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($condition1)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubFacade->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + $conditionFactory = new ConditionFactory($stubContainer); + + $collection = new ConditionCollection(); + $collection->add($condition1); + + $serialized = $conditionFactory->serializeConditionCollection($collection); + $unserialized = $conditionFactory->unserializeConditionCollection($serialized); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed.