Skip to content

Commit 1609448

Browse files
Merge pull request #1082 from magento-frontend/PR_26042017
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
2 parents b67cf43 + 655b160 commit 1609448

File tree

13 files changed

+324
-17
lines changed

13 files changed

+324
-17
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;
7+
8+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
9+
use Magento\Framework\Api\Filter;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
13+
class ProductStoreFilter implements CustomFilterInterface
14+
{
15+
/**
16+
* Apply store Filter to Product Collection
17+
*
18+
* @param Filter $filter
19+
* @param AbstractDb $collection
20+
* @return bool Whether the filter is applied
21+
*/
22+
public function apply(Filter $filter, AbstractDb $collection)
23+
{
24+
/** @var Collection $collection */
25+
$collection->addStoreFilter($filter->getValue());
26+
return true;
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;
7+
8+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
9+
use Magento\Framework\Api\Filter;
10+
use Magento\Framework\Api\SearchCriteria\CollectionProcessor\FilterProcessor\CustomFilterInterface;
11+
use Magento\Framework\Data\Collection\AbstractDb;
12+
13+
class ProductWebsiteFilter implements CustomFilterInterface
14+
{
15+
/**
16+
* Apply website Filter to Product Collection
17+
*
18+
* @param Filter $filter
19+
* @param AbstractDb $collection
20+
* @return bool Whether the filter is applied
21+
*/
22+
public function apply(Filter $filter, AbstractDb $collection)
23+
{
24+
$value = $filter->getValue();
25+
if (strpos($value, ',') !== false) {
26+
$value = explode(',', $value);
27+
}
28+
/** @var Collection $collection */
29+
$collection->addWebsiteFilter($value);
30+
return true;
31+
}
32+
}

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,15 @@ public function copy(\Magento\Catalog\Model\Product $product)
5454
$product->getWebsiteIds();
5555
$product->getCategoryIds();
5656

57+
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
58+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
59+
5760
/** @var \Magento\Catalog\Model\Product $duplicate */
5861
$duplicate = $this->productFactory->create();
5962
$duplicate->setData($product->getData());
6063
$duplicate->setOptions([]);
6164
$duplicate->setIsDuplicate(true);
62-
$duplicate->setOriginalId($product->getEntityId());
65+
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
6366
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
6467
$duplicate->setCreatedAt(null);
6568
$duplicate->setUpdatedAt(null);
@@ -81,7 +84,6 @@ public function copy(\Magento\Catalog\Model\Product $product)
8184
}
8285
} while (!$isDuplicateSaved);
8386
$this->getOptionRepository()->duplicate($product, $duplicate);
84-
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
8587
$product->getResource()->duplicate(
8688
$product->getData($metadata->getLinkField()),
8789
$duplicate->getData($metadata->getLinkField())

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ protected function duplicate($product)
297297
$this->resourceModel->duplicate(
298298
$this->getAttribute()->getAttributeId(),
299299
isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [],
300-
$product->getOriginalId(),
300+
$product->getOriginalLinkId(),
301301
$product->getData($this->metadata->getLinkField())
302302
);
303303

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Catalog\Test\Unit\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor;
7+
8+
use Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductWebsiteFilter;
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Framework\Api\Filter;
11+
12+
class ProductWebsiteFilterTest extends \PHPUnit_Framework_TestCase
13+
{
14+
/** @var ProductWebsiteFilter */
15+
private $model;
16+
17+
protected function setUp()
18+
{
19+
$this->model = new ProductWebsiteFilter();
20+
}
21+
22+
public function testApply()
23+
{
24+
/** @var Filter|\PHPUnit_Framework_MockObject_MockObject $filterMock */
25+
$filterMock = $this->getMockBuilder(Filter::class)
26+
->disableOriginalConstructor()
27+
->getMock();
28+
29+
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collectionMock */
30+
$collectionMock = $this->getMockBuilder(Collection::class)
31+
->disableOriginalConstructor()
32+
->getMock();
33+
34+
$filterMock->expects($this->once())
35+
->method('getValue')
36+
->willReturn('1,2');
37+
38+
$collectionMock->expects($this->once())
39+
->method('addWebsiteFilter')
40+
->with(['1', '2']);
41+
42+
$this->assertTrue($this->model->apply($filterMock, $collectionMock));
43+
}
44+
}

app/code/Magento/Catalog/Test/Unit/Model/Product/CopierTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public function testCopy()
9898
'setOptions',
9999
'getData',
100100
'setIsDuplicate',
101-
'setOriginalId',
101+
'setOriginalLinkId',
102102
'setStatus',
103103
'setCreatedAt',
104104
'setUpdatedAt',
@@ -117,7 +117,7 @@ public function testCopy()
117117

118118
$duplicateMock->expects($this->once())->method('setOptions')->with([]);
119119
$duplicateMock->expects($this->once())->method('setIsDuplicate')->with(true);
120-
$duplicateMock->expects($this->once())->method('setOriginalId')->with(1);
120+
$duplicateMock->expects($this->once())->method('setOriginalLinkId')->with(1);
121121
$duplicateMock->expects(
122122
$this->once()
123123
)->method(

app/code/Magento/Catalog/etc/di.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,8 @@
835835
<arguments>
836836
<argument name="customFilters" xsi:type="array">
837837
<item name="category_id" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductCategoryFilter</item>
838+
<item name="store" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductStoreFilter</item>
839+
<item name="website_id" xsi:type="object">Magento\Catalog\Model\Api\SearchCriteria\CollectionProcessor\FilterProcessor\ProductWebsiteFilter</item>
838840
</argument>
839841
</arguments>
840842
</virtualType>

app/code/Magento/Deploy/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "N/A",
44
"require": {
55
"php": "7.0.2|7.0.4|~7.0.6|~7.1.0",
6-
"magento/framework": "100.*.*",
6+
"magento/framework": "100.2.*",
77
"magento/module-store": "100.2.*",
88
"magento/module-require-js": "100.2.*",
99
"magento/module-user": "100.2.*",

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -710,6 +710,132 @@ public function testGetList()
710710
$this->assertEquals($expectedResult, $response['items'][0]['custom_attributes'][$index]['value']);
711711
}
712712

713+
/**
714+
* @magentoApiDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
715+
* @return void
716+
*/
717+
public function testGetListWithFilteringByWebsite()
718+
{
719+
$website = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(Website::class);
720+
$website->load('test', 'code');
721+
$searchCriteria = [
722+
'searchCriteria' => [
723+
'filter_groups' => [
724+
[
725+
'filters' => [
726+
[
727+
'field' => 'website_id',
728+
'value' => $website->getId(),
729+
'condition_type' => 'eq',
730+
],
731+
],
732+
],
733+
],
734+
'current_page' => 1,
735+
'page_size' => 10,
736+
],
737+
];
738+
$serviceInfo = [
739+
'rest' => [
740+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
741+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
742+
],
743+
'soap' => [
744+
'service' => self::SERVICE_NAME,
745+
'serviceVersion' => self::SERVICE_VERSION,
746+
'operation' => self::SERVICE_NAME . 'GetList',
747+
],
748+
];
749+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
750+
751+
$this->assertArrayHasKey('search_criteria', $response);
752+
$this->assertArrayHasKey('total_count', $response);
753+
$this->assertArrayHasKey('items', $response);
754+
$this->assertTrue(count($response['items']) == 1);
755+
$this->assertTrue(isset($response['items'][0]['sku']));
756+
$this->assertEquals('simple-2', $response['items'][0]['sku']);
757+
}
758+
759+
/**
760+
* @magentoApiDataFixture Magento/Catalog/_files/products_with_websites_and_stores.php
761+
* @dataProvider testGetListWithFilteringByStoreDataProvider
762+
*
763+
* @param array $searchCriteria
764+
* @param array $skus
765+
* @param int $expectedProductCount
766+
* @return void
767+
*/
768+
public function testGetListWithFilteringByStore(array $searchCriteria, array $skus, $expectedProductCount = null)
769+
{
770+
$serviceInfo = [
771+
'rest' => [
772+
'resourcePath' => self::RESOURCE_PATH . '?' . http_build_query($searchCriteria),
773+
'httpMethod' => \Magento\Framework\Webapi\Rest\Request::HTTP_METHOD_GET,
774+
],
775+
'soap' => [
776+
'service' => self::SERVICE_NAME,
777+
'serviceVersion' => self::SERVICE_VERSION,
778+
'operation' => self::SERVICE_NAME . 'GetList',
779+
],
780+
];
781+
$response = $this->_webApiCall($serviceInfo, $searchCriteria);
782+
783+
$this->assertArrayHasKey('search_criteria', $response);
784+
$this->assertArrayHasKey('total_count', $response);
785+
$this->assertArrayHasKey('items', $response);
786+
if ($expectedProductCount) {
787+
$this->assertTrue(count($response['items']) == $expectedProductCount);
788+
}
789+
790+
$isResultValid = false;
791+
foreach ($skus as $sku) {
792+
foreach ($response['items'] as $item) {
793+
if ($item['sku'] == $sku) {
794+
$isResultValid = true;
795+
}
796+
}
797+
$this->assertTrue($isResultValid);
798+
}
799+
}
800+
801+
public function testGetListWithFilteringByStoreDataProvider()
802+
{
803+
return [
804+
[
805+
[
806+
'searchCriteria' => [
807+
'filter_groups' => [
808+
[
809+
'filters' => [
810+
[
811+
'field' => 'store',
812+
'value' => 'fixture_second_store',
813+
'condition_type' => 'eq',
814+
],
815+
],
816+
],
817+
],
818+
'current_page' => 1,
819+
'page_size' => 10,
820+
],
821+
],
822+
['simple-2'],
823+
1,
824+
],
825+
[
826+
[
827+
'searchCriteria' => [
828+
'filter_groups' => [],
829+
'current_page' => 1,
830+
'page_size' => 10,
831+
],
832+
],
833+
['simple-2', 'simple-1'],
834+
null
835+
]
836+
];
837+
}
838+
713839
/**
714840
* @magentoApiDataFixture Magento/Catalog/_files/products_for_search.php
715841
*/

dev/tests/functional/tests/app/Magento/Backend/Test/TestCase/ConfigureSecureUrlsTest.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,14 @@ class ConfigureSecureUrlsTest extends Injectable
9393
*
9494
* @param FixtureFactory $fixtureFactory
9595
* @param SystemConfigEdit $configurationAdminPage
96-
* @param Cache $cache
97-
* @param StaticContent $staticContent
9896
* @return void
9997
*/
10098
public function __inject(
10199
FixtureFactory $fixtureFactory,
102-
SystemConfigEdit $configurationAdminPage,
103-
Cache $cache,
104-
StaticContent $staticContent
100+
SystemConfigEdit $configurationAdminPage
105101
) {
106102
$this->fixtureFactory = $fixtureFactory;
107103
$this->configurationAdminPage = $configurationAdminPage;
108-
$this->cache = $cache;
109-
$this->staticContent = $staticContent;
110104
}
111105

112106
/**
@@ -117,9 +111,6 @@ public function __inject(
117111
*/
118112
public function test($configData)
119113
{
120-
$this->markTestSkipped(
121-
'MAGETWO-63197: ConfigureSecureUrlsTest is failing and next functional tests are also failing after it'
122-
);
123114
$data = [
124115
'web/secure/base_url' => [
125116
'scope' => 'default',
@@ -138,7 +129,14 @@ public function test($configData)
138129
$this->configurationAdminPage->getPageActions()->save();
139130
$_ENV['app_backend_url'] = str_replace('http', 'https', $_ENV['app_backend_url']);
140131

132+
$this->configurationAdminPage = $this->objectManager->create(
133+
\Magento\Backend\Test\Page\Adminhtml\SystemConfigEdit::class
134+
);
135+
136+
$this->cache = $this->objectManager->create(\Magento\Mtf\Util\Command\Cli\Cache::class);
141137
$this->cache->flush(['config', 'full_page']);
138+
139+
$this->staticContent = $this->objectManager->create(\Magento\Mtf\Util\Command\Cli\StaticContent::class);
142140
$this->staticContent->deploy();
143141
}
144142

0 commit comments

Comments
 (0)