diff --git a/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php b/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php index 992c63cf893f541fef9b1458542cd922b5a7e433..59d183ee6510eeba9fc301aeaec0417c464920e1 100644 --- a/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php +++ b/app/code/Magento/Customer/Model/Customer/Attribute/Backend/Password.php @@ -53,17 +53,8 @@ class Password extends \Magento\Eav\Model\Entity\Attribute\Backend\AbstractBacke ); } - if ($this->string->substr( - $password, - 0, - 1 - ) == ' ' || $this->string->substr( - $password, - $length - 1, - 1 - ) == ' ' - ) { - throw new LocalizedException(__('The password can\'t begin or end with a space.')); + if (trim($password) != $password) { + throw new LocalizedException(__('The password can not begin or end with a space.')); } $object->setPasswordHash($object->hashPassword($password)); diff --git a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml index 21762022d84e565b42a9808389c03c6777d0d5ae..8bf281411f8b171dce5a5b627a8c3e9c3fbe4b77 100644 --- a/app/code/Magento/Customer/view/base/ui_component/customer_form.xml +++ b/app/code/Magento/Customer/view/base/ui_component/customer_form.xml @@ -303,6 +303,9 @@ <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> + <item name="imports" xsi:type="array"> + <item name="default" xsi:type="string">${ $.provider }:data.customer.firstname</item> + </item> </item> </argument> </field> @@ -325,6 +328,9 @@ <item name="validation" xsi:type="array"> <item name="required-entry" xsi:type="boolean">true</item> </item> + <item name="imports" xsi:type="array"> + <item name="default" xsi:type="string">${ $.provider }:data.customer.lastname</item> + </item> </item> </argument> </field> diff --git a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js index 112f9406bdaf4e664e57478393a6b73409098119..2ed8935a30cf8249df7721e61773a5a955d2d3ad 100644 --- a/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js +++ b/app/code/Magento/Wishlist/view/frontend/web/js/add-to-wishlist.js @@ -32,7 +32,8 @@ define([ this._on(events); }, _updateWishlistData: function(event) { - var dataToAdd = {}; + var dataToAdd = {}, + isFileUploaded = false; if (event.handleObj.selector == this.options.qtyInfo) { this._updateAddToWishlistButton({}); event.stopPropagation(); @@ -40,15 +41,22 @@ define([ } var self = this; $(event.handleObj.selector).each(function(index, element){ - if ($(element).attr('type') == 'text') { + if ($(element).is('input[type=text]') + || $(element).is('input[type=checkbox]:checked') + || $(element).is('input[type=radio]:checked') + || $('#' + element.id + ' option:selected').length + || $(element).is('textarea') + ) { dataToAdd = $.extend({}, dataToAdd, self._getElementData(element)); return; } - if ($(element).is(':checked') || $(element).find(':checked').length) { - dataToAdd = $.extend({}, dataToAdd, self._getElementData(element)); + if ($(element).is('input[type=file]') && $(element).val()) { + isFileUploaded = true; } }); - + if (isFileUploaded) { + this.bindFormSubmit(); + } this._updateAddToWishlistButton(dataToAdd); event.stopPropagation(); }, @@ -90,7 +98,9 @@ define([ data[elementName + '[' + option + ']'] = option; }); } else { - data[elementName] = elementValue; + if (elementValue) { + data[elementName] = elementValue; + } } return data; }, @@ -99,6 +109,23 @@ define([ $.each(dataToRemove, function(key, value) { delete params.data[key]; }); + }, + bindFormSubmit: function() { + var self = this; + $('[data-action="add-to-wishlist"]').on('click', function(event) { + event.stopPropagation(); + event.preventDefault(); + + var element = $('input[type=file]' + self.options.customOptionsInfo), + params = $(event.currentTarget).data('post'), + form = $(element).closest('form'), + action = params.action; + if (params.data.uenc) { + action += 'uenc/' + params.data.uenc; + } + + $(form).attr('action', action).submit(); + }); } }); diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions.php new file mode 100644 index 0000000000000000000000000000000000000000..0cdd46da28ece5bf94756fde012f0bec0a0e7e1f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions.php @@ -0,0 +1,66 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\GiftMessage\Test\Block\Cart; + +use Magento\GiftMessage\Test\Fixture\GiftMessage; +use Magento\Mtf\Block\Form; + +/** + * Class GiftOptions + * Add gift options on checkout cart order level + */ +class GiftOptions extends Form +{ + /** + * Selector for gift message on order form + * + * @var string + */ + protected $giftMessageOrderForm = ".gift-message fieldset"; + + /** + * Allow gift message on order level + * + * @var string + */ + protected $allowGiftOptions = '.title'; + + /** + * Selector for apply Gift Message button on item + * + * @var string + */ + protected $giftMessageOrderButton = ".action-update"; + + /** + * Selector for Gift Message Summary + * + * @var string + */ + protected $giftMessageSummary = ".gift-message-summary"; + + /** + * Fill gift message form on order level + * + * @param GiftMessage $giftMessage + * @return void + */ + public function fillGiftMessageOrder(GiftMessage $giftMessage) + { + /** @var \Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm $giftMessageForm */ + if ($giftMessage->getAllowGiftMessagesForOrder() === 'Yes') { + $this->_rootElement->find($this->allowGiftOptions)->click(); + $giftMessageForm = $this->blockFactory->create( + 'Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm', + ['element' => $this->_rootElement->find($this->giftMessageOrderForm)] + ); + $giftMessageForm->fill($giftMessage); + $this->_rootElement->find($this->giftMessageOrderButton)->click(); + $this->waitForElementVisible($this->giftMessageSummary); + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.php similarity index 80% rename from dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.php rename to dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.php index 2c1a696e6929dc5c6bec4daa66abe309ccb4432a..a8b0c26d710726878c7a7d147fc9c1f077156fce 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.php +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.php @@ -4,7 +4,7 @@ * See COPYING.txt for license details. */ -namespace Magento\GiftMessage\Test\Block\Message\Inline; +namespace Magento\GiftMessage\Test\Block\Cart\GiftOptions; use Magento\Mtf\Block\Form; diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.xml b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.xml similarity index 58% rename from dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.xml rename to dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.xml index 220c89ef22a04bc1c04c9a3f4542b53512d9c39b..43407c31535f56a199a96b9bcca36b21f3095fb3 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline/GiftMessageForm.xml +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/GiftOptions/GiftMessageForm.xml @@ -8,13 +8,13 @@ <mapping strict="0"> <fields> <sender> - <selector>[id^='gift-message'][name$='[from]']</selector> + <selector>[id='gift-message-whole-from']</selector> </sender> <recipient> - <selector>[id^='gift-message'][name$='[to]']</selector> + <selector>[id='gift-message-whole-to']</selector> </recipient> <message> - <selector>[id^='gift-message'][name$='[message]']</selector> + <selector>[id='gift-message-whole-message']</selector> </message> </fields> </mapping> diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/Item/GiftOptions.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/Item/GiftOptions.php new file mode 100644 index 0000000000000000000000000000000000000000..78ce8fe619261744f1a8dfd817ea6980fce21a32 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/Item/GiftOptions.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\GiftMessage\Test\Block\Cart\Item; + +use Magento\GiftMessage\Test\Fixture\GiftMessage; +use Magento\Mtf\Block\Form; +use Magento\Mtf\Client\Locator; + +/** + * Add gift options on checkout cart item level + */ +class GiftOptions extends Form +{ + /** + * Selector for gift message on item form + * + * @var string + */ + protected $giftMessageItemForm = '//div[@class="gift-message"]//fieldset[ancestor::tbody[contains(.,"%s")]]'; + + /** + * Allow Gift Options for items + * + * @var string + */ + protected $allowGiftOptions = '//a[contains(@class,"action-gift")][ancestor::tbody[contains(.,"%s")]]'; + + /** + * Selector for apply Gift Message button on order + * + * @var string + */ + protected $giftMessageItemButton = ".action-update"; + + /** + * Selector for Gift Message Summary + * + * @var string + */ + protected $giftMessageSummary = '//div[@class="gift-message-summary"][ancestor::tbody[contains(.,"%s")]]'; + + /** + * Fill gift message form on item level + * + * @param GiftMessage $giftMessage + * @param array $products + * @return void + */ + public function fillGiftMessageItem(GiftMessage $giftMessage, $products = []) + { + /** @var \Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm $giftMessageForm */ + if ($giftMessage->getAllowGiftOptionsForItems() === 'Yes') { + foreach ($products as $product) { + if ($product->getIsVirtual() !== 'Yes') { + $this->_rootElement->find( + sprintf($this->allowGiftOptions, $product->getName()), + Locator::SELECTOR_XPATH + )->click(); + $giftMessageForm = $this->blockFactory->create( + 'Magento\GiftMessage\Test\Block\Cart\GiftOptions\GiftMessageForm', + [ + 'element' => $this->_rootElement->find( + sprintf($this->giftMessageItemForm, $product->getName()), + Locator::SELECTOR_XPATH + ) + ] + ); + $giftMessageForm->fill($giftMessage); + $this->_rootElement->find($this->giftMessageItemButton)->click(); + $this->waitForElementVisible( + sprintf($this->giftMessageSummary, $product->getName()), + Locator::SELECTOR_XPATH + ); + } + } + } + } +} diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline.xml b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/Item/GiftOptions.xml similarity index 100% rename from dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline.xml rename to dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Cart/Item/GiftOptions.xml diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline.php deleted file mode 100644 index 0c41872447b7796c0ee47861fa32e44403797dbf..0000000000000000000000000000000000000000 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Inline.php +++ /dev/null @@ -1,87 +0,0 @@ -<?php -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - -namespace Magento\GiftMessage\Test\Block\Message; - -use Magento\GiftMessage\Test\Fixture\GiftMessage; -use Magento\Mtf\Block\Form; -use Magento\Mtf\Client\Locator; - -/** - * Class Inline - * Checkout add gift options - */ -class Inline extends Form -{ - /** - * Selector for gift message on item form - * - * @var string - */ - protected $giftMessageItemForm = ".//li[@class='item'][contains(.,'%s')]/div[@class='options']"; - - /** - * Selector for gift message on order form - * - * @var string - */ - protected $giftMessageOrderForm = ".gift-messages-order"; - - /** - * Selector for "Gift Message" button on order - * - * @var string - */ - protected $giftMessageItemButton = ".//li[@class='item'][contains(.,'%s')]/div[@class='options']/a"; - - /** - * Selector for "Gift Message" button on item - * - * @var string - */ - protected $giftMessageOrderButton = "#allow-gift-options-for-order-container > a"; - - /** - * Fill gift message form - * - * @param GiftMessage $giftMessage - * @param array $products - * @return void - */ - public function fillGiftMessage(GiftMessage $giftMessage, $products = []) - { - $this->fill($giftMessage); - - /** @var \Magento\GiftMessage\Test\Block\Message\Inline\GiftMessageForm $giftMessageForm */ - if ($giftMessage->getAllowGiftMessagesForOrder() === 'Yes') { - $this->_rootElement->find($this->giftMessageOrderButton)->click(); - $giftMessageForm = $this->blockFactory->create( - 'Magento\GiftMessage\Test\Block\Message\Inline\GiftMessageForm', - ['element' => $this->_rootElement->find($this->giftMessageOrderForm)] - ); - $giftMessageForm->fill($giftMessage); - } - - if ($giftMessage->getAllowGiftOptionsForItems() === 'Yes') { - foreach ($products as $product) { - $this->_rootElement->find( - sprintf($this->giftMessageItemButton, $product->getName()), - Locator::SELECTOR_XPATH - )->click(); - $giftMessageForm = $this->blockFactory->create( - 'Magento\GiftMessage\Test\Block\Message\Inline\GiftMessageForm', - [ - 'element' => $this->_rootElement->find( - sprintf($this->giftMessageItemForm, $product->getName()), - Locator::SELECTOR_XPATH - ) - ] - ); - $giftMessageForm->fill($giftMessage); - } - } - } -} diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Order/Items/View.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Order/Items/View.php index b3c29e2252085a4470eaeb586d78fe42b8d8109a..c680b61b485b4b7addb8334a548ea6f2c91a4121 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Order/Items/View.php +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Block/Message/Order/Items/View.php @@ -57,6 +57,9 @@ class View extends Block */ public function getGiftMessage($itemName) { + if (!$this->giftMessageButtonIsVisible($itemName)) { + return []; + } $message = []; $labelsToSkip = []; $this->clickGiftMessageButton($itemName); @@ -88,4 +91,18 @@ class View extends Block Locator::SELECTOR_XPATH )->click(); } + + /** + * Click "Gift Message" for special item. + * + * @param string $itemName + * @return bool + */ + protected function giftMessageButtonIsVisible($itemName) + { + return $this->_rootElement->find( + sprintf($this->giftMessageButtonSelector, $itemName), + Locator::SELECTOR_XPATH + )->isVisible(); + } } diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Constraint/AssertGiftMessageInFrontendOrderItems.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Constraint/AssertGiftMessageInFrontendOrderItems.php index a9a17c123c4c1b44d43312727d49111b29735da7..932115cdf37abb0a769342973706c00a20f05734 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Constraint/AssertGiftMessageInFrontendOrderItems.php +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Constraint/AssertGiftMessageInFrontendOrderItems.php @@ -62,6 +62,10 @@ class AssertGiftMessageInFrontendOrderItems extends AbstractConstraint 'message' => $itemGiftMessage->getMessage(), ]; } + if ($product->getIsVirtual() == 'Yes') { + $expectedData = []; + } + \PHPUnit_Framework_Assert::assertEquals( $expectedData, $customerOrderView->getGiftMessageForItemBlock()->getGiftMessage($product->getName()), diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutCart.xml b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutCart.xml new file mode 100644 index 0000000000000000000000000000000000000000..c911cebf77f4afe51df39d6159bc5ef6f2874499 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutCart.xml @@ -0,0 +1,13 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd"> + <page name="CheckoutCart" mca="checkout/cart"> + <block name="giftMessagesItemBlock" class="Magento\GiftMessage\Test\Block\Cart\Item\GiftOptions" locator=".gift-options-cart-item" strategy="css selector"/> + <block name="giftMessagesOrderBlock" class="Magento\GiftMessage\Test\Block\Cart\GiftOptions" locator=".cart-gift-item" strategy="css selector"/> + </page> +</config> diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutOnepage.xml b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutOnepage.xml deleted file mode 100644 index 0a83605791e225384c20d3572d861bfd0d31b927..0000000000000000000000000000000000000000 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/Page/CheckoutOnepage.xml +++ /dev/null @@ -1,12 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- -/** - * Copyright © 2015 Magento. All rights reserved. - * See COPYING.txt for license details. - */ - --> -<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/pages.xsd"> - <page name="CheckoutOnepage" mca="checkout/onepage"> - <block name="giftMessagesBlock" class="Magento\GiftMessage\Test\Block\Message\Inline" locator=".gift-message" strategy="css selector"/> - </page> -</config> diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/TestStep/AddGiftMessageStep.php b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/TestStep/AddGiftMessageStep.php index 190de05c9eecdf1d89c29a6aeea3cc18416de37e..35c7994df9e5434e5f647e3bf5716433ce8de6de 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/TestStep/AddGiftMessageStep.php +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/TestStep/AddGiftMessageStep.php @@ -6,7 +6,7 @@ namespace Magento\GiftMessage\Test\TestStep; -use Magento\Checkout\Test\Page\CheckoutOnepage; +use Magento\Checkout\Test\Page\CheckoutCart; use Magento\GiftMessage\Test\Fixture\GiftMessage; use Magento\Mtf\TestStep\TestStepInterface; @@ -19,9 +19,9 @@ class AddGiftMessageStep implements TestStepInterface /** * Onepage checkout page * - * @var CheckoutOnepage + * @var CheckoutCart */ - protected $checkoutOnepage; + protected $checkoutCart; /** * Gift message fixture @@ -39,13 +39,13 @@ class AddGiftMessageStep implements TestStepInterface /** * @constructor - * @param CheckoutOnepage $checkoutOnepage + * @param CheckoutCart $checkoutCart * @param GiftMessage $giftMessage * @param array $products */ - public function __construct(CheckoutOnepage $checkoutOnepage, GiftMessage $giftMessage, array $products = []) + public function __construct(CheckoutCart $checkoutCart, GiftMessage $giftMessage, array $products = []) { - $this->checkoutOnepage = $checkoutOnepage; + $this->checkoutCart = $checkoutCart; $this->giftMessage = $giftMessage; $this->products = $products; } @@ -57,6 +57,8 @@ class AddGiftMessageStep implements TestStepInterface */ public function run() { - $this->checkoutOnepage->getGiftMessagesBlock()->fillGiftMessage($this->giftMessage, $this->products); + $this->checkoutCart->open(); + $this->checkoutCart->getGiftMessagesItemBlock()->fillGiftMessageItem($this->giftMessage, $this->products); + $this->checkoutCart->getGiftMessagesOrderBlock()->fillGiftMessageOrder($this->giftMessage, $this->products); } } diff --git a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/etc/testcase.xml b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/etc/testcase.xml index de5469059a9b89883c6210b648f0783b8af43fd8..0dfdf20437f1c1d626d645680346d0d8f31f2228 100644 --- a/dev/tests/functional/tests/app/Magento/GiftMessage/Test/etc/testcase.xml +++ b/dev/tests/functional/tests/app/Magento/GiftMessage/Test/etc/testcase.xml @@ -13,10 +13,10 @@ <step name="createProducts" module="Magento_Catalog" next="createCustomer" /> <step name="createCustomer" module="Magento_Customer" next="loginCustomerOnFrontend" /> <step name="loginCustomerOnFrontend" module="Magento_Customer" next="addProductsToTheCart" /> - <step name="addProductsToTheCart" module="Magento_Checkout" next="proceedToCheckout" /> + <step name="addProductsToTheCart" module="Magento_Checkout" next="addGiftMessage" /> + <step name="addGiftMessage" module="Magento_GiftMessage" next="proceedToCheckout" /> <step name="proceedToCheckout" module="Magento_Checkout" next="fillBillingInformation" /> - <step name="fillBillingInformation" module="Magento_Checkout" next="addGiftMessage" /> - <step name="addGiftMessage" module="Magento_GiftMessage" next="fillShippingMethod" /> + <step name="fillBillingInformation" module="Magento_Checkout" next="fillShippingMethod" /> <step name="fillShippingMethod" module="Magento_Checkout" next="selectPaymentMethod" /> <step name="selectPaymentMethod" module="Magento_Checkout" next="placeOrder" /> <step name="placeOrder" module="Magento_Checkout" />