diff --git a/core/lib/Thelia/Action/Coupon.php b/core/lib/Thelia/Action/Coupon.php index 7b95d80fa..331265b73 100755 --- a/core/lib/Thelia/Action/Coupon.php +++ b/core/lib/Thelia/Action/Coupon.php @@ -43,6 +43,29 @@ use Propel\Runtime\Exception\PropelException; class Coupon extends BaseAction implements EventSubscriberInterface { + /** + * Disable a Coupon + * + * @param ActionEvent $event + */ + public function delete(CategoryDeleteEvent $event) + { + $this->checkAuth("ADMIN", "admin.category.delete"); + + $category = CategoryQuery::create()->findPk($event->getId()); + + if ($category !== null) { + + $event->setDeletedCategory($category); + + $event->getDispatcher()->dispatch(TheliaEvents::BEFORE_DELETECATEGORY, $event); + + $category->delete(); + + $event->getDispatcher()->dispatch(TheliaEvents::AFTER_DELETECATEGORY, $event); + } + } + /** * Returns an array of event names this subscriber listens to. * diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php new file mode 100644 index 000000000..c03e21f17 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Coupon/CouponCreateEvent.php @@ -0,0 +1,82 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Core\Event\Coupon; + +use Thelia\Model\Coupon; + +class CouponCreateEvent extends ActionEvent +{ + protected $title; + protected $parent; + protected $locale; + protected $created_category; + + public function __construct($title, $parent, $locale) + { + $this->title = $title; + $this->parent = $parent; + $this->locale = $locale; + } + + public function getTitle() + { + return $this->title; + } + + public function setTitle($title) + { + $this->title = $title; + } + + public function getParent() + { + return $this->parent; + } + + public function setParent($parent) + { + $this->parent = $parent; + } + + public function getLocale() + { + return $this->locale; + } + + public function setLocale($locale) + { + $this->locale = $locale; + } + + public function getCreatedCategory() + { + return $this->created_category; + } + + public function setCreatedCategory(Category $created_category) + { + $this->created_category = $created_category; +var_dump($this->created_category); + } +} diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php new file mode 100644 index 000000000..db8e14243 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Coupon/CouponDisableEvent.php @@ -0,0 +1,103 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Core\Event\Coupon; +use Thelia\Model\Coupon; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/29/13 + * Time: 3:45 PM + * + * Occurring when a Coupon is disabled + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class CouponDisableEvent extends ActionEvent +{ + /** @var int Coupon id */ + protected $couponId; + + /** @var Coupon Coupon being disabled */ + protected $disabledCoupon; + + /** + * Constructor + * + * @param int $id Coupon Id + */ + public function __construct($id) + { + $this->id = $id; + } + + /** + * Get Coupon id + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set Coupon id + * + * @param int $id Coupon id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Get Coupon being disabled + * + * @return Coupon + */ + public function getDisabledCoupon() + { + return $this->disabledCoupon; + } + + /** + * Set Coupon to be disabled + * + * @param Coupon $disabledCoupon Coupon to disable + * + * @return $this + */ + public function setDisabledCoupon(Coupon $disabledCoupon) + { + $this->disabledCoupon = $disabledCoupon; + + return $this; + } +} diff --git a/core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php b/core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php new file mode 100644 index 000000000..ab06953e5 --- /dev/null +++ b/core/lib/Thelia/Core/Event/Coupon/CouponEnableEvent.php @@ -0,0 +1,103 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Core\Event\Coupon; +use Thelia\Model\Coupon; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/29/13 + * Time: 3:45 PM + * + * Occurring when a Coupon is enabled + * + * @package Coupon + * @author Guillaume MOREL + * + */ +class CouponEnableEvent extends ActionEvent +{ + /** @var int Coupon id */ + protected $couponId; + + /** @var Coupon Coupon being enabled */ + protected $enabledCoupon; + + /** + * Constructor + * + * @param int $id Coupon Id + */ + public function __construct($id) + { + $this->id = $id; + } + + /** + * Get Coupon id + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set Coupon id + * + * @param int $id Coupon id + * + * @return $this + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Get Coupon being enabled + * + * @return Coupon + */ + public function getEnabledCoupon() + { + return $this->enabledCoupon; + } + + /** + * Set Coupon to be enabled + * + * @param Coupon $enabledCoupon Coupon to enabled + * + * @return $this + */ + public function setEnabledCoupon(Coupon $enabledCoupon) + { + $this->enabledCoupon = $enabledCoupon; + + return $this; + } +} diff --git a/core/lib/Thelia/Model/Base/RewritingUrl.php b/core/lib/Thelia/Model/Base/RewritingUrl.php index 75ee97e79..a6bcd3a26 100644 --- a/core/lib/Thelia/Model/Base/RewritingUrl.php +++ b/core/lib/Thelia/Model/Base/RewritingUrl.php @@ -298,7 +298,7 @@ abstract class RewritingUrl implements ActiveRecordInterface */ public function hasVirtualColumn($name) { - return array_key_exists($name, $this->virtualColumns); + return isset($this->virtualColumns[$name]); } /** diff --git a/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php new file mode 100644 index 000000000..2cdec7846 --- /dev/null +++ b/core/lib/Thelia/Tests/Constraint/Validator/CustomerParamTest.php @@ -0,0 +1,161 @@ +. */ +/* */ +/**********************************************************************************/ + +namespace Thelia\Coupon; + +use InvalidArgumentException; +use Thelia\Constraint\Validator\CustomerParam; +use Thelia\Constraint\Validator\PriceParam; +use Thelia\Constraint\Validator\QuantityParam; +use Thelia\Model\Customer; + +/** + * Created by JetBrains PhpStorm. + * Date: 8/19/13 + * Time: 3:24 PM + * + * Unit Test CustomerParam Class + * + * @package Constraint + * @author Guillaume MOREL + * + */ +class CustomerParamTest extends \PHPUnit_Framework_TestCase +{ + + /** @var CouponAdapterInterface $stubTheliaAdapter */ + protected $stubTheliaAdapter = null; + + /** + * Sets up the fixture, for example, opens a network connection. + * This method is called before a test is executed. + */ + protected function setUp() + { + /** @var CouponAdapterInterface $stubTheliaAdapter */ + $this->stubTheliaAdapter = $this->generateValidCouponBaseAdapterMock(); + } + + /** + * Generate valid CouponBaseAdapter + * + * @param int $customerId Customer id + * + * @return CouponAdapterInterface + */ + protected function generateValidCouponBaseAdapterMock($customerId = 4521) + { + $customer = new Customer(); + $customer->setId($customerId); + $customer->setFirstname('Firstname'); + $customer->setLastname('Lastname'); + $customer->setEmail('em@il.com'); + + /** @var CouponAdapterInterface $stubTheliaAdapter */ + $stubTheliaAdapter = $this->getMock( + 'Thelia\Coupon\CouponBaseAdapter', + array('getCustomer'), + array() + ); + $stubTheliaAdapter->expects($this->any()) + ->method('getCustomer') + ->will($this->returnValue($customer)); + + return $stubTheliaAdapter; + } + + /** + * + * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo + * + */ + public function testCanUseCoupon() + { + $customerId = 4521; + $couponValidForCustomerId = 4521; + + $adapter = $this->generateValidCouponBaseAdapterMock($customerId); + + $customerParam = new CustomerParam($adapter, $couponValidForCustomerId); + + $expected = 0; + $actual = $customerParam->compareTo($customerId); + $this->assertEquals($expected, $actual); + } + +// /** +// * +// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo +// * +// */ +// public function testCanNotUseCouponTest() +// { +// +// } +// +// /** +// * +// * @covers Thelia\Coupon\Parameter\QuantityParam::compareTo +// * @expectedException InvalidArgumentException +// * +// */ +// public function testCanNotUseCouponCustomerNotFoundTest() +// { +// +// } + + + + +// /** +// * Test is the object is serializable +// * If no data is lost during the process +// */ +// public function isSerializableTest() +// { +// $adapter = new CouponBaseAdapter(); +// $intValidator = 42; +// $intToValidate = -1; +// +// $param = new QuantityParam($adapter, $intValidator); +// +// $serialized = base64_encode(serialize($param)); +// /** @var QuantityParam $unserialized */ +// $unserialized = base64_decode(serialize($serialized)); +// +// $this->assertEquals($param->getValue(), $unserialized->getValue()); +// $this->assertEquals($param->getInteger(), $unserialized->getInteger()); +// +// $new = new QuantityParam($adapter, $unserialized->getInteger()); +// $this->assertEquals($param->getInteger(), $new->getInteger()); +// } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + } + +}