Coupon : Fix unit test

This commit is contained in:
gmorel
2013-12-29 15:45:42 +01:00
parent 9a22bdafa1
commit 2508ee3230
3 changed files with 100 additions and 0 deletions

View File

@@ -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);
}
}

View File

@@ -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.

View File

@@ -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.