Written coupons unit tests

This commit is contained in:
Franck Allimant
2014-06-17 19:58:56 +02:00
parent 6f12882850
commit cbf2eae842
16 changed files with 4583 additions and 3 deletions

View File

@@ -0,0 +1,365 @@
<?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,365 @@
<?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,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\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,312 @@
<?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;
/**
* @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('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

@@ -13,7 +13,6 @@
namespace Thelia\Condition\Implementation;
use Thelia\Condition\ConditionEvaluator;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Currency;

View File

@@ -12,13 +12,12 @@
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\Condition\ConditionCollection;
use Thelia\Coupon\FacadeInterface;
use Thelia\Model\Currency;
use Thelia\Model\CurrencyQuery;

View File

@@ -0,0 +1,329 @@
<?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
{
var $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()
{
}
}