diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php index 7789f79d907f85d2402a82899af1de3f63db29de..4059f06bccded2f5dbaec98de627a0dc90407eb9 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php @@ -491,7 +491,7 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D null )->join( ['e' => $this->getTable('catalog_product_entity')], - "i.entity_id=e.$linkField", + "i.entity_id=e.entity_id", [] )->where( 'e.type_id=?', @@ -502,7 +502,7 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D $select = $connection->select()->from( ['tp' => $this->getTable('catalog_product_entity_tier_price')], - [$linkField] + ['e.entity_id'] )->join( ['e' => $this->getTable('catalog_product_entity')], "tp.{$linkField} = e.{$linkField}", @@ -523,11 +523,11 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D )->columns( new \Zend_Db_Expr('MIN(tp.value)') )->group( - ["tp.{$linkField}", 'cg.customer_group_id', 'cw.website_id'] + ['e.entity_id', 'cg.customer_group_id', 'cw.website_id'] ); if (!empty($entityIds)) { - $select->where("tp.{$linkField} IN(?)", $entityIds); + $select->where('e.entity_id IN(?)', $entityIds); } $query = $select->insertFromSelect($this->_getTierPriceIndexTable()); diff --git a/app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php b/app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php index d57db33131b9d3cbe16f60119b9e97b82d72cdad..9a407b118461c19e0db02b92ad2b16a8eb8f5816 100644 --- a/app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php +++ b/app/code/Magento/CatalogWidget/Block/Product/Widget/Conditions.php @@ -85,7 +85,7 @@ class Conditions extends Template implements RendererInterface $widget = $this->registry->registry('current_widget_instance'); if ($widget) { $widgetParameters = $widget->getWidgetParameters(); - } elseif($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) { + } elseif ($widgetOptions = $this->getLayout()->getBlock('wysiwyg_widget.options')) { $widgetParameters = $widgetOptions->getWidgetValues(); } @@ -100,6 +100,7 @@ class Conditions extends Template implements RendererInterface public function render(AbstractElement $element) { $this->element = $element; + $this->rule->getConditions()->setJsFormObject($this->getHtmlId()); return $this->toHtml(); } diff --git a/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php b/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php index 8d87c0ebf0d21768bbe05f5903aded09011e1663..b825e92bab1c2ef2eea4d2c08cd8da1ac1e9e192 100644 --- a/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php +++ b/app/code/Magento/CatalogWidget/Test/Unit/Block/Product/Widget/ConditionsTest.php @@ -15,6 +15,7 @@ use Magento\Framework\View\Element\BlockInterface; /** * Test class for \Magento\CatalogWidget\Block\Product\Widget\Conditions + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ class ConditionsTest extends \PHPUnit_Framework_TestCase { @@ -175,4 +176,116 @@ class ConditionsTest extends \PHPUnit_Framework_TestCase ] ); } + + /** + * @return void + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ + public function testRender() + { + $data = ['area' => 'backend']; + $abstractElementMock = $this->getMock( + \Magento\Framework\Data\Form\Element\AbstractElement::class, + ['getContainer'], + [], + '', + false + ); + $eventManagerMock = $this->getMock( + \Magento\Framework\Event\ManagerInterface::class, + [], + [], + '', + false + ); + $scopeConfigMock = $this->getMock( + \Magento\Framework\App\Config\ScopeConfigInterface::class, + [], + [], + '', + false + ); + $fieldsetMock = $this->getMock( + \Magento\Framework\Data\Form\Element\Fieldset::class, + [], + [], + '', + false + ); + $combineMock = $this->getMock( + \Magento\Rule\Model\Condition\Combine::class, + [], + [], + '', + false + ); + $resolverMock = $this->getMock( + \Magento\Framework\View\Element\Template\File\Resolver::class, + [], + [], + '', + false + ); + $filesystemMock = $this->getMock( + \Magento\Framework\Filesystem::class, + ['getDirectoryRead'], + [], + '', + false + ); + $validatorMock = $this->getMock( + \Magento\Framework\View\Element\Template\File\Validator::class, + [], + [], + '', + false + ); + $templateEnginePoolMock = $this->getMock( + \Magento\Framework\View\TemplateEnginePool::class, + [], + [], + '', + false + ); + $templateEngineMock = $this->getMock( + \Magento\Framework\View\TemplateEngineInterface::class, + [], + [], + '', + false + ); + $directoryReadMock = $this->getMock( + \Magento\Framework\Filesystem\Directory\ReadInterface::class, + [], + [], + '', + false + ); + + $this->ruleMock->expects($this->once())->method('getConditions')->willReturn($combineMock); + $combineMock->expects($this->once())->method('setJsFormObject')->willReturnSelf(); + $abstractElementMock->expects($this->any())->method('getContainer')->willReturn($fieldsetMock); + $filesystemMock->expects($this->once())->method('getDirectoryRead')->willReturn($directoryReadMock); + $validatorMock->expects($this->once())->method('isValid')->willReturn(true); + $this->contextMock->expects($this->once())->method('getEnginePool')->willReturn($templateEnginePoolMock); + $templateEnginePoolMock->expects($this->once())->method('get')->willReturn($templateEngineMock); + $templateEngineMock->expects($this->once())->method('render')->willReturn('html'); + + $this->widgetConditions = $this->objectManagerHelper->getObject( + Conditions::class, + [ + 'context' => $this->contextMock, + 'registry' => $this->registryMock, + 'rule' => $this->ruleMock, + '_eventManager' => $eventManagerMock, + '_filesystem' => $filesystemMock, + '_scopeConfig' => $scopeConfigMock, + 'validator' => $validatorMock, + 'resolver' => $resolverMock, + 'data' => $data + ] + ); + + $this->assertEquals($this->widgetConditions->render($abstractElementMock), 'html'); + } } diff --git a/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php b/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php index d2febaccb2fdf3644774f89626e6224bf6e89415..cf9eed3e84d26860792c4d3751e138ad84863eb8 100644 --- a/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php +++ b/app/code/Magento/OfflineShipping/Model/Quote/Address/FreeShipping.php @@ -5,8 +5,6 @@ */ namespace Magento\OfflineShipping\Model\Quote\Address; -use Magento\Quote\Model\Quote\Address; - class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInterface { /** @@ -48,7 +46,8 @@ class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInt $quote->getCustomerGroupId(), $quote->getCouponCode() ); - + $shippingAddress = $quote->getShippingAddress(); + $shippingAddress->setFreeShipping(0); /** @var \Magento\Quote\Api\Data\CartItemInterface $item */ foreach ($items as $item) { if ($item->getNoDiscount()) { @@ -66,10 +65,14 @@ class FreeShipping implements \Magento\Quote\Model\Quote\Address\FreeShippingInt $itemFreeShipping = (bool)$item->getFreeShipping(); $addressFreeShipping = $addressFreeShipping && $itemFreeShipping; + if ($addressFreeShipping && !$item->getAddress()->getFreeShipping()) { + $item->getAddress()->setFreeShipping(true); + } + /** Parent free shipping we apply to all children*/ $this->applyToChildren($item, $itemFreeShipping); } - return $addressFreeShipping; + return (bool)$shippingAddress->getFreeShipping(); } /** diff --git a/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php b/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php new file mode 100644 index 0000000000000000000000000000000000000000..27f3c375c91c5a70de74c3ed620838ec358144db --- /dev/null +++ b/app/code/Magento/OfflineShipping/Test/Unit/Model/Quote/Address/FreeShippingTest.php @@ -0,0 +1,111 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\OfflineShipping\Test\Unit\Model\Quote\Address; + +use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper; + +class FreeShippingTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\OfflineShipping\Model\Quote\Address\FreeShipping + */ + private $model; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Store\Model\StoreManagerInterface + */ + private $storeManagerMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\OfflineShipping\Model\SalesRule\Calculator + */ + private $calculatorMock; + + protected function setUp() + { + $this->storeManagerMock = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class); + $this->calculatorMock = $this->getMock( + \Magento\OfflineShipping\Model\SalesRule\Calculator::class, + [], + [], + '', + false + ); + + $this->model = new \Magento\OfflineShipping\Model\Quote\Address\FreeShipping( + $this->storeManagerMock, + $this->calculatorMock + ); + } + + public function testIsFreeShippingIfNoItems() + { + $quoteMock = $this->getMock(\Magento\Quote\Model\Quote::class, [], [], '', false); + $this->assertFalse($this->model->isFreeShipping($quoteMock, [])); + } + + public function testIsFreeShipping() + { + $storeId = 100; + $websiteId = 200; + $customerGroupId = 300; + $objectManagerMock = new ObjectManagerHelper($this); + $quoteMock = $this->getMock( + \Magento\Quote\Model\Quote::class, + ['getShippingAddress', 'getStoreId', 'getCustomerGroupId', 'getCouponCode'], + [], + '', + false + ); + $itemMock = $this->getMock( + \Magento\Quote\Model\Quote\Item::class, + [ + 'getNoDiscount', + 'getParentItemId', + 'getFreeShipping', + 'getAddress', + 'isChildrenCalculated', + 'getHasChildren', + 'getChildren' + ], + [], + '', + false + ); + + $quoteMock->expects($this->once())->method('getStoreId')->willReturn($storeId); + $storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class); + $storeMock->expects($this->once())->method('getWebsiteId')->willReturn($websiteId); + $this->storeManagerMock->expects($this->once())->method('getStore')->with($storeId)->willReturn($storeMock); + + $quoteMock->expects($this->once())->method('getCustomerGroupId')->willReturn($customerGroupId); + $quoteMock->expects($this->once())->method('getCouponCode')->willReturn(null); + + $this->calculatorMock->expects($this->once()) + ->method('init') + ->with($websiteId, $customerGroupId, null) + ->willReturnSelf(); + + $itemMock->expects($this->once())->method('getNoDiscount')->willReturn(false); + $itemMock->expects($this->once())->method('getParentItemId')->willReturn(false); + $this->calculatorMock->expects($this->exactly(2))->method('processFreeShipping')->willReturnSelf(); + $itemMock->expects($this->once())->method('getFreeShipping')->willReturn(true); + + $addressMock = $objectManagerMock->getObject(\Magento\Quote\Model\Quote\Address::class); + $quoteMock->expects($this->once())->method('getShippingAddress')->willReturn($addressMock); + $itemMock->expects($this->exactly(2))->method('getAddress')->willReturn($addressMock); + + $itemMock->expects($this->once())->method('getHasChildren')->willReturn(true); + $itemMock->expects($this->once())->method('isChildrenCalculated')->willReturn(true); + + $childMock = $this->getMock(\Magento\Quote\Model\Quote\Item::class, ['setFreeShipping'], [], '', false); + $childMock->expects($this->once())->method('setFreeShipping')->with(true)->willReturnSelf(); + $itemMock->expects($this->once())->method('getChildren')->willReturn([$childMock]); + + $this->assertTrue($this->model->isFreeShipping($quoteMock, [$itemMock])); + } +} diff --git a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php index cd049799e7b497b5b657bd03122a2dcf4e2986ab..ae9ea20fd35fd110e796d87564409cadcd8fe57e 100644 --- a/app/code/Magento/Sales/Block/Status/Grid/Column/State.php +++ b/app/code/Magento/Sales/Block/Status/Grid/Column/State.php @@ -49,8 +49,9 @@ class State extends \Magento\Backend\Block\Widget\Grid\Column */ public function decorateState($value, $row, $column, $isExport) { + $status = $row->getStatus(); if ($value) { - $cell = $value . '[' . $this->_config->getStateLabel($value) . ']'; + $cell = $value . '[' . $this->_config->getStateLabelByStateAndStatus($value, $status) . ']'; } else { $cell = $value; } diff --git a/app/code/Magento/Sales/Model/Order/Config.php b/app/code/Magento/Sales/Model/Order/Config.php index 8c6f2e55f55acfa9ea8b0c26e25efac97f330f30..535e2975ee13da8458cba83666ba49abb942a89a 100644 --- a/app/code/Magento/Sales/Model/Order/Config.php +++ b/app/code/Magento/Sales/Model/Order/Config.php @@ -256,4 +256,22 @@ class Config } return $this->statuses[(bool) $visibility]; } + + /** + * Retrieve label by state and status + * + * @param string $state + * @param string $status + * @return \Magento\Framework\Phrase|string + */ + public function getStateLabelByStateAndStatus($state, $status) + { + foreach ($this->_getCollection() as $item) { + if ($item->getData('state') == $state && $item->getData('status') == $status) { + $label = $item->getData('label'); + return __($label); + } + } + return $state; + } } diff --git a/app/code/Magento/Sales/Setup/UpgradeSchema.php b/app/code/Magento/Sales/Setup/UpgradeSchema.php index d35825242fb291a41961eb882ad93f7d24c58ee9..288e8085a0dab51947905ed0254e69c8479e79ff 100644 --- a/app/code/Magento/Sales/Setup/UpgradeSchema.php +++ b/app/code/Magento/Sales/Setup/UpgradeSchema.php @@ -76,8 +76,9 @@ class UpgradeSchema implements UpgradeSchemaInterface 'sales_shipment_grid', ]; foreach ($tables as $table) { - $setup->getConnection()->modifyColumn( - $setup->getTable($table), + $salesConnection = $setup->getConnection(self::$connectionName); + $salesConnection->modifyColumn( + $installer->getTable($table, self::$connectionName), 'customer_group_id', ['type' => 'integer'] ); diff --git a/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php b/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php new file mode 100644 index 0000000000000000000000000000000000000000..59e7accb583d051a62821276a3c6521c8abb54f2 --- /dev/null +++ b/app/code/Magento/Sales/Test/Unit/Block/Status/Grid/Column/StateTest.php @@ -0,0 +1,91 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\Sales\Test\Unit\Block\Status\Grid\Column; + +class StateTest extends \PHPUnit_Framework_TestCase +{ + /** + * @var \Magento\Sales\Block\Status\Grid\Column\State + */ + private $stateColumn; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $orderStatusCollectionFactoryMock; + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $configMock; + + protected function setUp() + { + $helper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $this->orderStatusCollectionFactoryMock = $this->getMock( + \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory::class, + ['create'], + [], + '', + false, + false + ); + $this->configMock = $helper->getObject( + \Magento\Sales\Model\Order\Config::class, + [ + 'orderStatusCollectionFactory' => $this->orderStatusCollectionFactoryMock + ] + ); + $this->stateColumn = $helper + ->getObject( + \Magento\Sales\Block\Status\Grid\Column\State::class, + [ + 'config' => $this->configMock, + ] + ); + } + + public function testDecorateState() + { + $rowMock = $this->getMock(\Magento\Sales\Model\Order\Status::class, [], [], '', false); + $rowMock->expects($this->any())->method('getStatus')->willReturn('fraud'); + $columnMock = $this->getMock(\Magento\Backend\Block\Widget\Grid\Column::class, [], [], '', false); + $statuses = [ + new \Magento\Framework\DataObject( + [ + 'status' => 'fraud', + 'state' => 'processing', + 'label' => 'Suspected Fraud', + ] + ), + new \Magento\Framework\DataObject( + [ + 'status' => 'processing', + 'state' => 'processing', + 'label' => 'Processing', + ] + ) + ]; + $collectionMock = $this->getMock( + \Magento\Sales\Model\ResourceModel\Order\Status\Collection::class, + ['create', 'joinStates'], + [], + '', + false, + false + ); + $this->orderStatusCollectionFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($collectionMock)); + $collectionMock->expects($this->once()) + ->method('joinStates') + ->will($this->returnValue($statuses)); + + $result = $this->stateColumn->decorateState('processing', $rowMock, $columnMock, false); + $this->assertSame('processing[processing]', $result); + } +} diff --git a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php index 1f29235efaef29a790daccd7cf16447d9254adac..7ee4f745cde8f75de23147c956ca0bf039ab2e3a 100644 --- a/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php +++ b/app/code/Magento/Sales/Test/Unit/Model/Order/ConfigTest.php @@ -5,8 +5,6 @@ */ namespace Magento\Sales\Test\Unit\Model\Order; -use \Magento\Sales\Model\Order\Config; - /** * Class ConfigTest */ @@ -95,4 +93,40 @@ class ConfigTest extends \PHPUnit_Framework_TestCase $result = $this->salesConfig->getInvisibleOnFrontStatuses(); $this->assertSame($expectedResult, $result); } + + public function testGetStateLabelByStateAndStatus() + { + $statuses = [ + new \Magento\Framework\DataObject( + [ + 'status' => 'fraud', + 'state' => 'processing', + 'label' => 'Suspected Fraud', + ] + ), + new \Magento\Framework\DataObject( + [ + 'status' => 'processing', + 'state' => 'processing', + 'label' => 'Processing', + ] + ) + ]; + $collectionMock = $this->getMock( + \Magento\Sales\Model\ResourceModel\Order\Status\Collection::class, + ['create', 'joinStates'], + [], + '', + false, + false + ); + $this->orderStatusCollectionFactoryMock->expects($this->once()) + ->method('create') + ->will($this->returnValue($collectionMock)); + $collectionMock->expects($this->once()) + ->method('joinStates') + ->will($this->returnValue($statuses)); + $result = $this->salesConfig->getStateLabelByStateAndStatus('processing', 'fraud'); + $this->assertSame('Suspected Fraud', $result->getText()); + } } diff --git a/app/code/Magento/Vault/Setup/UpgradeData.php b/app/code/Magento/Vault/Setup/UpgradeData.php index 757b5f4d3167cb00254e8f2ef20fad3addc1cb27..1c3f113ba9831de6123cbf0c0af361a0f520a1fb 100644 --- a/app/code/Magento/Vault/Setup/UpgradeData.php +++ b/app/code/Magento/Vault/Setup/UpgradeData.php @@ -20,9 +20,11 @@ use Magento\Vault\Model\CreditCardTokenFactory; class UpgradeData implements UpgradeDataInterface { /** - * @var AdapterInterface + * Predefined name for sales connection + * + * @var string */ - private $connection; + private static $salesConnectionName = 'sales'; /** * @inheritdoc @@ -30,12 +32,11 @@ class UpgradeData implements UpgradeDataInterface public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - $connection = $this->getConnection(); // data update for Vault module < 2.0.1 if (version_compare($context->getVersion(), '2.0.1', '<')) { // update sets credit card as default token type - $connection->update($setup->getTable(InstallSchema::PAYMENT_TOKEN_TABLE), [ + $setup->getConnection()->update($setup->getTable(InstallSchema::PAYMENT_TOKEN_TABLE), [ PaymentTokenInterface::TYPE => CreditCardTokenFactory::TOKEN_TYPE_CREDIT_CARD ], PaymentTokenInterface::TYPE . ' = ""'); } @@ -43,12 +44,13 @@ class UpgradeData implements UpgradeDataInterface // data update for Vault module < 2.0.2 if (version_compare($context->getVersion(), '2.0.2', '<')) { // update converts additional info with token metadata to single dimensional array - $select = $connection->select() + $salesConnection = $setup->getConnection(self::$salesConnectionName); + $select = $salesConnection->select() ->from($setup->getTable('sales_order_payment'), 'entity_id') ->columns(['additional_information']) ->where('additional_information LIKE ?', '%token_metadata%'); - $items = $connection->fetchAll($select); + $items = $salesConnection->fetchAll($select); foreach ($items as $item) { $additionalInfo = unserialize($item['additional_information']); $additionalInfo[PaymentTokenInterface::CUSTOMER_ID] = @@ -57,7 +59,7 @@ class UpgradeData implements UpgradeDataInterface $additionalInfo['token_metadata'][PaymentTokenInterface::PUBLIC_HASH]; unset($additionalInfo['token_metadata']); - $connection->update( + $salesConnection->update( $setup->getTable('sales_order_payment'), ['additional_information' => serialize($additionalInfo)], ['entity_id = ?' => $item['entity_id']] @@ -67,23 +69,4 @@ class UpgradeData implements UpgradeDataInterface $setup->endSetup(); } - - /** - * Tries to get connection for scalable sales DB, otherwise returns default connection - * @return AdapterInterface - */ - private function getConnection() - { - if ($this->connection === null) { - /** @var ResourceConnection $conn */ - $conn = ObjectManager::getInstance()->get(ResourceConnection::class); - try { - $this->connection = $conn->getConnectionByName('sales'); - } catch (\DomainException $e) { - $this->connection = $conn->getConnection(); - } - } - - return $this->connection; - } } diff --git a/dev/tests/functional/tests/app/Magento/Bundle/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Bundle/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..a34bf44d38cae01f46f711fd6181c1ae8895ae68 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Bundle/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyComparedProductsOnOrderPageTest"> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariationWithBundleProduct1"> + <data name="products/0" xsi:type="string">bundleProduct::bundle_dynamic_product</data> + <data name="products/1" xsi:type="string">bundleProduct::bundle_dynamic_product</data> + <data name="productsIsConfigured" xsi:type="boolean">true</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Bundle/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/Bundle/Test/etc/di.xml index 402dcca44c9485a46d9c40b5103f1cac50b86122..61eac871df9722550fff8735930febc339e4ea4d 100644 --- a/dev/tests/functional/tests/app/Magento/Bundle/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/Bundle/Test/etc/di.xml @@ -11,4 +11,17 @@ <argument name="severity" xsi:type="string">S2</argument> </arguments> </type> + <type name="Magento\Sales\Test\Block\Adminhtml\Order\Create\CustomerActivities\Sidebar\RecentlyComparedProducts"> + <arguments> + <argument name="config" xsi:type="array"> + <item name="renders" xsi:type="array"> + <item name="bundle" xsi:type="array"> + <item name="class" xsi:type="string">\Magento\Bundle\Test\Block\Adminhtml\Product\Composite\Configure</item> + <item name="locator" xsi:type="string">//ancestor::body//*[contains(@class, "modal-slide") and contains(@class, "_show")]</item> + <item name="strategy" xsi:type="string">xpath</item> + </item> + </item> + </argument> + </arguments> + </type> </config> diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Page/Adminhtml/OrderCreateIndex.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Page/Adminhtml/OrderCreateIndex.xml index a67119cbf19aa5ac5aa1541672a30242edd29a93..97809af4bff7875f1bb4c90fe0f3a9c05d037b24 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Page/Adminhtml/OrderCreateIndex.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/Page/Adminhtml/OrderCreateIndex.xml @@ -6,9 +6,9 @@ */ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../../vendor/magento/mtf/etc/pages.xsd"> - <page name="OrderCreateIndex" area="Adminhtml" mca="sales/order_create/index"> - <block name="configureProductBlock"> - <render name="configurable" class="Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Composite\Configure"/> - </block> - </page> + <page name="OrderCreateIndex" area="Adminhtml" mca="sales/order_create/index"> + <block name="configureProductBlock"> + <render name="configurable" class="Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Composite\Configure" /> + </block> + </page> </config> diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateCreditMemoEntityTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateCreditMemoEntityTest.xml index dd92edc82b3310ad9610c70138578a220e4358cd..8a8195db638d565564ae0e2bdf20ad46fbb05bbd 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateCreditMemoEntityTest.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/CreateCreditMemoEntityTest.xml @@ -14,6 +14,7 @@ <data name="order/dataset" xsi:type="string">default</data> <data name="order/data/entity_id/products" xsi:type="string">configurableProduct::configurable_with_qty_1</data> <data name="order/data/price/dataset" xsi:type="string">full_refund</data> + <data name="configData" xsi:type="string"/> <constraint name="Magento\Sales\Test\Constraint\AssertRefundSuccessCreateMessage" /> <constraint name="Magento\ConfigurableProduct\Test\Constraint\AssertProductQtyDecreasedAfterCreditmemo" /> </variation> diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..aaa9b3e1f88f918aa63f852b28a5ac653f94cdef --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml @@ -0,0 +1,16 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyComparedProductsOnOrderPageTest"> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariationWithConfigurableProduct1"> + <data name="products/0" xsi:type="string">configurableProduct::configurable_with_qty_1</data> + <data name="products/1" xsi:type="string">configurableProduct::configurable_with_qty_1</data> + <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml index 002ccfc4ed80ca48fb1b851558efa909b2e1c503..8bdf098cea58341cf83b081fca7bc946281e4884 100644 --- a/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml +++ b/dev/tests/functional/tests/app/Magento/ConfigurableProduct/Test/etc/di.xml @@ -26,4 +26,17 @@ <argument name="severity" xsi:type="string">high</argument> </arguments> </type> + <type name="Magento\Sales\Test\Block\Adminhtml\Order\Create\CustomerActivities\Sidebar\RecentlyComparedProducts"> + <arguments> + <argument name="config" xsi:type="array"> + <item name="renders" xsi:type="array"> + <item name="configurable" xsi:type="array"> + <item name="class" xsi:type="string">Magento\ConfigurableProduct\Test\Block\Adminhtml\Product\Composite\Configure</item> + <item name="locator" xsi:type="string">//ancestor::body//*[contains(@class, "modal-slide") and contains(@class, "_show")]</item> + <item name="strategy" xsi:type="string">xpath</item> + </item> + </item> + </argument> + </arguments> + </type> </config> diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Adminhtml/Product/Composite/Configure.xml b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Adminhtml/Product/Composite/Configure.xml index 04a918c3bf8d9598b74b0f53ebd41b9f477e778f..676ae6a64f3d820b4d65d821053d6d0ab7971542 100644 --- a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Adminhtml/Product/Composite/Configure.xml +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Block/Adminhtml/Product/Composite/Configure.xml @@ -8,7 +8,7 @@ <mapping strict="0"> <fields> <qty> - <selector>//tr[contains(.,"%product_name%")]//input[contains(@class,"qty")]</selector> + <selector>.//tr[contains(.,"%product_name%")]//input[contains(@class,"qty")]</selector> <strategy>xpath</strategy> </qty> </fields> diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Constraint/AssertProductInItemsOrderedGrid.php b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Constraint/AssertProductInItemsOrderedGrid.php new file mode 100644 index 0000000000000000000000000000000000000000..918c86f93340730e19ac576c1cda37255d86f0b3 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/Constraint/AssertProductInItemsOrderedGrid.php @@ -0,0 +1,57 @@ +<?php +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +namespace Magento\GroupedProduct\Test\Constraint; + +/** + * Assert product was added to Items Ordered grid in customer account on Order creation page backend. + */ +class AssertProductInItemsOrderedGrid extends \Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid +{ + /** + * Prepare data. + * + * @param array $data + * @param \Magento\Sales\Test\Block\Adminhtml\Order\Create\Items $itemsBlock + * @return array + */ + protected function prepareData(array $data, \Magento\Sales\Test\Block\Adminhtml\Order\Create\Items $itemsBlock) + { + $fixtureData = []; + foreach ($data as $product) { + $fixtureData = array_merge($fixtureData, $this->getOptionsDetails($product)); + } + $pageData = $itemsBlock->getProductsDataByFields($this->fields); + $preparePageData = $this->arraySort($fixtureData, $pageData); + return ['fixtureData' => $fixtureData, 'pageData' => $preparePageData]; + } + + /** + * Get product options details. + * + * @param \Magento\Mtf\Fixture\FixtureInterface $product + * @return array + */ + private function getOptionsDetails(\Magento\Mtf\Fixture\FixtureInterface $product) + { + /** @var \Magento\GroupedProduct\Test\Fixture\GroupedProduct $product */ + $fixtureProducts = []; + $optionsPrices = $this->getProductPrice($product); + $optionsQtys = $product->getCheckoutData()['cartItem']['qty']; + $assignedProducts = $product->getAssociated()['assigned_products']; + + foreach ($assignedProducts as $key => $assignedProduct) { + $fixtureProducts[] = [ + 'name' => $assignedProduct['name'], + 'price' => number_format($optionsPrices['product_key_' . $key], 2), + 'checkout_data' => [ + 'qty' => $this->productsIsConfigured ? $optionsQtys['product_key_' . $key] : 1 + ] + ]; + } + return $fixtureProducts; + } +} diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml new file mode 100644 index 0000000000000000000000000000000000000000..1de8aeda4e9a4415b476d73c8b454b17ad4f5824 --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 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/variations.xsd"> + <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyComparedProductsOnOrderPageTest"> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariationWithGroupedProduct1"> + <data name="products/0" xsi:type="string">groupedProduct::three_simple_products</data> + <data name="products/1" xsi:type="string">groupedProduct::three_simple_products</data> + <data name="productsIsConfigured" xsi:type="boolean">true</data> + <constraint name="Magento\GroupedProduct\Test\Constraint\AssertProductInItemsOrderedGrid" /> + </variation> + </testCase> +</config> diff --git a/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/etc/di.xml b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/etc/di.xml new file mode 100644 index 0000000000000000000000000000000000000000..5b12a012749fb6feb0e90b1910d964a19394ca8d --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/GroupedProduct/Test/etc/di.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + --> +<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> + <type name="Magento\Sales\Test\Block\Adminhtml\Order\Create\CustomerActivities\Sidebar\RecentlyComparedProducts"> + <arguments> + <argument name="config" xsi:type="array"> + <item name="renders" xsi:type="array"> + <item name="grouped" xsi:type="array"> + <item name="class" xsi:type="string">\Magento\GroupedProduct\Test\Block\Adminhtml\Product\Composite\Configure</item> + <item name="locator" xsi:type="string">//ancestor::body//*[contains(@class, "modal-slide") and contains(@class, "_show")]</item> + <item name="strategy" xsi:type="string">xpath</item> + </item> + </item> + </argument> + </arguments> + </type> +</config> diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php index 050f797d83825e99eaf08728c2dc69149f8faaae..3fc41e0db1785d06eb29bd58b7343b02a274ee00 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Adminhtml/Order/Create/CustomerActivities/Sidebar.php @@ -21,6 +21,13 @@ abstract class Sidebar extends Block */ protected $addToOrder = './/tr[td[.="%s"]]//input[contains(@name,"add")]'; + /** + * 'Add to order' configure. + * + * @var string + */ + protected $addToOrderConfigure = './/tr[td[contains(.,"%s")]]//a[contains(@class, "icon-configure")]'; + /** * 'Add to order' checkbox. * @@ -39,9 +46,18 @@ abstract class Sidebar extends Block foreach ($products as $product) { $name = $product->getName(); $this->_rootElement->find(sprintf($this->addToOrderProductName, $name), Locator::SELECTOR_XPATH)->click(); - $this->_rootElement->click(); - $this->_rootElement->find(sprintf($this->addToOrder, $name), Locator::SELECTOR_XPATH, 'checkbox') - ->setValue('Yes'); + + $dataConfig = $product->getDataConfig(); + $typeId = isset($dataConfig['type_id']) ? $dataConfig['type_id'] : null; + + if ($this->hasRender($typeId)) { + $this->_rootElement->find(sprintf($this->addToOrderConfigure, $name), Locator::SELECTOR_XPATH)->click(); + $this->callRender($typeId, 'configProduct', ['product' => $product]); + } else { + $this->_rootElement->click(); + $this->_rootElement->find(sprintf($this->addToOrder, $name), Locator::SELECTOR_XPATH, 'checkbox') + ->setValue('Yes'); + } } } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php index 49487ff1b2e8ea9b9e23543a44a2878b797c4f2c..a501ec3cd228d8c60a5225027719e463dbf6c688 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.php @@ -142,9 +142,10 @@ class MoveRecentlyComparedProductsOnOrderPageTest extends Injectable * * @param Customer $customer * @param string $products + * @param bool $productsIsConfigured * @return array */ - public function test(Customer $customer, $products) + public function test(Customer $customer, $products, $productsIsConfigured = false) { // Preconditions // Create product @@ -168,6 +169,6 @@ class MoveRecentlyComparedProductsOnOrderPageTest extends Injectable $activitiesBlock->getRecentlyComparedProductsBlock()->addProductsToOrder($products); $activitiesBlock->updateChanges(); - return ['products' => $products, 'productsIsConfigured' => false]; + return ['products' => $products, 'productsIsConfigured' => $productsIsConfigured]; } } diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml index 601f550e4588bfd3c613ef8a50e8615174b298ae..76282ff3eec53867d257029f5184b941899ac2db 100644 --- a/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml +++ b/dev/tests/functional/tests/app/Magento/Sales/Test/TestCase/MoveRecentlyComparedProductsOnOrderPageTest.xml @@ -7,17 +7,10 @@ --> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../../vendor/magento/mtf/etc/variations.xsd"> <testCase name="Magento\Sales\Test\TestCase\MoveRecentlyComparedProductsOnOrderPageTest" summary="Add Products to Order from Recently Compared Products Section" ticketId="MAGETWO-28109"> - <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariation1"> - <data name="tag" xsi:type="string">stable:no</data> + <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariationWithSimpleProduct1"> <data name="products/0" xsi:type="string">catalogProductSimple::default</data> <data name="products/1" xsi:type="string">catalogProductSimple::default</data> <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> </variation> - <variation name="MoveRecentlyComparedProductsOnOrderPageTestVariation2"> - <data name="tag" xsi:type="string">to_maintain:yes</data> - <data name="products/0" xsi:type="string">configurableProduct::configurable_with_qty_1</data> - <data name="products/1" xsi:type="string">configurableProduct::configurable_with_qty_1</data> - <constraint name="Magento\Sales\Test\Constraint\AssertProductInItemsOrderedGrid" /> - </variation> </testCase> </config>