Skip to content

Commit a120e60

Browse files
committed
MC-20425: [Integration Test] Check behavior when attribute set was changed to a new set with deleted attribute from the previous set
1 parent 418a065 commit a120e60

File tree

3 files changed

+19
-28
lines changed

3 files changed

+19
-28
lines changed

dev/tests/integration/testsuite/Magento/Catalog/Controller/Product/ViewTest.php

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
use Magento\Eav\Model\Entity\Type;
2020
use Magento\Framework\Filesystem;
2121
use Magento\Framework\Filesystem\Directory\WriteInterface;
22-
use Magento\TestFramework\Helper\Bootstrap;
22+
use Magento\Framework\Filesystem\File\WriteInterface as FileWriteInterface;
23+
use Magento\Framework\Filesystem\Driver\File;
2324

2425
/**
2526
* Integration test for product view front action.
@@ -84,11 +85,10 @@ public function testViewActionWithCanonicalTag(): void
8485
* View product with custom attribute when attribute removed from it.
8586
*
8687
* It tests that after changing product attribute set from Default to Custom
87-
* there are no waring messages in log in case Custom not contains attribute from Default.
88+
* there are no warning messages in log in case Custom not contains attribute from Default.
8889
*
8990
* @magentoDataFixture Magento/Catalog/_files/product_simple_with_country_of_manufacture.php
9091
* @magentoDataFixture Magento/Catalog/_files/attribute_set_based_on_default_without_country_of_manufacture.php
91-
* @magentoDbIsolation disabled
9292
* @return void
9393
*/
9494
public function testViewActionCustomAttributeSetWithoutCountryOfManufacture(): void
@@ -129,9 +129,7 @@ private function checkSystemLogForMessage(string $message): bool
129129
*/
130130
private function getProductBySku(string $sku): Product
131131
{
132-
$product = $this->productRepository->get($sku);
133-
134-
return $product;
132+
return $this->productRepository->get($sku);
135133
}
136134

137135
/**
@@ -175,31 +173,28 @@ private function getProductAttributeSetByName(string $attributeSetName): ?Set
175173
private function getSystemLogContent(): string
176174
{
177175
$logDir = $this->getLogDirectoryWrite();
178-
$logFullFileName = $logDir->getAbsolutePath($this->systemLogFileName);
179-
$content = $this->tail($logFullFileName, 10);
176+
$logFile = $logDir->openFile($this->systemLogFileName, 'rb');
177+
$content = $this->tail($logFile, 10);
180178

181179
return $content;
182180
}
183181

184182
/**
185183
* Get file tail.
186184
*
187-
* @param string $filename
185+
* @param FileWriteInterface $file
188186
* @param int $lines
189187
* @param int $buffer
190188
* @return false|string
191189
*/
192-
private function tail(string $filename, int $lines = 10, int $buffer = 4096)
190+
private function tail(FileWriteInterface $file, int $lines = 10, int $buffer = 4096)
193191
{
194-
// Open the file
195-
$f = fopen($filename, "rb");
196-
197192
// Jump to last character
198-
fseek($f, -1, SEEK_END);
193+
$file->seek(-1, SEEK_END);
199194

200195
// Read it and adjust line number if necessary
201196
// (Otherwise the result would be wrong if file doesn't end with a blank line)
202-
if (fread($f, 1) != "\n") {
197+
if ($file->read(1) != "\n") {
203198
$lines--;
204199
}
205200

@@ -208,18 +203,18 @@ private function tail(string $filename, int $lines = 10, int $buffer = 4096)
208203
$chunk = '';
209204

210205
// While we would like more
211-
while (ftell($f) > 0 && $lines >= 0) {
206+
while ($file->tell() > 0 && $lines >= 0) {
212207
// Figure out how far back we should jump
213-
$seek = min(ftell($f), $buffer);
208+
$seek = min($file->tell(), $buffer);
214209

215210
// Do the jump (backwards, relative to where we are)
216-
fseek($f, -$seek, SEEK_CUR);
211+
$file->seek(-$seek, SEEK_CUR);
217212

218213
// Read a chunk and prepend it to our output
219-
$output = ($chunk = fread($f, $seek)) . $output;
214+
$output = ($chunk = $file->read($seek)) . $output;
220215

221216
// Jump back to where we started reading
222-
fseek($f, -mb_strlen($chunk, '8bit'), SEEK_CUR);
217+
$file->seek(-mb_strlen($chunk, '8bit'), SEEK_CUR);
223218

224219
// Decrease our line counter
225220
$lines -= substr_count($chunk, "\n");
@@ -233,7 +228,7 @@ private function tail(string $filename, int $lines = 10, int $buffer = 4096)
233228
}
234229

235230
// Close file and return
236-
fclose($f);
231+
$file->close();
237232

238233
return $output;
239234
}

dev/tests/integration/testsuite/Magento/Catalog/_files/attribute_set_based_on_default_without_country_of_manufacture.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,9 @@
2222

2323
/** @var Magento\Eav\Model\Entity\Attribute\Set $attributeSet */
2424
$attributeSet = $objectManager->create(Set::class);
25+
/** @var Type $entityType */
2526
$entityType = $objectManager->create(Type::class)
2627
->loadByCode(Magento\Catalog\Model\Product::ENTITY);
27-
$defaultSetId = $objectManager->create(Product::class)
28-
->getDefaultAttributeSetid();
2928
$data = [
3029
'attribute_set_name' => 'custom_attribute_set_wout_com',
3130
'entity_type_id' => $entityType->getId(),
@@ -35,7 +34,7 @@
3534
$attributeSet->setData($data);
3635
$attributeSet->validate();
3736
$attributeSet->save();
38-
$attributeSet->initFromSkeleton($defaultSetId);
37+
$attributeSet->initFromSkeleton($entityType->getDefaultAttributeSetId());
3938
/** @var Group $group */
4039
foreach ($attributeSet->getGroups() as $group) {
4140
$groupAttributes = $group->getAttributes();

dev/tests/integration/testsuite/Magento/Catalog/_files/product_simple_with_country_of_manufacture.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,9 @@
2121
$productFactory = $objectManager->create(ProductInterfaceFactory::class);
2222
/** @var $product \Magento\Catalog\Model\Product */
2323

24-
$defaultSetId = $objectManager->create(Product::class)
25-
->getDefaultAttributeSetid();
26-
2724
$product = $productFactory->create();
2825
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE)
29-
->setAttributeSetId($defaultSetId)
26+
->setAttributeSetId($product->getDefaultAttributeSetId())
3027
->setWebsiteIds([1])
3128
->setName('Simple Product With Country Of Manufacture')
3229
->setSku('simple_with_com')

0 commit comments

Comments
 (0)