From dfb264b5455fa1247c623d9d8321f781aece34af Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Thu, 6 Apr 2017 17:38:33 +0300 Subject: [PATCH 01/14] MAGETWO-66278: Timeline fix. --- app/code/Magento/Ui/view/base/web/js/timeline/timeline.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js b/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js index 571b03317ac09..e86064a8606f8 100644 --- a/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js +++ b/app/code/Magento/Ui/view/base/web/js/timeline/timeline.js @@ -104,7 +104,7 @@ define([ * @returns {Boolean} */ isActive: function (record) { - return record.status === 1; + return Number(record.status) === 1; }, /** @@ -115,7 +115,7 @@ define([ * @returns {Boolean} */ isUpcoming: function (record) { - return record.status === 2; + return Number(record.status) === 2; }, /** From f19cd09708b92b1efec9f021748b0a50ef5c0e8d Mon Sep 17 00:00:00 2001 From: DianaRusin Date: Fri, 7 Apr 2017 14:50:01 +0300 Subject: [PATCH 02/14] MAGETWO-61097: [BACKPORT] UK mobile phone number validation is outdated --- app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js | 2 +- lib/web/mage/validation.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js index 4702120860285..c78f253c8aec0 100644 --- a/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js +++ b/app/code/Magento/Ui/view/base/web/js/lib/validation/rules.js @@ -213,7 +213,7 @@ define([ ], "mobileUK": [ function(value) { - return value.length > 9 && value.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/); + return value.length > 9 && value.match(/^((0|\+44)7\d{3}\s?\d{6})$/); }, $.mage.__('Please specify a valid mobile number') ], diff --git a/lib/web/mage/validation.js b/lib/web/mage/validation.js index 0238f2cb9840b..9d57001b6d2dc 100644 --- a/lib/web/mage/validation.js +++ b/lib/web/mage/validation.js @@ -320,7 +320,7 @@ "mobileUK": [ function (phone_number, element) { return this.optional(element) || phone_number.length > 9 && - phone_number.match(/^((0|\+44)7(5|6|7|8|9){1}\d{2}\s?\d{6})$/); + phone_number.match(/^((0|\+44)7\d{3}\s?\d{6})$/); }, 'Please specify a valid mobile number' ], From 96e08fad04e36ea1415eb55cf50b62d3af57ca96 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 11:33:21 +0300 Subject: [PATCH 03/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../Adminhtml/Promo/Quote/Generate.php | 69 +++++++-- .../Model/Service/CouponManagementService.php | 2 - .../Block/Onepage/Payment/DiscountCodes.php | 13 +- .../Promo/Quote/Edit/PromoQuoteForm.xml | 16 +++ .../BlockPromoSalesRuleEditTabCoupons.php | 97 +++++++++++++ .../Grid.php | 37 +++++ ...ssertCouponCodeSuccessGeneratedMessage.php | 61 ++++++++ .../Constraint/AssertUsesPerCouponWorks.php | 135 ++++++++++++++++++ .../SalesRule/Test/Fixture/SalesRule.xml | 6 + .../TestCase/CreateSalesRuleEntityTest.php | 33 ++++- .../TestCase/CreateSalesRuleEntityTest.xml | 23 +++ 11 files changed, 475 insertions(+), 17 deletions(-) create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php create mode 100644 dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php index 4db27d3607c9f..0771f826b33e6 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php @@ -8,6 +8,39 @@ class Generate extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote { + /** + * @var \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory + */ + private $generationSpecFactory; + /** + * @var \Magento\SalesRule\Model\Service\CouponManagementService + */ + private $couponManagementService; + + /** + * Generate constructor. + * @param \Magento\Backend\App\Action\Context $context + * @param \Magento\Framework\Registry $coreRegistry + * @param \Magento\Framework\App\Response\Http\FileFactory $fileFactory + * @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter + * @param \Magento\SalesRule\Model\Service\CouponManagementService|null $couponManagementService + * @param \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory|null $generationSpecFactory + */ + public function __construct( + \Magento\Backend\App\Action\Context $context, + \Magento\Framework\Registry $coreRegistry, + \Magento\Framework\App\Response\Http\FileFactory $fileFactory, + \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter, + \Magento\SalesRule\Model\Service\CouponManagementService $couponManagementService = null, + \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory $generationSpecFactory = null + ) { + parent::__construct($context, $coreRegistry, $fileFactory, $dateFilter); + $this->generationSpecFactory = $generationSpecFactory ?: + $this->_objectManager->get(\Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory::class); + $this->couponManagementService = $couponManagementService ?: + $this->_objectManager->get(\Magento\SalesRule\Model\Service\CouponManagementService::class); + } + /** * Generate Coupons action * @@ -17,6 +50,7 @@ public function execute() { if (!$this->getRequest()->isAjax()) { $this->_forward('noroute'); + return; } $result = []; @@ -35,18 +69,15 @@ public function execute() $data = $inputFilter->getUnescaped(); } - /** @var $generator \Magento\SalesRule\Model\Coupon\Massgenerator */ - $generator = $this->_objectManager->get('Magento\SalesRule\Model\Coupon\Massgenerator'); - if (!$generator->validateData($data)) { - $result['error'] = __('Invalid data provided'); - } else { - $generator->setData($data); - $generator->generatePool(); - $generated = $generator->getGeneratedCount(); - $this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated)); - $this->_view->getLayout()->initMessages(); - $result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml(); - } + $data = $this->convertCouponSpecData($data); + $couponSpec = $this->generationSpecFactory->create(['data' => $data]); + $couponCodes = $this->couponManagementService->generate($couponSpec); + $generated = count($couponCodes); + $this->messageManager->addSuccess(__('%1 coupon(s) have been generated.', $generated)); + $this->_view->getLayout()->initMessages(); + $result['messages'] = $this->_view->getLayout()->getMessagesBlock()->getGroupedHtml(); + } catch (\Magento\Framework\Exception\InputException $inputException) { + $result['error'] = __('Invalid data provided'); } catch (\Magento\Framework\Exception\LocalizedException $e) { $result['error'] = $e->getMessage(); } catch (\Exception $e) { @@ -60,4 +91,18 @@ public function execute() $this->_objectManager->get('Magento\Framework\Json\Helper\Data')->jsonEncode($result) ); } + + /** + * We should map old values to new one + * We need to do this, as new service with another key names was added + * + * @param array $data + * @return array + */ + private function convertCouponSpecData(array $data) + { + $data['quantity'] = $data['qty']; + + return $data; + } } diff --git a/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php b/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php index 153b26fbad496..a69e17478dea4 100644 --- a/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php +++ b/app/code/Magento/SalesRule/Model/Service/CouponManagementService.php @@ -5,8 +5,6 @@ */ namespace Magento\SalesRule\Model\Service; -use Magento\SalesRule\Model\Coupon; - /** * Coupon management service class * diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php index bfc9988dfd060..a6fc1f3a04192 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php @@ -15,6 +15,15 @@ */ class DiscountCodes extends Form { + // @codingStandardsIgnoreStart + /** + * Message after coupon applying. + * + * @var string + */ + protected $couponApplyingMessage = './/div[contains(@class,"messages")]//div[contains(@class,"message")]'; + // @codingStandardsIgnoreEnd + /** * Form wrapper selector * @@ -47,12 +56,14 @@ class DiscountCodes extends Form * Enter discount code and click apply button * * @param string $code - * @return void + * @return string */ public function applyCouponCode($code) { $this->_rootElement->find($this->openForm, Locator::SELECTOR_CSS)->click(); $this->_rootElement->find($this->couponCode, Locator::SELECTOR_CSS)->setValue($code); $this->_rootElement->find($this->applyButton, Locator::SELECTOR_CSS)->click(); + + return $this->_rootElement->find($this->couponApplyingMessage, Locator::SELECTOR_XPATH)->getText(); } } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml index 7e30946214475..7e214aa38acf5 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.xml @@ -27,6 +27,9 @@ select + + checkbox + @@ -80,4 +83,17 @@ [data-index="labels"] css selector + + \Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\BlockPromoSalesRuleEditTabCoupons + [data-index="block_promo_sales_rule_edit_tab_coupons"] + css selector + + + + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php new file mode 100644 index 0000000000000..b10da4ab4cf6c --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php @@ -0,0 +1,97 @@ +_rootElement->find($this->generateButtonSelector, Locator::SELECTOR_XPATH)->click(); + } + + /** + * Get success message from section. + * + * @return string + */ + public function getSuccessMessage() + { + $this->waitForElementVisible($this->successMessage); + + return $this->_rootElement->find($this->successMessage)->getText(); + } + + /** + * Get coupon codes grid. + * + * @return \Magento\Mtf\Block\BlockInterface + */ + public function getCouponGrid() + { + $element = $this->_rootElement->find($this->gridSelector); + + return $this->blockFactory->create(Grid::class, ['element' => $element]); + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php new file mode 100644 index 0000000000000..572acbe6b8149 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php @@ -0,0 +1,37 @@ +waitLoader(); + + $data = []; + $rows = $this->_rootElement->getElements($this->rowItem); + foreach ($rows as $row) { + $rowData = []; + foreach ($columns as $columnName) { + $rowData[$columnName] = trim($row->find('.col-' . $columnName)->getText()); + } + + $data[] = $rowData; + } + + return $data; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php new file mode 100644 index 0000000000000..8c2a1db140659 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php @@ -0,0 +1,61 @@ +getQty()); + + /** @var PromoQuoteForm $salesRuleForm */ + $salesRuleForm = $promoQuoteNew->getSalesRuleForm(); + + /** @var BlockPromoSalesRuleEditTabCoupons $manageCouponCodesSection */ + $manageCouponCodesSection = $salesRuleForm->getSection('block_promo_sales_rule_edit_tab_coupons'); + + $actualMessage = $manageCouponCodesSection->getSuccessMessage(); + + \PHPUnit_Framework_Assert::assertEquals( + $expectedMessage, + $actualMessage, + 'Wrong success message is displayed.' + . "\nExpected: " . $expectedMessage + . "\nActual: " . $actualMessage + ); + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Coupon generating success message is present.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php new file mode 100644 index 0000000000000..6572ff4a36eba --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php @@ -0,0 +1,135 @@ +getUsesPerCoupon() + 1; $i++) { + //add product to cart. + $objectManager->create( + \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class, + ['products' => [$productForSalesRule1]] + )->run(); + + // go to checkout. + $checkoutOnepage->open(); + + //fill shipping address. + $objectManager->create( + \Magento\Checkout\Test\TestStep\FillShippingAddressStep::class, + ['shippingAddress' => $shippingAddress] + )->run(); + + //fill sipping method. + $objectManager->create( + \Magento\Checkout\Test\TestStep\FillShippingMethodStep::class, + ['shipping' => $shipping] + )->run(); + + // select payment method. + $objectManager->create( + \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, + ['payment' => $payment]) + ->run(); + + // apply coupon code and get message. + $message = $checkoutOnepage->getDiscountCodesBlock()->applyCouponCode($generatedCouponCodes[0]['code']); + + // check coupon code applying message. + $this->assertCouponCodeApplyingMessage($message, $salesRule->getUsesPerCoupon(), $i); + + // place order. + $objectManager->create(\Magento\Checkout\Test\TestStep\PlaceOrderStep::class)->run(); + } + } + + /** + * @param string $message + * @param int $usesPerCoupon + * @param int $i + * + * @return void + */ + private function assertCouponCodeApplyingMessage($message, $usesPerCoupon, $i) + { + if ($usesPerCoupon > $i) { + \PHPUnit_Framework_Assert::assertEquals( + $this->successCouponAppliedMessage, + $message + ); + } else { + \PHPUnit_Framework_Assert::assertEquals( + $this->errorCouponAppliedMessage, + $message + ); + } + } + + /** + * Returns a string representation of the object. + * + * @return string + */ + public function toString() + { + return 'Uses per coupon configuration works ok.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml index 03e4d31406e2a..dd652d1f646fb 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml @@ -43,5 +43,11 @@ + + + + + + diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php index e19b79e3474e8..6a4f9012a3fad 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php @@ -6,6 +6,9 @@ namespace Magento\SalesRule\Test\TestCase; +use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\PromoQuoteForm; +use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\BlockPromoSalesRuleEditTabCoupons; +use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\BlockPromoSalesRuleEditTabCoupons\Grid; use Magento\SalesRule\Test\Fixture\SalesRule; use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteEdit; use Magento\SalesRule\Test\Page\Adminhtml\PromoQuoteIndex; @@ -102,15 +105,20 @@ public function __inject( * @param CatalogProductSimple $productForSalesRule2 * @param Customer $customer * @param string $conditionEntity + * @param SalesRule $manageCouponCodes + * + * @return array */ public function testCreateSalesRule( SalesRule $salesRule, CatalogProductSimple $productForSalesRule1, CatalogProductSimple $productForSalesRule2 = null, Customer $customer = null, - $conditionEntity = null + $conditionEntity = null, + SalesRule $manageCouponCodes = null ) { $replace = null; + $generatedCouponCodes = []; $this->salesRuleName = $salesRule->getName(); // Prepare data @@ -128,7 +136,28 @@ public function testCreateSalesRule( // Steps $this->promoQuoteNew->open(); $this->promoQuoteNew->getSalesRuleForm()->fill($salesRule, null, $replace); - $this->promoQuoteNew->getFormPageActions()->save(); + + if ($salesRule->getUseAutoGeneration() == 'Yes') { + $this->promoQuoteNew->getFormPageActions()->saveAndContinue(); + + /** @var PromoQuoteForm $salesRuleForm */ + $salesRuleForm = $this->promoQuoteNew->getSalesRuleForm(); + $salesRuleForm->fill($manageCouponCodes); + + /** @var BlockPromoSalesRuleEditTabCoupons $manageCouponCodesSection */ + $manageCouponCodesSection = $salesRuleForm->getSection('block_promo_sales_rule_edit_tab_coupons'); + $manageCouponCodesSection->pressGenerateButton(); + + /** @var Grid $couponGrid */ + $couponGrid = $manageCouponCodesSection->getCouponGrid(); + + $generatedCouponCodes = $couponGrid->getRowsData(['code']);; + ; + } else { + $this->promoQuoteNew->getFormPageActions()->save(); + } + + return ['generatedCouponCodes' => $generatedCouponCodes]; } /** diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml index 2fed474f73d6a..f9713a9a3960e 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -403,6 +403,29 @@ 75.00 + --> + + Cart Price Rule3 %isolation% + Cart Price Rule Description %isolation% + Yes + Main Website + NOT LOGGED IN + Specific Coupon + Yes + Fixed amount discount for whole cart + 1 + 50 + No + No + 1 + simple_for_salesrule_1 + 5 + US_address_1 + checkmo + Flat Rate + Fixed + + From 2075175821070ed544e8bdb2610b65b53b29a33d Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 11:33:40 +0300 Subject: [PATCH 04/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml index f9713a9a3960e..ece5e09c55493 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -403,7 +403,7 @@ 75.00 - --> + Cart Price Rule3 %isolation% Cart Price Rule Description %isolation% From fd0a6945f1974ce81f7472323598beff59b63809 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 11:40:11 +0300 Subject: [PATCH 05/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../Test/Constraint/AssertUsesPerCouponWorks.php | 13 +++++++------ .../TestSuite/InjectableTests/MAGETWO-67267.xml | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php index 6572ff4a36eba..01016bb8bb136 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php @@ -84,18 +84,19 @@ public function processAssert( ['shipping' => $shipping] )->run(); - // select payment method. - $objectManager->create( - \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, - ['payment' => $payment]) - ->run(); - // apply coupon code and get message. $message = $checkoutOnepage->getDiscountCodesBlock()->applyCouponCode($generatedCouponCodes[0]['code']); // check coupon code applying message. $this->assertCouponCodeApplyingMessage($message, $salesRule->getUsesPerCoupon(), $i); + + // select payment method. + $objectManager->create( + \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, + ['payment' => $payment]) + ->run(); + // place order. $objectManager->create(\Magento\Checkout\Test\TestStep\PlaceOrderStep::class)->run(); } diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml new file mode 100644 index 0000000000000..eafb758b22576 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml @@ -0,0 +1,15 @@ + + + + + + + + + From 68513b643405e2a58e2efac39277645f5053c39e Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 12:29:15 +0300 Subject: [PATCH 06/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php | 1 + .../SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php | 1 - .../Magento/Test/Integrity/_files/blacklist/reference.txt | 2 ++ 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php index 0771f826b33e6..d8a6845f7a019 100644 --- a/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php +++ b/app/code/Magento/SalesRule/Controller/Adminhtml/Promo/Quote/Generate.php @@ -12,6 +12,7 @@ class Generate extends \Magento\SalesRule\Controller\Adminhtml\Promo\Quote * @var \Magento\SalesRule\Api\Data\CouponGenerationSpecInterfaceFactory */ private $generationSpecFactory; + /** * @var \Magento\SalesRule\Model\Service\CouponManagementService */ diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php index 01016bb8bb136..3fa5ad3e9601a 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php @@ -90,7 +90,6 @@ public function processAssert( // check coupon code applying message. $this->assertCouponCodeApplyingMessage($message, $salesRule->getUsesPerCoupon(), $i); - // select payment method. $objectManager->create( \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt index cafac52cd5afe..7bb9bd2cfaff1 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt @@ -59,7 +59,9 @@ Model3 \Magento\TestModule2\Service\V1\Entity\ItemBuilder \Magento\TestModule4\Service\V1\Entity\DataObjectResponse \Magento\TestModule4\Service\V1\Entity\DataObjectRequest +\Magento\Mtf\ObjectManager \Magento\Mtf\ObjectManager\Config\Mapper\Dom +\Magento\Mtf\Block\BlockInterface \Magento\Mtf\Data\Argument\Interpreter\Constant \Magento\Mtf\Data\Argument\Interpreter\Boolean \Magento\Mtf\Data\Argument\Interpreter\StringType From aee5c61be7fafcebb83b287a56c8692cfb109e19 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 13:10:21 +0300 Subject: [PATCH 07/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php | 4 ++-- .../SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php | 3 +-- .../InjectableTests/{MAGETWO-67267.xml => MAGETWO-65161.xml} | 0 3 files changed, 3 insertions(+), 4 deletions(-) rename dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/{MAGETWO-67267.xml => MAGETWO-65161.xml} (100%) diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php index 3fa5ad3e9601a..86ade02802ed1 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php @@ -93,8 +93,8 @@ public function processAssert( // select payment method. $objectManager->create( \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, - ['payment' => $payment]) - ->run(); + ['payment' => $payment] + )->run(); // place order. $objectManager->create(\Magento\Checkout\Test\TestStep\PlaceOrderStep::class)->run(); diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php index 6a4f9012a3fad..a15a1dc7f4e4e 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php @@ -151,8 +151,7 @@ public function testCreateSalesRule( /** @var Grid $couponGrid */ $couponGrid = $manageCouponCodesSection->getCouponGrid(); - $generatedCouponCodes = $couponGrid->getRowsData(['code']);; - ; + $generatedCouponCodes = $couponGrid->getRowsData(['code']); } else { $this->promoQuoteNew->getFormPageActions()->save(); } diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml similarity index 100% rename from dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-67267.xml rename to dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml From c43eba1cf3742bd916ac2c1d615d6d9825f6af51 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Mon, 10 Apr 2017 15:17:38 +0300 Subject: [PATCH 08/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../TestSuite/InjectableTests/MAGETWO-65161.xml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml deleted file mode 100644 index eafb758b22576..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - From 7a41d4dd4da5a4b9e37b52bc150fb32cb684d370 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Tue, 11 Apr 2017 11:28:34 +0300 Subject: [PATCH 09/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../Block/Onepage/Payment/DiscountCodes.php | 25 +++++++------ .../Promo/Quote/Edit/PromoQuoteForm.php | 19 ++++++++++ .../BlockPromoSalesRuleEditTabCoupons.php | 36 +++++-------------- .../Grid.php | 22 ------------ ...ssertCouponCodeSuccessGeneratedMessage.php | 8 +++-- ...ouponWorks.php => AssertUsesPerCoupon.php} | 34 ++++++++---------- .../TestCase/CreateSalesRuleEntityTest.php | 20 +++++++---- .../TestCase/CreateSalesRuleEntityTest.xml | 5 ++- .../InjectableTests/MAGETWO-65161.xml | 15 ++++++++ .../Integrity/_files/blacklist/reference.txt | 2 -- 10 files changed, 92 insertions(+), 94 deletions(-) rename dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/{AssertUsesPerCouponWorks.php => AssertUsesPerCoupon.php} (83%) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php index a6fc1f3a04192..0b7148538d5c5 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php @@ -10,59 +10,64 @@ use Magento\Mtf\Client\Locator; /** - * Class DiscountCodes - * Discount codes block + * Discount codes block. */ class DiscountCodes extends Form { - // @codingStandardsIgnoreStart /** * Message after coupon applying. * * @var string */ protected $couponApplyingMessage = './/div[contains(@class,"messages")]//div[contains(@class,"message")]'; - // @codingStandardsIgnoreEnd /** - * Form wrapper selector + * Form wrapper selector. * * @var string */ protected $formWrapper = '.content'; /** - * Open discount codes form selector + * Open discount codes form selector. * * @var string */ protected $openForm = '.payment-option-title'; /** - * Fill discount code input selector + * Fill discount code input selector. * * @var string */ protected $couponCode = '#discount-code'; /** - * Click apply button selector + * Click apply button selector. * * @var string */ protected $applyButton = '.action.action-apply'; /** - * Enter discount code and click apply button + * Enter discount code and click apply button. * * @param string $code - * @return string + * @return void */ public function applyCouponCode($code) { $this->_rootElement->find($this->openForm, Locator::SELECTOR_CSS)->click(); $this->_rootElement->find($this->couponCode, Locator::SELECTOR_CSS)->setValue($code); $this->_rootElement->find($this->applyButton, Locator::SELECTOR_CSS)->click(); + } + + /** + * Get message after coupon applying. + * + * @return string + */ + public function getCouponApplyingMessage() { return $this->_rootElement->find($this->couponApplyingMessage, Locator::SELECTOR_XPATH)->getText(); } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php index 607dc20047dd5..7882bd9b6edd0 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/PromoQuoteForm.php @@ -8,6 +8,7 @@ use Magento\Ui\Test\Block\Adminhtml\FormSections; use Magento\Mtf\Client\Element\SimpleElement; use Magento\Mtf\Fixture\FixtureInterface; +use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\BlockPromoSalesRuleEditTabCoupons; /** * Sales rule edit form. @@ -45,6 +46,24 @@ public function fill(FixtureInterface $fixture, SimpleElement $element = null, a $this->fillContainers($sections, $element); } + /** + * Generate coupons for Cart Rule. + * + * @param array $generateSettings + * + * @return void + */ + public function generateCoupons(array $generateSettings) + { + $this->fillContainers([ + 'block_promo_sales_rule_edit_tab_coupons' => $generateSettings + ]); + + /** @var BlockPromoSalesRuleEditTabCoupons $couponSection */ + $couponSection = $this->getSection('block_promo_sales_rule_edit_tab_coupons'); + $couponSection->pressGenerateButton(); + } + /** * Replace placeholders in each values of data. * diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php index b10da4ab4cf6c..715b44f39c1ef 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons.php @@ -6,12 +6,7 @@ namespace Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section; -use Magento\Mtf\Block\BlockFactory; -use Magento\Mtf\Block\Mapper; -use Magento\Mtf\Client\BrowserInterface; -use Magento\Mtf\Client\Element\SimpleElement; use Magento\Mtf\Client\Locator; -use Magento\Mtf\Util\ModuleResolver\SequenceSorterInterface; use Magento\SalesRule\Test\Block\Adminhtml\Promo\Quote\Edit\Section\BlockPromoSalesRuleEditTabCoupons\Grid; use Magento\Ui\Test\Block\Adminhtml\Section; @@ -39,27 +34,7 @@ class BlockPromoSalesRuleEditTabCoupons extends Section * * @var string */ - private $gridSelector = '#couponCodesGrid_table'; - - /** - * BlockPromoSalesRuleEditTabCoupons constructor. - * @param SimpleElement $element - * @param BlockFactory $blockFactory - * @param Mapper $mapper - * @param BrowserInterface $browser - * @param SequenceSorterInterface $sequenceSorter - * @param array $config - */ - public function __construct( - SimpleElement $element, - BlockFactory $blockFactory, - Mapper $mapper, - BrowserInterface $browser, - SequenceSorterInterface $sequenceSorter, - array $config = [] - ) { - parent::__construct($element, $blockFactory, $mapper, $browser, $sequenceSorter, $config); - } + private $gridSelector = '#couponCodesGrid'; /** * Press generate button to generate coupons. @@ -69,6 +44,8 @@ public function __construct( public function pressGenerateButton() { $this->_rootElement->find($this->generateButtonSelector, Locator::SELECTOR_XPATH)->click(); + + $this->waitForElementVisible($this->successMessage); } /** @@ -86,12 +63,15 @@ public function getSuccessMessage() /** * Get coupon codes grid. * - * @return \Magento\Mtf\Block\BlockInterface + * @return Grid */ public function getCouponGrid() { $element = $this->_rootElement->find($this->gridSelector); - return $this->blockFactory->create(Grid::class, ['element' => $element]); + /** @var Grid $couponGrid */ + $couponGrid = $this->blockFactory->create(Grid::class, ['element' => $element]); + + return $couponGrid; } } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php index 572acbe6b8149..36ffcbb3874a9 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php @@ -11,27 +11,5 @@ */ class Grid extends \Magento\Backend\Test\Block\Widget\Grid { - /** - * Get rows data - * - * @param array $columns - * @return array - */ - public function getRowsData(array $columns) - { - $this->waitLoader(); - $data = []; - $rows = $this->_rootElement->getElements($this->rowItem); - foreach ($rows as $row) { - $rowData = []; - foreach ($columns as $columnName) { - $rowData[$columnName] = trim($row->find('.col-' . $columnName)->getText()); - } - - $data[] = $rowData; - } - - return $data; - } } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php index 8c2a1db140659..493205f6e4ed5 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertCouponCodeSuccessGeneratedMessage.php @@ -23,14 +23,16 @@ class AssertCouponCodeSuccessGeneratedMessage extends AbstractConstraint * Assert that success message is displayed after generating coupon('s). * * @param PromoQuoteNew $promoQuoteNew - * @param SalesRule $manageCouponCodes + * @param array $generateCouponsSettings * @return void */ public function processAssert( PromoQuoteNew $promoQuoteNew, - SalesRule $manageCouponCodes + array $generateCouponsSettings ) { - $expectedMessage = sprintf(self::SUCCESS_MESSAGE, $manageCouponCodes->getQty()); + $qty = isset($generateCouponsSettings['qty']) ? $generateCouponsSettings['qty'] : null; + + $expectedMessage = sprintf(self::SUCCESS_MESSAGE, $qty); /** @var PromoQuoteForm $salesRuleForm */ $salesRuleForm = $promoQuoteNew->getSalesRuleForm(); diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCoupon.php similarity index 83% rename from dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php rename to dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCoupon.php index 86ade02802ed1..ad487d63d91b7 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCouponWorks.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Constraint/AssertUsesPerCoupon.php @@ -7,6 +7,7 @@ namespace Magento\SalesRule\Test\Constraint; use Magento\Mtf\Constraint\AbstractConstraint; +use Magento\Mtf\TestStep\TestStepFactory; use Magento\SalesRule\Test\Fixture\SalesRule; use Magento\Checkout\Test\Page\CheckoutOnepage; use Magento\Catalog\Test\Fixture\CatalogProductSimple; @@ -14,7 +15,7 @@ /** * Assert uses per coupon configuration works ok. */ -class AssertUsesPerCouponWorks extends AbstractConstraint +class AssertUsesPerCoupon extends AbstractConstraint { /** * Message when coupon is applied successfully. @@ -30,13 +31,6 @@ class AssertUsesPerCouponWorks extends AbstractConstraint */ private $errorCouponAppliedMessage = 'Coupon code is not valid'; - /** - * First product from precondition. - * - * @var CatalogProductSimple - */ - protected $productForSalesRule1; - /** * Assert uses per coupon configuration works ok. * @@ -44,9 +38,10 @@ class AssertUsesPerCouponWorks extends AbstractConstraint * @param CatalogProductSimple $productForSalesRule1 * @param CheckoutOnepage $checkoutOnepage * @param array $shippingAddress - * @param array $generatedCouponCodes + * @param array $couponCodes * @param array $payment * @param array $shipping + * @param TestStepFactory $testStepFactory * * @return void */ @@ -55,16 +50,15 @@ public function processAssert( CatalogProductSimple $productForSalesRule1, CheckoutOnepage $checkoutOnepage, array $shippingAddress, - array $generatedCouponCodes, + array $couponCodes, array $payment, - array $shipping + array $shipping, + TestStepFactory $testStepFactory ) { - $objectManager = \Magento\Mtf\ObjectManager::getInstance(); - //need to place order one more time than uses_per_coupon to get error message. for ($i = 0; $i < $salesRule->getUsesPerCoupon() + 1; $i++) { //add product to cart. - $objectManager->create( + $testStepFactory->create( \Magento\Checkout\Test\TestStep\AddProductsToTheCartStep::class, ['products' => [$productForSalesRule1]] )->run(); @@ -73,31 +67,33 @@ public function processAssert( $checkoutOnepage->open(); //fill shipping address. - $objectManager->create( + $testStepFactory->create( \Magento\Checkout\Test\TestStep\FillShippingAddressStep::class, ['shippingAddress' => $shippingAddress] )->run(); //fill sipping method. - $objectManager->create( + $testStepFactory->create( \Magento\Checkout\Test\TestStep\FillShippingMethodStep::class, ['shipping' => $shipping] )->run(); // apply coupon code and get message. - $message = $checkoutOnepage->getDiscountCodesBlock()->applyCouponCode($generatedCouponCodes[0]['code']); + $checkoutOnepage->getDiscountCodesBlock()->applyCouponCode($couponCodes[0]); + + $message = $checkoutOnepage->getDiscountCodesBlock()->getCouponApplyingMessage(); // check coupon code applying message. $this->assertCouponCodeApplyingMessage($message, $salesRule->getUsesPerCoupon(), $i); // select payment method. - $objectManager->create( + $testStepFactory->create( \Magento\Checkout\Test\TestStep\SelectPaymentMethodStep::class, ['payment' => $payment] )->run(); // place order. - $objectManager->create(\Magento\Checkout\Test\TestStep\PlaceOrderStep::class)->run(); + $testStepFactory->create(\Magento\Checkout\Test\TestStep\PlaceOrderStep::class)->run(); } } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php index a15a1dc7f4e4e..005888a358a00 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php @@ -105,7 +105,7 @@ public function __inject( * @param CatalogProductSimple $productForSalesRule2 * @param Customer $customer * @param string $conditionEntity - * @param SalesRule $manageCouponCodes + * @param array $generateCouponsSettings * * @return array */ @@ -115,10 +115,10 @@ public function testCreateSalesRule( CatalogProductSimple $productForSalesRule2 = null, Customer $customer = null, $conditionEntity = null, - SalesRule $manageCouponCodes = null + array $generateCouponsSettings = null ) { $replace = null; - $generatedCouponCodes = []; + $generatedCouponCodes = null; $this->salesRuleName = $salesRule->getName(); // Prepare data @@ -137,26 +137,32 @@ public function testCreateSalesRule( $this->promoQuoteNew->open(); $this->promoQuoteNew->getSalesRuleForm()->fill($salesRule, null, $replace); - if ($salesRule->getUseAutoGeneration() == 'Yes') { + if ($salesRule->getUseAutoGeneration() == 'Yes' && !empty($generateCouponsSettings)) { $this->promoQuoteNew->getFormPageActions()->saveAndContinue(); /** @var PromoQuoteForm $salesRuleForm */ $salesRuleForm = $this->promoQuoteNew->getSalesRuleForm(); - $salesRuleForm->fill($manageCouponCodes); + $salesRuleForm->generateCoupons($generateCouponsSettings); /** @var BlockPromoSalesRuleEditTabCoupons $manageCouponCodesSection */ $manageCouponCodesSection = $salesRuleForm->getSection('block_promo_sales_rule_edit_tab_coupons'); - $manageCouponCodesSection->pressGenerateButton(); /** @var Grid $couponGrid */ $couponGrid = $manageCouponCodesSection->getCouponGrid(); + /** @var array $generatedCouponCodes */ $generatedCouponCodes = $couponGrid->getRowsData(['code']); + $generatedCouponCodes = array_map( + function ($element) { + return $element['code']; + }, + $generatedCouponCodes + ); } else { $this->promoQuoteNew->getFormPageActions()->save(); } - return ['generatedCouponCodes' => $generatedCouponCodes]; + return ['salesRule' => $salesRule, 'couponCodes' => $generatedCouponCodes]; } /** diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml index ece5e09c55493..430a31731dab5 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.xml @@ -417,15 +417,14 @@ 50 No No - 1 + 1 simple_for_salesrule_1 - 5 US_address_1 checkmo Flat Rate Fixed - + diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml new file mode 100644 index 0000000000000..eafb758b22576 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml @@ -0,0 +1,15 @@ + + + + + + + + + diff --git a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt index 7bb9bd2cfaff1..cafac52cd5afe 100644 --- a/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt +++ b/dev/tests/static/testsuite/Magento/Test/Integrity/_files/blacklist/reference.txt @@ -59,9 +59,7 @@ Model3 \Magento\TestModule2\Service\V1\Entity\ItemBuilder \Magento\TestModule4\Service\V1\Entity\DataObjectResponse \Magento\TestModule4\Service\V1\Entity\DataObjectRequest -\Magento\Mtf\ObjectManager \Magento\Mtf\ObjectManager\Config\Mapper\Dom -\Magento\Mtf\Block\BlockInterface \Magento\Mtf\Data\Argument\Interpreter\Constant \Magento\Mtf\Data\Argument\Interpreter\Boolean \Magento\Mtf\Data\Argument\Interpreter\StringType From 5178239f2c89b3ce2ce75adfc9e639f03319f339 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Tue, 11 Apr 2017 11:40:27 +0300 Subject: [PATCH 10/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../Checkout/Test/Block/Onepage/Payment/DiscountCodes.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php index 0b7148538d5c5..ac3f31feade74 100644 --- a/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php +++ b/dev/tests/functional/tests/app/Magento/Checkout/Test/Block/Onepage/Payment/DiscountCodes.php @@ -67,8 +67,8 @@ public function applyCouponCode($code) * * @return string */ - public function getCouponApplyingMessage() { - + public function getCouponApplyingMessage() + { return $this->_rootElement->find($this->couponApplyingMessage, Locator::SELECTOR_XPATH)->getText(); } } From 4818f9b8f239118f7b78ec33aaec9a83d7c1ea96 Mon Sep 17 00:00:00 2001 From: RomanKis Date: Tue, 11 Apr 2017 14:12:11 +0300 Subject: [PATCH 11/14] MAGETWO-65161: [Backport] - "Uses per Coupon" limit does not work for auto generated coupons - for 2.1 --- .../BlockPromoSalesRuleEditTabCoupons/Grid.php | 17 +++++++++++++++++ .../SalesRule/Test/Fixture/SalesRule.xml | 8 +------- .../Test/TestCase/CreateSalesRuleEntityTest.php | 8 +------- .../TestSuite/InjectableTests/MAGETWO-65161.xml | 15 --------------- 4 files changed, 19 insertions(+), 29 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php index 36ffcbb3874a9..afcd3e8ad16db 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Block/Adminhtml/Promo/Quote/Edit/Section/BlockPromoSalesRuleEditTabCoupons/Grid.php @@ -11,5 +11,22 @@ */ class Grid extends \Magento\Backend\Test\Block\Widget\Grid { + /** + * Return generated coupon codes as array of codes. + * + * @return array + */ + public function getCouponCodes() + { + /** @var array $generatedCouponCodes */ + $generatedCouponCodes = $this->getRowsData(['code']); + $generatedCouponCodes = array_map( + function ($element) { + return $element['code']; + }, + $generatedCouponCodes + ); + return $generatedCouponCodes; + } } diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml index dd652d1f646fb..967ce8c7aff26 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/Fixture/SalesRule.xml @@ -43,11 +43,5 @@ - - - - - - - + diff --git a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php index 005888a358a00..930ac94ffa37f 100644 --- a/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php +++ b/dev/tests/functional/tests/app/Magento/SalesRule/Test/TestCase/CreateSalesRuleEntityTest.php @@ -151,13 +151,7 @@ public function testCreateSalesRule( $couponGrid = $manageCouponCodesSection->getCouponGrid(); /** @var array $generatedCouponCodes */ - $generatedCouponCodes = $couponGrid->getRowsData(['code']); - $generatedCouponCodes = array_map( - function ($element) { - return $element['code']; - }, - $generatedCouponCodes - ); + $generatedCouponCodes = $couponGrid->getCouponCodes(); } else { $this->promoQuoteNew->getFormPageActions()->save(); } diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml deleted file mode 100644 index eafb758b22576..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-65161.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - From 9f36abf2d83566e2c87081df32003d4f2aaee25c Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Thu, 13 Apr 2017 17:57:17 +0300 Subject: [PATCH 12/14] MAGETWO-64922: Missing appropriate payment informations --- .../Order/Payment/Collection.php | 31 +------ .../ConvertAdditionalInfoObserver.php | 80 +++++++++++++++++++ app/code/Magento/Sales/etc/events.xml | 3 + .../Block/Adminhtml/Order/View/Tab/Info.php | 21 +++++ .../Order/View/Tab/Info/PaymentInfoBlock.php | 40 ++++++++++ 5 files changed, 146 insertions(+), 29 deletions(-) create mode 100644 app/code/Magento/Sales/Observer/ConvertAdditionalInfoObserver.php create mode 100644 dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info/PaymentInfoBlock.php diff --git a/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php b/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php index d0ad42bee9c99..f4a7414530c58 100644 --- a/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php +++ b/app/code/Magento/Sales/Model/ResourceModel/Order/Payment/Collection.php @@ -5,7 +5,6 @@ */ namespace Magento\Sales\Model\ResourceModel\Order\Payment; -use Magento\Sales\Api\Data\OrderPaymentInterface; use Magento\Sales\Api\Data\OrderPaymentSearchResultInterface; use Magento\Sales\Model\ResourceModel\Order\Collection\AbstractCollection; @@ -68,7 +67,7 @@ protected function _construct() } /** - * Unserialize additional_information in each item + * Unserialize additional_information in each item. * * @return $this */ @@ -76,34 +75,8 @@ protected function _afterLoad() { foreach ($this->_items as $item) { $this->getResource()->unserializeFields($item); - if (!empty($item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) { - $additionalInfo = $this->convertAdditionalInfo( - $item->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION) - ); - $item->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo); - } } - return parent::_afterLoad(); - } - /** - * Convert multidimensional additional information array to single - * - * @param array $info - * @return array - */ - private function convertAdditionalInfo($info) - { - $result = []; - foreach ($info as $key => $item) { - if (is_array($item)) { - $result += $this->convertAdditionalInfo($item); - unset($info[$key]); - } else { - $result[$key] = $item; - } - } - - return $result; + return parent::_afterLoad(); } } diff --git a/app/code/Magento/Sales/Observer/ConvertAdditionalInfoObserver.php b/app/code/Magento/Sales/Observer/ConvertAdditionalInfoObserver.php new file mode 100644 index 0000000000000..f2853c30126ec --- /dev/null +++ b/app/code/Magento/Sales/Observer/ConvertAdditionalInfoObserver.php @@ -0,0 +1,80 @@ +state = $state; + } + + /** + * Convert additional info from multidimensional array into single one for API calls. + * + * @param Observer $observer + * @return void + */ + public function execute(\Magento\Framework\Event\Observer $observer) + { + /** @var Collection $paymentCollection */ + $paymentCollection = $observer->getData('order_payment_collection'); + $areaCode = $this->state->getAreaCode(); + if ($areaCode == Area::AREA_WEBAPI_REST || $areaCode == Area::AREA_WEBAPI_SOAP) { + foreach ($paymentCollection as $payment) { + if (!empty($payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION))) { + $additionalInfo = $this->convertAdditionalInfo( + $payment->getData(OrderPaymentInterface::ADDITIONAL_INFORMATION) + ); + $payment->setData(OrderPaymentInterface::ADDITIONAL_INFORMATION, $additionalInfo); + } + } + } + } + + /** + * Convert multidimensional additional information array to single. + * + * @param array $info + * @return array + */ + private function convertAdditionalInfo($info) + { + $result = []; + foreach ($info as $key => $item) { + if (is_array($item)) { + $result += $this->convertAdditionalInfo($item); + unset($info[$key]); + } else { + $result[$key] = $item; + } + } + + return $result; + } +} diff --git a/app/code/Magento/Sales/etc/events.xml b/app/code/Magento/Sales/etc/events.xml index 464f5a615b84f..164d7a23267f0 100644 --- a/app/code/Magento/Sales/etc/events.xml +++ b/app/code/Magento/Sales/etc/events.xml @@ -51,4 +51,7 @@ + + + diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php index d6fb589a0663d..cf7204dd72fdc 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info.php @@ -7,6 +7,7 @@ namespace Magento\Sales\Test\Block\Adminhtml\Order\View\Tab; use Magento\Mtf\Block\Block; +use Magento\Sales\Test\Block\Adminhtml\Order\View\Tab\Info\PaymentInfoBlock; /** * Order information tab block. @@ -20,6 +21,13 @@ class Info extends Block */ protected $orderStatus = '#order_status'; + /** + * Selector for 'Payment Information' block. + * + * @var string + */ + private $paymentInfoBlockSelector = '.order-payment-method'; + /** * Get order status from info block * @@ -29,4 +37,17 @@ public function getOrderStatus() { return $this->_rootElement->find($this->orderStatus)->getText(); } + + /** + * Returns Payment Information block. + * + * @return PaymentInfoBlock + */ + public function getPaymentInfoBlock() + { + return $this->blockFactory->create( + PaymentInfoBlock::class, + ['element' => $this->_rootElement->find($this->paymentInfoBlockSelector)] + ); + } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info/PaymentInfoBlock.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info/PaymentInfoBlock.php new file mode 100644 index 0000000000000..0d38cf5e19c05 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/View/Tab/Info/PaymentInfoBlock.php @@ -0,0 +1,40 @@ +_rootElement->getElements($this->info); + foreach ($elements as $row) { + $key = rtrim($row->find('th')->getText(), ':'); + $value = $row->find('td')->getText(); + $result[$key] = $value; + } + + return $result; + } +} From 1d0d5933661a8c5717807dfb6fc91f8f3a0c66a9 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Fri, 14 Apr 2017 10:38:22 +0300 Subject: [PATCH 13/14] MAGETWO-64922: Missing appropriate payment informations --- .../TestSuite/InjectableTests/MAGETWO-64922.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml new file mode 100644 index 0000000000000..594e2e902ba63 --- /dev/null +++ b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml @@ -0,0 +1,15 @@ + + + + + + + + + From 0f45ca14fcd9e771a359a5069dde8f87bb0c781a Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Fri, 14 Apr 2017 10:55:26 +0300 Subject: [PATCH 14/14] MAGETWO-64922: Missing appropriate payment informations --- .../TestSuite/InjectableTests/MAGETWO-64922.xml | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml diff --git a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml b/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml deleted file mode 100644 index 594e2e902ba63..0000000000000 --- a/dev/tests/functional/testsuites/Magento/Mtf/TestSuite/InjectableTests/MAGETWO-64922.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - -