From 2508ee323096e4c073c38c676375e65e35866217 Mon Sep 17 00:00:00 2001 From: gmorel Date: Sun, 29 Dec 2013 15:45:42 +0100 Subject: [PATCH] Coupon : Fix unit test --- .../Thelia/Tests/Coupon/CouponFactoryTest.php | 66 +++++++++++++++++++ .../Tests/Coupon/Type/RemoveXAmountTest.php | 16 +++++ .../Tests/Coupon/Type/RemoveXPercentTest.php | 18 +++++ 3 files changed, 100 insertions(+) diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php index 5c18469dd..1314244b6 100755 --- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php +++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php @@ -401,4 +401,70 @@ Sed facilisis pellentesque nisl, eu tincidunt erat scelerisque a. Nullam malesua $factory->buildCouponFromCode('XMAS'); } + + /** + * @covers Thelia\Coupon\CouponFactory::buildCouponFromModel + */ + public function testBuildCouponFromModel() + { + $stubFacade = $this->generateFacadeStub(); + + $stubContainer = $this->getMock('\Symfony\Component\DependencyInjection\Container'); + + $conditionFactory = new ConditionFactory($stubContainer); + $couponModel = $this->generateCouponModel($stubFacade, $conditionFactory); + $stubFacade->expects($this->any()) + ->method('findOneCouponByCode') + ->will($this->returnValue($couponModel)); + + $couponManager = new RemoveXAmount($stubFacade); + + + $condition1 = new MatchForTotalAmount($stubFacade); + $operators = array( + MatchForTotalAmount::INPUT1 => Operators::SUPERIOR, + MatchForTotalAmount::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmount::INPUT1 => 40.00, + MatchForTotalAmount::INPUT2 => 'EUR' + ); + $condition1->setValidatorsFromForm($operators, $values); + + $condition2 = new MatchForTotalAmount($stubFacade); + $operators = array( + MatchForTotalAmount::INPUT1 => Operators::INFERIOR, + MatchForTotalAmount::INPUT2 => Operators::EQUAL + ); + $values = array( + MatchForTotalAmount::INPUT1 => 400.00, + MatchForTotalAmount::INPUT2 => 'EUR' + ); + $condition2->setValidatorsFromForm($operators, $values); + + $conditions = new ConditionCollection(); + $conditions->add($condition1); + $conditions->add($condition2); + $stubConditionFactory = $this->getMockBuilder('\Thelia\Condition\ConditionFactory') + ->disableOriginalConstructor() + ->getMock(); + $stubConditionFactory->expects($this->any()) + ->method('unserializeConditionCollection') + ->will($this->returnValue($conditions)); + + + $stubContainer->expects($this->any()) + ->method('get') + ->will($this->onConsecutiveCalls($stubFacade, $couponManager, $stubConditionFactory)); + + $stubContainer->expects($this->any()) + ->method('has') + ->will($this->returnValue(true)); + + $factory = new CouponFactory($stubContainer); + $expected = $couponManager; + $actual = $factory->buildCouponFromModel($couponModel); + + $this->assertEquals($expected, $actual); + } } diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php index 10f19c8ab..9b992248c 100755 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php @@ -204,6 +204,22 @@ class RemoveXAmountTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip + */ + public function testGetInputName() + { + $inputName = 'Amount removed from the cart'; + $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); + + /** @var FacadeInterface $stubFacade */ + $coupon = new RemoveXAmount($stubFacade); + + $actual = $coupon->getInputName(); + $expected = $inputName; + $this->assertEquals($expected, $actual); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed. diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php index e2815a573..356ab7e5f 100755 --- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php +++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php @@ -160,6 +160,8 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals(254, $coupon->getMaxUsage()); $this->assertEquals($date, $coupon->getExpirationDate()); + $this->assertEquals(array(RemoveXPercent::INPUT_PERCENTAGE_NAME), $coupon->getExtendedInputs()); + $this->assertEquals(40.00, $coupon->exec()); } @@ -194,6 +196,22 @@ class RemoveXPercentTest extends \PHPUnit_Framework_TestCase $this->assertEquals($expected, $actual); } + /** + * @covers Thelia\Coupon\Type\RemoveXPercent::getToolTip + */ + public function testGetInputName() + { + $inputName = 'Percentage removed from the cart'; + $stubFacade = $this->generateFacadeStub(399, 'EUR', $inputName); + + /** @var FacadeInterface $stubFacade */ + $coupon = new RemoveXPercent($stubFacade); + + $actual = $coupon->getInputName(); + $expected = $inputName; + $this->assertEquals($expected, $actual); + } + /** * Tears down the fixture, for example, closes a network connection. * This method is called after a test is executed.