Skip to content

Commit

Permalink
Merge pull request #1082 from magento-frontend/PR_26042017
Browse files Browse the repository at this point in the history
Fixed issues:
- MAGETWO-63197: ConfigureSecureUrlsTest is failing and next functional tests are also failing after it
- MAGETWO-66501: Build to create 2.2 packages is broken
- MAGETWO-63667: Can't get store-specific data via catalog API
- MAGETWO-62404: Product image does not displays on Product detail page
- MAGETWO-65540: When duplicating a product wrong images are assigned to the new duplicate product
  • Loading branch information
MomotenkoNatalia authored May 4, 2017
2 parents b67cf43 + 655b160 commit 1609448
Show file tree
Hide file tree
Showing 13 changed files with 324 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;

use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
use Magento\Framework\Data\Collection\AbstractDb;

class ProductStoreFilter implements CustomFilterInterface
{
/**
* Apply store Filter to Product Collection
*
* @param Filter $filter
* @param AbstractDb $collection
* @return bool Whether the filter is applied
*/
public function apply(Filter $filter, AbstractDb $collection)
{
/** @var Collection $collection */
$collection->addStoreFilter($filter->getValue());
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;

use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\Api\Filter;
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
use Magento\Framework\Data\Collection\AbstractDb;

class ProductWebsiteFilter implements CustomFilterInterface
{
/**
* Apply website Filter to Product Collection
*
* @param Filter $filter
* @param AbstractDb $collection
* @return bool Whether the filter is applied
*/
public function apply(Filter $filter, AbstractDb $collection)
{
$value = $filter->getValue();
if (strpos($value, ',') !== false) {
$value = explode(',', $value);
}
/** @var Collection $collection */
$collection->addWebsiteFilter($value);
return true;
}
}
6 changes: 4 additions & 2 deletions app/code/Magento/Catalog/Model/Product/Copier.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ public function copy(\Magento\Catalog\Model\Product $product)
$product->getWebsiteIds();
$product->getCategoryIds();

/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);

/** @var \Magento\Catalog\Model\Product $duplicate */
$duplicate = $this->productFactory->create();
$duplicate->setData($product->getData());
$duplicate->setOptions([]);
$duplicate->setIsDuplicate(true);
$duplicate->setOriginalId($product->getEntityId());
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
$duplicate->setCreatedAt(null);
$duplicate->setUpdatedAt(null);
Expand All @@ -81,7 +84,6 @@ public function copy(\Magento\Catalog\Model\Product $product)
}
} while (!$isDuplicateSaved);
$this->getOptionRepository()->duplicate($product, $duplicate);
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
$product->getResource()->duplicate(
$product->getData($metadata->getLinkField()),
$duplicate->getData($metadata->getLinkField())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ protected function duplicate($product)
$this->resourceModel->duplicate(
$this->getAttribute()->getAttributeId(),
isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [],
$product->getOriginalId(),
$product->getOriginalLinkId(),
$product->getData($this->metadata->getLinkField())
);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Test\Unit\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;

use Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductWebsiteFilter;
use Magento\Catalog\Model\ResourceModel\Product\Collection;
use Magento\Framework\Api\Filter;

class ProductWebsiteFilterTest extends \PHPUnit_Framework_TestCase
{
/** @var ProductWebsiteFilter */
private $model;

protected function setUp()
{
$this->model = new ProductWebsiteFilter();
}

public function testApply()
{
/** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */
$filterMock = $this->getMockBuilder(Filter::class)
->disableOriginalConstructor()
->getMock();

/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
$collectionMock = $this->getMockBuilder(Collection::class)
->disableOriginalConstructor()
->getMock();

$filterMock->expects($this->once())
->method('getValue')
->willReturn('1,2');

$collectionMock->expects($this->once())
->method('addWebsiteFilter')
->with(['1', '2']);

$this->assertTrue($this->model->apply($filterMock, $collectionMock));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testCopy()
'setOptions',
'getData',
'setIsDuplicate',
'setOriginalId',
'setOriginalLinkId',
'setStatus',
'setCreatedAt',
'setUpdatedAt',
Expand All @@ -117,7 +117,7 @@ public function testCopy()

$duplicateMock->expects($this->once())->method('setOptions')->with([]);
$duplicateMock->expects($this->once())->method('setIsDuplicate')->with(true);
$duplicateMock->expects($this->once())->method('setOriginalId')->with(1);
$duplicateMock->expects($this->once())->method('setOriginalLinkId')->with(1);
$duplicateMock->expects(
$this->once()
)->method(
Expand Down
2 changes: 2 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,8 @@
<arguments>
<argument name="customFilters" xsi:type="array">
<item name="category_id" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductCategoryFilter</item>
<item name="store" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductStoreFilter</item>
<item name="website_id" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductWebsiteFilter</item>
</argument>
</arguments>
</virtualType>
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Deploy/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "N/A",
"require": {
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
"magento/framework": "100.*.*",
"magento/framework": "100.2.*",
"magento/module-store": "100.2.*",
"magento/module-require-js": "100.2.*",
"magento/module-user": "100.2.*",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,132 @@ public function testGetList()
$this->assertEquals($expectedResult, $response['items'][0]['custom_attributes'][$index]['value']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
* @return void
*/
public function testGetListWithFilteringByWebsite()
{
$website = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Website::class);
$website->load('test', 'code');
$searchCriteria = [
'searchCriteria' => [
'filter_groups' => [
[
'filters' => [
[
'field' => 'website_id',
'value' => $website->getId(),
'condition_type' => 'eq',
],
],
],
],
'current_page' => 1,
'page_size' => 10,
],
];
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetList',
],
];
$response = $this->_webApiCall($serviceInfo, $searchCriteria);

$this->assertArrayHasKey('search_criteria', $response);
$this->assertArrayHasKey('total_count', $response);
$this->assertArrayHasKey('items', $response);
$this->assertTrue(count($response['items']) == 1);
$this->assertTrue(isset($response['items'][0]['sku']));
$this->assertEquals('simple-2', $response['items'][0]['sku']);
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
* @dataProvider testGetListWithFilteringByStoreDataProvider
*
* @param array $searchCriteria
* @param array $skus
* @param int $expectedProductCount
* @return void
*/
public function testGetListWithFilteringByStore(array $searchCriteria, array $skus, $expectedProductCount = null)
{
$serviceInfo = [
'rest' => [
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
],
'soap' => [
'service' => self::SERVICE_NAME,
'serviceVersion' => self::SERVICE_VERSION,
'operation' => self::SERVICE_NAME . 'GetList',
],
];
$response = $this->_webApiCall($serviceInfo, $searchCriteria);

$this->assertArrayHasKey('search_criteria', $response);
$this->assertArrayHasKey('total_count', $response);
$this->assertArrayHasKey('items', $response);
if ($expectedProductCount) {
$this->assertTrue(count($response['items']) == $expectedProductCount);
}

$isResultValid = false;
foreach ($skus as $sku) {
foreach ($response['items'] as $item) {
if ($item['sku'] == $sku) {
$isResultValid = true;
}
}
$this->assertTrue($isResultValid);
}
}

public function testGetListWithFilteringByStoreDataProvider()
{
return [
[
[
'searchCriteria' => [
'filter_groups' => [
[
'filters' => [
[
'field' => 'store',
'value' => 'fixture_second_store',
'condition_type' => 'eq',
],
],
],
],
'current_page' => 1,
'page_size' => 10,
],
],
['simple-2'],
1,
],
[
[
'searchCriteria' => [
'filter_groups' => [],
'current_page' => 1,
'page_size' => 10,
],
],
['simple-2', 'simple-1'],
null
]
];
}

/**
* @magentoApiDataFixture Magento/Catalog/_files/products_for_search.php
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,14 @@ class ConfigureSecureUrlsTest extends Injectable
*
* @param FixtureFactory $fixtureFactory
* @param SystemConfigEdit $configurationAdminPage
* @param Cache $cache
* @param StaticContent $staticContent
* @return void
*/
public function __inject(
FixtureFactory $fixtureFactory,
SystemConfigEdit $configurationAdminPage,
Cache $cache,
StaticContent $staticContent
SystemConfigEdit $configurationAdminPage
) {
$this->fixtureFactory = $fixtureFactory;
$this->configurationAdminPage = $configurationAdminPage;
$this->cache = $cache;
$this->staticContent = $staticContent;
}

/**
Expand All @@ -117,9 +111,6 @@ public function __inject(
*/
public function test($configData)
{
$this->markTestSkipped(
'MAGETWO-63197: ConfigureSecureUrlsTest is failing and next functional tests are also failing after it'
);
$data = [
'web/secure/base_url' => [
'scope' => 'default',
Expand All @@ -138,7 +129,14 @@ public function test($configData)
$this->configurationAdminPage->getPageActions()->save();
$_ENV['app_backend_url'] = str_replace('http', 'https', $_ENV['app_backend_url']);

$this->configurationAdminPage = $this->objectManager->create(
\Magento\Backend\Test\Page\Adminhtml\SystemConfigEdit::class
);

$this->cache = $this->objectManager->create(\Magento\Mtf\Util\Command\Cli\Cache::class);
$this->cache->flush(['config', 'full_page']);

$this->staticContent = $this->objectManager->create(\Magento\Mtf\Util\Command\Cli\StaticContent::class);
$this->staticContent->deploy();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

require __DIR__ . '/../../Store/_files/second_website_with_two_stores.php';

$website = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Store\Model\Website::class);
/** @var $website \Magento\Store\Model\Website */
$websiteId = $website->load('test', 'code')->getId();

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setWebsiteIds([$websiteId])
->setName('Simple Product on second website')
->setSku('simple-2')
->setPrice(10)
->setDescription('Description with <b>html tag</b>')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setCategoryIds([2])
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->save();

/** @var $product \Magento\Catalog\Model\Product */
$product = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Product::class);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
->setAttributeSetId(4)
->setWebsiteIds([1])
->setName('Simple Product')
->setSku('simple-1')
->setPrice(10)
->setDescription('Description with <b>html tag</b>')
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setCategoryIds([2])
->setStockData(['use_config_manage_stock' => 1, 'qty' => 100, 'is_qty_decimal' => 0, 'is_in_stock' => 1])
->save();
Loading

0 comments on commit 1609448

Please sign in to comment.