WIP : Condition : Fix unit text
This commit is contained in:
@@ -45,33 +45,33 @@ class SerializableCondition
|
||||
/** @var array Values set by Admin for this Condition */
|
||||
public $values = array();
|
||||
|
||||
/**
|
||||
* Get Operators set by Admin for this Condition
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getOperators()
|
||||
{
|
||||
return $this->operators;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Condition Service id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getConditionServiceId()
|
||||
{
|
||||
return $this->conditionServiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Values set by Admin for this Condition
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getValues()
|
||||
{
|
||||
return $this->values;
|
||||
}
|
||||
// /**
|
||||
// * Get Operators set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getOperators()
|
||||
// {
|
||||
// return $this->operators;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get Condition Service id
|
||||
// *
|
||||
// * @return string
|
||||
// */
|
||||
// public function getConditionServiceId()
|
||||
// {
|
||||
// return $this->conditionServiceId;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Get Values set by Admin for this Condition
|
||||
// *
|
||||
// * @return array
|
||||
// */
|
||||
// public function getValues()
|
||||
// {
|
||||
// return $this->values;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -259,6 +259,140 @@ class ConditionFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputs()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = $condition1->getValidators();
|
||||
$actual = $conditionFactory->getInputs('thelia.condition.match_for_x_articles');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check the getInputs method
|
||||
*/
|
||||
public function testGetInputsFalse()
|
||||
{
|
||||
$stubTranslator = $this->getMockBuilder('\Thelia\Core\Translation\Translator')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getTranslator')
|
||||
->will($this->returnValue($stubTranslator));
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currencies = CurrencyQuery::create();
|
||||
$currencies = $currencies->find();
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue($currencies));
|
||||
|
||||
$stubContainer = $this->getMockBuilder('\Symfony\Component\DependencyInjection\Container')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$condition1 = new MatchForTotalAmountManager($stubAdapter);
|
||||
$stubContainer->expects($this->any())
|
||||
->method('get')
|
||||
->will($this->returnValue($condition1));
|
||||
|
||||
$stubContainer->expects($this->any())
|
||||
->method('has')
|
||||
->will($this->returnValue(false));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getContainer')
|
||||
->will($this->returnValue($stubContainer));
|
||||
|
||||
|
||||
$operators = array(
|
||||
MatchForTotalAmountManager::INPUT1 => Operators::SUPERIOR,
|
||||
MatchForTotalAmountManager::INPUT2 => Operators::EQUAL
|
||||
);
|
||||
$values = array(
|
||||
MatchForTotalAmountManager::INPUT1 => 40.00,
|
||||
MatchForTotalAmountManager::INPUT2 => 'EUR'
|
||||
);
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
|
||||
$conditions = new ConditionCollection();
|
||||
$conditions->add($condition1);
|
||||
|
||||
$conditionFactory = new ConditionFactory($stubContainer);
|
||||
|
||||
$expected = false;
|
||||
$actual = $conditionFactory->getInputs('thelia.condition.unknown');
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
@@ -0,0 +1,129 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Condition\Implementation;
|
||||
|
||||
use Thelia\Condition\ConditionEvaluator;
|
||||
use Thelia\Condition\Operators;
|
||||
use Thelia\Coupon\AdapterInterface;
|
||||
use Thelia\Exception\InvalidConditionValueException;
|
||||
use Thelia\Model\Currency;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Unit Test MatchForEveryoneManager Class
|
||||
*
|
||||
* @package Condition
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/** @var AdapterInterface $stubTheliaAdapter */
|
||||
protected $stubTheliaAdapter = null;
|
||||
|
||||
/**
|
||||
* Generate adapter stub
|
||||
*
|
||||
* @param int $cartTotalPrice Cart total price
|
||||
* @param string $checkoutCurrency Checkout currency
|
||||
*
|
||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||
*/
|
||||
public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR')
|
||||
{
|
||||
$stubAdapter = $this->getMockBuilder('\Thelia\Coupon\BaseAdapter')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCartTotalPrice')
|
||||
->will($this->returnValue($cartTotalPrice));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getCheckoutCurrency')
|
||||
->will($this->returnValue($checkoutCurrency));
|
||||
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getConditionEvaluator')
|
||||
->will($this->returnValue(new ConditionEvaluator()));
|
||||
|
||||
$currency1 = new Currency();
|
||||
$currency1->setCode('EUR');
|
||||
$currency2 = new Currency();
|
||||
$currency2->setCode('USD');
|
||||
$stubAdapter->expects($this->any())
|
||||
->method('getAvailableCurrencies')
|
||||
->will($this->returnValue(array($currency1, $currency2)));
|
||||
|
||||
return $stubAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if validity test on BackOffice inputs are working
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::setValidators
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInputOperator()
|
||||
{
|
||||
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$condition1 = new MatchForEveryoneManager($stubAdapter);
|
||||
$operators = array();
|
||||
$values = array();
|
||||
$condition1->setValidatorsFromForm($operators, $values);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual =$isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if condition is always matching
|
||||
*
|
||||
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::isMatching
|
||||
*
|
||||
*/
|
||||
public function testIsMatching()
|
||||
{
|
||||
$stubAdapter = $this->generateAdapterStub(399, 'EUR');
|
||||
|
||||
/** @var AdapterInterface $stubAdapter */
|
||||
$condition1 = new MatchForEveryoneManager($stubAdapter);
|
||||
|
||||
$isValid = $condition1->isMatching();
|
||||
|
||||
$expected = true;
|
||||
$actual = $isValid;
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user