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..c5799d3fcaa0849290c392e5c356c2854501adc7 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 $isVisible = $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" />