WIP Coupon

Implementation CouponInterface 1st class : RemoveXAmount
Implementation CouponRuleInterface 1st class : AvailableForTotalAmount
This commit is contained in:
gmorel
2013-08-21 20:03:03 +02:00
parent df08158cff
commit c02e286d09
56 changed files with 3919 additions and 854 deletions

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -84,6 +84,13 @@ interface CouponAdapterInterface
*
* @return int
*/
public function getNbArticlesInTheCart();
public function getNbArticlesInTheCart();
/**
* Return all Coupon given during the Checkout
*
* @return array Array of CouponInterface
*/
public function getCurrentCoupons();
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -104,5 +104,25 @@ class CouponBaseAdapter implements CouponAdapterInterface
// TODO: Implement getNbArticlesInTheCart() method.
}
/**
* Return all Coupon given during the Checkout
*
* @return array Array of CouponInterface
*/
public function getCurrentCoupons()
{
$couponFactory = new CouponFactory();
// @todo Get from Session
$couponCodes = array('XMAS', 'SPRINGBREAK');
$coupons = array();
foreach ($couponCodes as $couponCode) {
$coupons[] = $couponFactory->buildCouponFromCode($couponCode);
}
return $coupons;
}
}

View File

@@ -1,28 +1,30 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type\CouponInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
@@ -39,11 +41,11 @@ class CouponFactory
/**
* Build a CouponInterface from its database data
*
* @param int $couponId CouponInterface id
* @param int $couponCode CouponInterface id
*
* @return CouponInterface ready to be processed
*/
public function buildCouponFromId($couponId)
public function buildCouponFromCode($couponCode)
{
}
}

View File

@@ -1,28 +1,30 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type\CouponInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
@@ -42,13 +44,87 @@ class CouponManager
/** @var array CouponInterface to process*/
protected $coupons = array();
/**
* Constructor
* Gather Coupons from Adapter
* via $adapter->getCurrentCoupons();
*
* @param CouponAdapterInterface $adapter Provide necessary value from Thelia
*/
function __construct($adapter)
{
$this->adapter = $adapter;
$this->coupons = $this->adapter->getCurrentCoupons();
}
/**
* Get Discount for the given Coupons
*
* @api
* @return float checkout discount
*/
public function getDiscount()
{
return 10.00;
$discount = 0.00;
if (count($this->coupons) > 0) {
$couponsKept = $this->sortCoupons();
$isRemovingPostage = $this->isCouponRemovingPostage($couponsKept);
if ($isRemovingPostage) {
$postage = $this->adapter->getCheckoutPostagePrice();
$discount -= $postage;
}
// Just In Case test
if ($discount >= $this->adapter->getCheckoutTotalPrice()) {
$discount = 0.00;
}
}
return $discount;
}
/**
* Check if there is a Coupon removing Postage
*
* @param array $couponsKept Array of CouponInterface sorted
*
* @return bool
*/
protected function isCouponRemovingPostage(array $couponsKept)
{
$isRemovingPostage = false;
/** @var CouponInterface $coupon */
foreach ($couponsKept as $coupon) {
if ($coupon->isRemovingPostage()) {
$isRemovingPostage = true;
}
}
return $isRemovingPostage;
}
/**
* Sort Coupon to keep
* Coupon not cumulative cancels previous
*
* @return array Array of CouponInterface sorted
*/
protected function sortCoupons()
{
$couponsKept = array();
/** @var CouponInterface $coupon */
foreach ($this->coupons as $coupon) {
if (!$coupon->isCumulative()) {
$couponsKept = array();
$couponsKept[] = $coupon;
}
}
return $couponsKept;
}
}

View File

@@ -1,35 +1,36 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
/**
* Comparable interface that allows to compare two value objects to each other for similarity.
* Comparable interface
* Allows to compare two value objects to each other for similarity.
*
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Benjamin Eberlei <kontakt@beberlei.de>
* @author Guilherme Blanco <guilhermeblanco@hotmail.com>
*/
interface Comparable
interface ComparableInterface
{
/**
* Compare the current object to the passed $other.
@@ -37,7 +38,7 @@ interface Comparable
* 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
* This method should not check for identity using ===, only for semantically equality for example
* when two different DateTime instances point to the exact same Date + TZ.
*
* @param mixed $other Object

View File

@@ -1,29 +1,29 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
use Thelia\Coupon\Parameter\ComparableInterface;
/**
* Created by JetBrains PhpStorm.
@@ -36,7 +36,7 @@ use Thelia\Coupon\Parameter\Comparable;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class DateParam implements Comparable
class DateParam implements ComparableInterface
{
/** @var \DateTime Date */
protected $dateTime = null;
@@ -67,11 +67,12 @@ class DateParam implements Comparable
* 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
* This method should not check for identity using ===, only for semantically 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)

