diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php index e692ea59d2d6e..4c08c948e4f58 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php @@ -107,7 +107,7 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu $query ); } elseif ($filter->getField() === 'category_ids') { - return 'category_ids_index.category_id = ' . $filter->getValue(); + return 'category_ids_index.category_id = ' . (int) $filter->getValue(); } elseif ($attribute->isStatic()) { $alias = $this->tableMapper->getMappingAlias($filter); $resultQuery = str_replace( @@ -194,10 +194,10 @@ private function processTermSelect(FilterInterface $filter, $isNegation) $value = sprintf( '%s IN (%s)', ($isNegation ? 'NOT' : ''), - implode(',', $filter->getValue()) + implode(',', array_map([$this->connection, 'quote'], $filter->getValue())) ); } else { - $value = ($isNegation ? '!' : '') . '= ' . $filter->getValue(); + $value = ($isNegation ? '!' : '') . '= ' . $this->connection->quote($filter->getValue()); } $resultQuery = sprintf( '%1$s.value %2$s', diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php index ccc83be62eb11..368fdb039fdf4 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php @@ -104,7 +104,7 @@ protected function setUp() ->getMock(); $this->connection = $this->getMockBuilder('\Magento\Framework\DB\Adapter\AdapterInterface') ->disableOriginalConstructor() - ->setMethods(['select', 'getIfNullSql']) + ->setMethods(['select', 'getIfNullSql', 'quote']) ->getMockForAbstractClass(); $this->select = $this->getMockBuilder('\Magento\Framework\DB\Select') ->disableOriginalConstructor() @@ -170,9 +170,25 @@ public function testProcessPrice() $this->assertSame($expectedResult, $this->removeWhitespaces($actualResult)); } - public function testProcessCategoryIds() + /** + * @return array + */ + public function processCategoryIdsDataProvider() + { + return [ + ['5', 'category_ids_index.category_id = 5'], + [3, 'category_ids_index.category_id = 3'], + ["' and 1 = 0", 'category_ids_index.category_id = 0'], + ]; + } + + /** + * @param string|int $categoryId + * @param string $expectedResult + * @dataProvider processCategoryIdsDataProvider + */ + public function testProcessCategoryIds($categoryId, $expectedResult) { - $expectedResult = 'category_ids_index.category_id = FilterValue'; $isNegation = false; $query = 'SELECT category_ids FROM catalog_product_entity'; @@ -182,7 +198,7 @@ public function testProcessCategoryIds() $this->filter->expects($this->once()) ->method('getValue') - ->will($this->returnValue('FilterValue')); + ->will($this->returnValue($categoryId)); $this->config->expects($this->exactly(1)) ->method('getAttribute') @@ -249,6 +265,7 @@ public function testProcessTermFilter($frontendInput, $fieldValue, $isNegation, ->method('getValue') ->willReturn($fieldValue); + $this->connection->expects($this->atLeastOnce())->method('quote')->willReturnArgument(0); $actualResult = $this->target->process($this->filter, $isNegation, 'This filter is not depends on used query'); $this->assertSame($expected, $this->removeWhitespaces($actualResult)); } diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php index d9e904b7000cf..161b72ada2c70 100644 --- a/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php +++ b/app/code/Magento/Newsletter/Test/Unit/Model/Queue/TransportBuilderTest.php @@ -24,13 +24,16 @@ class TransportBuilderTest extends \Magento\Framework\Mail\Test\Unit\Template\Tr * @param int $templateType * @param string $messageType * @param string $bodyText + * @param string $templateNamespace * @return void * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function testGetTransport( $templateType = TemplateTypesInterface::TYPE_HTML, $messageType = MessageInterface::TYPE_HTML, - $bodyText = '

Html message

' + $bodyText = '

Html message

', + $templateNamespace = '' ) { $filter = $this->getMock('Magento\Email\Model\Template\Filter', [], [], '', false); $data = [ diff --git a/app/code/Magento/Review/Controller/Product/Post.php b/app/code/Magento/Review/Controller/Product/Post.php index a68f0d18c3bc5..e20872b41dcd6 100644 --- a/app/code/Magento/Review/Controller/Product/Post.php +++ b/app/code/Magento/Review/Controller/Product/Post.php @@ -37,10 +37,10 @@ public function execute() $data = $this->getRequest()->getPostValue(); $rating = $this->getRequest()->getParam('ratings', []); } - if (($product = $this->initProduct()) && !empty($data)) { /** @var \Magento\Review\Model\Review $review */ $review = $this->reviewFactory->create()->setData($data); + $review->unsetData('review_id'); $validate = $review->validate(); if ($validate === true) { diff --git a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php index 9cedb87e15afe..38f1a27a4d430 100644 --- a/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php +++ b/app/code/Magento/Review/Test/Unit/Controller/Product/PostTest.php @@ -127,7 +127,7 @@ public function setUp() '\Magento\Review\Model\Review', [ 'setData', 'validate', 'setEntityId', 'getEntityIdByCode', 'setEntityPkValue', 'setStatusId', - 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate' + 'setCustomerId', 'setStoreId', 'setStores', 'save', 'getId', 'aggregate', 'unsetData' ], [], '', @@ -219,7 +219,10 @@ public function setUp() */ public function testExecute() { - $ratingsData = ['ratings' => [1 => 1]]; + $reviewData = [ + 'ratings' => [1 => 1], + 'review_id' => 2 + ]; $productId = 1; $customerId = 1; $storeId = 1; @@ -230,7 +233,7 @@ public function testExecute() ->willReturn(true); $this->reviewSession->expects($this->any())->method('getFormData') ->with(true) - ->willReturn($ratingsData); + ->willReturn($reviewData); $this->request->expects($this->at(0))->method('getParam') ->with('category', false) ->willReturn(false); @@ -260,7 +263,7 @@ public function testExecute() ->with('product', $product) ->willReturnSelf(); $this->review->expects($this->once())->method('setData') - ->with($ratingsData) + ->with($reviewData) ->willReturnSelf(); $this->review->expects($this->once())->method('validate') ->willReturn(true); @@ -270,6 +273,7 @@ public function testExecute() $this->review->expects($this->once())->method('setEntityId') ->with(1) ->willReturnSelf(); + $this->review->expects($this->once())->method('unsetData')->with('review_id'); $product->expects($this->exactly(2)) ->method('getId') ->willReturn($productId); diff --git a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php index 6a8ada8a43693..11db842dd9169 100644 --- a/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php +++ b/app/code/Magento/SampleData/Console/Command/SampleDataDeployCommand.php @@ -77,6 +77,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { + $this->updateMemoryLimit(); $sampleDataPackages = $this->sampleDataDependency->getSampleDataPackages(); if (!empty($sampleDataPackages)) { $baseDir = $this->filesystem->getDirectoryRead(DirectoryList::ROOT)->getAbsolutePath(); @@ -101,4 +102,39 @@ protected function execute(InputInterface $input, OutputInterface $output) $output->writeln('' . 'There is no sample data for current set of modules.' . ''); } } + + /** + * @return void + */ + private function updateMemoryLimit() + { + if (function_exists('ini_set')) { + @ini_set('display_errors', 1); + $memoryLimit = trim(ini_get('memory_limit')); + if ($memoryLimit != -1 && $this->getMemoryInBytes($memoryLimit) < 768 * 1024 * 1024) { + @ini_set('memory_limit', '768M'); + } + } + } + + /** + * @param string $value + * @return int + */ + private function getMemoryInBytes($value) + { + $unit = strtolower(substr($value, -1, 1)); + $value = (int) $value; + switch($unit) { + case 'g': + $value *= 1024 * 1024 * 1024; + break; + case 'm': + $value *= 1024 * 1024; + break; + case 'k': + $value *= 1024; + } + return $value; + } } diff --git a/app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataDeployCommandTest.php b/app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataDeployCommandTest.php index cbc3d330e725b..2739c19f2db9f 100644 --- a/app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataDeployCommandTest.php +++ b/app/code/Magento/SampleData/Test/Unit/Console/Command/SampleDataDeployCommandTest.php @@ -11,55 +11,92 @@ class SampleDataDeployCommandTest extends \PHPUnit_Framework_TestCase { - public function testExecute() + /** + * @param array $sampleDataPackages + * @param int $appRunResult - int 0 if everything went fine, or an error code + * @param string $expectedMsg + * @return void + * + * @dataProvider processDataProvider + */ + public function testExecute(array $sampleDataPackages, $appRunResult, $expectedMsg) { - $this->markTestSkipped('MAGETWO-43636: This test should be fixed by NORD team'); $directoryRead = $this->getMock('\Magento\Framework\Filesystem\Directory\ReadInterface', [], [], '', false); - $directoryRead->expects($this->atLeastOnce())->method('getAbsolutePath')->willReturn('/path/to/composer.json'); + $directoryRead->expects($this->any())->method('getAbsolutePath')->willReturn('/path/to/composer.json'); $filesystem = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); - $filesystem->expects($this->atLeastOnce())->method('getDirectoryRead')->with(DirectoryList::ROOT) + $filesystem->expects($this->any())->method('getDirectoryRead')->with(DirectoryList::ROOT) ->willReturn($directoryRead); $sampleDataDependency = $this->getMock('Magento\SampleData\Model\Dependency', [], [], '', false); - $sampleDataDependency->expects($this->atLeastOnce())->method('getSampleDataPackages')->willReturn( - [ - 'magento/module-cms-sample-data' => '1.0.0-beta' - ] - ); + $sampleDataDependency + ->expects($this->any()) + ->method('getSampleDataPackages') + ->willReturn($sampleDataPackages); - $arrayInput = $this->getMock('Symfony\Component\Console\Input\ArrayInput', [], [], '', false); + $commandInput = $this->getMock('Symfony\Component\Console\Input\ArrayInput', [], [], '', false); $arrayInputFactory = $this ->getMock('Symfony\Component\Console\Input\ArrayInputFactory', ['create'], [], '', false); + + array_walk($sampleDataPackages, function (&$v, $k) { + $v = "$k:$v"; + }); + + $packages = array_values($sampleDataPackages); + $requireArgs = [ - 'command' => 'require', + 'command' => 'require', '--working-dir' => '/path/to/composer.json', - '--no-interaction' => 1, '--no-progress' => 1, - 'packages' => ['magento/module-cms-sample-data:1.0.0-beta'] + 'packages' => $packages, ]; - $arrayInputFactory->expects($this->atLeastOnce()) + $arrayInputFactory->expects($this->any()) ->method('create') ->with(['parameters' => $requireArgs]) - ->willReturn($arrayInput); + ->willReturn($commandInput); + $application = $this->getMock('Composer\Console\Application', [], [], '', false); - $application->expects($this->atLeastOnce())->method('run')->with($arrayInput, $this->anything()) - ->willReturnCallback(function ($input, $output) { - $input->getFirstArgument(); - $output->writeln('./composer.json has been updated'); - }); + $application->expects($this->any())->method('run') + ->with($commandInput, $this->anything()) + ->willReturn($appRunResult); $applicationFactory = $this->getMock('Composer\Console\ApplicationFactory', ['create'], [], '', false); - $applicationFactory->expects($this->atLeastOnce())->method('create')->willReturn($application); + $applicationFactory->expects($this->any())->method('create')->willReturn($application); $commandTester = new CommandTester( new SampleDataDeployCommand($filesystem, $sampleDataDependency, $arrayInputFactory, $applicationFactory) ); $commandTester->execute([]); - $expectedMsg = './composer.json has been updated' . PHP_EOL; - $this->assertEquals($expectedMsg, $commandTester->getDisplay()); } + + /** + * @return array + */ + public function processDataProvider() + { + return [ + [ + 'sampleDataPackages' => [], + 'appRunResult' => 1, + 'expectedMsg' => 'There is no sample data for current set of modules.' . PHP_EOL, + ], + [ + 'sampleDataPackages' => [ + 'magento/module-cms-sample-data' => '1.0.0-beta', + ], + 'appRunResult' => 1, + 'expectedMsg' => 'There is an error during sample data deployment.' . PHP_EOL, + ], + [ + 'sampleDataPackages' => [ + 'magento/module-cms-sample-data' => '1.0.0-beta', + ], + 'appRunResult' => 0, + 'expectedMsg' => '', + ], + ]; + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php old mode 100755 new mode 100644 index 1495125992d31..36df757dc6008 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/View.php @@ -161,6 +161,27 @@ class View extends AbstractConfigureBlock */ protected $ajaxLoading = 'body.ajax-loading'; + /** + * Full image selector + * + * @var string + */ + protected $fullImage = '[data-gallery-role="gallery"] img.fotorama__img.fotorama__img--full'; + + /** + * Full image close selector + * + * @var string + */ + protected $fullImageClose = '[data-gallery-role="fotorama__fullscreen-icon"]'; + + /** + * Base image selector + * + * @var string + */ + protected $baseImage = '[data-gallery-role="gallery"] img.fotorama__img.fotorama__img'; + /** * Get block price. * @@ -436,4 +457,65 @@ public function isGalleryVisible() { return $this->_rootElement->find($this->mediaGallery)->isVisible(); } + + /** + * Check is full image into gallery is visible for the product. + * + * @return bool + */ + public function isFullImageVisible() + { + return $this->browser->find($this->fullImage)->isVisible(); + } + + /** + * Get full image source from media gallery into product + * + * @return string + */ + public function getFullImageSource() + { + return $this->browser->find($this->fullImage)->getAttribute('src'); + } + + /** + * Check is base image into gallery is visible for the product. + * + * @return bool + */ + public function isBaseImageVisible() + { + return $this->_rootElement->find($this->baseImage)->isVisible(); + } + + /** + * Get full image source from media gallery into product + * + * @return string + */ + public function getBaseImageSource() + { + return $this->_rootElement->find($this->baseImage)->getAttribute('src'); + } + + /** + * Click link. + * + * @return void + */ + public function clickBaseImage() + { + $this->_rootElement->find($this->baseImage, Locator::SELECTOR_CSS)->click(); + $this->waitForElementVisible($this->fullImage); + } + + /** + * Click link. + * + * @return void + */ + public function closeFullImage() + { + $this->browser->find($this->fullImageClose, Locator::SELECTOR_CSS)->click(); + } } diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertImagesAreVisibleOnProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertImagesAreVisibleOnProductPage.php new file mode 100644 index 0000000000000..d1a0f90ab105f --- /dev/null +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertImagesAreVisibleOnProductPage.php @@ -0,0 +1,153 @@ +open($_ENV['app_frontend_url'] . $product->getUrlKey() . '.html'); + + $this->product = $product; + $this->productView = $catalogProductView->getViewBlock(); + + $errors = $this->verify(); + \PHPUnit_Framework_Assert::assertEmpty( + $errors, + "\nFound the following errors:\n" . implode(" \n", $errors) + ); + } + + /** + * Assert that media gallery images are displayed correctly on product page(front-end). + * + * @return array + */ + protected function verify() + { + $errors = []; + + $errors[] = $this->verifyGallery(); + $errors[] = $this->verifyBaseImage(); + $errors[] = $this->verifyFullImage(); + + return array_filter($errors); + } + + /** + * Verify gallery on product page(front-end) is displayed correctly + * + * @return string|null + */ + protected function verifyGallery() + { + if ($this->productView->isGalleryVisible()) { + return null; + } + + return 'Gallery for product ' . $this->product->getName() . ' is not visible.'; + } + + /** + * Verify base image on product page(front-end) is displayed correctly + * + * @return string|null + */ + protected function verifyBaseImage() + { + if (!$this->productView->isBaseImageVisible()) { + return 'Base image for product ' . $this->product->getName() . ' is not visible.'; + } + + if (!$this->isImageLoaded($this->productView->getBaseImageSource())) { + return 'Base image file is corrupted or does not exist for product ' . $this->product->getName(); + } + + return null; + } + + /** + * Verify full image on product page(front-end) is displayed correctly + * + * @return string|null + */ + protected function verifyFullImage() + { + // click base image to see full image + $this->productView->clickBaseImage(); + if (!$this->productView->isFullImageVisible()) { + return 'Full image for product ' . $this->product->getName() . ' should be visible after click on base one'; + } + + if (!$this->isImageLoaded($this->productView->getFullImageSource())) { + return 'Full image file is corrupted or does not exist for product ' . $this->product->getName(); + } + + $this->productView->closeFullImage(); + + return null; + } + + /** + * Check is image file can be loaded (displayed) + * + * @param string $src + * @return bool + */ + protected function isImageLoaded($src) + { + return (bool) file_get_contents($src, 0, null, 0, 1); + } + + /** + * Returns a string representation of the object + * + * @return string + */ + public function toString() + { + return 'Product images on product view page are correct.'; + } +} diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php index 03e44bab0d5e0..14beb28ecbb63 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Constraint/AssertProductPage.php @@ -7,7 +7,6 @@ namespace Magento\Catalog\Test\Constraint; use Magento\Catalog\Test\Page\Product\CatalogProductView; -use Magento\ConfigurableProduct\Test\Fixture\ConfigurableProduct; use Magento\Mtf\Client\BrowserInterface; use Magento\Mtf\Constraint\AbstractAssertForm; use Magento\Mtf\Fixture\FixtureInterface; @@ -21,14 +20,14 @@ class AssertProductPage extends AbstractAssertForm /** * Product view block on frontend page * - * @var \Magento\ConfigurableProduct\Test\Block\Product\View + * @var \Magento\Catalog\Test\Block\Product\View */ protected $productView; /** * Product fixture * - * @var ConfigurableProduct + * @var FixtureInterface */ protected $product; @@ -168,7 +167,7 @@ protected function verifyDescription() $fixtureProductDescription = $this->product->getDescription(); $formProductDescription = $this->productView->getProductDescription(); - if ($fixtureProductDescription == $formProductDescription) { + if ($fixtureProductDescription === null || $fixtureProductDescription == $formProductDescription) { return null; } return "Displayed product description on product page(front-end) not equals passed from fixture. " @@ -182,14 +181,14 @@ protected function verifyDescription() */ protected function verifyShortDescription() { - $fixtureProductShortDescription = $this->product->getShortDescription(); + $fixtureShortDescription = $this->product->getShortDescription(); $formProductShortDescription = $this->productView->getProductShortDescription(); - if ($fixtureProductShortDescription == $formProductShortDescription) { + if ($fixtureShortDescription === null || $fixtureShortDescription == $formProductShortDescription) { return null; } return "Displayed product short description on product page(front-end) not equals passed from fixture. " - . "Actual: {$formProductShortDescription}, expected: {$fixtureProductShortDescription}."; + . "Actual: {$formProductShortDescription}, expected: {$fixtureShortDescription}."; } /** diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml index 8f4ddfac5acd4..ae8f34d1960b7 100644 --- a/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml +++ b/dev/tests/functional/tests/app/Magento/Catalog/Test/Repository/CatalogProductSimple.xml @@ -1039,5 +1039,13 @@ default_subcategory + + + 1 + Overnight Duffle + 24-WB07 + overnight-duffle + + diff --git a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml index 39a4e1099dd8f..86bcc3e8e88b9 100644 --- a/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml +++ b/dev/tests/functional/tests/app/Magento/Install/Test/TestCase/InstallTest.xml @@ -8,19 +8,13 @@ - Install with default values. - default - - - - Install with custom admin path. default custom - + Install with custom encryption key and changed currency and locale. default Yes @@ -34,7 +28,7 @@ - + Install with table prefix. default pref_ @@ -42,7 +36,7 @@ - + Install with enabled url rewrites. default Yes @@ -50,7 +44,7 @@ - + Install with enabled secure urls. default Yes @@ -59,5 +53,11 @@ + + Install with default values. + default + + + diff --git a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php index 1b67d126ac6e9..e6ba349fee089 100644 --- a/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php +++ b/dev/tests/integration/testsuite/Magento/Quote/Model/QuoteManagementTest.php @@ -17,6 +17,7 @@ class QuoteManagementTest extends \PHPUnit_Framework_TestCase */ public function testSubmit() { + $this->markTestSkipped('Skipped because of MAGETWO-47215'); /** * Preconditions: * Load quote with Bundle product that has at least to child products diff --git a/lib/internal/Magento/Framework/Search/AbstractKeyValuePair.php b/lib/internal/Magento/Framework/Search/AbstractKeyValuePair.php index 392ec1159fd9c..2c956c36146c5 100644 --- a/lib/internal/Magento/Framework/Search/AbstractKeyValuePair.php +++ b/lib/internal/Magento/Framework/Search/AbstractKeyValuePair.php @@ -46,7 +46,7 @@ public function getName() /** * Get field values * - * @return mixed + * @return mixed Return data in raw-formt. Must be escaped for using in sql * @codeCoverageIgnore */ public function getValue()