Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,170 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition;
use Thelia\Condition\Implementation\MatchForTotalAmount;
use Thelia\Model\CurrencyQuery;
/**
* Unit Test ConditionCollection Class
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-11-17 at 18:59:24.
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionCollectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ConditionCollection
*/
protected $object;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$currencies = CurrencyQuery::create();
$currencies = $currencies->find();
$stubFacade->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue($currencies));
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
return $stubFacade;
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
/**
*
*/
public function testGetConditions()
{
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$collection = new ConditionCollection();
$collection[] = $condition1;
$expected = $condition1;
$actual = $collection[0];
$this->assertEquals($expected, $actual);
$this->assertFalse($collection->count() == 0);
}
/**
* @covers Thelia\Condition\ConditionCollection::count
*/
public function testIsEmpty()
{
$collection = new ConditionCollection();
$this->assertTrue($collection->count() == 0);
}
/**
* @covers Thelia\Condition\ConditionCollection::__toString
*/
public function test__toString()
{
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchForTotalAmount($stubFacade);
$operators1 = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values1 = array(
MatchForTotalAmount::CART_TOTAL => 400,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators1, $values1);
$condition2 = new MatchForTotalAmount($stubFacade);
$operators2 = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values2 = array(
MatchForTotalAmount::CART_TOTAL => 600,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition2->setValidatorsFromForm($operators2, $values2);
$collection = new ConditionCollection();
$collection[] = $condition1;
$collection[] = $condition2;
$expected = '[{"conditionServiceId":"thelia.condition.match_for_total_amount","operators":{"price":">","currency":"=="},"values":{"price":400,"currency":"EUR"}},{"conditionServiceId":"thelia.condition.match_for_total_amount","operators":{"price":"<","currency":"=="},"values":{"price":600,"currency":"EUR"}}]';
$actual = $collection->__toString();
;
$this->assertEquals($expected, $actual);
}
}

View File

