WIP Coupon
Implementation CouponInterface 1st class : RemoveXAmount Implementation CouponRuleInterface 1st class : AvailableForTotalAmount
This commit is contained in:
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:06:16.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponFactoryTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:05:02.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -39,4 +69,55 @@ class CouponManagerTest extends \PHPUnit_Framework_TestCase
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\CouponManager::getDiscount
|
||||
* @todo Implement testGetDiscount().
|
||||
*/
|
||||
public function testGetDiscountAlwaysInferiorToPrice()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\CouponManager::getDiscount
|
||||
* @covers Thelia\Coupon\CouponManager::sortCoupons
|
||||
* @todo Implement testGetDiscount().
|
||||
*/
|
||||
public function testGetDiscountCouponNotCumulativeCancelOthers()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\CouponManager::getDiscount
|
||||
* @covers Thelia\Coupon\CouponManager::sortCoupons
|
||||
* @todo Implement testGetDiscount().
|
||||
*/
|
||||
public function testGetDiscountCouponCumulativeCumulatesWithOthers()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\CouponManager::isCouponRemovingPostage
|
||||
* @covers Thelia\Coupon\CouponManager::sortCoupons
|
||||
* @todo Implement testGetDiscount().
|
||||
*/
|
||||
public function testIsCouponRemovingPostage()
|
||||
{
|
||||
// Remove the following lines when you implement this test.
|
||||
$this->markTestIncomplete(
|
||||
'This test has not been implemented yet.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,41 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
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.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -40,7 +70,7 @@ class DateParamTest extends \PHPUnit_Framework_TestCase
|
||||
* @covers Thelia\Coupon\Parameter\DateParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEquelsDate()
|
||||
public function testEqualsDate()
|
||||
{
|
||||
$dateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-07-08");
|
||||
|
||||
128
core/lib/Thelia/Tests/Coupon/Parameter/IntegerParamTest.php
Normal file
128
core/lib/Thelia/Tests/Coupon/Parameter/IntegerParamTest.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Parameter\IntegerParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntegerParamTest 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\IntegerParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorInteger()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 41;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsInteger()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 42;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorInteger()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 43;
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\IntegerParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = '42';
|
||||
|
||||
$integerParam = new IntegerParam($intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$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,11 +1,41 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
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.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class IntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
193
core/lib/Thelia/Tests/Coupon/Parameter/PriceParamTest.php
Normal file
193
core/lib/Thelia/Tests/Coupon/Parameter/PriceParamTest.php
Normal file
@@ -0,0 +1,193 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Parameter\PriceParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class PriceParamTest 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\PriceParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorPrice()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 1.00;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorPrice2()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.49;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsPrice()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.50;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorPrice()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 42.51;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = '42.50';
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException2()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = -1;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException3()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 0;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\PriceParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException4()
|
||||
{
|
||||
$priceValidator = 42.50;
|
||||
$priceToValidate = 1;
|
||||
|
||||
$integerParam = new PriceParam($priceValidator, 'EUR');
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($priceToValidate);
|
||||
$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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
161
core/lib/Thelia/Tests/Coupon/Parameter/QuantityParamTest.php
Normal file
161
core/lib/Thelia/Tests/Coupon/Parameter/QuantityParamTest.php
Normal file
@@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use Thelia\Coupon\Parameter\QuantityParam;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class QuantityParamTest 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\QuantityParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorQuantity()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 0;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testInferiorQuantity2()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 41;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = 1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testEqualsQuantity()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 42;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
*
|
||||
*/
|
||||
public function testSuperiorQuantity()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = 43;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = '42';
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Thelia\Coupon\Parameter\QuantityParam::compareTo
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testInvalidArgumentException2()
|
||||
{
|
||||
$intValidator = 42;
|
||||
$intToValidate = -1;
|
||||
|
||||
$integerParam = new QuantityParam($intValidator);
|
||||
|
||||
$expected = 0;
|
||||
$actual = $integerParam->compareTo($intToValidate);
|
||||
$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,4 +1,26 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use InvalidArgumentException;
|
||||
@@ -6,7 +28,15 @@ 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.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,11 +1,41 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
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.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -302,18 +332,36 @@ class RepeatedIntervalParamTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testSuperiorDateRepeatEveryMonthFourTime()
|
||||
{
|
||||
$startDateValidator = new \DateTime("2012-10-08");
|
||||
$startDateValidator = new \DateTime("2012-07-08");
|
||||
$dateToValidate = new \DateTime("2012-10-19");
|
||||
$duration = 10;
|
||||
|
||||
$RepeatedIntervalParam = new RepeatedIntervalParam();
|
||||
$RepeatedIntervalParam->setFrom($startDateValidator);
|
||||
$RepeatedIntervalParam->setDurationInDays($duration);
|
||||
$RepeatedIntervalParam->repeatEveryMonth(1, 0);
|
||||
|
||||
$expected = -1;
|
||||
$actual = $RepeatedIntervalParam->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;
|
||||
$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);
|
||||
$RepeatedIntervalParam->compareTo($dateToValidate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Parameter\PriceParam;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Exception\InvalidRuleOperatorException;
|
||||
use Thelia\Exception\InvalidRuleValueException;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForTotalAmountTest 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 $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getCheckoutTotalPrice'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapter->expects($this->any())
|
||||
->method('getCheckoutTotalPrice')
|
||||
->will($this->returnValue(421.23));
|
||||
|
||||
return $stubTheliaAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
* @expectedException \Thelia\Exception\InvalidRuleOperatorException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputOperator()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => 'X',
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkBackOfficeInput
|
||||
* @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInputValue()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => 421
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
|
||||
*
|
||||
*/
|
||||
public function testValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
|
||||
* @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
*
|
||||
*/
|
||||
public function testInValidCheckoutInputValue()
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::checkCheckoutInput
|
||||
* @expectedException \Thelia\Exception\InvalidRuleValueException
|
||||
*
|
||||
*/
|
||||
public function testInValidCheckoutInputType()
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkCheckoutInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::EQUAL,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => $stubTheliaAdapter->getCheckoutTotalPrice()
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleEqual()
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::EQUAL,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.22
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.24
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->isMatching();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForTotalAmount::isMatching
|
||||
*
|
||||
*/
|
||||
public function testNotMatchingRuleSuperior()
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => Operators::SUPERIOR,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam(421.23, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
$validated = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => 421.23
|
||||
);
|
||||
$rule = new AvailableForTotalAmount($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()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,10 +1,40 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Rule\AvailableForXArticles;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@@ -19,70 +49,70 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
protected function generateValidCouponBaseAdapterMock()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->getMock(
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->getMock(
|
||||
'CouponBaseAdapter',
|
||||
array('getNbArticlesInTheCart'),
|
||||
array()
|
||||
);
|
||||
$stubTheliaAdapater->expects($this->any())
|
||||
$stubTheliaAdapter->expects($this->any())
|
||||
->method('getNbArticlesInTheCart')
|
||||
->will($this->returnValue(4));
|
||||
|
||||
return $stubTheliaAdapater;
|
||||
return $stubTheliaAdapter;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
*
|
||||
*/
|
||||
public function testValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeIntput
|
||||
* @covers Thelia\Coupon\Rule\AvailableForXArticles::checkBackOfficeInput
|
||||
*
|
||||
*/
|
||||
public function testInValidBackOfficeInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
$actual = $rule->checkBackOfficeIntput();
|
||||
$actual = $rule->checkBackOfficeInput();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -95,11 +125,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
@@ -114,11 +144,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testInValidCheckoutInput()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4.5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
@@ -126,7 +156,7 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array(-1);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
@@ -134,7 +164,7 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
|
||||
$validators = array('bad');
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
@@ -149,11 +179,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleEqual()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(4);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
@@ -168,11 +198,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testMatchingRuleSuperior()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(5);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = true;
|
||||
@@ -187,11 +217,11 @@ class AvailableForXArticlesTest extends \PHPUnit_Framework_TestCase
|
||||
*/
|
||||
public function testNotMatchingRule()
|
||||
{
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapater */
|
||||
$stubTheliaAdapater = $this->generateValidCouponBaseAdapterMock();
|
||||
/** @var CouponAdapterInterface $stubTheliaAdapter */
|
||||
$stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock();
|
||||
|
||||
$validators = array(3);
|
||||
$validated = array($stubTheliaAdapater->getNbArticlesInTheCart());
|
||||
$validated = array($stubTheliaAdapter->getNbArticlesInTheCart());
|
||||
$rule = new AvailableForXArticles($validators, $validated);
|
||||
|
||||
$expected = false;
|
||||
|
||||
403
core/lib/Thelia/Tests/Coupon/Rule/OperatorTest.php
Normal file
403
core/lib/Thelia/Tests/Coupon/Rule/OperatorTest.php
Normal file
@@ -0,0 +1,403 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use Thelia\Coupon\Parameter\QuantityParam;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
|
||||
/**
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class OperatorTest 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\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorValidBefore()
|
||||
{
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorInvalidEquals()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorInvalidAfter()
|
||||
{
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::INFERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorOrEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorOrEqualValidBefore()
|
||||
{
|
||||
// Given
|
||||
$a = 10;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInferiorOrEqualInValidAfter()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::INFERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorEqualInValidBefore()
|
||||
{
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorEqualInValidAfter()
|
||||
{
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::EQUAL;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorOrEqualValidEqual()
|
||||
{
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorOrEqualAfter()
|
||||
{
|
||||
// Given
|
||||
$a = 14;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorOrEqualInvalidBefore()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR_OR_EQUAL;
|
||||
$b = new QuantityParam(13);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorValidAfter()
|
||||
{
|
||||
// Given
|
||||
$a = 13;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorInvalidEqual()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorSuperiorInvalidBefore()
|
||||
{
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::SUPERIOR;
|
||||
$b = new QuantityParam(12);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorDifferentValid()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertTrue($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorDifferentInvalidEquals()
|
||||
{
|
||||
// Given
|
||||
$a = 11;
|
||||
$operator = Operators::DIFFERENT;
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\Rule\Operator::isValidAccordingToOperator
|
||||
*
|
||||
*/
|
||||
public function testOperatorInValid()
|
||||
{
|
||||
// Given
|
||||
$a = 12;
|
||||
$operator = 'X';
|
||||
$b = new QuantityParam(11);
|
||||
|
||||
// When
|
||||
$actual = Operators::isValidAccordingToOperator($a, $operator, $b);
|
||||
|
||||
// Then
|
||||
$this->assertFalse($actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
* This method is called after a test is executed.
|
||||
*/
|
||||
protected function tearDown()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:27:07.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RuleOrganizerTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXAmountForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,13 +1,45 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Thelia\Coupon\Parameter\PriceParam;
|
||||
use Thelia\Coupon\Rule\AvailableForTotalAmount;
|
||||
use Thelia\Coupon\Rule\Operators;
|
||||
use Thelia\Coupon\Type\RemoveXAmount;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXAmountTest extends PHPUnit_Framework_TestCase
|
||||
class RemoveXAmountTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
CONST VALID_COUPON_CODE = 'XMAS';
|
||||
@@ -159,6 +191,212 @@ class RemoveXAmountTest extends PHPUnit_Framework_TestCase
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::addRule
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
*
|
||||
*/
|
||||
public function testAddRuleValid()
|
||||
{
|
||||
// Given
|
||||
$rule1 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
100.23
|
||||
);
|
||||
$rule2 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
421.23
|
||||
);
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule1)
|
||||
->addRule($rule2);
|
||||
|
||||
// Then
|
||||
$expected = 2;
|
||||
$this->assertCount($expected, $coupon->getRules());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getRules
|
||||
*
|
||||
*/
|
||||
public function testSetRulesValid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
20.00
|
||||
);
|
||||
$rule1 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
100.23
|
||||
);
|
||||
$rule2 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
421.23
|
||||
);
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0)
|
||||
->setRules(array($rule1, $rule2));
|
||||
|
||||
|
||||
// Then
|
||||
$expected = 2;
|
||||
$this->assertCount($expected, $coupon->getRules());
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::setRules
|
||||
* @expectedException \Thelia\Exception\InvalidRuleException
|
||||
*
|
||||
*/
|
||||
public function testSetRulesInvalid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
20.00
|
||||
);
|
||||
$rule1 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
100.23
|
||||
);
|
||||
$rule2 = $this;
|
||||
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0)
|
||||
->setRules(array($rule1, $rule2));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR,
|
||||
400.00
|
||||
);
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0);
|
||||
|
||||
// Then
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getEffect();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountInferiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::INFERIOR_OR_EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0);
|
||||
|
||||
// Then
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getEffect();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0);
|
||||
|
||||
// Then
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getEffect();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorOrEqualTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR_OR_EQUAL,
|
||||
400.00
|
||||
);
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0);
|
||||
|
||||
// Then
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getEffect();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @covers Thelia\Coupon\type\RemoveXAmount::getEffect
|
||||
*
|
||||
*/
|
||||
public function testGetEffectIfTotalAmountSuperiorTo400Valid()
|
||||
{
|
||||
// Given
|
||||
$rule0 = $this->generateValideRuleAvailableForTotalAmountOperatorTo(
|
||||
Operators::SUPERIOR,
|
||||
400.00
|
||||
);
|
||||
$coupon = $this->generateValidNonCumulativeNonRemovingPostageCoupon();
|
||||
|
||||
// When
|
||||
$coupon->addRule($rule0);
|
||||
|
||||
// Then
|
||||
$expected = -30.00;
|
||||
$actual = $coupon->getEffect();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Tears down the fixture, for example, closes a network connection.
|
||||
@@ -168,4 +406,25 @@ class RemoveXAmountTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate valid rule AvailableForTotalAmount
|
||||
* according to given operator and amount
|
||||
*
|
||||
* @param string $operator Operators::CONST
|
||||
* @param float $amount Amount with 2 decimals
|
||||
*
|
||||
* @return AvailableForTotalAmount
|
||||
*/
|
||||
protected function generateValideRuleAvailableForTotalAmountOperatorTo($operator, $amount)
|
||||
{
|
||||
$validators = array(
|
||||
AvailableForTotalAmount::PARAM1_PRICE => array(
|
||||
AvailableForTotalAmount::OPERATOR => $operator,
|
||||
AvailableForTotalAmount::VALUE => new PriceParam($amount, 'EUR')
|
||||
)
|
||||
);
|
||||
|
||||
return new AvailableForTotalAmount($validators);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,38 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercenForCategoryYTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
@@ -1,11 +1,41 @@
|
||||
<?php
|
||||
/**********************************************************************************/
|
||||
/* */
|
||||
/* Thelia */
|
||||
/* */
|
||||
/* Copyright (c) OpenStudio */
|
||||
/* email : info@thelia.net */
|
||||
/* web : http://www.thelia.net */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it and/or modify */
|
||||
/* it under the terms of the GNU General Public License as published by */
|
||||
/* the Free Software Foundation; either version 3 of the License */
|
||||
/* */
|
||||
/* This program is distributed in the hope that it will be useful, */
|
||||
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
||||
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
||||
/* GNU General Public License for more details. */
|
||||
/* */
|
||||
/* You should have received a copy of the GNU General Public License */
|
||||
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
/* */
|
||||
/**********************************************************************************/
|
||||
|
||||
namespace Thelia\Coupon;
|
||||
|
||||
use PHPUnit_Framework_TestCase;
|
||||
use Thelia\Coupon\Type\RemoveXPercent;
|
||||
|
||||
/**
|
||||
* Generated by PHPUnit_SkeletonGenerator 1.2.1 on 2013-08-19 at 18:26:01.
|
||||
* Created by JetBrains PhpStorm.
|
||||
* Date: 8/19/13
|
||||
* Time: 3:24 PM
|
||||
*
|
||||
* Thrown when a Rule receive an invalid Parameter
|
||||
*
|
||||
* @package Coupon
|
||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||
*
|
||||
*/
|
||||
class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user