From 73c0a96979501b5c9a3f44e4dd69e6aed824954f Mon Sep 17 00:00:00 2001 From: gmorel Date: Mon, 16 Sep 2013 23:05:46 +0200 Subject: [PATCH] WIP : Coupon : unit tests on Operator --- .../Tests/Constraint/Rule/OperatorsTest.php | 62 +++++++++++++++++-- 1 file changed, 56 insertions(+), 6 deletions(-) diff --git a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php index 0b29baa62..d5a340d2b 100644 --- a/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php +++ b/core/lib/Thelia/Tests/Constraint/Rule/OperatorsTest.php @@ -23,7 +23,6 @@ namespace Thelia\Coupon; -use Thelia\Constraint\Validator\QuantityParam; use Thelia\Constraint\Rule\Operators; /** @@ -48,14 +47,58 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase { } - public function testSomething() +// public function testSomething() +// { +// // Stop here and mark this test as incomplete. +// $this->markTestIncomplete( +// 'This test has not been implemented yet.' +// ); +// } + + public function testOperatorI18n() { - // Stop here and mark this test as incomplete. - $this->markTestIncomplete( - 'This test has not been implemented yet.' - ); + $stubTranslator = $this->getMockBuilder('\Symfony\Component\Translation\Translator') + ->disableOriginalConstructor() + ->getMock(); + + $stubTranslator->expects($this->any()) + ->method('trans') + ->will($this->returnCallback((array($this, 'callbackI18n')))); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR); + $expected = 'inferior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::INFERIOR_OR_EQUAL); + $expected = 'inferior or equal to'; + $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 = 'superior or equal to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::SUPERIOR); + $expected = 'superior to'; + $this->assertEquals($expected, $actual); + + $actual = Operators::getI18n($stubTranslator, Operators::DIFFERENT); + $expected = 'different from'; + $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); } + // /** // * // * @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator @@ -424,4 +467,11 @@ class OperatorsTest extends \PHPUnit_Framework_TestCase { } + function callbackI18n() { + $args = func_get_args(); + + return $args[0]; + } } + +