Skip to content

Commit 5670915

Browse files
committed
Merge remote-tracking branch 'performance-ce/MCP-806' into MCP-811
2 parents 2a1c6db + d151798 commit 5670915

File tree

3 files changed

+200
-67
lines changed

3 files changed

+200
-67
lines changed

dev/tests/api-functional/testsuite/Magento/Downloadable/Api/SampleRepositoryTest.php

Lines changed: 18 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,17 @@ class SampleRepositoryTest extends WebapiAbstract
3636
*/
3737
protected $deleteServiceInfo;
3838

39+
/**
40+
* @var DomainManagerInterface
41+
*/
42+
private $domainManager;
43+
3944
protected function setUp(): void
4045
{
46+
$objectManager = Bootstrap::getObjectManager();
47+
$this->domainManager = $objectManager->get(DomainManagerInterface::class);
48+
$this->domainManager->addDomains(['example.com']);
49+
4150
$this->createServiceInfo = [
4251
'rest' => [
4352
'resourcePath' => '/V1/products/downloadable-product/downloadable-links/samples',
@@ -75,6 +84,15 @@ protected function setUp(): void
7584
$this->testImagePath = __DIR__ . str_replace('/', DIRECTORY_SEPARATOR, '/_files/test_image.jpg');
7685
}
7786

87+
/**
88+
* Remove example domain from whitelist and call parent restore configuration
89+
*/
90+
protected function tearDown(): void
91+
{
92+
parent::tearDown();
93+
$this->domainManager->removeDomains(['example.com']);
94+
}
95+
7896
/**
7997
* Retrieve product that was updated by test
8098
*
@@ -155,58 +173,6 @@ public function testCreateUploadsProvidedFileContent()
155173
$this->assertNull($sample->getSampleUrl());
156174
}
157175

158-
/**
159-
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
160-
*/
161-
public function testCreateSavesTitleInStoreViewScope()
162-
{
163-
$requestData = [
164-
'isGlobalScopeContent' => false,
165-
'sku' => 'downloadable-product',
166-
'sample' => [
167-
'title' => 'Store View Title',
168-
'sort_order' => 1,
169-
'sample_url' => 'http://www.sample.example.com/',
170-
'sample_type' => 'url',
171-
],
172-
];
173-
174-
$newSampleId = $this->_webApiCall($this->createServiceInfo, $requestData);
175-
$sample = $this->getTargetSample($this->getTargetProduct(), $newSampleId);
176-
$globalScopeSample = $this->getTargetSample($this->getTargetProduct(true), $newSampleId);
177-
$this->assertNotNull($sample);
178-
$this->assertEquals($requestData['sample']['title'], $sample->getTitle());
179-
$this->assertEquals($requestData['sample']['sort_order'], $sample->getSortOrder());
180-
$this->assertEquals($requestData['sample']['sample_url'], $sample->getSampleUrl());
181-
$this->assertEquals($requestData['sample']['sample_type'], $sample->getSampleType());
182-
$this->assertEmpty($globalScopeSample->getTitle());
183-
}
184-
185-
/**
186-
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
187-
*/
188-
public function testCreateSavesProvidedUrls()
189-
{
190-
$requestData = [
191-
'isGlobalScopeContent' => false,
192-
'sku' => 'downloadable-product',
193-
'sample' => [
194-
'title' => 'Sample with URL resource',
195-
'sort_order' => 1,
196-
'sample_url' => 'http://www.sample.example.com/',
197-
'sample_type' => 'url',
198-
],
199-
];
200-
201-
$newSampleId = $this->_webApiCall($this->createServiceInfo, $requestData);
202-
$sample = $this->getTargetSample($this->getTargetProduct(), $newSampleId);
203-
$this->assertNotNull($sample);
204-
$this->assertEquals($requestData['sample']['title'], $sample->getTitle());
205-
$this->assertEquals($requestData['sample']['sort_order'], $sample->getSortOrder());
206-
$this->assertEquals($requestData['sample']['sample_type'], $sample->getSampleType());
207-
$this->assertEquals($requestData['sample']['sample_url'], $sample->getSampleUrl());
208-
}
209-
210176
/**
211177
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
212178
*/
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Downloadable\Model;
9+
10+
use Magento\Catalog\Api\ProductRepositoryInterface;
11+
use Magento\Catalog\Model\Product;
12+
use Magento\Catalog\Model\ProductFactory;
13+
use Magento\Downloadable\Api\Data\SampleInterfaceFactory;
14+
15+
/**
16+
* Test class for \Magento\Downloadable\Model\SampleRepository
17+
*/
18+
class SampleRepositoryTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var \Magento\Downloadable\Model\Product\Type
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var \Magento\Framework\ObjectManagerInterface
27+
*/
28+
private $objectManager;
29+
30+
protected function setUp(): void
31+
{
32+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
33+
$this->model = $this->objectManager->create(\Magento\Downloadable\Model\Product\Type::class);
34+
}
35+
36+
/**
37+
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
38+
*/
39+
public function testCreateSavesProvidedUrls()
40+
{
41+
/** @var ProductRepositoryInterface $productRepository */
42+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
43+
$product = $this->getTargetProduct(false);
44+
45+
$links = $this->model->getLinks($product);
46+
$this->assertNotEmpty($links);
47+
$samples = $this->model->getSamples($product);
48+
$this->assertEmpty($samples->getData());
49+
$downloadableSampleData = [
50+
'title' => 'Sample with URL resource',
51+
'sort_order' => 1,
52+
'sample_url' => 'http://www.sample.example.com/',
53+
'sample_type' => 'url',
54+
];
55+
56+
$sampleFactory = $this->objectManager->create(SampleInterfaceFactory::class);
57+
$extension = $product->getExtensionAttributes();
58+
$sample = $sampleFactory->create(['data' => $downloadableSampleData]);
59+
$sample->setStoreId($product->getStoreId());
60+
$sample->setSampleType($downloadableSampleData['sample_type']);
61+
$sample->setSampleUrl($downloadableSampleData['sample_url']);
62+
if (!$sample->getSortOrder()) {
63+
$sample->setSortOrder(1);
64+
}
65+
$extension->setDownloadableProductSamples([$sample]);
66+
$product->setExtensionAttributes($extension);
67+
$productRepository->save($product);
68+
69+
$samples = $this->getTargetProduct(false)->getExtensionAttributes()->getDownloadableProductSamples();
70+
$sample = reset($samples);
71+
72+
$this->assertNotEmpty($sample->getData());
73+
$this->assertCount(1, $samples);
74+
75+
/** @var \Magento\Downloadable\Model\Sample $sample */
76+
$sampleData = $sample->getData();
77+
/** @var \Magento\User\Api\Data\UserInterface $testAttribute */
78+
foreach ($downloadableSampleData as $key => $value) {
79+
$this->assertArrayHasKey($key, $sampleData);
80+
$this->assertEquals($value, $sampleData[$key]);
81+
}
82+
}
83+
84+
/**
85+
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
86+
*/
87+
public function testCreateSavesTitleInStoreViewScope(): void
88+
{
89+
/** @var ProductRepositoryInterface $productRepository */
90+
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
91+
$product = $this->getTargetProduct(false);
92+
93+
$links = $this->model->getLinks($product);
94+
$this->assertNotEmpty($links);
95+
$samples = $this->model->getSamples($product);
96+
$this->assertEmpty($samples->getData());
97+
$downloadableSampleData = [
98+
'title' => 'Store View Title',
99+
'sort_order' => 1,
100+
'sample_url' => 'http://www.sample.example.com/',
101+
'sample_type' => 'url'
102+
];
103+
104+
$sampleFactory = $this->objectManager->create(SampleInterfaceFactory::class);
105+
$extension = $product->getExtensionAttributes();
106+
$sample = $sampleFactory->create(['data' => $downloadableSampleData]);
107+
$sample->setStoreId($product->getStoreId());
108+
$sample->setSampleType($downloadableSampleData['sample_type']);
109+
$sample->setSampleUrl($downloadableSampleData['sample_url']);
110+
if (!$sample->getSortOrder()) {
111+
$sample->setSortOrder(1);
112+
}
113+
$extension->setDownloadableProductSamples([$sample]);
114+
$product->setExtensionAttributes($extension);
115+
$productRepository->save($product);
116+
117+
$samples = $this->getTargetProduct(false)->getExtensionAttributes()->getDownloadableProductSamples();
118+
$sample = reset($samples);
119+
120+
$this->assertNotEmpty($sample->getData());
121+
$this->assertCount(1, $samples);
122+
123+
/** @var \Magento\Downloadable\Model\Sample $sample */
124+
$sampleData = $sample->getData();
125+
/** @var \Magento\User\Api\Data\UserInterface $testAttribute */
126+
foreach ($downloadableSampleData as $key => $value) {
127+
$this->assertArrayHasKey($key, $sampleData);
128+
$this->assertEquals($value, $sampleData[$key]);
129+
}
130+
131+
$globalScopeSample = $this->getTargetSample(
132+
$this->getTargetProduct(true),
133+
(int)$sampleData['sample_id']
134+
);
135+
$this->assertEmpty($globalScopeSample->getTitle());
136+
}
137+
138+
/**
139+
* Retrieve product that was updated by test
140+
*
141+
* @param bool $isScopeGlobal if true product store ID will be set to 0
142+
* @return Product
143+
*/
144+
private function getTargetProduct(bool $isScopeGlobal): Product
145+
{
146+
if ($isScopeGlobal) {
147+
$product = $this->objectManager->get(ProductFactory::class)
148+
->create()->setStoreId(0)->load(1);
149+
} else {
150+
$product = $this->objectManager->get(ProductFactory::class)
151+
->create()
152+
->load(1);
153+
}
154+
155+
return $product;
156+
}
157+
158+
/**
159+
* Retrieve product sample by its ID (or first sample if ID is not specified)
160+
*
161+
* @param Product $product
162+
* @param int|null $sampleId
163+
* @return Sample|null
164+
*/
165+
private function getTargetSample(Product $product, int $sampleId = null): ?Sample
166+
{
167+
$samples = $product->getExtensionAttributes()->getDownloadableProductSamples();
168+
if ($sampleId) {
169+
if ($samples) {
170+
foreach ($samples as $sample) {
171+
if ((int)$sample->getId() === $sampleId) {
172+
return $sample;
173+
}
174+
}
175+
}
176+
177+
return null;
178+
}
179+
180+
return $samples[0];
181+
}
182+
}

lib/internal/Magento/Framework/App/DeploymentConfig/Reader.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ public function load($fileKey = null)
100100
if ($fileKey) {
101101
$filePath = $path . '/' . $this->configFilePool->getPath($fileKey);
102102
if ($fileDriver->isExists($filePath)) {
103-
$this->refreshCache($filePath);
104103
$result = include $filePath;
105104
if (!is_array($result)) {
106105
throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$filePath]));
@@ -111,7 +110,6 @@ public function load($fileKey = null)
111110
foreach ($configFiles as $file) {
112111
$configFile = $path . '/' . $file;
113112
if ($fileDriver->isExists($configFile)) {
114-
$this->refreshCache($configFile);
115113
$fileData = include $configFile;
116114
if (!is_array($fileData)) {
117115
throw new RuntimeException(new Phrase("Invalid configuration file: '%1'", [$configFile]));
@@ -126,17 +124,4 @@ public function load($fileKey = null)
126124
}
127125
return $result ?: [];
128126
}
129-
130-
/**
131-
* Invalidate cache
132-
*
133-
* @param string $filePath
134-
*/
135-
private function refreshCache(string $filePath): void
136-
{
137-
if (function_exists('opcache_invalidate')
138-
&& filter_var(ini_get('opcache.enable'), FILTER_VALIDATE_BOOLEAN)) {
139-
opcache_invalidate($filePath);
140-
}
141-
}
142127
}

0 commit comments

Comments
 (0)