@@ -0,0 +1,193 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Condition;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\ConditionCollection;
/**
* Unit Test ConditionEvaluator Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionEvaluatorTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
}
/**
* Test variable comparison
*
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
*/
public function testVariableOpComparisonSuccess()
{
$conditionEvaluator = new ConditionEvaluator();
$expected = true;
$actual = $conditionEvaluator->variableOpComparison(1, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::DIFFERENT, 2);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR, 0);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR, 2);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::INFERIOR_OR_EQUAL, 2);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::SUPERIOR_OR_EQUAL, 0);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::IN, array(1, 2, 3));
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(1, Operators::OUT, array(0, 2, 3));
$this->assertEquals($expected, $actual);
}
/**
* Test variable comparison
*
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
*/
public function testVariableOpComparisonFail()
{
$conditionEvaluator = new ConditionEvaluator();
$expected = false;
$actual = $conditionEvaluator->variableOpComparison(2, Operators::EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::DIFFERENT, 2);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(0, Operators::SUPERIOR, 0);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(3, Operators::INFERIOR, 2);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::INFERIOR_OR_EQUAL, 1);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(3, Operators::SUPERIOR_OR_EQUAL, 4);
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(0, Operators::IN, array(1, 2, 3));
$this->assertEquals($expected, $actual);
$actual = $conditionEvaluator->variableOpComparison(2, Operators::OUT, array(0, 2, 3));
$this->assertEquals($expected, $actual);
}
/**
* Test variable comparison
*
* @expectedException \Exception
* @covers Thelia\Condition\ConditionEvaluator::variableOpComparison
*/
public function testVariableOpComparisonException()
{
$conditionEvaluator = new ConditionEvaluator();
$expected = true;
$actual = $conditionEvaluator->variableOpComparison(1, 'bad', 1);
$this->assertEquals($expected, $actual);
}
/**
* Test condition collection matching
*
* @covers Thelia\Condition\ConditionEvaluator::isMatching
*/
public function testIsMatchingTrue()
{
$stubConditionTrue1 = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
->disableOriginalConstructor()
->getMock();
$stubConditionTrue1->expects($this->any())
->method('isMatching')
->will($this->returnValue(true));
$stubConditionTrue2 = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
->disableOriginalConstructor()
->getMock();
$stubConditionTrue2->expects($this->any())
->method('isMatching')
->will($this->returnValue(true));
$collection = new ConditionCollection();
$collection[] = $stubConditionTrue1;
$collection[] = $stubConditionTrue2;
$conditionEvaluator = new ConditionEvaluator();
$actual = $conditionEvaluator->isMatching($collection);
$this->assertTrue($actual);
}
/**
* Test condition collection matching
*
* @covers Thelia\Condition\ConditionEvaluator::isMatching
*/
public function testIsMatchingFalse()
{
$stubConditionTrue = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
->disableOriginalConstructor()
->getMock();
$stubConditionTrue->expects($this->any())
->method('isMatching')
->will($this->returnValue(true));
$stubConditionFalse = $this->getMockBuilder('\Thelia\Condition\Implementation\MatchForXArticles')
->disableOriginalConstructor()
->getMock();
$stubConditionFalse->expects($this->any())
->method('isMatching')
->will($this->returnValue(false));
$collection = new ConditionCollection();
$collection[] = $stubConditionTrue;
$collection[] = $stubConditionFalse;
$conditionEvaluator = new ConditionEvaluator();
$actual = $conditionEvaluator->isMatching($collection);
$this->assertFalse($actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,439 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Condition;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Implementation\MatchForEveryone;
use Thelia\Condition\Implementation\MatchForTotalAmount;
use Thelia\Condition\Operators;
use Thelia\Coupon\FacadeInterface;
use Thelia\Condition\ConditionCollection;
use Thelia\Model\CurrencyQuery;
/**
* Unit Test ConditionFactory Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
public function setUp()
{
}
/**
* Check the Rules serialization module
*/
public function testBuild()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
/** @var 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 MatchForTotalAmount($stubFacade)));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValue(true));
$stubFacade->expects($this->any())
->method('getContainer')
->will($this->returnValue($stubContainer));
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$conditionFactory = new ConditionFactory($stubContainer);
$ruleManager1 = $conditionFactory->build($condition1->getServiceId(), $operators, $values);
$expected = $condition1;
$actual = $ruleManager1;
$this->assertEquals($expected, $actual);
$this->assertEquals($condition1->getServiceId(), $ruleManager1->getServiceId());
$this->assertEquals($condition1->getValidators(), $ruleManager1->getValidators());
}
/**
* Check the Rules serialization module
*/
public function testBuildFail()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
/** @var 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 MatchForTotalAmount($stubFacade)));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValueMap(array('unset.service', false)));
$stubFacade->expects($this->any())
->method('getContainer')
->will($this->returnValue($stubContainer));
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$conditionFactory = new ConditionFactory($stubContainer);
$conditionManager1 = $conditionFactory->build('unset.service', $operators, $values);
$expected = false;
$actual = $conditionManager1;
$this->assertEquals($expected, $actual);
}
/**
* Check the Rules serialization module
*/
public function testRuleSerialisation()
{
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
/** @var 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 MatchForTotalAmount($stubFacade)));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValue(true));
$stubFacade->expects($this->any())
->method('getContainer')
->will($this->returnValue($stubContainer));
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$condition2 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition2->setValidatorsFromForm($operators, $values);
$conditions = new ConditionCollection();
$conditions[] = $condition1;
$conditions[] = $condition2;
$conditionFactory = new ConditionFactory($stubContainer);
$serializedConditions = $conditionFactory->serializeConditionCollection($conditions);
$unserializedConditions = $conditionFactory->unserializeConditionCollection($serializedConditions);
$expected = (string) $conditions;
$actual = (string) $unserializedConditions;
$this->assertEquals($expected, $actual);
}
/**
* Check the getInputs method
*/
public function testGetInputs()
{
$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();
$condition1 = new MatchForTotalAmount($stubFacade);
$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));
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$conditions = new ConditionCollection();
$conditions[] = $condition1;
$conditionFactory = new ConditionFactory($stubContainer);
$expected = $condition1->getValidators();
$actual = $conditionFactory->getInputsFromServiceId('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 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();
$condition1 = new MatchForTotalAmount($stubFacade);
$stubContainer->expects($this->any())
->method('get')
->will($this->returnValue($condition1));
$stubContainer->expects($this->any())
->method('has')
->will($this->returnValue(false));
$stubFacade->expects($this->any())
->method('getContainer')
->will($this->returnValue($stubContainer));
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 40.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR'
);
$condition1->setValidatorsFromForm($operators, $values);
$conditions = new ConditionCollection();
$conditions[] = $condition1;
$conditionFactory = new ConditionFactory($stubContainer);
$expected = false;
$actual = $conditionFactory->getInputsFromServiceId('thelia.condition.unknown');
$this->assertEquals($expected, $actual);
}
/**
* 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 MatchForEveryone($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 MatchForEveryone($stubFacade);
$expectedCollection = new ConditionCollection();
$expectedCollection[] = $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.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,360 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Category;
use Thelia\Model\Product;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class CartContainsCategoriesTest 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()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$category1 = new Category();
$category1->setId(10);
$category2 = new Category();
$category2->setId(20);
$category3 = new Category();
$category3->setId(30);
$product1 = new Product();
$product1->addCategory($category1)->addCategory($category2);
$product2 = new Product();
$product2->addCategory($category3);
$cartItem1Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
->disableOriginalConstructor()
->getMock();
$cartItem1Stub
->expects($this->any())
->method('getProduct')
->will($this->returnValue($product1))
;
$cartItem1Stub
->expects($this->any())
->method('getQuantity')
->will($this->returnValue(1))
;
$cartItem2Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
->disableOriginalConstructor()
->getMock();
$cartItem2Stub
->expects($this->any())
->method('getProduct')
->will($this->returnValue($product2));
$cartItem2Stub
->expects($this->any())
->method('getQuantity')
->will($this->returnValue(2))
;
$cartStub = $this->getMockBuilder('\Thelia\Model\Cart')
->disableOriginalConstructor()
->getMock();
$cartStub
->expects($this->any())
->method('getCartItems')
->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
$stubFacade->expects($this->any())
->method('getCart')
->will($this->returnValue($cartStub));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::INFERIOR_OR_EQUAL
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::IN
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::IN
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array(10, 20)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::IN
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::IN
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsCategories($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsCategories($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\CartContainsCategories::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsCategories($stubFacade);
$operators = array(
CartContainsCategories::CATEGORIES_LIST => Operators::IN
);
$values = array(
CartContainsCategories::CATEGORIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
CartContainsCategories::CATEGORIES_LIST => array(
'availableOperators' => array(
'in' => 'Price',
'out' => 'Price',
),
'value' => '',
'selectedOperator' => 'in'
)
),
'setOperators' => array(
'categories' => 'in'
),
'setValues' => array(
'categories' => array(50, 60)
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,360 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Category;
use Thelia\Model\Product;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class CartContainsProductsTest 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()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$category1 = new Category();
$category1->setId(10);
$category2 = new Category();
$category2->setId(20);
$category3 = new Category();
$category3->setId(30);
$product1 = new Product();
$product1->setId(10)->addCategory($category1)->addCategory($category2);
$product2 = new Product();
$product2->setId(20)->addCategory($category3);
$cartItem1Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
->disableOriginalConstructor()
->getMock();
$cartItem1Stub
->expects($this->any())
->method('getProduct')
->will($this->returnValue($product1))
;
$cartItem1Stub
->expects($this->any())
->method('getQuantity')
->will($this->returnValue(1))
;
$cartItem2Stub = $this->getMockBuilder('\Thelia\Model\CartItem')
->disableOriginalConstructor()
->getMock();
$cartItem2Stub
->expects($this->any())
->method('getProduct')
->will($this->returnValue($product2));
$cartItem2Stub
->expects($this->any())
->method('getQuantity')
->will($this->returnValue(2))
;
$cartStub = $this->getMockBuilder('\Thelia\Model\Cart')
->disableOriginalConstructor()
->getMock();
$cartStub
->expects($this->any())
->method('getCartItems')
->will($this->returnValue([$cartItem1Stub, $cartItem2Stub]));
$stubFacade->expects($this->any())
->method('getCart')
->will($this->returnValue($cartStub));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::INFERIOR_OR_EQUAL
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::IN
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::IN
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array(10, 20)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::IN
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::IN
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsProducts($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsProducts($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\CartContainsProducts::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new CartContainsProducts($stubFacade);
$operators = array(
CartContainsProducts::PRODUCTS_LIST => Operators::IN
);
$values = array(
CartContainsProducts::PRODUCTS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
CartContainsProducts::PRODUCTS_LIST => array(
'availableOperators' => array(
'in' => 'Price',
'out' => 'Price',
),
'value' => '',
'selectedOperator' => 'in'
)
),
'setOperators' => array(
'products' => 'in'
),
'setValues' => array(
'products' => array(50, 60)
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,299 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Customer;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class ForSomeCustomersTest 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()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$customer = new Customer();
$customer->setId(10);
$stubFacade->expects($this->any())
->method('getCustomer')
->will($this->returnValue($customer));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::INFERIOR_OR_EQUAL
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array(10, 20)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new ForSomeCustomers($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new ForSomeCustomers($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\ForSomeCustomers::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new ForSomeCustomers($stubFacade);
$operators = array(
ForSomeCustomers::CUSTOMERS_LIST => Operators::IN
);
$values = array(
ForSomeCustomers::CUSTOMERS_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
ForSomeCustomers::CUSTOMERS_LIST => array(
'availableOperators' => array(
'in' => 'Price',
'out' => 'Price',
),
'value' => '',
'selectedOperator' => 'in'
)
),
'setOperators' => array(
'customers' => 'in'
),
'setValues' => array(
'customers' => array(50, 60)
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,307 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Address;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class MatchBillingCountriesTest 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()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$address = new Address();
$address->setCountryId(10);
$stubCustomer = $this->getMockBuilder('\Thelia\Model\Customer')
->disableOriginalConstructor()
->getMock();
$stubCustomer->expects($this->any())
->method('getDefaultAddress')
->will($this->returnValue($address));
$stubFacade->expects($this->any())
->method('getCustomer')
->will($this->returnValue($stubCustomer));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::INFERIOR_OR_EQUAL
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array(10, 20)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchBillingCountries($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchBillingCountries($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\MatchBillingCountries::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchBillingCountries($stubFacade);
$operators = array(
MatchBillingCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchBillingCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
MatchBillingCountries::COUNTRIES_LIST => array(
'availableOperators' => array(
'in' => 'Price',
'out' => 'Price',
),
'value' => '',
'selectedOperator' => 'in'
)
),
'setOperators' => array(
'countries' => 'in'
),
'setValues' => array(
'countries' => array(50, 60)
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,304 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Address;
use Thelia\Model\Customer;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class MatchDeliveryCountriesTest 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()
{
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$address = new Address();
$address->setCountryId(10);
$stubFacade->expects($this->any())
->method('getCustomer')
->will($this->returnValue(new Customer()));
$stubFacade->expects($this->any())
->method('getDeliveryAddress')
->will($this->returnValue($address));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::INFERIOR_OR_EQUAL
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array()
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array(10, 20)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchDeliveryCountries($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchDeliveryCountries($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\MatchDeliveryCountries::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchDeliveryCountries($stubFacade);
$operators = array(
MatchDeliveryCountries::COUNTRIES_LIST => Operators::IN
);
$values = array(
MatchDeliveryCountries::COUNTRIES_LIST => array(50, 60)
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
MatchDeliveryCountries::COUNTRIES_LIST => array(
'availableOperators' => array(
'in' => 'Price',
'out' => 'Price',
),
'value' => '',
'selectedOperator' => 'in'
)
),
'setOperators' => array(
'countries' => 'in'
),
'setValues' => array(
'countries' => array(50, 60)
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,184 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Currency;
/**
* Unit Test MatchForEveryone Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class MatchForEveryoneTest extends \PHPUnit_Framework_TestCase
{
/** @var FacadeInterface $stubTheliaAdapter */
protected $stubTheliaAdapter = null;
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$currency1 = new Currency();
$currency1->setCode('EUR');
$currency2 = new Currency();
$currency2->setCode('USD');
$stubFacade->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue(array($currency1, $currency2)));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForEveryone::setValidators
*
*/
public function testValidBackOfficeInputOperator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForEveryone($stubFacade);
$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\MatchForEveryone::isMatching
*
*/
public function testIsMatching()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForEveryone($stubFacade);
$isValid = $condition1->isMatching();
$expected = true;
$actual = $isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\MatchForEveryone::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Everybody can use it (no condition)');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForEveryone($stubFacade);
$actual = $condition1->getName();
$expected = 'Everybody can use it (no condition)';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\MatchForEveryone::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Will return always true');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForEveryone($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Will return always true';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\MatchForEveryone::generateInputs
* @covers Thelia\Condition\Implementation\MatchForEveryone::setValidatorsFromForm
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForEveryone($stubFacade);
$actual1 = $condition1->setValidatorsFromForm(array(), array());
$expected1 = $condition1;
$actual2 = $condition1->getValidators();
$validators = array();
$validators['inputs'] = array();
$validators['setOperators'] = array();
$validators['setValues'] = array();
$expected2 = $validators;
$this->assertEquals($expected1, $actual1);
$this->assertEquals($expected2, $actual2);
}
}

