Adding/Refactoring unit test for ConditionFactory/ConditionManagerAbstract
This commit is contained in:
@@ -609,7 +609,7 @@ class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
|
||||
* @expectedException \Thelia\Exception\InvalidConditionValueException
|
||||
*
|
||||
*/
|
||||
public function testUnknownCurrency()
|
||||
public function testUnknownCurrencyCode()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
@@ -669,6 +669,140 @@ class MatchForTotalAmountManagerTest extends \PHPUnit_Framework_TestCase
|
||||
$unserialized = $conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invalid currency
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionManagerAbstract::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 MatchForTotalAmountManager($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 'notfloat',
|
||||
MatchForTotalAmountManager::INPUT2 => '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->add($condition1);
|
||||
|
||||
$serialized = $conditionFactory->serializeConditionCollection($collection);
|
||||
$unserialized = $conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check invalid currency
|
||||
*
|
||||
* @covers Thelia\Condition\ConditionManagerAbstract::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 MatchForTotalAmountManager($stubFacade);
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::EQUAL,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 0.00,
|
||||
MatchForTotalAmountManager::INPUT2 => '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->add($condition1);
|
||||
|
||||
$serialized = $conditionFactory->serializeConditionCollection($collection);
|
||||
$unserialized = $conditionFactory->unserializeConditionCollection($serialized);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
|
||||
Reference in New Issue
Block a user