From 7c03614c09fe85893e5ab8f4d78bd9bb5880af56 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Wed, 10 Jan 2018 18:29:00 +0200 Subject: [PATCH 01/16] magento/magento2#5015: Report error csv doesn't work when trying to import a csv file with semicolon delimiter[forwardport]. --- .../Magento/ImportExport/Helper/Report.php | 11 +++++++- .../Magento/ImportExport/Model/Report/Csv.php | 3 ++- .../Test/Unit/Helper/ReportTest.php | 25 +++++++++++++++++++ .../Test/Unit/Model/Report/CsvTest.php | 14 ++++++++++- .../Adminhtml/Import/ValidateTest.php | 23 +++++++++++++---- .../incorrect_catalog_product_comma.csv | 2 ++ .../incorrect_catalog_product_semicolon.csv | 2 ++ 7 files changed, 72 insertions(+), 8 deletions(-) create mode 100644 dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_comma.csv create mode 100644 dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_semicolon.csv diff --git a/app/code/Magento/ImportExport/Helper/Report.php b/app/code/Magento/ImportExport/Helper/Report.php index 708aa2e39df9a..92eaecfc16903 100644 --- a/app/code/Magento/ImportExport/Helper/Report.php +++ b/app/code/Magento/ImportExport/Helper/Report.php @@ -7,7 +7,6 @@ namespace Magento\ImportExport\Helper; use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Stdlib\DateTime; use Magento\ImportExport\Model\Import; /** @@ -127,4 +126,14 @@ protected function getFilePath($filename) { return $this->varDirectory->getRelativePath(Import::IMPORT_HISTORY_DIR . $filename); } + + /** + * Get csv delimiter from request. + * + * @return string + */ + public function getDelimiter() + { + return $this->_request->getParam(Import::FIELD_FIELD_SEPARATOR, ','); + } } diff --git a/app/code/Magento/ImportExport/Model/Report/Csv.php b/app/code/Magento/ImportExport/Model/Report/Csv.php index f45910e519847..86c68d7c4df77 100644 --- a/app/code/Magento/ImportExport/Model/Report/Csv.php +++ b/app/code/Magento/ImportExport/Model/Report/Csv.php @@ -130,7 +130,8 @@ protected function createSourceCsvModel($sourceFile) return $this->sourceCsvFactory->create( [ 'file' => $sourceFile, - 'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR) + 'directory' => $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR), + 'delimiter' => $this->reportHelper->getDelimiter(), ] ); } diff --git a/app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php b/app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php index baaf0071e54ea..52b6bdcfc5ee7 100644 --- a/app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php +++ b/app/code/Magento/ImportExport/Test/Unit/Helper/ReportTest.php @@ -44,12 +44,21 @@ class ReportTest extends \PHPUnit\Framework\TestCase */ protected $report; + /** + * @var \Magento\Framework\App\Request\Http|\PHPUnit_Framework_MockObject_MockObject + */ + private $requestMock; + /** * Set up */ protected function setUp() { $this->context = $this->createMock(\Magento\Framework\App\Helper\Context::class); + $this->requestMock = $this->getMockBuilder(\Magento\Framework\App\Request\Http::class) + ->disableOriginalConstructor() + ->getMock(); + $this->context->expects($this->any())->method('getRequest')->willReturn($this->requestMock); $this->timezone = $this->createPartialMock( \Magento\Framework\Stdlib\DateTime\Timezone::class, ['date', 'getConfigTimezone', 'diff', 'format'] @@ -159,4 +168,20 @@ public function testGetReportSize() $result = $this->report->getReportSize('file'); $this->assertNull($result); } + + /** + * Test getDelimiter() take into consideration request param '_import_field_separator'. + */ + public function testGetDelimiter() + { + $testDelimiter = 'some delimiter'; + $this->requestMock->expects($this->once()) + ->method('getParam') + ->with($this->identicalTo(\Magento\ImportExport\Model\Import::FIELD_FIELD_SEPARATOR)) + ->willReturn($testDelimiter); + $this->assertEquals( + $testDelimiter, + $this->report->getDelimiter() + ); + } } diff --git a/app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php b/app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php index a305127f8461b..cf961d033946e 100644 --- a/app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php +++ b/app/code/Magento/ImportExport/Test/Unit/Model/Report/CsvTest.php @@ -45,8 +45,10 @@ class CsvTest extends \PHPUnit\Framework\TestCase protected function setUp() { $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + $testDelimiter = 'some_delimiter'; $this->reportHelperMock = $this->createMock(\Magento\ImportExport\Helper\Report::class); + $this->reportHelperMock->expects($this->any())->method('getDelimiter')->willReturn($testDelimiter); $this->outputCsvFactoryMock = $this->createPartialMock( \Magento\ImportExport\Model\Export\Adapter\CsvFactory::class, @@ -65,7 +67,17 @@ protected function setUp() [23 => 'first error'], [27 => 'second error'] ); - $this->sourceCsvFactoryMock->expects($this->any())->method('create')->willReturn($this->sourceCsvMock); + $this->sourceCsvFactoryMock + ->expects($this->any()) + ->method('create') + ->with( + [ + 'file' => 'some_file_name', + 'directory' => null, + 'delimiter' => $testDelimiter + ] + ) + ->willReturn($this->sourceCsvMock); $this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class); diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php index f30663a199a67..552a23a0c1fd5 100644 --- a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/ValidateTest.php @@ -18,10 +18,11 @@ class ValidateTest extends \Magento\TestFramework\TestCase\AbstractBackendContro * @dataProvider validationDataProvider * @param string $fileName * @param string $message + * @param string $delimiter * @backupGlobals enabled * @magentoDbIsolation enabled */ - public function testValidationReturn($fileName, $message) + public function testValidationReturn($fileName, $message, $delimiter) { $validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR; @@ -36,7 +37,7 @@ public function testValidationReturn($fileName, $message) $this->getRequest()->setPostValue('behavior', 'append'); $this->getRequest()->setPostValue(Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy); $this->getRequest()->setPostValue(Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0); - $this->getRequest()->setPostValue('_import_field_separator', ','); + $this->getRequest()->setPostValue('_import_field_separator', $delimiter); /** @var \Magento\TestFramework\App\Filesystem $filesystem */ $filesystem = $this->_objectManager->get(\Magento\Framework\Filesystem::class); @@ -83,12 +84,24 @@ public function validationDataProvider() return [ [ 'file_name' => 'catalog_product.csv', - 'message' => 'File is valid' + 'message' => 'File is valid', + 'delimiter' => ',', ], [ 'file_name' => 'test.txt', - 'message' => '\'txt\' file extension is not supported' - ] + 'message' => '\'txt\' file extension is not supported', + 'delimiter' => ',', + ], + [ + 'file_name' => 'incorrect_catalog_product_comma.csv', + 'message' => 'Download full report', + 'delimiter' => ',', + ], + [ + 'file_name' => 'incorrect_catalog_product_semicolon.csv', + 'message' => 'Download full report', + 'delimiter' => ';', + ], ]; } } diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_comma.csv b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_comma.csv new file mode 100644 index 0000000000000..67114a40b2244 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_comma.csv @@ -0,0 +1,2 @@ +sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,related_position,crosssell_skus,crosssell_position,upsell_skus,upsell_position,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,bundle_shipment_type,configurable_variations,configurable_variation_labels,associated_skus +Simple,,Default,simple,"Default Category/New",base,Simple,,,,1,"Taxable Goods","Catalo g, Search",100.0000,,,,simple,Simple,Simple,"Simple ",,,,,,,,,"10/25/17, 8:21 AM","10/25/17, 8:21 AM",,,"Block after Info Column",,,,"Use config",,,,,,,,,,100.0000,0.0000,1,0,0,1,1.0000,1,10000.0000,1,1,1.0000,1,1,1,1,1.0000,1,0,0,0,,,,,,,,,,,,,,,,,,, diff --git a/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_semicolon.csv b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_semicolon.csv new file mode 100644 index 0000000000000..d0a0b8639cf78 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/ImportExport/Controller/Adminhtml/Import/_files/incorrect_catalog_product_semicolon.csv @@ -0,0 +1,2 @@ +sku;store_view_code;attribute_set_code;product_type;categories;product_websites;name;description;short_description;weight;product_online;tax_class_name;visibility;price;special_price;special_price_from_date;special_price_to_date;url_key;meta_title;meta_keywords;meta_description;base_image;base_image_label;small_image;small_image_label;thumbnail_image;thumbnail_image_label;swatch_image;swatch_image_label;created_at;updated_at;new_from_date;new_to_date;display_product_options_in;map_price;msrp_price;map_enabled;gift_message_available;custom_design;custom_design_from;custom_design_to;custom_layout_update;page_layout;product_options_container;msrp_display_actual_price_type;country_of_manufacture;additional_attributes;qty;out_of_stock_qty;use_config_min_qty;is_qty_decimal;allow_backorders;use_config_backorders;min_cart_qty;use_config_min_sale_qty;max_cart_qty;use_config_max_sale_qty;is_in_stock;notify_on_stock_below;use_config_notify_stock_qty;manage_stock;use_config_manage_stock;use_config_qty_increments;qty_increments;use_config_enable_qty_inc;enable_qty_increments;is_decimal_divided;website_id;related_skus;related_position;crosssell_skus;crosssell_position;upsell_skus;upsell_position;additional_images;additional_image_labels;hide_from_product_page;custom_options;bundle_price_type;bundle_sku_type;bundle_price_view;bundle_weight_type;bundle_values;bundle_shipment_type;configurable_variations;configurable_variation_labels;associated_skus +Simple;;Default;simple;"Default Category/New";base;Simple;;;;1;"Taxable Goods";"Catalo g, Search";100.0000;;;;simple;Simple;Simple;"Simple ";;;;;;;;;"10/25/17, 8,21 AM";"10/25/17, 8,21 AM";;;"Block after Info Column";;;;"Use config";;;;;;;;;;100.0000;0.0000;1;0;0;1;1.0000;1;10000.0000;1;1;1.0000;1;1;1;1;1.0000;1;0;0;0;;;;;;;;;;;;;;;;;;; From c4fbc5c115d79b5d69f9ae909700e446422e9976 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Jan 2018 17:16:10 +0700 Subject: [PATCH 02/16] Fix URL passed to static.php in PHP in-dev server --- phpserver/router.php | 1 + 1 file changed, 1 insertion(+) diff --git a/phpserver/router.php b/phpserver/router.php index a12e9178ecad4..06c23ecdfe3cd 100644 --- a/phpserver/router.php +++ b/phpserver/router.php @@ -103,6 +103,7 @@ } else { $debug('file does not exist'); if (strpos($route, 'static/') === 0) { + $route = preg_replace('#static/#', '', $route, 1); $_GET['resource'] = $route; $debug("static: $route"); include($magentoPackagePubDir.'/static.php'); From 19119c194559ec4854c7663d984ac4211aa7696b Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 25 Jan 2018 19:49:22 +0700 Subject: [PATCH 03/16] Fix command to start PHP in-dev server in doc. --- phpserver/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpserver/README.md b/phpserver/README.md index 63436c8af7883..6bb814fe5f5f2 100644 --- a/phpserver/README.md +++ b/phpserver/README.md @@ -31,7 +31,7 @@ For more informations about the installation process using the CLI, you can cons ### How to run Magento -Example usage: ```php -S 127.0.0.1:8082 -t ./pub/ ./phpserver/router.php``` +Example usage: ```php -S 127.0.0.1:8082 -t ./pub/ ../phpserver/router.php``` ### What exactly the script does From 52875a8dce56d3db4953aef2b3b93da7a65cf3b0 Mon Sep 17 00:00:00 2001 From: Kirill Morozov Date: Thu, 15 Feb 2018 15:35:45 -0500 Subject: [PATCH 04/16] #13685: Replaced .size() with .length to be compatible with jQuery 3.* --- .../Swatches/view/frontend/web/js/swatch-renderer.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js index d1f7c477ba8d7..a24c72c473fe9 100644 --- a/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js +++ b/app/code/Magento/Swatches/view/frontend/web/js/swatch-renderer.js @@ -90,7 +90,7 @@ define([ $title, $corner; - if (!$element.size()) { + if (!$element.length) { $element = $('
' @@ -810,7 +810,7 @@ define([ $widget._Rewind(controls); // done if nothing selected - if (selected.size() <= 0) { + if (selected.length <= 0) { return; } @@ -820,7 +820,7 @@ define([ id = $this.attr('attribute-id'), products = $widget._CalcProducts(id); - if (selected.size() === 1 && selected.first().attr('attribute-id') === id) { + if (selected.length === 1 && selected.first().attr('attribute-id') === id) { return; } @@ -1016,7 +1016,7 @@ define([ _EnableProductMediaLoader: function ($this) { var $widget = this; - if ($('body.catalog-product-view').size() > 0) { + if ($('body.catalog-product-view').length > 0) { $this.parents('.column.main').find('.photo.image') .addClass($widget.options.classes.loader); } else { @@ -1035,7 +1035,7 @@ define([ _DisableProductMediaLoader: function ($this) { var $widget = this; - if ($('body.catalog-product-view').size() > 0) { + if ($('body.catalog-product-view').length > 0) { $this.parents('.column.main').find('.photo.image') .removeClass($widget.options.classes.loader); } else { From ee11b50fc373c2e84a51cdd52782ba7d9b747b10 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Fri, 9 Feb 2018 16:04:27 +0100 Subject: [PATCH 05/16] Show IP-address without comma --- .../Setup/Console/Command/MaintenanceAllowIpsCommand.php | 2 +- .../Setup/Console/Command/MaintenanceStatusCommand.php | 2 +- .../Unit/Console/Command/MaintenanceAllowIpsCommandTest.php | 2 +- .../Unit/Console/Command/MaintenanceStatusCommandTest.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php index 3df2825dfec1d..5445bca8713e5 100644 --- a/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceAllowIpsCommand.php @@ -93,7 +93,7 @@ protected function execute(InputInterface $input, OutputInterface $output) if (!empty($addresses)) { $this->maintenanceMode->setAddresses(implode(',', $addresses)); $output->writeln( - 'Set exempt IP-addresses: ' . implode(', ', $this->maintenanceMode->getAddressInfo()) . + 'Set exempt IP-addresses: ' . implode(' ', $this->maintenanceMode->getAddressInfo()) . '' ); } diff --git a/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php b/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php index 9162cc47f6bd9..0ac8095c31c0c 100644 --- a/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php +++ b/setup/src/Magento/Setup/Console/Command/MaintenanceStatusCommand.php @@ -54,7 +54,7 @@ protected function execute(InputInterface $input, OutputInterface $output) ($this->maintenanceMode->isOn() ? 'active' : 'not active') . '' ); $addressInfo = $this->maintenanceMode->getAddressInfo(); - $addresses = implode(', ', $addressInfo); + $addresses = implode(' ', $addressInfo); $output->writeln('List of exempt IP-addresses: ' . ($addresses ? $addresses : 'none') . ''); } } diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php index 88038c2e817c1..35af019436d71 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceAllowIpsCommandTest.php @@ -75,7 +75,7 @@ public function executeDataProvider() [ ['ip' => ['127.0.0.1', '127.0.0.2'], '--none' => false], [], - 'Set exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + 'Set exempt IP-addresses: 127.0.0.1 127.0.0.2' . PHP_EOL ], [ ['--none' => true], diff --git a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php index 07f9990a0bb6f..0b36c86cf8ada 100644 --- a/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php +++ b/setup/src/Magento/Setup/Test/Unit/Console/Command/MaintenanceStatusCommandTest.php @@ -50,7 +50,7 @@ public function executeDataProvider() [ [true, ['127.0.0.1', '127.0.0.2']], 'Status: maintenance mode is active' . PHP_EOL . - 'List of exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + 'List of exempt IP-addresses: 127.0.0.1 127.0.0.2' . PHP_EOL ], [ [true, []], @@ -63,7 +63,7 @@ public function executeDataProvider() [ [false, ['127.0.0.1', '127.0.0.2']], 'Status: maintenance mode is not active' . PHP_EOL . - 'List of exempt IP-addresses: 127.0.0.1, 127.0.0.2' . PHP_EOL + 'List of exempt IP-addresses: 127.0.0.1 127.0.0.2' . PHP_EOL ], ]; } From 8a2e547729f580d2b01a47f1a3b64b89c28738f7 Mon Sep 17 00:00:00 2001 From: igortregub Date: Mon, 5 Feb 2018 14:55:21 +0200 Subject: [PATCH 06/16] issue #13497 - Method getUrl in Magento\Catalog\Model\Product\Attribute\Frontend returns image url with double slash --- .../Product/Attribute/Frontend/Image.php | 19 +++--- .../Product/Attribute/Frontend/ImageTest.php | 62 +++++++++++++------ 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Image.php b/app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Image.php index 6173a76eca421..cdd6da7019da5 100644 --- a/app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Image.php +++ b/app/code/Magento/Catalog/Model/Product/Attribute/Frontend/Image.php @@ -9,23 +9,28 @@ * * @author Magento Core Team */ + namespace Magento\Catalog\Model\Product\Attribute\Frontend; -class Image extends \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend +use Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend; +use Magento\Framework\UrlInterface; +use Magento\Store\Model\StoreManagerInterface; + +class Image extends AbstractFrontend { /** * Store manager * - * @var \Magento\Store\Model\StoreManagerInterface + * @var StoreManagerInterface */ protected $_storeManager; /** * Construct * - * @param \Magento\Store\Model\StoreManagerInterface $storeManager + * @param StoreManagerInterface $storeManager */ - public function __construct(\Magento\Store\Model\StoreManagerInterface $storeManager) + public function __construct(StoreManagerInterface $storeManager) { $this->_storeManager = $storeManager; } @@ -42,9 +47,9 @@ public function getUrl($product) $image = $product->getData($this->getAttribute()->getAttributeCode()); $url = false; if (!empty($image)) { - $url = $this->_storeManager->getStore($product->getStore()) - ->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) - . 'catalog/product/' . $image; + $url = $this->_storeManager + ->getStore($product->getStore()) + ->getBaseUrl(UrlInterface::URL_TYPE_MEDIA) . 'catalog/product/' . ltrim($image, '/'); } return $url; } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Frontend/ImageTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Frontend/ImageTest.php index 115a333a38b5b..3ceedddc2b713 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Frontend/ImageTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Attribute/Frontend/ImageTest.php @@ -3,45 +3,71 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Catalog\Test\Unit\Model\Product\Attribute\Frontend; +use Magento\Catalog\Model\Product; +use Magento\Catalog\Model\Product\Attribute\Frontend\Image; +use Magento\Eav\Model\Entity\Attribute\AbstractAttribute; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; +use Magento\Store\Model\Store; +use Magento\Store\Model\StoreManagerInterface; +use PHPUnit\Framework\TestCase; -class ImageTest extends \PHPUnit\Framework\TestCase +class ImageTest extends TestCase { /** - * @var \Magento\Catalog\Model\Product\Attribute\Frontend\Image + * @var Image */ private $model; - public function testGetUrl() + /** + * @dataProvider getUrlDataProvider + * @param string $expectedImage + * @param string $productImage + */ + public function testGetUrl(string $expectedImage, string $productImage) + { + $this->assertEquals($expectedImage, $this->model->getUrl($this->getMockedProduct($productImage))); + } + + /** + * Data provider for testGetUrl + * + * @return array + */ + public function getUrlDataProvider(): array { - $this->assertEquals('catalog/product/img.jpg', $this->model->getUrl($this->getMockedProduct())); + return [ + ['catalog/product/img.jpg', 'img.jpg'], + ['catalog/product/img.jpg', '/img.jpg'], + ]; } protected function setUp() { $helper = new ObjectManager($this); $this->model = $helper->getObject( - \Magento\Catalog\Model\Product\Attribute\Frontend\Image::class, + Image::class, ['storeManager' => $this->getMockedStoreManager()] ); $this->model->setAttribute($this->getMockedAttribute()); } /** - * @return \Magento\Catalog\Model\Product + * @param string $productImage + * @return Product */ - private function getMockedProduct() + private function getMockedProduct(string $productImage): Product { - $mockBuilder = $this->getMockBuilder(\Magento\Catalog\Model\Product::class); + $mockBuilder = $this->getMockBuilder(Product::class); $mock = $mockBuilder->setMethods(['getData', 'getStore', '__wakeup']) ->disableOriginalConstructor() ->getMock(); $mock->expects($this->any()) ->method('getData') - ->will($this->returnValue('img.jpg')); + ->will($this->returnValue($productImage)); $mock->expects($this->any()) ->method('getStore'); @@ -50,13 +76,13 @@ private function getMockedProduct() } /** - * @return \Magento\Store\Model\StoreManagerInterface + * @return StoreManagerInterface */ - private function getMockedStoreManager() + private function getMockedStoreManager(): StoreManagerInterface { $mockedStore = $this->getMockedStore(); - $mockBuilder = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class); + $mockBuilder = $this->getMockBuilder(StoreManagerInterface::class); $mock = $mockBuilder->setMethods(['getStore']) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -69,11 +95,11 @@ private function getMockedStoreManager() } /** - * @return \Magento\Store\Model\Store + * @return Store */ - private function getMockedStore() + private function getMockedStore(): Store { - $mockBuilder = $this->getMockBuilder(\Magento\Store\Model\Store::class); + $mockBuilder = $this->getMockBuilder(Store::class); $mock = $mockBuilder->setMethods(['getBaseUrl', '__wakeup']) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -86,11 +112,11 @@ private function getMockedStore() } /** - * @return \Magento\Eav\Model\Entity\Attribute\AbstractAttribute + * @return AbstractAttribute */ - private function getMockedAttribute() + private function getMockedAttribute(): AbstractAttribute { - $mockBuilder = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class); + $mockBuilder = $this->getMockBuilder(AbstractAttribute::class); $mockBuilder->setMethods(['getAttributeCode', '__wakeup']); $mockBuilder->disableOriginalConstructor(); $mock = $mockBuilder->getMockForAbstractClass(); From ea55d50528cee7e56a27f3126a895b8df76eeb0c Mon Sep 17 00:00:00 2001 From: David Angel Date: Thu, 15 Feb 2018 08:33:45 -0500 Subject: [PATCH 07/16] Update StorageInterface.php --- app/code/Magento/Backend/Model/Auth/StorageInterface.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Backend/Model/Auth/StorageInterface.php b/app/code/Magento/Backend/Model/Auth/StorageInterface.php index 52b2b089c71e1..e643165a93317 100644 --- a/app/code/Magento/Backend/Model/Auth/StorageInterface.php +++ b/app/code/Magento/Backend/Model/Auth/StorageInterface.php @@ -23,7 +23,7 @@ interface StorageInterface public function processLogin(); /** - * Perform login specific actions + * Perform logout specific actions * * @return $this * @abstract From 34a1deedbba82c4d877bb043a5650a0be14b23ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Thu, 21 Dec 2017 15:38:27 +0200 Subject: [PATCH 08/16] Display a more meaningful error message in case of misspelt module name. [LogicException] Component 'VendorA_ModuleB' of type '' is not correctly registered. instead of [Magento\Framework\Exception\FileSystemException] The file "/composer.json" doesn't exist --- lib/internal/Magento/Framework/Module/Dir.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 936fce3a046b7..ecd24c5db767a 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,6 +45,10 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); + if (! isset($path)) { + throw new \LogicException("Component '$moduleName' of type '$type' is not correctly registered."); + } + if ($type) { if (!in_array($type, [ self::MODULE_ETC_DIR, From 82f701aa68f29964164be618229ddbb49a287ec1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 22:04:12 +0200 Subject: [PATCH 09/16] Do not throw \LogicException, as it would break backwards-compatibility. --- lib/internal/Magento/Framework/Module/Dir.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index ecd24c5db767a..47e0836db7f33 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,8 +45,9 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - if (! isset($path)) { - throw new \LogicException("Component '$moduleName' of type '$type' is not correctly registered."); + if (!isset($path)) { + // (Do not throw \LogicException, as it would break backwards-compatibility.) + throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); } if ($type) { From 7a0ce57ac06759778f6375bada4b6deba5557b4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:18:20 +0200 Subject: [PATCH 10/16] Allow directory to be not set for non-module types. --- lib/internal/Magento/Framework/Module/Dir.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 47e0836db7f33..309fa33778de4 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,8 +45,9 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - if (!isset($path)) { - // (Do not throw \LogicException, as it would break backwards-compatibility.) + // An empty $type means it's gettind the directory of the module itself. + if (empty($type) && !isset($path)) { + // Note: do not throw \LogicException, as it would break backwards-compatibility. throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); } From 57a6e17413d6626122e225d8ee4441ca45c7e94f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:21:34 +0200 Subject: [PATCH 11/16] Fix misspelling. --- lib/internal/Magento/Framework/Module/Dir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 309fa33778de4..8ce818961cdf8 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -45,7 +45,7 @@ public function getDir($moduleName, $type = '') { $path = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName); - // An empty $type means it's gettind the directory of the module itself. + // An empty $type means it's getting the directory of the module itself. if (empty($type) && !isset($path)) { // Note: do not throw \LogicException, as it would break backwards-compatibility. throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); From 70b2722cbbe33d35ac4c90cfa13d7adca2747454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=81nis=20Elmeris?= Date: Fri, 22 Dec 2017 23:37:43 +0200 Subject: [PATCH 12/16] Simpler message, as this appears only for the modules themselves. --- lib/internal/Magento/Framework/Module/Dir.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/Magento/Framework/Module/Dir.php b/lib/internal/Magento/Framework/Module/Dir.php index 8ce818961cdf8..688c7c43ac0e4 100644 --- a/lib/internal/Magento/Framework/Module/Dir.php +++ b/lib/internal/Magento/Framework/Module/Dir.php @@ -48,7 +48,7 @@ public function getDir($moduleName, $type = '') // An empty $type means it's getting the directory of the module itself. if (empty($type) && !isset($path)) { // Note: do not throw \LogicException, as it would break backwards-compatibility. - throw new \InvalidArgumentException("Component '$moduleName' of type '$type' is not correctly registered."); + throw new \InvalidArgumentException("Module '$moduleName' is not correctly registered."); } if ($type) { From d77d9a0c1a1324d968f0c38001bbc40a7d8a13d3 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Mon, 19 Feb 2018 16:22:12 +0200 Subject: [PATCH 13/16] [Forwardport] Display a more meaningful error message in case of misspelled module name. Cover new code with tests. --- .../Magento/Framework/Module/Test/Unit/DirTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php index 335228888cc4b..055e4be71baf1 100644 --- a/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php +++ b/lib/internal/Magento/Framework/Module/Test/Unit/DirTest.php @@ -59,4 +59,17 @@ public function testGetDirModuleSubDirUnknown() $this->_model->getDir('Test_Module', 'unknown'); } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessage Module 'Test Module' is not correctly registered. + */ + public function testGetDirModuleIncorrectlyRegistered() + { + $this->moduleRegistryMock->expects($this->once()) + ->method('getPath') + ->with($this->identicalTo(ComponentRegistrar::MODULE), $this->identicalTo('Test Module')) + ->willReturn(null); + $this->_model->getDir('Test Module'); + } } From 44940bef8ebf0b5f5b9811e10884388278b43694 Mon Sep 17 00:00:00 2001 From: Pierre Martin Date: Wed, 14 Feb 2018 18:15:47 +0100 Subject: [PATCH 14/16] Refactoring: remove unuseful temporary variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …since there is no usage of `$data` in this method --- .../Magento/Catalog/Controller/Adminhtml/Category/Save.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php index 6ba0348b45986..bcc7d468fd0f4 100644 --- a/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php +++ b/app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php @@ -127,8 +127,7 @@ public function execute() return $resultRedirect->setPath('catalog/*/', ['_current' => true, 'id' => null]); } - $data['general'] = $this->getRequest()->getPostValue(); - $categoryPostData = $data['general']; + $categoryPostData = $this->getRequest()->getPostValue(); $isNewCategory = !isset($categoryPostData['entity_id']); $categoryPostData = $this->stringToBoolConverting($categoryPostData); From 310e4503b605983ee1a38bc191aada0f0b0b27c2 Mon Sep 17 00:00:00 2001 From: mszydlo Date: Sat, 10 Feb 2018 12:11:34 +0100 Subject: [PATCH 15/16] Fix adding values to variable collection Changed select fields in joined variable value table in Magento\Variable\Model\ResourceModel\Variable\Collection#addValuesToResult() method to match DB schema --- .../Variable/Model/ResourceModel/Variable/Collection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Variable/Model/ResourceModel/Variable/Collection.php b/app/code/Magento/Variable/Model/ResourceModel/Variable/Collection.php index 3b74849352274..64c541e8c70b9 100644 --- a/app/code/Magento/Variable/Model/ResourceModel/Variable/Collection.php +++ b/app/code/Magento/Variable/Model/ResourceModel/Variable/Collection.php @@ -62,7 +62,7 @@ public function addValuesToResult() $this->getSelect()->join( ['value_table' => $this->getTable('variable_value')], 'value_table.variable_id = main_table.variable_id', - ['value_table.value'] + ['value_table.plain_value', 'value_table.html_value'] ); $this->addFieldToFilter('value_table.store_id', ['eq' => $this->getStoreId()]); return $this; From d5114a81f6beccc7c8311fa3fd9442cf48c53fb0 Mon Sep 17 00:00:00 2001 From: nmalevanec Date: Mon, 19 Feb 2018 18:41:37 +0200 Subject: [PATCH 16/16] [Forwardport] Fix adding values to system variable collection. Cover code changes with unit test. --- .../ResourceModel/Variable/CollectionTest.php | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 app/code/Magento/Variable/Test/Unit/Model/ResourceModel/Variable/CollectionTest.php diff --git a/app/code/Magento/Variable/Test/Unit/Model/ResourceModel/Variable/CollectionTest.php b/app/code/Magento/Variable/Test/Unit/Model/ResourceModel/Variable/CollectionTest.php new file mode 100644 index 0000000000000..38cf2fefcef97 --- /dev/null +++ b/app/code/Magento/Variable/Test/Unit/Model/ResourceModel/Variable/CollectionTest.php @@ -0,0 +1,94 @@ +getMockBuilder(Select::class) + ->disableOriginalConstructor() + ->getMock(); + $select->expects($this->once()) + ->method('from') + ->with($this->identicalTo(['main_table' => $mainTableName])) + ->willReturnSelf(); + $select->expects($this->once()) + ->method('join') + ->with( + $this->identicalTo(['value_table' => $tableName]), + $this->identicalTo('value_table.variable_id = main_table.variable_id'), + $this->identicalTo(['value_table.plain_value', 'value_table.html_value']) + )->willReturnSelf(); + + $connection = $this->getMockBuilder(AdapterInterface::class) + ->disableOriginalConstructor() + ->setMethods(['select', 'prepareSqlCondition', 'quoteIdentifier']) + ->getMockForAbstractClass(); + $connection->expects($this->any()) + ->method('select') + ->willReturn($select); + $connection->expects($this->once()) + ->method('quoteIdentifier') + ->with($this->identicalTo($field)) + ->willReturn($field); + $connection->expects($this->once()) + ->method('prepareSqlCondition') + ->with( + $this->identicalTo($field), + $this->identicalTo(['eq' => 0]) + )->willReturn('testResultCondition'); + + $resource = $this->getMockBuilder(AbstractDb::class) + ->setMethods(['getTable', 'getMainTable', 'getConnection']) + ->disableOriginalConstructor() + ->getMockForAbstractClass(); + $resource->expects($this->any()) + ->method('getConnection') + ->willReturn($connection); + $resource->expects($this->once()) + ->method('getMainTable') + ->willReturn('testMainTable'); + $resource->expects($this->exactly(2)) + ->method('getTable') + ->withConsecutive( + [$mainTableName], + [$tableName] + )->willReturnOnConsecutiveCalls( + $mainTableName, + $tableName + ); + + $objectManager = new ObjectManager($this); + $collection = $objectManager->getObject( + Collection::class, + [ + 'resource' => $resource, + ] + ); + $this->assertInstanceOf(Collection::class, $collection->addValuesToResult()); + } +}