diff --git a/core/lib/Thelia/Controller/Admin/CouponController.php b/core/lib/Thelia/Controller/Admin/CouponController.php index 0b5b24daa..6803addfd 100755 --- a/core/lib/Thelia/Controller/Admin/CouponController.php +++ b/core/lib/Thelia/Controller/Admin/CouponController.php @@ -157,9 +157,10 @@ class CouponController extends BaseAdminController // If no input for expirationDate, now + 2 months $defaultDate = new \DateTime(); $args['defaultDate'] = $defaultDate->modify('+2 month') - ->format($lang->getDateFormat()); + ->format('Y-m-d'); } + $args['dateFormat'] = $this->getSession()->getLang()->getDateFormat(); $args['availableCoupons'] = $this->getAvailableCoupons(); $args['formAction'] = 'admin/coupon/create/'; @@ -224,7 +225,7 @@ class CouponController extends BaseAdminController 'shortDescription' => $coupon->getShortDescription(), 'description' => $coupon->getDescription(), 'isEnabled' => ($coupon->getIsEnabled() == 1), - 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()), + 'expirationDate' => $coupon->getExpirationDate('Y-m-d'), 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1), 'isCumulative' => ($coupon->getIsCumulative() == 1), 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), @@ -273,103 +274,6 @@ class CouponController extends BaseAdminController return $this->render('coupon-update', $args); } - -// /** -// * Manage Coupons Rule creation display -// * -// * @param int $couponId Coupon id -// * -// * @return \Symfony\Component\HttpFoundation\Response -// */ -// public function createRuleAction($couponId) -// { -// // Check current user authorization -// $response = $this->checkAuth('admin.coupon.update'); -// if ($response !== null) { -// return $response; -// } -// -// /** @var Coupon $coupon */ -// $coupon = CouponQuery::create()->findOneById($couponId); -// if (!$coupon) { -// $this->pageNotFound(); -// } -// -// // Parameters given to the template -// $args = array(); -// -// $i18n = new I18n(); -// /** @var Lang $lang */ -// $lang = $this->getSession()->get('lang'); -// $eventToDispatch = TheliaEvents::COUPON_RULE_CREATE; -// -// if ($this->getRequest()->isMethod('POST')) { -// $this->validateCreateOrUpdateForm( -// $i18n, -// $lang, -// $eventToDispatch, -// 'updated', -// 'update' -// ); -// } else { -// // Prepare the data that will hydrate the form -// -// /** @var ConstraintFactory $constraintFactory */ -// $constraintFactory = $this->container->get('thelia.constraint.factory'); -// -// $data = array( -// 'code' => $coupon->getCode(), -// 'title' => $coupon->getTitle(), -// 'amount' => $coupon->getAmount(), -// 'effect' => $coupon->getType(), -// 'shortDescription' => $coupon->getShortDescription(), -// 'description' => $coupon->getDescription(), -// 'isEnabled' => ($coupon->getIsEnabled() == 1), -// 'expirationDate' => $coupon->getExpirationDate($lang->getDateFormat()), -// 'isAvailableOnSpecialOffers' => ($coupon->getIsAvailableOnSpecialOffers() == 1), -// 'isCumulative' => ($coupon->getIsCumulative() == 1), -// 'isRemovingPostage' => ($coupon->getIsRemovingPostage() == 1), -// 'maxUsage' => $coupon->getMaxUsage(), -// 'rules' => $constraintFactory->unserializeCouponRuleCollection($coupon->getSerializedRules()), -// 'locale' => $coupon->getLocale(), -// ); -// -// /** @var CouponAdapterInterface $adapter */ -// $adapter = $this->container->get('thelia.adapter'); -// /** @var Translator $translator */ -// $translator = $this->container->get('thelia.translator'); -// -// $args['rulesObject'] = array(); -// /** @var CouponRuleInterface $rule */ -// foreach ($coupon->getRules()->getRules() as $rule) { -// $args['rulesObject'][] = array( -// 'name' => $rule->getName($translator), -// 'tooltip' => $rule->getToolTip($translator), -// 'validators' => $rule->getValidators() -// ); -// } -// -// $args['rules'] = $this->cleanRuleForTemplate($coupon->getRules()->getRules()); -// -// // Setup the object form -// $changeForm = new CouponCreationForm($this->getRequest(), 'form', $data); -// -// // Pass it to the parser -// $this->getParserContext()->addForm($changeForm); -// } -// -// $args['formAction'] = 'admin/coupon/update/' . $couponId; -// -// return $this->render( -// 'coupon-update', -// $args -// ); -// } - - - - - /** * Manage Coupons read display * @@ -569,7 +473,7 @@ class CouponController extends BaseAdminController /** * Validate the CreateOrUpdate form * - * @param string $i18n Local code (fr_FR) + * @param I18n $i18n Local code (fr_FR) * @param Lang $lang Local variables container * @param string $eventToDispatch Event which will activate actions * @param string $log created|edited @@ -577,7 +481,7 @@ class CouponController extends BaseAdminController * * @return $this */ - protected function validateCreateOrUpdateForm($i18n, $lang, $eventToDispatch, $log, $action) + protected function validateCreateOrUpdateForm(I18n $i18n, Lang $lang, $eventToDispatch, $log, $action) { // Create the form from the request $creationForm = new CouponCreationForm($this->getRequest()); @@ -597,7 +501,7 @@ class CouponController extends BaseAdminController $data['shortDescription'], $data['description'], $data['isEnabled'], - $i18n->getDateTimeFromForm($lang, $data['expirationDate']), + \DateTime::createFromFormat('Y-m-d', $data['expirationDate']), $data['isAvailableOnSpecialOffers'], $data['isCumulative'], $data['isRemovingPostage'], diff --git a/core/lib/Thelia/Form/CouponCreationForm.php b/core/lib/Thelia/Form/CouponCreationForm.php index 9e41bae4f..1625ab685 100755 --- a/core/lib/Thelia/Form/CouponCreationForm.php +++ b/core/lib/Thelia/Form/CouponCreationForm.php @@ -24,6 +24,7 @@ namespace Thelia\Form; use Symfony\Component\Validator\Constraints\Date; +use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\GreaterThanOrEqual; use Symfony\Component\Validator\Constraints\NotBlank; use Symfony\Component\Validator\Constraints\NotEqualTo; diff --git a/core/lib/Thelia/Model/Coupon.php b/core/lib/Thelia/Model/Coupon.php index 7a7ce1e4a..032de412a 100755 --- a/core/lib/Thelia/Model/Coupon.php +++ b/core/lib/Thelia/Model/Coupon.php @@ -76,7 +76,6 @@ class Coupon extends BaseCoupon ->setType($effect) ->setAmount($amount) ->setIsRemovingPostage($isRemovingPostage) - ->setType($amount) ->setIsEnabled($isEnabled) ->setExpirationDate($expirationDate) ->setIsAvailableOnSpecialOffers($isAvailableOnSpecialOffers) diff --git a/templates/admin/default/assets/js/coupon.js b/templates/admin/default/assets/js/coupon.js index 37f8de41f..41e0c1430 100644 --- a/templates/admin/default/assets/js/coupon.js +++ b/templates/admin/default/assets/js/coupon.js @@ -140,28 +140,21 @@ $(function($){ couponManager.onUsageUnlimitedChange = function() { if (!$('#max-usage').parent().hasClass('has-error')) { $('#max-usage').hide().attr('value', '-1'); + $('#max-usage-label').hide(); } $('#is-unlimited').change(function(){ var $this = $(this); if ($this.is(':checked')) { $('#max-usage').hide().attr('value', '-1'); + $('#max-usage-label').hide(); } else { $('#max-usage').show().val('').attr('value', ''); + $('#max-usage-label').show(); } }); }; couponManager.onUsageUnlimitedChange(); -// // -- Effect description -// if($('[name=effect]').length){ -// var $effectSelect = $('[name=effect]'), -// $helpBlock = $effectSelect.next('.help-block'); -// -// $effectSelect.change(function(){ -// var description = $(this).find(":selected").data('description'); -// $helpBlock.text(description); -// }); -// } }); // Rule to save @@ -175,4 +168,5 @@ couponManager.ruleToSave.values = {}; // Rules payload to save couponManager.rulesToSave = []; // Rule being updated id -couponManager.ruleToUpdateId = false; \ No newline at end of file +couponManager.ruleToUpdateId = false; + diff --git a/templates/admin/default/coupon-create.html b/templates/admin/default/coupon-create.html index b87b21195..f8a0411e1 100755 --- a/templates/admin/default/coupon-create.html +++ b/templates/admin/default/coupon-create.html @@ -20,7 +20,6 @@ {form name="thelia.admin.coupon.creation"} {include file='coupon/form.html' formAction={url path={$formAction}} noRules=true} {/form} - {include file='includes/confirmation-modal.html'} @@ -42,4 +41,13 @@ {javascripts file='assets/js/coupon.js'} {/javascripts} + + {**} + {**} + + {/block} diff --git a/templates/admin/default/coupon/form.html b/templates/admin/default/coupon/form.html index 92b834fe7..a4ec8b14a 100644 --- a/templates/admin/default/coupon/form.html +++ b/templates/admin/default/coupon/form.html @@ -11,7 +11,7 @@ {/form_field} {form_field form=$form field='success_url'} - + {/form_field}
@@ -35,40 +35,40 @@ {form_field form=$form field='isEnabled'}
-
{/form_field} {form_field form=$form field='isAvailableOnSpecialOffers'}
-
{/form_field} {form_field form=$form field='isCumulative'}
-
{/form_field} {form_field form=$form field='isRemovingPostage'}
-
{/form_field} @@ -77,7 +77,7 @@
- + {if $error}{$message}{/if}
@@ -86,11 +86,12 @@ {form_field form=$form field='maxUsage'}
- + + {if $error}{$message}{/if}
@@ -118,6 +119,7 @@
{form_field form=$form field='amount'}
+ {$value} {if $error}{$message}{/if} @@ -157,7 +159,7 @@
{/form_field} - +
diff --git a/tests/functionnal/casperjs/exe/00_parameters.js b/tests/functionnal/casperjs/exe/00_parameters.js index a32ee89b5..df5470229 100644 --- a/tests/functionnal/casperjs/exe/00_parameters.js +++ b/tests/functionnal/casperjs/exe/00_parameters.js @@ -3,7 +3,7 @@ casper.test.comment('Please edit 00_parameters.js to add your configuration'); var thelia2_login_admin_url = thelia2_base_url + 'admin/login'; var thelia2_login_coupon_list_url = thelia2_base_url + 'admin/login'; -var thelia2_login_coupon_create_url = thelia2_base_url + 'admin/coupon/create'; +var thelia2_login_coupon_create_url = thelia2_base_url + 'admin/coupon/create/'; var thelia2_login_coupon_read_url = thelia2_base_url + 'admin/coupon/read/1'; var thelia2_login_coupon_update_url = thelia2_base_url + 'admin/coupon/update/1'; diff --git a/tests/functionnal/casperjs/exe/30_coupons.js b/tests/functionnal/casperjs/exe/30_coupons.js index 7cbd70578..2147c14cf 100644 --- a/tests/functionnal/casperjs/exe/30_coupons.js +++ b/tests/functionnal/casperjs/exe/30_coupons.js @@ -15,8 +15,137 @@ casper.test.comment('Testing coupons'); // @todo implement ////CREATE -// @todo implement +casper.start(thelia2_login_coupon_create_url, function() { + this.test.assertHttpStatus(200); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/init.png'); + this.test.comment('COUPON - CREATE EMPTY'); + // Click on is unlimited button + this.click("form #is-unlimited"); + this.sendKeys('input#max-usage', '-2'); + + // cleaning expiration date default value + this.evaluate(function() { + $("#expiration-date").val('').change(); + return true; + }); + + this.capture('tests/functionnal/casperjs/screenshot/coupons/creating-new-coupon.png'); + this.click("form .control-group .btn.btn-default.btn-primary"); + +}); + +casper.wait(1000, function() { + this.echo("\nWaiting...."); +}); + +// Test Coupon creation if no input +casper.then(function(){ + this.test.assertHttpStatus(200); + this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-empty-coupon.png'); + this.test.assertExists('.has-error #code', 'Error on code input found'); + this.test.assertExists('.has-error #title', 'Error on title input found'); + + this.test.assertExists('.has-error #expiration-date', 'Error on expiration date input found'); + this.test.assertExists('.has-error #max-usage', 'Error on max usage input found'); + this.test.assertExists('.has-error #description', 'Error on description input found'); + this.test.assertExists('.has-error #effect', 'Error on effect input found'); + this.test.assertExists('.has-error #amount', 'Error on amount input found'); + this.test.assertExists('.has-error #short-description', 'Error on short-description input found'); +}); + +// Test Coupon creation if good input +casper.then(function(){ + + this.sendKeys('input#code', 'XMAS10'); + this.sendKeys('input#title', 'christmas'); + this.click("form #is-enabled"); + this.click("form #is-available-on-special-offers"); + this.click("form #is-cumulative"); + this.click("form #is-removing-postage"); + + this.evaluate(function() { + $("#expiration-date").val('2013-11-14').change(); + return true; + }); + + // Click on is unlimited button + this.click("form #is-unlimited"); + this.sendKeys('input#max-usage', '40'); + + this.evaluate(function() { + $('#effect').val('thelia.coupon.type.remove_x_amount').change(); + return true; + }); + + this.test.assertSelectorHasText( + '#effectToolTip', + this.evaluate(function () { + return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description'); + }), + 'Tooltip found' + ); + this.sendKeys('input#amount', '42.12'); + this.sendKeys('#short-description', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.'); + this.sendKeys('#description', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.'); + + this.capture('tests/functionnal/casperjs/screenshot/coupons/coupon-created-ready-to-be-saved.png'); + this.click("#save-coupon-btn"); +}); + +casper.wait(2000, function() { + this.echo("\nWaiting...."); +}); + +// Test Coupon creation if good input is well saved +casper.then(function(){ + this.test.assertHttpStatus(302); + this.test.comment('Now on : ' + this.getCurrentUrl()); + this.capture('tests/functionnal/casperjs/screenshot/coupons/created-new-coupon.png'); + this.test.assertField('thelia_coupon_creation[code]', 'XMAS10', 'Code found'); + this.test.assertField('thelia_coupon_creation[title]', 'christmas', 'Title found'); + + this.test.assert(this.evaluate(function () { + return document.getElementById('is-enabled').checked; + }), 'Checkbox is enabled checked'); + this.test.assert(this.evaluate(function () { + return document.getElementById('is-available-on-special-offers').checked; + }), 'Checkbox is available on special offers checked'); + this.test.assert(this.evaluate(function () { + return document.getElementById('is-cumulative').checked; + }), 'Checkbox is cumulative checked'); + this.test.assert(this.evaluate(function () { + return document.getElementById('is-removing-postage').checked; + }), 'Checkbox is cumulative checked'); + + this.test.assertField('thelia_coupon_creation[expirationDate]', '2013-11-14', 'Expiration date found'); + this.test.assertField('thelia_coupon_creation[maxUsage]', '40', 'Max usage found'); + this.test.assert(this.evaluate(function () { + return !document.getElementById('is-unlimited').checked; + }), 'Checkbox is unlimited not checked'); + + this.test.assert( + this.evaluate(function () { + return $("#effect").val(); + }), + 'thelia.coupon.type.remove_x_amount', + 'Effect found' + ); + this.test.assertSelectorHasText( + '#effectToolTip', + this.evaluate(function () { + return $("#effect option[value^='thelia.coupon.type.remove_x_amount']").attr('data-description'); + }), + 'Tooltip found' + ); + this.test.assertField('thelia_coupon_creation[amount]', '42.12', 'Amount found'); + + this.test.assertField('thelia_coupon_creation[shortDescription]', 'Mauris sed risus imperdiet, blandit arcu ac, tempus metus. Aliquam erat volutpat. Nullam dictum sed.', 'Short description found'); + this.test.assertField('thelia_coupon_creation[description]', 'Etiam sodales non nisi a condimentum. Morbi luctus mauris mattis sem ornare; ac blandit tortor porta! Sed vel viverra dolor. Nulla eget viverra eros. Donec rutrum felis ut quam blandit, eu massa nunc.', 'Description found'); + + +}); ////EDIT CHECK // @todo implement