diff --git a/core/lib/Thelia/Coupon/CouponAdapterInterface.php b/core/lib/Thelia/Coupon/CouponAdapterInterface.php
index 06e3a3ca7..0a900183e 100644
--- a/core/lib/Thelia/Coupon/CouponAdapterInterface.php
+++ b/core/lib/Thelia/Coupon/CouponAdapterInterface.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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();
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/CouponBaseAdapter.php b/core/lib/Thelia/Coupon/CouponBaseAdapter.php
index 6908b3317..a79ac5407 100644
--- a/core/lib/Thelia/Coupon/CouponBaseAdapter.php
+++ b/core/lib/Thelia/Coupon/CouponBaseAdapter.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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;
+ }
+
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/CouponFactory.php b/core/lib/Thelia/Coupon/CouponFactory.php
index f999eabff..7f74c7f21 100644
--- a/core/lib/Thelia/Coupon/CouponFactory.php
+++ b/core/lib/Thelia/Coupon/CouponFactory.php
@@ -1,28 +1,30 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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)
{
}
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/CouponManager.php b/core/lib/Thelia/Coupon/CouponManager.php
index 958f65db5..765068c96 100644
--- a/core/lib/Thelia/Coupon/CouponManager.php
+++ b/core/lib/Thelia/Coupon/CouponManager.php
@@ -1,28 +1,30 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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;
}
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Parameter/Comparable.php b/core/lib/Thelia/Coupon/Parameter/ComparableInterface.php
similarity index 70%
rename from core/lib/Thelia/Coupon/Parameter/Comparable.php
rename to core/lib/Thelia/Coupon/Parameter/ComparableInterface.php
index 37a7faeab..26bb3ca30 100644
--- a/core/lib/Thelia/Coupon/Parameter/Comparable.php
+++ b/core/lib/Thelia/Coupon/Parameter/ComparableInterface.php
@@ -1,35 +1,36 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
- * @author Guilherme Blanco
+ * @author Benjamin Eberlei
+ * @author Guilherme Blanco
*/
-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
diff --git a/core/lib/Thelia/Coupon/Parameter/DateParam.php b/core/lib/Thelia/Coupon/Parameter/DateParam.php
index 29dab530d..fa4ea7d97 100644
--- a/core/lib/Thelia/Coupon/Parameter/DateParam.php
+++ b/core/lib/Thelia/Coupon/Parameter/DateParam.php
@@ -1,29 +1,29 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
*
*/
-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)
diff --git a/core/lib/Thelia/Coupon/Parameter/IntegerParam.php b/core/lib/Thelia/Coupon/Parameter/IntegerParam.php
new file mode 100644
index 000000000..c4d6ca5e7
--- /dev/null
+++ b/core/lib/Thelia/Coupon/Parameter/IntegerParam.php
@@ -0,0 +1,97 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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;
+ }
+
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Parameter/IntervalParam.php b/core/lib/Thelia/Coupon/Parameter/IntervalParam.php
index 656cf69ca..88444fe36 100644
--- a/core/lib/Thelia/Coupon/Parameter/IntervalParam.php
+++ b/core/lib/Thelia/Coupon/Parameter/IntervalParam.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Parameter;
@@ -34,7 +34,7 @@ namespace Thelia\Coupon\Parameter;
* @author Guillaume MOREL
*
*/
-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)
diff --git a/core/lib/Thelia/Coupon/Parameter/PriceParam.php b/core/lib/Thelia/Coupon/Parameter/PriceParam.php
new file mode 100644
index 000000000..7d74101a0
--- /dev/null
+++ b/core/lib/Thelia/Coupon/Parameter/PriceParam.php
@@ -0,0 +1,116 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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;
+ }
+
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Parameter/QuantityParam.php b/core/lib/Thelia/Coupon/Parameter/QuantityParam.php
new file mode 100644
index 000000000..e4dffb221
--- /dev/null
+++ b/core/lib/Thelia/Coupon/Parameter/QuantityParam.php
@@ -0,0 +1,78 @@
+. */
+/* */
+/**********************************************************************************/
+
+namespace Thelia\Coupon\Parameter;
+
+/**
+ * Created by JetBrains PhpStorm.
+ * Date: 8/19/13
+ * Time: 3:24 PM
+ *
+ * Represent a Quantity
+ *
+ * @package Coupon
+ * @author Guillaume MOREL
+ *
+ */
+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);
+ }
+
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php
index 150f632b8..dc99a0d26 100644
--- a/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php
+++ b/core/lib/Thelia/Coupon/Parameter/RepeatedDateParam.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
@@ -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
diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php
index 4bbbd8569..4d857716f 100644
--- a/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php
+++ b/core/lib/Thelia/Coupon/Parameter/RepeatedIntervalParam.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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)
diff --git a/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php b/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php
index ed5dcbf03..1d9dd4905 100644
--- a/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php
+++ b/core/lib/Thelia/Coupon/Parameter/RepeatedParam.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Parameter;
@@ -38,7 +38,7 @@ use DateTime;
* @author Guillaume MOREL
*
*/
-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;
}
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForDate.php b/core/lib/Thelia/Coupon/Rule/AvailableForDate.php
index f55c48973..800db5066 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForDate.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForDate.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForLocationX.php b/core/lib/Thelia/Coupon/Rule/AvailableForLocationX.php
index c57702b2f..f0ef8926a 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForLocationX.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForLocationX.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForPeriod.php b/core/lib/Thelia/Coupon/Rule/AvailableForPeriod.php
index 1a2753dc4..fe7347c46 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForPeriod.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForPeriod.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedDate.php b/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedDate.php
index 7d03a1c5b..21ebd01d3 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedDate.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedDate.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedPeriod.php b/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedPeriod.php
index 8552947c2..2824b584a 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedPeriod.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForRepeatedPeriod.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmount.php b/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmount.php
index b90ef1da5..2f1de57ba 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmount.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmount.php
@@ -1,38 +1,171 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
*
*/
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;
+ }
+
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmountForCategoryY.php b/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmountForCategoryY.php
index 08bdc23e5..a4153e5a1 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmountForCategoryY.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForTotalAmountForCategoryY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php b/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php
index 1fac12f94..7016eda95 100644
--- a/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php
+++ b/core/lib/Thelia/Coupon/Rule/AvailableForXArticles.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
}
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php b/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php
index 4a01494ae..a8a51cd00 100644
--- a/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php
+++ b/core/lib/Thelia/Coupon/Rule/CouponRuleAbstract.php
@@ -1,28 +1,33 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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
*
*/
-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'
+ );
+ }
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/CouponRuleInterface.php b/core/lib/Thelia/Coupon/Rule/CouponRuleInterface.php
new file mode 100644
index 000000000..8ab6abe34
--- /dev/null
+++ b/core/lib/Thelia/Coupon/Rule/CouponRuleInterface.php
@@ -0,0 +1,91 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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);
+
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/Rule/Operators.php b/core/lib/Thelia/Coupon/Rule/Operators.php
new file mode 100644
index 000000000..c11198caf
--- /dev/null
+++ b/core/lib/Thelia/Coupon/Rule/Operators.php
@@ -0,0 +1,109 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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;
+ }
+}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/RuleOrganizer.php b/core/lib/Thelia/Coupon/RuleOrganizer.php
index b3699fc6c..4c16ea1ff 100644
--- a/core/lib/Thelia/Coupon/RuleOrganizer.php
+++ b/core/lib/Thelia/Coupon/RuleOrganizer.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon;
diff --git a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php
index bc901d24c..b8b222028 100644
--- a/core/lib/Thelia/Coupon/RuleOrganizerInterface.php
+++ b/core/lib/Thelia/Coupon/RuleOrganizerInterface.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon;
diff --git a/core/lib/Thelia/Coupon/CouponAbstract.php b/core/lib/Thelia/Coupon/Type/CouponAbstract.php
similarity index 60%
rename from core/lib/Thelia/Coupon/CouponAbstract.php
rename to core/lib/Thelia/Coupon/Type/CouponAbstract.php
index b2d4f9268..3ef3166b3 100644
--- a/core/lib/Thelia/Coupon/CouponAbstract.php
+++ b/core/lib/Thelia/Coupon/Type/CouponAbstract.php
@@ -1,29 +1,33 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
-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;
+ }
+
+
}
\ No newline at end of file
diff --git a/core/lib/Thelia/Coupon/CouponInterface.php b/core/lib/Thelia/Coupon/Type/CouponInterface.php
similarity index 67%
rename from core/lib/Thelia/Coupon/CouponInterface.php
rename to core/lib/Thelia/Coupon/Type/CouponInterface.php
index ad332ad0a..e2f49e3bb 100644
--- a/core/lib/Thelia/Coupon/CouponInterface.php
+++ b/core/lib/Thelia/Coupon/Type/CouponInterface.php
@@ -1,27 +1,27 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
-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();
-}
\ No newline at end of file
+
+ /**
+ * 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();
+}
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php
index 6c9a6e7ba..d7cfeb989 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXAmount.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXAmount.php
@@ -1,29 +1,29 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
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;
- }
-
-
-}
\ No newline at end of file
+}
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXAmountForCategoryY.php b/core/lib/Thelia/Coupon/Type/RemoveXAmountForCategoryY.php
index 2cd8e5db6..4a75683bc 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXAmountForCategoryY.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXAmountForCategoryY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php
index 3f0fd43fc..5fd25ae8f 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXPercent.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXPercent.php
@@ -1,29 +1,29 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
-use Thelia\Coupon\CouponAbstract;
+use Thelia\Coupon\Type\CouponAbstract;
use Thelia\Exception\MissingAdapterException;
/**
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php
index 643016c93..f0a7ef472 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentForAttributeY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php
index 6ad0d21df..717807da7 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentForCategoryY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductSaleElementIdY.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductSaleElementIdY.php
index b19913617..bb052cd68 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductSaleElementIdY.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductSaleElementIdY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
diff --git a/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php b/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php
index 494e30fcd..0b88ca44d 100644
--- a/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php
+++ b/core/lib/Thelia/Coupon/Type/RemoveXPercentForProductY.php
@@ -1,25 +1,25 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
namespace Thelia\Coupon\Type;
diff --git a/core/lib/Thelia/Coupon/Rule/CuponRuleInterface.php b/core/lib/Thelia/Exception/InvalidRuleException.php
similarity index 60%
rename from core/lib/Thelia/Coupon/Rule/CuponRuleInterface.php
rename to core/lib/Thelia/Exception/InvalidRuleException.php
index b0cbfa767..834a6e962 100644
--- a/core/lib/Thelia/Coupon/Rule/CuponRuleInterface.php
+++ b/core/lib/Thelia/Exception/InvalidRuleException.php
@@ -1,60 +1,54 @@
. */
-/* */
-/*************************************************************************************/
+/**********************************************************************************/
+/* */
+/* 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 . */
+/* */
+/**********************************************************************************/
-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
*
*/
-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();
-
-}
\ No newline at end of file
+ parent::__construct($message);
+ }
+}
diff --git a/core/lib/Thelia/Exception/InvalidRuleOperatorException.php b/core/lib/Thelia/Exception/InvalidRuleOperatorException.php
new file mode 100644
index 000000000..82556b2ef
--- /dev/null
+++ b/core/lib/Thelia/Exception/InvalidRuleOperatorException.php
@@ -0,0 +1,54 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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);
+ }
+}
diff --git a/core/lib/Thelia/Exception/InvalidRuleValueException.php b/core/lib/Thelia/Exception/InvalidRuleValueException.php
new file mode 100644
index 000000000..cbb86d16f
--- /dev/null
+++ b/core/lib/Thelia/Exception/InvalidRuleValueException.php
@@ -0,0 +1,54 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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);
+ }
+}
diff --git a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php
index 57d0ce131..932dba9fc 100644
--- a/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php
+++ b/core/lib/Thelia/Tests/Coupon/CouponBaseAdapterTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class CouponBaseAdapterTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php
index 9a637b299..465754cd3 100644
--- a/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php
+++ b/core/lib/Thelia/Tests/Coupon/CouponFactoryTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class CouponFactoryTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php
index 55b48f4d9..c7d2233f4 100644
--- a/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php
+++ b/core/lib/Thelia/Tests/Coupon/CouponManagerTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
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.'
+ );
+ }
}
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php
index 7ba6610df..3062568c4 100644
--- a/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/DateParamTest.php
@@ -1,11 +1,41 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
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");
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/IntegerParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/IntegerParamTest.php
new file mode 100644
index 000000000..bcc24542e
--- /dev/null
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/IntegerParamTest.php
@@ -0,0 +1,128 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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()
+ {
+ }
+
+}
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php
index 0c1018af5..59583bfe6 100644
--- a/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/IntervalParamTest.php
@@ -1,11 +1,41 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class IntervalParamTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/PriceParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/PriceParamTest.php
new file mode 100644
index 000000000..c85b5af1a
--- /dev/null
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/PriceParamTest.php
@@ -0,0 +1,193 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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()
+ {
+ }
+
+}
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/QuantityParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/QuantityParamTest.php
new file mode 100644
index 000000000..c7ee0d915
--- /dev/null
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/QuantityParamTest.php
@@ -0,0 +1,161 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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()
+ {
+ }
+
+}
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php
index 5d5f1badc..5e0bf033d 100644
--- a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedDateParamTest.php
@@ -1,4 +1,26 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class RepeatedDateParamTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php
index 0783bac3e..6830d5670 100644
--- a/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Parameter/RepeatedIntervalParamTest.php
@@ -1,11 +1,41 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
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);
}
/**
diff --git a/core/lib/Thelia/Tests/Coupon/Rule/AvailableForTotalAmountTest.php b/core/lib/Thelia/Tests/Coupon/Rule/AvailableForTotalAmountTest.php
new file mode 100644
index 000000000..aaf49e352
--- /dev/null
+++ b/core/lib/Thelia/Tests/Coupon/Rule/AvailableForTotalAmountTest.php
@@ -0,0 +1,338 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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()
+ {
+ }
+
+}
diff --git a/core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php b/core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php
index cb0b59853..2110f76bb 100644
--- a/core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Rule/AvailableForXArticlesTest.php
@@ -1,10 +1,40 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
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;
diff --git a/core/lib/Thelia/Tests/Coupon/Rule/OperatorTest.php b/core/lib/Thelia/Tests/Coupon/Rule/OperatorTest.php
new file mode 100644
index 000000000..2fbf6f339
--- /dev/null
+++ b/core/lib/Thelia/Tests/Coupon/Rule/OperatorTest.php
@@ -0,0 +1,403 @@
+. */
+/* */
+/**********************************************************************************/
+
+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
+ *
+ */
+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()
+ {
+ }
+
+}
diff --git a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php
index e892a7b79..5c8dfc983 100644
--- a/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php
+++ b/core/lib/Thelia/Tests/Coupon/RuleOrganizerTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class RuleOrganizerTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php
index ed8a57833..0178bae10 100644
--- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountForCategoryYTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class RemoveXAmountForCategoryYTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php
index 27d0e9afb..f9e765b35 100644
--- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXAmountTest.php
@@ -1,13 +1,45 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
-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);
+ }
+
}
diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php
index f2e36d0bb..39533d62b 100644
--- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentForCategoryYTest.php
@@ -1,8 +1,38 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class RemoveXPercenForCategoryYTest extends \PHPUnit_Framework_TestCase
{
diff --git a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php
index 33372cdb2..a2dd87f62 100644
--- a/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php
+++ b/core/lib/Thelia/Tests/Coupon/Type/RemoveXPercentTest.php
@@ -1,11 +1,41 @@
. */
+/* */
+/**********************************************************************************/
+
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
+ *
*/
class RemoveXPercentTest extends \PHPUnit_Framework_TestCase
{