Skip to content

Commit d151798

Browse files
committed
MCP-806: Prevent opcache invalidation on every request
- Move test from web api to integration because of error on CI builds that domain is not in the list of downloadable domains in env.php
1 parent 38193f2 commit d151798

File tree

2 files changed

+46
-34
lines changed

2 files changed

+46
-34
lines changed

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

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -173,31 +173,6 @@ public function testCreateUploadsProvidedFileContent()
173173
$this->assertNull($sample->getSampleUrl());
174174
}
175175

176-
/**
177-
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
178-
*/
179-
public function testCreateSavesProvidedUrls()
180-
{
181-
$requestData = [
182-
'isGlobalScopeContent' => false,
183-
'sku' => 'downloadable-product',
184-
'sample' => [
185-
'title' => 'Sample with URL resource',
186-
'sort_order' => 1,
187-
'sample_url' => 'http://www.sample.example.com/',
188-
'sample_type' => 'url',
189-
],
190-
];
191-
192-
$newSampleId = $this->_webApiCall($this->createServiceInfo, $requestData);
193-
$sample = $this->getTargetSample($this->getTargetProduct(), $newSampleId);
194-
$this->assertNotNull($sample);
195-
$this->assertEquals($requestData['sample']['title'], $sample->getTitle());
196-
$this->assertEquals($requestData['sample']['sort_order'], $sample->getSortOrder());
197-
$this->assertEquals($requestData['sample']['sample_type'], $sample->getSampleType());
198-
$this->assertEquals($requestData['sample']['sample_url'], $sample->getSampleUrl());
199-
}
200-
201176
/**
202177
* @magentoApiDataFixture Magento/Downloadable/_files/product_downloadable.php
203178
*/

dev/tests/integration/testsuite/Magento/Downloadable/Model/SampleRepositoryTest.php

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,9 @@ protected function setUp(): void
3434
}
3535

3636
/**
37-
* Originally this test belonged to \Magento\Downloadable\Api\SampleRepositoryTest
38-
* but it was moved to integration tests
39-
* because of error on CI builds that sample URL's domain is not in the list of downloadable_domains in env.php
40-
*
4137
* @magentoDataFixture Magento/Downloadable/_files/product_downloadable.php
4238
*/
43-
public function testCreateSavesTitleInStoreViewScope(): void
39+
public function testCreateSavesProvidedUrls()
4440
{
4541
/** @var ProductRepositoryInterface $productRepository */
4642
$productRepository = $this->objectManager->create(ProductRepositoryInterface::class);
@@ -51,7 +47,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
5147
$samples = $this->model->getSamples($product);
5248
$this->assertEmpty($samples->getData());
5349
$downloadableSampleData = [
54-
'title' => 'Store View Title',
50+
'title' => 'Sample with URL resource',
5551
'sort_order' => 1,
5652
'sample_url' => 'http://www.sample.example.com/',
5753
'sample_type' => 'url',
@@ -70,13 +66,54 @@ public function testCreateSavesTitleInStoreViewScope(): void
7066
$product->setExtensionAttributes($extension);
7167
$productRepository->save($product);
7268

73-
$expectedSample = [
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 = [
7498
'title' => 'Store View Title',
7599
'sort_order' => 1,
76100
'sample_url' => 'http://www.sample.example.com/',
77-
'sample_type' => 'url',
101+
'sample_type' => 'url'
78102
];
79103

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+
80117
$samples = $this->getTargetProduct(false)->getExtensionAttributes()->getDownloadableProductSamples();
81118
$sample = reset($samples);
82119

@@ -86,7 +123,7 @@ public function testCreateSavesTitleInStoreViewScope(): void
86123
/** @var \Magento\Downloadable\Model\Sample $sample */
87124
$sampleData = $sample->getData();
88125
/** @var \Magento\User\Api\Data\UserInterface $testAttribute */
89-
foreach ($expectedSample as $key => $value) {
126+
foreach ($downloadableSampleData as $key => $value) {
90127
$this->assertArrayHasKey($key, $sampleData);
91128
$this->assertEquals($value, $sampleData[$key]);
92129
}

0 commit comments

Comments
 (0)