View File

@@ -0,0 +1,97 @@
<?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\ComparableInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Represent an Integer
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class IntegerParam implements ComparableInterface
{
/** @var int Integer to compare with */
protected $integer = 0;
/**
* Constructor
*
* @param int $integer Integer
*/
public function __construct($integer)
{
$this->integer = $integer;
}
/**
* Get integer
*
* @return int
*/
public function getInteger()
{
return $this->integer;
}
/**
* 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 semantically 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 (!is_integer($other)) {
throw new \InvalidArgumentException('IntegerParam can compare only int');
}
$ret = -1;
if ($this->integer == $other) {
$ret = 0;
} elseif ($this->integer > $other) {
$ret = 1;
} else {
$ret = -1;
}
return $ret;
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,7 +34,7 @@ namespace Thelia\Coupon\Parameter;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class IntervalParam implements Comparable
class IntervalParam implements ComparableInterface
{
/** @var \DatePeriod Date period */
protected $datePeriod = null;
@@ -66,11 +66,12 @@ class IntervalParam implements Comparable
* 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
* This method should not check for identity using ===, only for semantically 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)

View File

@@ -0,0 +1,116 @@
<?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\ComparableInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Represent a Price
* Positive value with currency
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class PriceParam implements ComparableInterface
{
/** @var float Positive Float to compare with */
protected $price = null;
/** @var string Currency Code ISO 4217 EUR|USD|GBP */
protected $currency = null;
/**
* Constructor
*
* @param float $price Positive float
* @param string $currency Currency Code ISO 4217 EUR|USD|GBP
*/
public function __construct($price, $currency)
{
$this->price = $price;
$this->currency = $currency;
}
/**
* Get currency code
*
* @return string
*/
public function getCurrency()
{
return $this->currency;
}
/**
* Get price
*
* @return float
*/
public function getPrice()
{
return $this->price;
}
/**
* 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 semantically 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 (!is_float($other)) {
throw new \InvalidArgumentException(
'PriceParam can compare only positive float'
);
}
$epsilon = 0.00001;
$ret = -1;
if (abs($this->price - $other) < $epsilon) {
$ret = 0;
} elseif ($this->price > $other) {
$ret = 1;
} else {
$ret = -1;
}
return $ret;
}
}

View File

@@ -0,0 +1,78 @@
<?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 Quantity
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class QuantityParam extends IntegerParam
{
/**
* Constructor
*
* @param int $integer Integer
*/
public function __construct($integer)
{
if ($integer < 0) {
$integer = 0;
}
$this->integer = $integer;
}
/**
* 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 semantically 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 (!is_integer($other) || $other < 0) {
throw new \InvalidArgumentException(
'IntegerParam can compare only positive int'
);
}
return parent::compareTo($other);
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -35,7 +35,8 @@ namespace Thelia\Coupon\Parameter;
* 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
* x5 : $this->recurrences How many repeated cycle, 1st excluded
* x6 : How many occurrence
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
@@ -57,7 +58,7 @@ class RepeatedDateParam extends RepeatedParam
* 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
* This method should not check for identity using ===, only for semantically equality for example
* when two different DateTime instances point to the exact same Date + TZ.
*
* @param mixed $other Object

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -35,7 +35,8 @@ namespace Thelia\Coupon\Parameter;
* 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
* x5 : $this->recurrences How many repeated cycle, 1st excluded
* x6 : How many occurrence
* **** : $this->durationInDays Duration of a period
*
* @package Coupon
@@ -86,11 +87,12 @@ class RepeatedIntervalParam extends RepeatedParam
* 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
* This method should not check for identity using ===, only for semantically 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)

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -38,7 +38,7 @@ use DateTime;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
abstract class RepeatedParam implements Comparable
abstract class RepeatedParam implements ComparableInterface
{
/** @var DateTime The start date of the period. */
protected $from = null;
@@ -46,7 +46,7 @@ abstract class RepeatedParam implements Comparable
/** @var DateInterval The interval between recurrences within the period. */
protected $interval = null;
/** @var int The number of recurrences. */
/** @var int Nb time the object will be repeated (1st occurrence excluded). */
protected $recurrences = null;
/** @var DatePeriod dates recurring at regular intervals, over a given period */
@@ -87,12 +87,13 @@ abstract class RepeatedParam implements Comparable
/**
* 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
* Ex : $obj->repeatEveryDay() will occur once
* $obj->repeatEveryDay(10) will occur once
* $obj->repeatEveryDay(10, 0) will occur once
* $obj->repeatEveryDay(10, 4) will occur every 10 days 5 times
*
* @param int $frequency Frequency the object will be repeated
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
* @param int $nbRepetition Time the object will be repeated
*
* @return $this
*/
@@ -105,16 +106,17 @@ abstract class RepeatedParam implements Comparable
/**
* 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
* Ex : $obj->repeatEveryWeek() will occur once
* $obj->repeatEveryWeek(10) will occur once
* $obj->repeatEveryWeek(10, 0) will occur once
* $obj->repeatEveryWeek(10, 4) will occur every 10 weeks (70days) 5 times
*
* @param int $frequency Frequency the object will be repeated
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
* @param int $nbRepetition Time the object will be repeated
*
* @return $this
*/
public function repeatEveryWeek($frequency = 1, $nbRepetition = null)
public function repeatEveryWeek($frequency = 1, $nbRepetition = 0)
{
$this->_repeatEveryPeriod($period = 'W', $frequency, $nbRepetition);
@@ -123,16 +125,17 @@ abstract class RepeatedParam implements Comparable
/**
* 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
* Ex : $obj->repeatEveryWeek() will occur once
* $obj->repeatEveryWeek(10) will occur once
* $obj->repeatEveryWeek(10, 0) will occur once
* $obj->repeatEveryWeek(10, 4) will occur every 10 month (70days) 5times
*
* @param int $frequency Frequency the object will be repeated
* @param int $nbRepetition Time the object will be repeated (0 = infinite)
* @param int $nbRepetition Time the object will be repeated
*
* @return $this
*/
public function repeatEveryMonth($frequency = 1, $nbRepetition = null)
public function repeatEveryMonth($frequency = 1, $nbRepetition = 0)
{
$this->_repeatEveryPeriod($period = 'M', $frequency, $nbRepetition);
@@ -141,16 +144,17 @@ abstract class RepeatedParam implements Comparable
/**
* 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
* Ex : $obj->repeatEveryWeek() will occur once
* $obj->repeatEveryWeek(10) will occur once
* $obj->repeatEveryWeek(10, 0) will occur once
* $obj->repeatEveryWeek(10, 4) will occur every 10 year 5 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)
public function repeatEveryYear($frequency = 1, $nbRepetition = 0)
{
$this->_repeatEveryPeriod($period = 'Y', $frequency, $nbRepetition);
@@ -159,9 +163,10 @@ abstract class RepeatedParam implements Comparable
/**
* 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
* Ex : $obj->repeatEveryPeriod('D') will occur once
* $obj->repeatEveryPeriod('W', 10) will occur once
* $obj->repeatEveryPeriod('W', 10, 0) will occur once
* $obj->repeatEveryPeriod('M', 10, 4) will occur every 10 month 5 times
*
* @param string $period Period Y|M||D|W
* @param int $frequency Frequency the object will be repeated
@@ -169,13 +174,13 @@ abstract class RepeatedParam implements Comparable
*
* @return $this
*/
private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = null)
private function _repeatEveryPeriod($period, $frequency = 1, $nbRepetition = 0)
{
if (is_numeric($frequency) && $frequency > 0) {
$this->interval = new \DateInterval('P' . $frequency . $period);
}
if (is_numeric($nbRepetition) && $nbRepetition > 0) {
if (is_numeric($nbRepetition) && $nbRepetition >= 0) {
$this->recurrences = $nbRepetition;
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForDate extends AvailableForPeriod
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForLocationX extends CouponRuleAbstract
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForPeriod extends CouponRuleAbstract
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForRepeatedDate extends AvailableForDate
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForRepeatedPeriod extends AvailableForPeriod
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,38 +1,171 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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 Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Coupon\Parameter\PriceParam;
use Thelia\Exception\InvalidRuleOperatorException;
use Thelia\Exception\InvalidRuleValueException;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Rule AvailableForTotalAmount
* Check if a Checkout total amount match criteria
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class AvailableForTotalAmount extends CouponRuleAbstract
{
/** Rule 1st parameter : price */
CONST PARAM1_PRICE = 'price';
/** @var array Available Operators (Operators::CONST) */
protected $availableOperators = array(
Operators::INFERIOR,
Operators::EQUAL,
Operators::SUPERIOR,
);
/** @var PriceParam Price Validator */
protected $priceValidator = null;
/**
* Constructor
*
* @param array $validators Parameters validating $paramsToValidate against
* @param array $validated Parameters to be paramsToValidate
*/
public function __construct(array $validators, array $validated = null)
{
parent::__construct($validators, $validated);
$this->priceValidator = $validators[self::PARAM1_PRICE][self::VALUE];
}
/**
* Check if backoffice inputs are relevant or not
*
* @throws InvalidRuleOperatorException if Operator is not allowed
* @throws InvalidRuleValueException if Value is not allowed
* @return bool
*/
public function checkBackOfficeInput()
{
if (!isset($this->validators)
|| empty($this->validators)
||!isset($this->validators[self::PARAM1_PRICE])
||!isset($this->validators[self::PARAM1_PRICE][self::VALUE])
||!$this->validators[self::PARAM1_PRICE][self::VALUE] instanceof PriceParam
) {
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
}
$this->checkBackOfficeInputsOperators();
/** @var PriceParam $price */
$price = $this->validators[self::PARAM1_PRICE][self::VALUE];
return $this->isPriceValid($price->getPrice());
}
/**
* Check if Checkout inputs are relevant or not
*
* @throws InvalidRuleValueException if Value is not allowed
* @return bool
*/
public function checkCheckoutInput()
{
if (!isset($this->paramsToValidate)
|| empty($this->paramsToValidate)
||!isset($this->paramsToValidate[self::PARAM1_PRICE])
) {
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
}
$quantity = $this->paramsToValidate[self::PARAM1_PRICE];
return $this->isPriceValid($quantity);
}
/**
* Check if a price is valid
*
* @param int $price Price to check
*
* @throws InvalidRuleValueException if Value is not allowed
* @return bool
*/
protected function isPriceValid($price)
{
$priceValidator = $this->priceValidator;
try {
$priceValidator->compareTo($price);
} catch(\InvalidArgumentException $e) {
throw new InvalidRuleValueException(get_class(), self::PARAM1_PRICE);
}
return true;
}
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
$adapter->getRule($this);
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
$this->paramsToValidate = array(
self::PARAM1_PRICE => $adapter->getCheckoutTotalPrice()
);
return $this;
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -34,5 +34,31 @@ namespace Thelia\Coupon\Rule;
*/
class AvailableForTotalAmountForCategoryY extends AvailableForTotalAmount
{
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
@@ -39,39 +39,31 @@ use Thelia\Type\IntType;
class AvailableForXArticles extends CouponRuleAbstract
{
/**
* @inheritdoc
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
public function checkBackOfficeIntput()
protected function setValidators(CouponAdapterInterface $adapter)
{
$ret = false;
$validator = new IntType();
$firstParam = reset($this->validators);
if ($firstParam) {
$ret = $validator->isValid($firstParam);
}
return $ret;
parent::setValidators($adapter); // TODO: Change the autogenerated stub
}
public function checkCheckoutInput()
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
$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)
}
parent::setParametersToValidate($adapter); // TODO: Change the autogenerated stub
}
}

View File

@@ -1,28 +1,33 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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 Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Coupon\Parameter\ComparableInterface;
use Thelia\Exception\InvalidRuleOperatorException;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
@@ -34,54 +39,124 @@ namespace Thelia\Coupon\Rule;
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class CouponRuleAbstract implements CuponRuleInterface
abstract class CouponRuleAbstract implements CouponRuleInterface
{
/** @var array Parameters validating $validated against */
/** Operator key in $validators */
CONST OPERATOR = 'operator';
/** Value key in $validators */
CONST VALUE = 'value';
/** @var array Available Operators (Operators::CONST) */
protected $availableOperators = array();
/** @var array Parameters validating parameters against */
protected $validators = array();
/** @var array Parameters to be validated */
protected $validated = array();
protected $paramsToValidate = array();
/**
* Constructor
* Ex:
* Param 1 :
* $validators['price']['operator'] = Operators::INFERIOR
* ['value'] = new IntegerParam(10)
*
* @param array $validators Parameters validating $validated against
* @param array $validated Parameters to be validated
* Param 2 :
* $paramsToValidate['price'] = 9
*
* @param array $validators Parameters validating $paramsToValidate against
* @param array $validated Parameters to be paramsToValidate
*/
public function __construct(array $validators, array $validated)
public function __construct(array $validators, array $validated = null)
{
$this->validators = $validators;
$this->validated = $validated;
$this->paramsToValidate = $validated;
}
/**
* Check if backoffice inputs are relevant or not
*
* @return bool
*/
public function checkBackOfficeIntput()
{
// TODO: Implement checkBackOfficeIntput() method.
}
/**
* Check if Checkout inputs are relevant or not
*
* @return bool
*/
public function checkCheckoutInput()
{
// TODO: Implement checkCheckoutInput() method.
}
/**
* Check if the current Checkout matchs this condition
* Check if the current Checkout matches this condition
*
* @return bool
*/
public function isMatching()
{
// TODO: Implement isMatching() method.
$this->checkBackOfficeInput();
$this->checkCheckoutInput();
$isMatching = true;
foreach ($this->validators as $param => $validator) {
$a = $this->paramsToValidate[$param];
$operator = $validator[self::OPERATOR];
/** @var ComparableInterface $b */
$b = $validator[self::VALUE];
if (!Operators::isValidAccordingToOperator($a, $operator, $b)) {
$isMatching = false;
}
}
return $isMatching;
}
/**
* Return all available Operators for this Rule
*
* @return array Operators::CONST
*/
public function getAvailableOperators()
{
return $this->availableOperators;
}
/**
* Check if Operators set for this Rule in the BackOffice are legit
*
* @throws InvalidRuleOperatorException if Operator is not allowed
* @return bool
*/
protected function checkBackOfficeInputsOperators()
{
foreach ($this->validators as $key => $param) {
if (!isset($param[self::OPERATOR])
||!in_array($param[self::OPERATOR], $this->availableOperators)
) {
throw new InvalidRuleOperatorException(get_class(), $key);
}
}
return true;
}
/**
* Generate current Rule validator from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setValidators(CouponAdapterInterface $adapter)
{
throw new NotImplementedException(
'CouponRuleInterface::setValidators needs to be implemented'
);
}
/**
* Generate current Rule param to be validated from adapter
*
* @param CouponAdapterInterface $adapter allowing to gather
* all necessary Thelia variables
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return $this
*/
protected function setParametersToValidate(CouponAdapterInterface $adapter)
{
throw new NotImplementedException(
'CouponRuleInterface::setValidators needs to be implemented'
);
}
}

View File

@@ -0,0 +1,91 @@
<?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\Coupon\CouponAdapterInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Represents a condition of whether the Rule is applied or not
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
interface CouponRuleInterface
{
/**
* Check if backoffice inputs are relevant or not
*
* @return bool
*/
public function checkBackOfficeInput();
/**
* Check if Checkout inputs are relevant or not
*
* @return bool
*/
public function checkCheckoutInput();
/**
* Check if the current Checkout matches this condition
*
* @return bool
*/
public function isMatching();
/**
* Return all available Operators for this Rule
*
* @return array Operators::CONST
*/
public function getAvailableOperators();
// /**
// * Generate current Rule validator from adapter
// * Ex :
// * $validator = array(
// *
// * @param CouponAdapterInterface $adapter allowing to gather
// * all necessary Thelia variables
// *
// * @return array Validators : array of ComparableInterface
// */
// public function getValidators(CouponAdapterInterface $adapter);
//
// /**
// * Retrieve all param to validate from adapter
// *
// * @param CouponAdapterInterface $adapter allowing to gather
// * all necessary Thelia variables
// *
// * @return array Validators : array of ComparableInterface
// */
// public function getParamToValidate(CouponAdapterInterface $adapter);
}

View File

@@ -0,0 +1,109 @@
<?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\Coupon\Parameter\ComparableInterface;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Represent available Operations in rule checking
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
abstract class Operators
{
/** Param1 is inferior to Param2 */
CONST INFERIOR = '<';
/** Param1 is inferior to Param2 */
CONST INFERIOR_OR_EQUAL = '<=';
/** Param1 is equal to Param2 */
CONST EQUAL = '==';
/** Param1 is superior to Param2 */
CONST SUPERIOR_OR_EQUAL = '>=';
/** Param1 is superior to Param2 */
CONST SUPERIOR = '>';
/** Param1 is different to Param2 */
CONST DIFFERENT = '!=';
/**
* Check if a parameter is valid against a ComparableInterface from its operator
*
* @param mixed $a Parameter to validate
* @param string $operator Operator to validate against
* @param ComparableInterface $b Comparable to validate against
*
* @return bool
*/
public static function isValidAccordingToOperator($a, $operator, ComparableInterface $b)
{
$ret = false;
try {
$comparison = $b->compareTo($a);
} catch (\Exception $e) {
return false;
}
switch ($operator) {
case self::INFERIOR:
if ($comparison == 1) {
return true;
}
break;
case self::INFERIOR_OR_EQUAL:
if ($comparison == 1 || $comparison == 0) {
return true;
}
break;
case self::EQUAL:
if ($comparison == 0) {
return true;
}
break;
case self::SUPERIOR_OR_EQUAL:
if ($comparison == -1 || $comparison == 0) {
return true;
}
break;
case self::SUPERIOR:
if ($comparison == -1) {
return true;
}
break;
case self::DIFFERENT:
if ($comparison != 0) {
return true;
}
break;
default:
}
return $ret;
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;

View File

@@ -1,29 +1,33 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
namespace Thelia\Coupon\Type;
use Symfony\Component\Intl\Exception\NotImplementedException;
use Thelia\Coupon\CouponAdapterInterface;
use Thelia\Coupon\Rule\CouponRuleInterface;
use Thelia\Coupon\RuleOrganizerInterface;
use Thelia\Exception\InvalidRuleException;
/**
* Created by JetBrains PhpStorm.
@@ -44,6 +48,9 @@ abstract class CouponAbstract implements CouponInterface
/** @var RuleOrganizerInterface */
protected $organizer = null;
/** @var array Array of CouponRuleInterface */
protected $rules = null;
/** @var string Coupon code (ex: XMAS) */
protected $code = null;
@@ -62,6 +69,9 @@ abstract class CouponAbstract implements CouponInterface
/** @var bool if Coupon is removing postage */
protected $isRemovingPostage = false;
/** @var float Amount that will be removed from the Checkout (Coupon Effect) */
protected $amount = 0;
/**
* Set Adapter containing all relevant data
*
@@ -154,15 +164,86 @@ abstract class CouponAbstract implements CouponInterface
/**
* Return effects generated by the coupon
*
* @throws \Symfony\Component\Intl\Exception\NotImplementedException
* @return \Closure
* A negative value
* @
* @return float Amount removed from the Total Checkout
*/
public function getEffect()
{
throw new NotImplementedException(
'Abstract method to implement (CouponAbstract->getEffect)'
);
return -$this->amount;
}
/**
* Return condition to validate the Coupon or not
*
* @return array An array of CouponRuleInterface
*/
public function getRules()
{
$arrayObject = new \ArrayObject($this->rules);
return $arrayObject->getArrayCopy();
}
/**
* Add a Rule to the Coupon
*
* @param CouponRuleInterface $rule Condition needed to match
* in order to get the Coupon effect
*
* @return $this
*/
public function addRule(CouponRuleInterface $rule)
{
$this->rules[] = $rule;
return $this;
}
/**
* Replace the existing Rules by those given in parameter
* If one Rule is badly implemented, no Rule will be added
*
* @param array $rules CouponRuleInterface to add
*
* @return $this
* @throws \Thelia\Exception\InvalidRuleException
*/
public function setRules(array $rules)
{
foreach ($rules as $rule) {
if (!$rule instanceof CouponRuleInterface) {
throw new InvalidRuleException(get_class());
}
}
$this->rules = array();
foreach ($rules as $rule) {
$this->addRule($rule);
}
return $this;
}
/**
* Check if the current Coupon is matching its conditions (Rules)
* Thelia variables are given by the CouponAdapterInterface
* In $this->adapter
*
* @return bool
*/
public function isMatching()
{
$isMatching = true;
/** @var CouponRuleInterface $rule */
foreach ($this->rules as $rule) {
if (!$rule->isMatching()) {
$isMatching = false;
}
}
return $isMatching;
}
}

View File

@@ -1,27 +1,27 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
namespace Thelia\Coupon\Type;
/**
* Created by JetBrains PhpStorm.
@@ -82,8 +82,31 @@ interface CouponInterface
/**
* Return effects generated by the coupon
* A negative value
*
* @return \Closure
* Effects could also affect something else than the final Checkout price
* CouponAdapter could be use to directly pass a Session value
* some would wish to modify
* Hence affecting a wide variety of Thelia elements
* Ex : $this->adapter->getTheliaInternalValue
*
* @return float Amount removed from the Total Checkout
*/
public function getEffect();
}
/**
* Return condition to validate the Coupon or not
*
* @return array An array of CouponRuleInterface
*/
public function getRules();
/**
* Check if the current Coupon is matching its conditions (Rules)
* Thelia variables are given by the CouponAdapterInterface
* In $this->adapter
*
* @return bool
*/
public function isMatching();
}

View File

@@ -1,29 +1,29 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;
use Thelia\Coupon\CouponAbstract;
use Thelia\Coupon\Type\CouponAbstract;
/**
* Created by JetBrains PhpStorm.
@@ -38,9 +38,6 @@ use Thelia\Coupon\CouponAbstract;
*/
class RemoveXAmount extends CouponAbstract
{
protected $amount = 0;
/**
* Constructor
*
@@ -65,16 +62,4 @@ class RemoveXAmount extends CouponAbstract
$this->amount = $amount;
}
/**
* Return effects generated by the coupon
* A negative value
*
* @return float
*/
public function getEffect()
{
return -$this->amount;
}
}
}

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;

View File

@@ -1,29 +1,29 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;
use Thelia\Coupon\CouponAbstract;
use Thelia\Coupon\Type\CouponAbstract;
use Thelia\Exception\MissingAdapterException;
/**

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;

View File

@@ -1,25 +1,25 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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\Type;

View File

@@ -1,60 +1,54 @@
<?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/>. */
/* */
/*************************************************************************************/
/**********************************************************************************/
/* */
/* 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;
namespace Thelia\Exception;
use Thelia\Log\Tlog;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Represents a condition of whether the Rule is applied or not
* Thrown when a Rule is badly implemented
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
interface CuponRuleInterface
class InvalidRuleException extends \RuntimeException
{
/**
* Check if backoffice inputs are relevant or not
* InvalidRuleOperatorException thrown when a Rule is badly implemented
*
* @return bool
* @param string $className Class name
* @param string $parameter array key parameter
*/
public function checkBackOfficeIntput();
public function __construct($className) {
/**
* Check if Checkout inputs are relevant or not
*
* @return bool
*/
public function checkCheckoutInput();
$message = 'Invalid Rule given to ' . $className;
Tlog::getInstance()->addError($message);
/**
* Check if the current Checkout matchs this condition
*
* @return bool
*/
public function isMatching();
}
parent::__construct($message);
}
}

View File

@@ -0,0 +1,54 @@
<?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\Exception;
use Thelia\Log\Tlog;
/**
* Created by JetBrains PhpStorm.
* Date: 8/19/13
* Time: 3:24 PM
*
* Thrown when a Rule receive an invalid Operator
*
* @package Coupon
* @author Guillaume MOREL <gmorel@openstudio.fr>
*
*/
class InvalidRuleOperatorException extends \RuntimeException
{
/**
* InvalidRuleOperatorException thrown when a Rule is given a bad Operator
*
* @param string $className Class name
* @param string $parameter array key parameter
*/
public function __construct($className, $parameter) {
$message = 'Invalid Operator for Rule ' . $className . ' on parameter ' . $parameter;
Tlog::getInstance()->addError($message);
parent::__construct($message);
}
}

View File

@@ -0,0 +1,54 @@
<?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\Exception;
use Thelia\Log\Tlog;
/**
* 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 InvalidRuleValueException extends \RuntimeException
{
/**
* InvalidRuleValueException thrown when a Rule is given a bad Parameter
*
* @param string $className Class name
* @param string $parameter array key parameter
*/
public function __construct($className, $parameter) {
$message = 'Invalid Parameter for Rule ' . $className . ' on parameter ' . $parameter;
Tlog::getInstance()->addError($message);
parent::__construct($message);
}
}

View File

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

View File

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

View File

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

View File

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

View 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()
{
}
}

View File

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

View 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()
{
}
}

View 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()
{
}
}

View File

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

View File

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

View File

@@ -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()
{
}
}

View File

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

View 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()
{
}
}

View File

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

View File

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

View File

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

View File

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

View File

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