View File

@@ -0,0 +1,946 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Tests\Condition\Implementation;
use Thelia\Condition\ConditionCollection;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\ConditionFactory;
use Thelia\Condition\Implementation\MatchForTotalAmount;
use Thelia\Condition\Operators;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Currency;
use Thelia\Model\CurrencyQuery;
/**
* Unit Test MatchForTotalAmount Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class MatchForTotalAmountTest extends \PHPUnit_Framework_TestCase
{
/** @var FacadeInterface $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')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalTaxPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$currency1 = new Currency();
$currency1->setCode('EUR');
$currency2 = new Currency();
$currency2->setCode('USD');
$stubFacade->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue(array($currency1, $currency2)));
return $stubFacade;
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator()
{
$stubFacade = $this->generateAdapterStub(399, 'EUR');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::IN,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => '400',
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*
*/
public function testInValidBackOfficeInputOperator2()
{
$stubFacade = $this->generateAdapterStub(399, 'EUR');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::INFERIOR
);
$values = array(
MatchForTotalAmount::CART_TOTAL => '400',
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 'X',
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInValidBackOfficeInputValue2()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400,
MatchForTotalAmount::CART_CURRENCY => 'FLA');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionInferior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionInferior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionInferiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionInferiorEquals2()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionInferiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::INFERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionEqual()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionEqual()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionSuperiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionSuperiorEquals2()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionSuperiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR_OR_EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionSuperior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(401, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionSuperior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(399, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::SUPERIOR,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testMatchingConditionCurrency()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check currency is checked
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::isMatching
*
*/
public function testNotMatchingConditionCurrency()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateAdapterStub(400.00, 'EUR');
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'USD');
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check unknown currency
*
* @covers Thelia\Condition\Implementation\ConditionAbstract::isCurrencyValid
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testUnknownCurrencyCode()
{
$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 MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => '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[] = $condition1;
$serialized = $conditionFactory->serializeConditionCollection($collection);
$conditionFactory->unserializeConditionCollection($serialized);
}
/**
* Check invalid currency
*
* @covers Thelia\Condition\Implementation\ConditionAbstract::isPriceValid
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testInvalidCurrencyValue()
{
$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 MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 'notfloat',
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$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[] = $condition1;
$serialized = $conditionFactory->serializeConditionCollection($collection);
$conditionFactory->unserializeConditionCollection($serialized);
}
/**
* Check invalid currency
*
* @covers Thelia\Condition\Implementation\ConditionAbstract::isPriceValid
* @expectedException \Thelia\Exception\InvalidConditionValueException
*
*/
public function testPriceAsZero()
{
$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 MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 0.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$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[] = $condition1;
$serialized = $conditionFactory->serializeConditionCollection($collection);
$conditionFactory->unserializeConditionCollection($serialized);
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$currency1 = new Currency();
$currency1->setCode('EUR');
$currency2 = new Currency();
$currency2->setCode('USD');
$stubFacade->expects($this->any())
->method('getAvailableCurrencies')
->will($this->returnValue(array($currency1, $currency2)));
return $stubFacade;
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Cart total amount');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForTotalAmount($stubFacade);
$actual = $condition1->getName();
$expected = 'Cart total amount';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'If cart total amount is <strong>%operator%</strong> %amount% %currency%');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getToolTip();
$expected = 'If cart total amount is <strong>%operator%</strong> %amount% %currency%';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\MatchForTotalAmount::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForTotalAmount($stubFacade);
$operators = array(
MatchForTotalAmount::CART_TOTAL => Operators::EQUAL,
MatchForTotalAmount::CART_CURRENCY => Operators::EQUAL
);
$values = array(
MatchForTotalAmount::CART_TOTAL => 400.00,
MatchForTotalAmount::CART_CURRENCY => 'EUR');
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
MatchForTotalAmount::CART_TOTAL => array(
'availableOperators' => array(
'<' => 'Price',
'<=' => 'Price',
'==' => 'Price',
'>=' => 'Price',
'>' => 'Price'
),
'availableValues' => '',
'value' => '',
'selectedOperator' => ''
),
MatchForTotalAmount::CART_CURRENCY => array(
'availableOperators' => array('==' => 'Price'),
'availableValues' => array(
'EUR' => '€',
'USD' => '$',
'GBP' => '£',
),
'value' => '',
'selectedOperator' => Operators::EQUAL
)
),
'setOperators' => array(
'price' => '==',
'currency' => '=='
),
'setValues' => array(
'price' => 400,
'currency' => 'EUR'
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,716 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
/**
* Unit Test MatchForXArticles Class
*
* @package Constraint
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class MatchForXArticlesTest 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()
{
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
/** @var FacadeInterface $stubFacade */
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::IN
);
$values = array(
MatchForXArticles::CART_QUANTITY => 5
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 'X'
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleInferior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 5
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testNotMatchingRuleInferior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4,
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleInferiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL,
);
$values = array(
MatchForXArticles::CART_QUANTITY => 5,
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleInferiorEquals2()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testNotMatchingRuleInferiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::INFERIOR_OR_EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 3
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleEqual()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test equals operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testNotMatchingRuleEqual()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 5
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleSuperiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleSuperiorEquals2()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 3
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testNotMatchingRuleSuperiorEquals()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
MatchForXArticles::CART_QUANTITY => 5
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testMatchingRuleSuperior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 3
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test superior operator is working
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::isMatching
*
*/
public function testNotMatchingRuleSuperior()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getNbArticlesInCart')
->will($this->returnValue(4));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$stubFacade->expects($this->any())
->method('getCartTotalPrice')
->will($this->returnValue($cartTotalPrice));
$stubFacade->expects($this->any())
->method('getCheckoutCurrency')
->will($this->returnValue($checkoutCurrency));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
return $stubFacade;
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForXArticles($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'If cart products quantity is <strong>superior to</strong> 4');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getToolTip();
$expected = 'If cart products quantity is <strong>superior to</strong> 4';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\MatchForXArticles::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new MatchForXArticles($stubFacade);
$operators = array(
MatchForXArticles::CART_QUANTITY => Operators::SUPERIOR
);
$values = array(
MatchForXArticles::CART_QUANTITY => 4
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
MatchForXArticles::CART_QUANTITY => array(
'availableOperators' => array(
'<' => 'Price',
'<=' => 'Price',
'==' => 'Price',
'>=' => 'Price',
'>' => 'Price'
),
'value' => '',
'selectedOperator' => ''
)
),
'setOperators' => array(
'quantity' => '>'
),
'setValues' => array(
'quantity' => 4
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,325 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Condition\Operators;
use Thelia\Condition\SerializableCondition;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Address;
use Thelia\Model\Lang;
/**
* @package Coupon
* @author Franck Allimant <franck@cqfdev.fr>
*/
class StartDateTest extends \PHPUnit_Framework_TestCase
{
public $startDate;
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->startDate = time() - 2000;
}
/**
* Generate adapter stub
*
* @param int $cartTotalPrice Cart total price
* @param string $checkoutCurrency Checkout currency
* @param string $i18nOutput Output from each translation
*
* @return \PHPUnit_Framework_MockObject_MockObject
*/
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
{
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
->disableOriginalConstructor()
->getMock();
$address = new Address();
$address->setCountryId(10);
$stubFacade->expects($this->any())
->method('getDeliveryAddress')
->will($this->returnValue($address));
$stubFacade->expects($this->any())
->method('getConditionEvaluator')
->will($this->returnValue(new ConditionEvaluator()));
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnValue($i18nOutput));
$stubFacade->expects($this->any())
->method('getTranslator')
->will($this->returnValue($stubTranslator));
$lang = new Lang();
$lang->setDateFormat("d/m/Y");
$stubSession = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Session\Session')
->disableOriginalConstructor()
->getMock();
$stubSession->expects($this->any())
->method('getLang')
->will($this->returnValue($lang));
$stubRequest = $this->getMockBuilder('\Thelia\Core\HttpFoundation\Request')
->disableOriginalConstructor()
->getMock();
$stubRequest->expects($this->any())
->method('getSession')
->will($this->returnValue($stubSession));
$stubFacade->expects($this->any())
->method('getRequest')
->will($this->returnValue($stubRequest));
return $stubFacade;
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\StartDate::setValidators
* @expectedException \Thelia\Exception\InvalidConditionOperatorException
*/
public function testInValidBackOfficeInputOperator()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => 'petite licorne'
);
$values = array(
StartDate::START_DATE => $this->startDate
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if validity test on BackOffice inputs are working
*
* @covers Thelia\Condition\Implementation\StartDate::setValidators
* @expectedException \Thelia\Exception\InvalidConditionValueException
*/
public function testInValidBackOfficeInputValue()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
StartDate::START_DATE => 'petit poney'
);
$condition1->setValidatorsFromForm($operators, $values);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\StartDate::isMatching
*
*/
public function testMatchingRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
StartDate::START_DATE => $this->startDate
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = true;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
/**
* Check if test inferior operator is working
*
* @covers Thelia\Condition\Implementation\StartDate::isMatching
*
*/
public function testNotMatching()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
StartDate::START_DATE => time() + 2000
);
$condition1->setValidatorsFromForm($operators, $values);
$isValid = $condition1->isMatching();
$expected = false;
$actual =$isValid;
$this->assertEquals($expected, $actual);
}
public function testGetSerializableRule()
{
/** @var FacadeInterface $stubFacade */
$stubFacade = $this->generateFacadeStub();
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
StartDate::START_DATE => $this->startDate
);
$condition1->setValidatorsFromForm($operators, $values);
$serializableRule = $condition1->getSerializableCondition();
$expected = new SerializableCondition();
$expected->conditionServiceId = $condition1->getServiceId();
$expected->operators = $operators;
$expected->values = $values;
$actual = $serializableRule;
$this->assertEquals($expected, $actual);
}
/**
* Check getName i18n
*
* @covers Thelia\Condition\Implementation\StartDate::getName
*
*/
public function testGetName()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Number of articles in cart');
/** @var FacadeInterface $stubFacade */
$condition1 = new StartDate($stubFacade);
$actual = $condition1->getName();
$expected = 'Number of articles in cart';
$this->assertEquals($expected, $actual);
}
/**
* Check tooltip i18n
*
* @covers Thelia\Condition\Implementation\StartDate::getToolTip
*
*/
public function testGetToolTip()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Sample coupon condition');
/** @var FacadeInterface $stubFacade */
$condition1 = new StartDate($stubFacade);
$actual = $condition1->getToolTip();
$expected = 'Sample coupon condition';
$this->assertEquals($expected, $actual);
}
/**
* Check validator
*
* @covers Thelia\Condition\Implementation\StartDate::generateInputs
*
*/
public function testGetValidator()
{
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Price');
/** @var FacadeInterface $stubFacade */
$condition1 = new StartDate($stubFacade);
$operators = array(
StartDate::START_DATE => Operators::SUPERIOR_OR_EQUAL
);
$values = array(
StartDate::START_DATE => $this->startDate
);
$condition1->setValidatorsFromForm($operators, $values);
$actual = $condition1->getValidators();
$validators = array(
'inputs' => array(
StartDate::START_DATE => array(
'availableOperators' => array(
'>=' => 'Price',
),
'value' => '',
'selectedOperator' => '>='
)
),
'setOperators' => array(
'start_date' => '>='
),
'setValues' => array(
'start_date' => $this->startDate
)
);
$expected = $validators;
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
}

