Adding/Refactoring unit test for MatchForEveryOneManager
This commit is contained in:
@@ -52,7 +52,7 @@ class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*
|
*
|
||||||
* @return \PHPUnit_Framework_MockObject_MockObject
|
* @return \PHPUnit_Framework_MockObject_MockObject
|
||||||
*/
|
*/
|
||||||
public function generateAdapterStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR')
|
public function generateFacadeStub($cartTotalPrice = 400, $checkoutCurrency = 'EUR', $i18nOutput = '')
|
||||||
{
|
{
|
||||||
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
$stubFacade = $this->getMockBuilder('\Thelia\Coupon\BaseFacade')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
@@ -70,6 +70,17 @@ class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
->method('getConditionEvaluator')
|
->method('getConditionEvaluator')
|
||||||
->will($this->returnValue(new ConditionEvaluator()));
|
->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 = new Currency();
|
||||||
$currency1->setCode('EUR');
|
$currency1->setCode('EUR');
|
||||||
$currency2 = new Currency();
|
$currency2 = new Currency();
|
||||||
@@ -89,7 +100,7 @@ class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testValidBackOfficeInputOperator()
|
public function testValidBackOfficeInputOperator()
|
||||||
{
|
{
|
||||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||||
|
|
||||||
/** @var FacadeInterface $stubFacade */
|
/** @var FacadeInterface $stubFacade */
|
||||||
$condition1 = new MatchForEveryoneManager($stubFacade);
|
$condition1 = new MatchForEveryoneManager($stubFacade);
|
||||||
@@ -112,7 +123,7 @@ class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
*/
|
*/
|
||||||
public function testIsMatching()
|
public function testIsMatching()
|
||||||
{
|
{
|
||||||
$stubFacade = $this->generateAdapterStub(399, 'EUR');
|
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||||
|
|
||||||
/** @var FacadeInterface $stubFacade */
|
/** @var FacadeInterface $stubFacade */
|
||||||
$condition1 = new MatchForEveryoneManager($stubFacade);
|
$condition1 = new MatchForEveryoneManager($stubFacade);
|
||||||
@@ -124,4 +135,65 @@ class MatchForEveryoneManagerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals($expected, $actual);
|
$this->assertEquals($expected, $actual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check getName i18n
|
||||||
|
*
|
||||||
|
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::getName
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testGetName()
|
||||||
|
{
|
||||||
|
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Everybody can use it (no condition)');
|
||||||
|
|
||||||
|
/** @var FacadeInterface $stubFacade */
|
||||||
|
$condition1 = new MatchForEveryoneManager($stubFacade);
|
||||||
|
|
||||||
|
$actual = $condition1->getName();
|
||||||
|
$expected = 'Everybody can use it (no condition)';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check tooltip i18n
|
||||||
|
*
|
||||||
|
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::getToolTip
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testGetToolTip()
|
||||||
|
{
|
||||||
|
$stubFacade = $this->generateFacadeStub(399, 'EUR', 'Will return always true');
|
||||||
|
|
||||||
|
/** @var FacadeInterface $stubFacade */
|
||||||
|
$condition1 = new MatchForEveryoneManager($stubFacade);
|
||||||
|
|
||||||
|
$actual = $condition1->getToolTip();
|
||||||
|
$expected = 'Will return always true';
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check validator
|
||||||
|
*
|
||||||
|
* @covers Thelia\Condition\Implementation\MatchForEveryoneManager::generateInputs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public function testGetValidator()
|
||||||
|
{
|
||||||
|
$stubFacade = $this->generateFacadeStub(399, 'EUR');
|
||||||
|
|
||||||
|
/** @var FacadeInterface $stubFacade */
|
||||||
|
$condition1 = new MatchForEveryoneManager($stubFacade);
|
||||||
|
|
||||||
|
$actual = $condition1->getValidators();
|
||||||
|
|
||||||
|
$validators = array();
|
||||||
|
$validators['inputs'] = array();
|
||||||
|
$validators['setOperators'] = array();
|
||||||
|
$validators['setValues'] = array();
|
||||||
|
$expected = $validators;
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user