WIP Coupon
Implementation Comparable Parameters
This commit is contained in:
96
core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php
Normal file
96
core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php
Normal file
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Parameter\DateParam;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEquelsDate()
|
||||
{
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorDate()
|
||||
{
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-09");
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$dateParam = new DateParam($dateValidator);
|
||||
|
||||
$dateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
121
core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php
Normal file
121
core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php
Normal file
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Parameter\IntervalParam;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDate()
|
||||
{
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
echo '1 ' . date_format($dateValidatorStart, 'g:ia \o\n l jS F Y') . "\n";
|
||||
echo '2 ' . date_format($dateToValidate, 'g:ia \o\n l jS F Y') . "\n";
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDate2()
|
||||
{
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorDate()
|
||||
{
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = new \DateTime("2012-08-09");
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $dateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$dateValidatorStart = new \DateTime("2012-07-08");
|
||||
$dateValidatorInterval = new \DateInterval("P1M"); //1month
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$dateParam = new IntervalParam($dateValidatorStart, $dateValidatorInterval);
|
||||
|
||||
$dateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
238
core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php
Normal file
238
core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php
Normal file
@@ -0,0 +1,238 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\Parameter\RepeatedDateParam;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
|
||||
$expected = -1;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthTenTimesThirdPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-09-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(1, 10);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthTenTimesTensPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-05-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(1, 10);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryFourMonthTwoTimesSecondPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-11-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryFourMonthTwoTimesLastPeriod()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-03-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryFourMonthTwoTimes1()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryFourMonthTwoTimes2()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-12-08");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedDateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorDateRepeatEveryFourMonthTwoTimes()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2013-03-09");
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $repeatedDateParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = 1377012588;
|
||||
|
||||
$repeatedDateParam = new RepeatedDateParam();
|
||||
$repeatedDateParam->setFrom($startDateValidator);
|
||||
$repeatedDateParam->repeatEveryMonth(4, 2);
|
||||
|
||||
$repeatedDateParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,327 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Symfony\Component\Intl\Exception\NotImplementedException;
|
||||
use Thelia\Coupon\Parameter\RepeatedIntervalParam;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorDate()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-07");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodBegining()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodMiddle()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeFirstPeriodEnding()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodBegining()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodMiddle()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthOneTimeSecondPeriodEnding()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-08-08");
|
||||
$dateToValidate = new \DateTime("2012-08-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth();
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodBegining()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-08");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodMiddle()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-13");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsDateRepeatEveryMonthFourTimeLastPeriodEnding()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-18");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheBegining()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-07-19");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheMiddle()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-08-01");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testNotEqualsDateRepeatEveryMonthFourTimeInTheEnd()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-08-07");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\RepeatedIntervalParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorDateRepeatEveryMonthFourTime()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$dateToValidate = new \DateTime("2012-10-19");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 4);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class RemoveXAmountForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
211
core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php
Normal file
211
core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?php
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Rule\AvailableForXArticles;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
*/
|
||||
class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Sets up the fixture, for example, opens a network connection.
|
||||
* This method is called before a test is executed.
|
||||
*/
|
||||
protected function setUp()
|
||||
{
|
||||
}
|
||||
|
||||
protected function generateValidCouponBaseAdapterMock()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getNbArticlesInTheCart'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapater->expects($this->any())
|
||||
->method('getNbArticlesInTheCart')
|
||||
->will($this->returnValue(4));
|
||||
|
||||
return $stubTheliaAdapater;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
|
||||
*
|
||||
*/
|
||||
public function testValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkCheckoutInput
|
||||
*
|
||||
*/
|
||||
public function testInValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRule()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(3);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user