WIP Coupon
Implementation Comparable Parameters
This commit is contained in:
@@ -79,4 +79,11 @@ interface CouponAdapterInterface
|
|||||||
*/
|
*/
|
||||||
public function getCheckoutPostagePrice();
|
public function getCheckoutPostagePrice();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of Products in the Cart
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNbArticlesInTheCart();
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -84,4 +84,25 @@ class CouponBaseAdapter implements CouponAdapterInterface
|
|||||||
// TODO: Implement getCheckoutPostagePrice() method.
|
// TODO: Implement getCheckoutPostagePrice() method.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return Products total price
|
||||||
|
*
|
||||||
|
* @return float
|
||||||
|
*/
|
||||||
|
public function getCheckoutTotalPriceWithoutDiscountAndPostagePrice()
|
||||||
|
{
|
||||||
|
// TODO: Implement getCheckoutTotalPriceWithoutDiscountAndPostagePrice() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the number of Products in the Cart
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getNbArticlesInTheCart()
|
||||||
|
{
|
||||||
|
// TODO: Implement getNbArticlesInTheCart() method.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -21,18 +21,28 @@
|
|||||||
/* */
|
/* */
|
||||||
/*************************************************************************************/
|
/*************************************************************************************/
|
||||||
|
|
||||||
namespace Thelia\Coupon\Rule;
|
namespace Thelia\Coupon\Parameter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by JetBrains PhpStorm.
|
* Comparable interface that allows to compare two value objects to each other for similarity.
|
||||||
* Date: 8/19/13
|
|
||||||
* Time: 3:24 PM
|
|
||||||
*
|
|
||||||
* @package Coupon
|
|
||||||
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
|
||||||
*
|
*
|
||||||
|
* @author Benjamin Eberlei <kontakt@beberlei.de>
|
||||||
|
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
|
||||||
*/
|
*/
|
||||||
class AvailableForNbArticles extends CouponRuleAbstract
|
interface Comparable
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Compare the current object to the passed $other.
|
||||||
|
*
|
||||||
|
* Returns 0 if they are semantically equal, 1 if the other object
|
||||||
|
* is less than the current one, or -1 if its more than the current one.
|
||||||
|
*
|
||||||
|
* This method should not check for identity using ===, only for semantical equality for example
|
||||||
|
* when two different DateTime instances point to the exact same Date + TZ.
|
||||||
|
*
|
||||||
|
* @param mixed $other Object
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function compareTo($other);
|
||||||
}
|
}
|
||||||
95
core/lib/Thelia/Coupon/Parameter/DateParam.php
Normal file
95
core/lib/Thelia/Coupon/Parameter/DateParam.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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\Parameter;
|
||||||
|
|
||||||
|
use Thelia\Coupon\Parameter\Comparable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Represent a DateTime
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class DateParam implements Comparable
|
||||||
|
{
|
||||||
|
/** @var \DateTime Date */
|
||||||
|
protected $dateTime = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \DateTime $dateTime DateTime
|
||||||
|
*/
|
||||||
|
public function __construct(\DateTime $dateTime)
|
||||||
|
{
|
||||||
|
$this->dateTime = $dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get DateTime
|
||||||
|
*
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getDateTime()
|
||||||
|
{
|
||||||
|
return clone $this->dateTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the current object to the passed $other.
|
||||||
|
*
|
||||||
|
* Returns 0 if they are semantically equal, 1 if the other object
|
||||||
|
* is less than the current one, or -1 if its more than the current one.
|
||||||
|
*
|
||||||
|
* This method should not check for identity using ===, only for semantical equality for example
|
||||||
|
* when two different DateTime instances point to the exact same Date + TZ.
|
||||||
|
*
|
||||||
|
* @param mixed $other Object
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function compareTo($other)
|
||||||
|
{
|
||||||
|
if (!$other instanceof \DateTime) {
|
||||||
|
throw new \InvalidArgumentException('DateParam can compare only DateTime');
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = -1;
|
||||||
|
if ($this->dateTime == $other) {
|
||||||
|
$ret = 0;
|
||||||
|
} elseif ($this->dateTime > $other) {
|
||||||
|
$ret = 1;
|
||||||
|
} else {
|
||||||
|
$ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
107
core/lib/Thelia/Coupon/Parameter/IntervalParam.php
Normal file
107
core/lib/Thelia/Coupon/Parameter/IntervalParam.php
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?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\Parameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Represent an DateTime period
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class IntervalParam implements Comparable
|
||||||
|
{
|
||||||
|
/** @var \DatePeriod Date period */
|
||||||
|
protected $datePeriod = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \DateTime $start Start interval
|
||||||
|
* @param \DateInterval $interval Period
|
||||||
|
*/
|
||||||
|
public function __construct(\DateTime $start, \DateInterval $interval)
|
||||||
|
{
|
||||||
|
$this->datePeriod = new \DatePeriod($start, $interval, 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get DatePeriod
|
||||||
|
*
|
||||||
|
* @return \DatePeriod
|
||||||
|
*/
|
||||||
|
public function getDatePeriod()
|
||||||
|
{
|
||||||
|
return clone $this->datePeriod;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the current object to the passed $other.
|
||||||
|
*
|
||||||
|
* Returns 0 if they are semantically equal, 1 if the other object
|
||||||
|
* is less than the current one, or -1 if its more than the current one.
|
||||||
|
*
|
||||||
|
* This method should not check for identity using ===, only for semantical equality for example
|
||||||
|
* when two different DateTime instances point to the exact same Date + TZ.
|
||||||
|
*
|
||||||
|
* @param mixed $other Object
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function compareTo($other)
|
||||||
|
{
|
||||||
|
if (!$other instanceof \DateTime) {
|
||||||
|
throw new \InvalidArgumentException('IntervalParam can compare only DateTime');
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @var \DateTime Start Date */
|
||||||
|
$startDate = null;
|
||||||
|
/** @var \DateTime End Date */
|
||||||
|
$endDate = null;
|
||||||
|
|
||||||
|
foreach ($this->datePeriod as $key => $value) {
|
||||||
|
if ($key == 0) {
|
||||||
|
$startDate = $value;
|
||||||
|
}
|
||||||
|
if ($key == 1) {
|
||||||
|
$endDate = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = -1;
|
||||||
|
if ($startDate <= $other && $other <= $endDate) {
|
||||||
|
$ret = 0;
|
||||||
|
} elseif ($startDate > $other) {
|
||||||
|
$ret = 1;
|
||||||
|
} else {
|
||||||
|
$ret = -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
89
core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php
Normal file
89
core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
<?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\Parameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Represent A repeated Date across the time
|
||||||
|
* Ex :
|
||||||
|
* A date repeated every 1 months 5 times
|
||||||
|
* ---------*---*---*---*---*---*---------------------------> time
|
||||||
|
* 1 2 3 4 5 6
|
||||||
|
* 1 : $this->from Start date of the repetition
|
||||||
|
* *--- : $this->interval Duration of a whole cycle
|
||||||
|
* x6 : $this->recurrences How many cycle
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class RepeatedDateParam extends RepeatedParam
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->defaultConstructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the current object to the passed $other.
|
||||||
|
*
|
||||||
|
* Returns 0 if they are semantically equal, 1 if the other object
|
||||||
|
* is less than the current one, or -1 if its more than the current one.
|
||||||
|
*
|
||||||
|
* This method should not check for identity using ===, only for semantical equality for example
|
||||||
|
* when two different DateTime instances point to the exact same Date + TZ.
|
||||||
|
*
|
||||||
|
* @param mixed $other Object
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function compareTo($other)
|
||||||
|
{
|
||||||
|
if (!$other instanceof \DateTime) {
|
||||||
|
throw new \InvalidArgumentException('RepeatedDateParam can compare only DateTime');
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = -1;
|
||||||
|
$dates = array();
|
||||||
|
/** @var $value \DateTime */
|
||||||
|
foreach ($this->datePeriod as $value) {
|
||||||
|
$dates[$value->getTimestamp()] = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
if ($date == $other) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
}
|
||||||
122
core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php
Normal file
122
core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php
Normal file
@@ -0,0 +1,122 @@
|
|||||||
|
<?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\Parameter;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Represent A repeated DateInterval across the time
|
||||||
|
* Ex :
|
||||||
|
* A duration of 1 month repeated every 2 months 5 times
|
||||||
|
* ---------****----****----****----****----****----****-----------------> time
|
||||||
|
* 1 2 3 4 5 6
|
||||||
|
* 1 : $this->from Start date of the repetition
|
||||||
|
* ****---- : $this->interval Duration of a whole cycle
|
||||||
|
* x6 : $this->recurrences How many cycle
|
||||||
|
* **** : $this->durationInDays Duration of a period
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class RepeatedIntervalParam extends RepeatedParam
|
||||||
|
{
|
||||||
|
|
||||||
|
/** @var int duration of the param */
|
||||||
|
protected $durationInDays = 1;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get how many day a Param is lasting
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function getDurationInDays()
|
||||||
|
{
|
||||||
|
return $this->durationInDays;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set how many day a Param is lasting
|
||||||
|
*
|
||||||
|
* @param int $durationInDays How many day a Param is lasting
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDurationInDays($durationInDays = 1)
|
||||||
|
{
|
||||||
|
$this->durationInDays = $durationInDays;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
$this->defaultConstructor();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compare the current object to the passed $other.
|
||||||
|
*
|
||||||
|
* Returns 0 if they are semantically equal, 1 if the other object
|
||||||
|
* is less than the current one, or -1 if its more than the current one.
|
||||||
|
*
|
||||||
|
* This method should not check for identity using ===, only for semantical equality for example
|
||||||
|
* when two different DateTime instances point to the exact same Date + TZ.
|
||||||
|
*
|
||||||
|
* @param mixed $other Object
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public function compareTo($other)
|
||||||
|
{
|
||||||
|
if (!$other instanceof \DateTime) {
|
||||||
|
throw new \InvalidArgumentException('RepeatedIntervalParam can compare only DateTime');
|
||||||
|
}
|
||||||
|
|
||||||
|
$ret = -1;
|
||||||
|
$dates = array();
|
||||||
|
/** @var $value \DateTime */
|
||||||
|
foreach ($this->datePeriod as $value) {
|
||||||
|
$dates[$value->getTimestamp()]['startDate'] = $value;
|
||||||
|
$endDate = new \DateTime();
|
||||||
|
$dates[$value->getTimestamp()]['endDate'] = $endDate->setTimestamp(
|
||||||
|
$value->getTimestamp() + ($this->durationInDays * 60 *60 *24)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($dates as $date) {
|
||||||
|
if ($date['startDate'] <= $other && $other <= $date['endDate']) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
236
core/lib/Thelia/Coupon/Parameter/RepeatedParam.php
Normal file
236
core/lib/Thelia/Coupon/Parameter/RepeatedParam.php
Normal file
@@ -0,0 +1,236 @@
|
|||||||
|
<?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\Parameter;
|
||||||
|
|
||||||
|
use DateInterval;
|
||||||
|
use DatePeriod;
|
||||||
|
use DateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Allow to set the way a parameter can be repeated across the time
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
abstract class RepeatedParam implements Comparable
|
||||||
|
{
|
||||||
|
/** @var DateTime The start date of the period. */
|
||||||
|
protected $from = null;
|
||||||
|
|
||||||
|
/** @var DateInterval The interval between recurrences within the period. */
|
||||||
|
protected $interval = null;
|
||||||
|
|
||||||
|
/** @var int The number of recurrences. */
|
||||||
|
protected $recurrences = null;
|
||||||
|
|
||||||
|
/** @var DatePeriod dates recurring at regular intervals, over a given period */
|
||||||
|
protected $datePeriod = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate default repetition
|
||||||
|
* Every 1 week 100 times from now
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function defaultConstructor()
|
||||||
|
{
|
||||||
|
$this->from = new \DateTime();
|
||||||
|
$this->interval = new \DateInterval('P1W'); // 1 week
|
||||||
|
$this->recurrences = 100;
|
||||||
|
$this->generateDatePeriod();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate DatePeriod from class attributes
|
||||||
|
* Will repeat every DatePeriod
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
protected function generateDatePeriod()
|
||||||
|
{
|
||||||
|
$this->datePeriod = new DatePeriod(
|
||||||
|
$this->from,
|
||||||
|
$this->interval,
|
||||||
|
$this->recurrences
|
||||||
|
);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Object to be repeated every days
|
||||||
|
* Ex : $obj->repeatEveryDay() will be repeated every days indefinitely
|
||||||
|
* $obj->repeatEveryDay(10) will be repeated every 10 days indefinitely
|
||||||
|
* $obj->repeatEveryDay(10, 4) will be repeated every 10 days only 4 times
|
||||||
|
*
|
||||||
|
* @param int $frequency Frequency the object will be repeated
|
||||||
|
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function repeatEveryDay($frequency = 1, $nbRepetition = 0)
|
||||||
|
{
|
||||||
|
$this->_repeatEveryPeriod($period = 'D', $frequency, $nbRepetition);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Object to be repeated every week
|
||||||
|
* Ex : $obj->repeatEveryWeek() will be repeated every week indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10) will be repeated every 10 weeks (70days) indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10, 4) will be repeated every 10 weeks (70days) only 4 times
|
||||||
|
*
|
||||||
|
* @param int $frequency Frequency the object will be repeated
|
||||||
|
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function repeatEveryWeek($frequency = 1, $nbRepetition = null)
|
||||||
|
{
|
||||||
|
$this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Object to be repeated every month
|
||||||
|
* Ex : $obj->repeatEveryWeek() will be repeated every month indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10) will be repeated every 10 month (70days) indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10, 4) will be repeated every 10 month (70days) only 4 times
|
||||||
|
*
|
||||||
|
* @param int $frequency Frequency the object will be repeated
|
||||||
|
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function repeatEveryMonth($frequency = 1, $nbRepetition = null)
|
||||||
|
{
|
||||||
|
$this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Object to be repeated every year
|
||||||
|
* Ex : $obj->repeatEveryWeek() will be repeated every year indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10) will be repeated every 10 year indefinitely
|
||||||
|
* $obj->repeatEveryWeek(10, 4) will be repeated every 10 year only 4 times
|
||||||
|
*
|
||||||
|
* @param int $frequency Frequency the object will be repeated
|
||||||
|
* @param int $nbRepetition Time the object will be repeated
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function repeatEveryYear($frequency = 1, $nbRepetition = null)
|
||||||
|
{
|
||||||
|
$this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Object to be repeated every Period
|
||||||
|
* Ex : $obj->repeatEveryPeriod('D') will be repeated every day once
|
||||||
|
* $obj->repeatEveryPeriod('W', 10) will be repeated every 10 week once
|
||||||
|
* $obj->repeatEveryPeriod('M', 10, 4) will be repeated every 10 month only 4 times
|
||||||
|
*
|
||||||
|
* @param string $period Period Y|M||D|W
|
||||||
|
* @param int $frequency Frequency the object will be repeated
|
||||||
|
* @param int $nbRepetition Time the object will be repeated
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = null)
|
||||||
|
{
|
||||||
|
if (is_numeric($frequency) && $frequency > 0) {
|
||||||
|
$this->interval = new \DateInterval('P' . $frequency . $period);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (is_numeric($nbRepetition) && $nbRepetition > 0) {
|
||||||
|
$this->recurrences = $nbRepetition;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->generateDatePeriod();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set Start time
|
||||||
|
*
|
||||||
|
* @param \DateTime $from Start time
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setFrom($from)
|
||||||
|
{
|
||||||
|
$this->from = $from;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get Start time
|
||||||
|
*
|
||||||
|
* @return \DateTime
|
||||||
|
*/
|
||||||
|
public function getFrom()
|
||||||
|
{
|
||||||
|
return clone $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set DatePeriod
|
||||||
|
*
|
||||||
|
* @param DatePeriod $datePeriod DatePeriod
|
||||||
|
*
|
||||||
|
* @return $this
|
||||||
|
*/
|
||||||
|
public function setDatePeriod(DatePeriod $datePeriod)
|
||||||
|
{
|
||||||
|
$this->datePeriod = $datePeriod;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get date DatePeriod
|
||||||
|
*
|
||||||
|
* @return DatePeriod
|
||||||
|
*/
|
||||||
|
public function getDatePeriod()
|
||||||
|
{
|
||||||
|
return clone $this->datePeriod;
|
||||||
|
}
|
||||||
|
}
|
||||||
77
core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php
Normal file
77
core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
<?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\Rule;
|
||||||
|
|
||||||
|
use Thelia\Type\IntType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by JetBrains PhpStorm.
|
||||||
|
* Date: 8/19/13
|
||||||
|
* Time: 3:24 PM
|
||||||
|
*
|
||||||
|
* Check a Checkout against its Product number
|
||||||
|
*
|
||||||
|
* @package Coupon
|
||||||
|
* @author Guillaume MOREL <gmorel@openstudio.fr>
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class AvailableForXArticles extends CouponRuleAbstract
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @inheritdoc
|
||||||
|
*/
|
||||||
|
public function checkBackOfficeIntput()
|
||||||
|
{
|
||||||
|
$ret = false;
|
||||||
|
$validator = new IntType();
|
||||||
|
$firstParam = reset($this->validators);
|
||||||
|
if ($firstParam) {
|
||||||
|
$ret = $validator->isValid($firstParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkCheckoutInput()
|
||||||
|
{
|
||||||
|
$ret = false;
|
||||||
|
$validator = new IntType();
|
||||||
|
$firstParam = reset($this->validated);
|
||||||
|
if ($firstParam) {
|
||||||
|
$ret = $validator->isValid($firstParam);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isMatching()
|
||||||
|
{
|
||||||
|
if ($this->checkBackOfficeIntput() && $this->checkCheckoutInput()) {
|
||||||
|
$firstValidatorsParam = reset($this->validators);
|
||||||
|
$firstValidatedParam = reset($this->validated);
|
||||||
|
// if($firstValidatedParam >= $firstValidatedParam)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -36,6 +36,24 @@ namespace Thelia\Coupon\Rule;
|
|||||||
*/
|
*/
|
||||||
class CouponRuleAbstract implements CuponRuleInterface
|
class CouponRuleAbstract implements CuponRuleInterface
|
||||||
{
|
{
|
||||||
|
/** @var array Parameters validating $validated against */
|
||||||
|
protected $validators = array();
|
||||||
|
|
||||||
|
/** @var array Parameters to be validated */
|
||||||
|
protected $validated = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $validators Parameters validating $validated against
|
||||||
|
* @param array $validated Parameters to be validated
|
||||||
|
*/
|
||||||
|
public function __construct(array $validators, array $validated)
|
||||||
|
{
|
||||||
|
$this->validators = $validators;
|
||||||
|
$this->validated = $validated;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if backoffice inputs are relevant or not
|
* Check if backoffice inputs are relevant or not
|
||||||
*
|
*
|
||||||
|
|||||||
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