diff --git a/core/lib/Thelia/Condition/SerializableCondition.php b/core/lib/Thelia/Condition/SerializableCondition.php index 9dbec171c..426052506 100644 --- a/core/lib/Thelia/Condition/SerializableCondition.php +++ b/core/lib/Thelia/Condition/SerializableCondition.php @@ -45,33 +45,33 @@ 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; - } +// /** +// * 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/Tests/Condition/ConstraintEvaluatorTest.php b/core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/ConstraintEvaluatorTest.php rename to core/lib/Thelia/Tests/Condition/ConditionEvaluatorTest.php diff --git a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php similarity index 69% rename from core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php rename to core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php index 6bc279479..97686e871 100644 --- a/core/lib/Thelia/Tests/Condition/ConstraintFactoryTest.php +++ b/core/lib/Thelia/Tests/Condition/ConditionFactoryTest.php @@ -259,6 +259,140 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * Check the getInputs method + */ + public function testGetInputs() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($condition1)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + + $conditionFactory = new ConditionFactory($stubContainer); + + $expected = $condition1->getValidators(); + $actual = $conditionFactory->getInputs('thelia.condition.match_for_x_articles'); + + $this->assertEquals($expected, $actual); + + } + + /** + * Check the getInputs method + */ + public function testGetInputsFalse() + { + $stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + /** @var AdapterInterface $stubAdapter */ + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getTranslator') + ->will($this->returnValue($stubTranslator)); + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currencies = CurrencyQuery::create(); + $currencies = $currencies->find(); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue($currencies)); + + $stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container') + ->disableOriginalConstructor() + ->getMock(); + $condition1 = new MatchForTotalAmountManager($stubAdapter); + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->returnValue($condition1)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(false)); + + $stubAdapter->expects($this->any()) + ->method('getContainer') + ->will($this->returnValue($stubContainer)); + + + $operators = array( + MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmountManager::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmountManager::INPUT1 => 40.00, + MatchForTotalAmountManager::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + + $conditionFactory = new ConditionFactory($stubContainer); + + $expected = false; + $actual = $conditionFactory->getInputs('thelia.condition.unknown'); + + $this->assertEquals($expected, $actual); + + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php new file mode 100644 index 000000000..85e357eca --- /dev/null +++ b/core/lib/Thelia/Tests/Condition/Implementation/MatchForEveryoneManagerTest.php @@ -0,0 +1,129 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Condition\Implementation; + +use Thelia\Condition\ConditionEvaluator; +use Thelia\Condition\Operators; +use Thelia\Coupon\AdapterInterface; +use Thelia\Exception\InvalidConditionValueException; +use Thelia\Model\Currency; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test MatchForEveryoneManager Class + * + * @package Condition + * @author Guillaume MOREL + * + */ +class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase +{ + /** @var AdapterInterface $stubTheliaAdapter */ + protected $stubTheliaAdapter = null; + + /** + * Generate adapter stub + * + * @param int $cartTotalPrice Cart total price + * @param string $checkoutCurrency Checkout currency + * + * @return \PHPUnit_Framework_MockObject_MockObject + */ + public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR') + { + $stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter') + ->disableOriginalConstructor() + ->getMock(); + + $stubAdapter->expects($this->any()) + ->method('getCartTotalPrice') + ->will($this->returnValue($cartTotalPrice)); + + $stubAdapter->expects($this->any()) + ->method('getCheckoutCurrency') + ->will($this->returnValue($checkoutCurrency)); + + $stubAdapter->expects($this->any()) + ->method('getConditionEvaluator') + ->will($this->returnValue(new ConditionEvaluator())); + + $currency1 = new Currency(); + $currency1->setCode('EUR'); + $currency2 = new Currency(); + $currency2->setCode('USD'); + $stubAdapter->expects($this->any()) + ->method('getAvailableCurrencies') + ->will($this->returnValue(array($currency1, $currency2))); + + return $stubAdapter; + } + + /** + * Check if validity test on BackOffice inputs are working + * + * @covers Thelia\Condition\Implementation\MatchForEveryoneManager::setValidators + * + */ + public function testValidBackOfficeInputOperator() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForEveryoneManager($stubAdapter); + $operators = array(); + $values = array(); + $condition1->setValidatorsFromForm($operators, $values); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual =$isValid; + $this->assertEquals($expected, $actual); + } + + + /** + * Check if condition is always matching + * + * @covers Thelia\Condition\Implementation\MatchForEveryoneManager::isMatching + * + */ + public function testIsMatching() + { + $stubAdapter = $this->generateAdapterStub(399, 'EUR'); + + /** @var AdapterInterface $stubAdapter */ + $condition1 = new MatchForEveryoneManager($stubAdapter); + + $isValid = $condition1->isMatching(); + + $expected = true; + $actual = $isValid; + $this->assertEquals($expected, $actual); + } + +} diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/Implementation/AvailableForTotalAmountManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/MatchForTotalAmountManagerTest.php diff --git a/core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php b/core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php similarity index 100% rename from core/lib/Thelia/Tests/Condition/Implementation/AvailableForXArticlesManagerTest.php rename to core/lib/Thelia/Tests/Condition/Implementation/MatchForXArticlesManagerTest.php