View File

@@ -0,0 +1,96 @@
<?php
/*************************************************************************************/
/* This file is part of the Thelia package. */
/* */
/* Copyright (c) OpenStudio */
/* email : dev@thelia.net */
/* web : http://www.thelia.net */
/* */
/* For the full copyright and license information, please view the LICENSE.txt */
/* file that was distributed with this source code. */
/*************************************************************************************/
namespace Thelia\Condition;
use Thelia\Core\Translation\Translator;
/**
* Unit Test Operators Class
*
* @package Condition
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class OperatorsTest extends \PHPUnit_Framework_TestCase
{
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
}
public function testOperatorI18n()
{
/** @var Translator $stubTranslator */
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
->disableOriginalConstructor()
->getMock();
$stubTranslator->expects($this->any())
->method('trans')
->will($this->returnCallback((array($this, 'callbackI18n'))));
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR);
$expected = 'Less than';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL);
$expected = 'Less than or equals';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::EQUAL);
$expected = 'Equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR_OR_EQUAL);
$expected = 'Greater than or equals';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR);
$expected = 'Greater than';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT);
$expected = 'Not equal to';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::IN);
$expected = 'In';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, Operators::OUT);
$expected = 'Not in';
$this->assertEquals($expected, $actual);
$actual = Operators::getI18n($stubTranslator, 'unexpected operator');
$expected = 'unexpected operator';
$this->assertEquals($expected, $actual);
}
/**
* Tears down the fixture, for example, closes a network connection.
* This method is called after a test is executed.
*/
protected function tearDown()
{
}
public function callbackI18n()
{
$args = func_get_args();
return $args[0];
}
}