Skip to content

Commit 44fdbd4

Browse files
oshmyheliukrganin
authored andcommitted
B2B-2091: [AWS S3]Stabilize general Import tests which require custom file assertion handler
1 parent 4a28d98 commit 44fdbd4

10 files changed

+398
-15
lines changed

app/code/Magento/AwsS3/Test/Mftf/Helper/FileAssertions.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ public function copy($source, $destination): void
9999
$this->helperInstance->copy($this->extractFilePath($source), $this->extractFilePath($destination));
100100
}
101101

102+
/**
103+
* {@inheritDoc}
104+
*
105+
* @param string $source - path to local file or json structure with paths by storage type.
106+
* @param string $destination - path to file or json structure with paths by storage type.
107+
* @throws \Magento\Framework\Exception\FileSystemException
108+
*/
109+
public function copyFromLocal($source, $destination): void
110+
{
111+
$this->helperInstance->copyFromLocal($this->extractFilePath($source), $this->extractFilePath($destination));
112+
}
113+
102114
/**
103115
* Create directory in the storage
104116
*

app/code/Magento/AwsS3/Test/Mftf/Helper/FileAssertionsInterface.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,17 @@ public function deleteFileIfExists($filePath): void;
4444
*/
4545
public function copy($source, $destination): void;
4646

47+
/**
48+
* Copy file from the local source into local or remote destination depends on storage FS
49+
*
50+
* @param string $source
51+
* @param string $destination
52+
* @return void
53+
*
54+
* @throws \Magento\Framework\Exception\FileSystemException
55+
*/
56+
public function copyFromLocal($source, $destination): void;
57+
4758
/**
4859
* Create directory in the storage
4960
*

app/code/Magento/AwsS3/Test/Mftf/Helper/S3FileAssertions.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,23 @@ public function copy($source, $destination): void
110110
$this->driver->copy($source, $destination);
111111
}
112112

113+
/**
114+
* Copy file from the local source into AWS S3 $destination
115+
*
116+
* @param string $source local FS path to the file which should be copied
117+
* @param string $destination path on AWS S3 where the file should be paste
118+
* @return void
119+
*
120+
* @throws \Magento\Framework\Exception\FileSystemException
121+
*/
122+
public function copyFromLocal($source, $destination): void
123+
{
124+
$this->driver->filePutContents(
125+
$destination,
126+
file_get_contents((substr($source, 0, 1) === '/') ? $source : MAGENTO_BP . '/' . $source)
127+
);
128+
}
129+
113130
/**
114131
* Create directory in the S3 bucket
115132
*
@@ -165,7 +182,10 @@ public function assertFileExists($filePath, $message = ''): void
165182
public function assertGlobbedFileExists($path, $pattern, $message = ''): void
166183
{
167184
$files = $this->driver->search($pattern, $path);
168-
$this->assertNotEmpty($files, "Failed asserting file matching glob pattern \"$pattern\" at location \"$path\" is not empty. " . $message);
185+
$this->assertNotEmpty(
186+
$files,
187+
"Failed asserting file matching glob pattern \"$pattern\" at location \"$path\" is not empty. " . $message
188+
);
169189
}
170190

171191
/**
@@ -221,7 +241,10 @@ public function assertFileDoesNotExist($filePath, $message = ''): void
221241
*/
222242
public function assertFileEmpty($filePath, $message = ''): void
223243
{
224-
$this->assertEmpty($this->driver->fileGetContents($filePath), "Failed asserting $filePath is empty. " . $message);
244+
$this->assertEmpty(
245+
$this->driver->fileGetContents($filePath),
246+
"Failed asserting $filePath is empty. " . $message
247+
);
225248
}
226249

227250
/**
@@ -235,7 +258,10 @@ public function assertFileEmpty($filePath, $message = ''): void
235258
*/
236259
public function assertFileNotEmpty($filePath, $message = ''): void
237260
{
238-
$this->assertNotEmpty($this->driver->fileGetContents($filePath), "Failed asserting $filePath is not empty. " . $message);
261+
$this->assertNotEmpty(
262+
$this->driver->fileGetContents($filePath),
263+
"Failed asserting $filePath is not empty. " . $message
264+
);
239265
}
240266

241267
/**
@@ -250,11 +276,16 @@ public function assertFileNotEmpty($filePath, $message = ''): void
250276
*/
251277
public function assertFileContainsString($filePath, $text, $message = ''): void
252278
{
253-
$this->assertStringContainsString($text, $this->driver->fileGetContents($filePath), "Failed asserting $filePath contains $text. " . $message);
279+
$this->assertStringContainsString(
280+
$text,
281+
$this->driver->fileGetContents($filePath),
282+
"Failed asserting $filePath contains $text. " . $message
283+
);
254284
}
255285

256286
/**
257-
* Asserts that a file with the given glob pattern at the given path on the remote storage system contains a given string
287+
* Asserts that a file with the given glob pattern at the given path
288+
* on the remote storage system contains a given string
258289
*
259290
* @param string $path
260291
* @param string $pattern
@@ -268,7 +299,12 @@ public function assertFileContainsString($filePath, $text, $message = ''): void
268299
public function assertGlobbedFileContainsString($path, $pattern, $text, $fileIndex = 0, $message = ''): void
269300
{
270301
$files = $this->driver->search($pattern, $path);
271-
$this->assertStringContainsString($text, $this->driver->fileGetContents($files[$fileIndex] ?? ''), "Failed asserting file of index \"$fileIndex\" matching glob pattern \"$pattern\" at location \"$path\" contains $text. " . $message);
302+
$this->assertStringContainsString(
303+
$text,
304+
$this->driver->fileGetContents($files[$fileIndex] ?? ''),
305+
"Failed asserting file of index \"$fileIndex\" matching glob pattern \"$pattern\""
306+
. " at location \"$path\" contains $text. " . $message
307+
);
272308
}
273309

274310
/**
@@ -283,7 +319,11 @@ public function assertGlobbedFileContainsString($path, $pattern, $text, $fileInd
283319
*/
284320
public function assertFileDoesNotContainString($filePath, $text, $message = ''): void
285321
{
286-
$this->assertStringNotContainsString($text, $this->driver->fileGetContents($filePath), "Failed asserting $filePath does not contain $text. " . $message);
322+
$this->assertStringNotContainsString(
323+
$text,
324+
$this->driver->fileGetContents($filePath),
325+
"Failed asserting $filePath does not contain $text. " . $message
326+
);
287327
}
288328

289329
/**
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminImportBundleProductTest">
12+
13+
<before>
14+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="createDirectory" stepKey="createDirectoryForImportImages">
15+
<argument name="path">var/import/images/{{ImportProduct_Bundle.name}}</argument>
16+
</helper>
17+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyProduct1BaseImage">
18+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProductSimple1_Bundle.baseImage}}</argument>
19+
<argument name="destination">var/import/images/{{ImportProduct_Bundle.name}}/{{ImportProductSimple1_Bundle.baseImage}}</argument>
20+
</helper>
21+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyProduct2BaseImage">
22+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProductSimple2_Bundle.smallImage}}</argument>
23+
<argument name="destination">var/import/images/{{ImportProduct_Bundle.name}}/{{ImportProductSimple2_Bundle.smallImage}}</argument>
24+
</helper>
25+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyProduct3BaseImage">
26+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProductSimple3_Bundle.thumbnailImage}}</argument>
27+
<argument name="destination">var/import/images/{{ImportProduct_Bundle.name}}/{{ImportProductSimple3_Bundle.thumbnailImage}}</argument>
28+
</helper>
29+
</before>
30+
31+
<after>
32+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="deleteDirectory" stepKey="deleteProductImageDirectory">
33+
<argument name="path">var/import/images/{{ImportProduct_Bundle.name}}</argument>
34+
</helper>
35+
</after>
36+
37+
</test>
38+
</tests>
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminImportDownloadableProductsWithFileLinksTest">
12+
13+
<before>
14+
<!-- Copy Images to Import Directory for Product Images -->
15+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="createDirectory" stepKey="createDirectoryForImportImages">
16+
<argument name="path">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}</argument>
17+
</helper>
18+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyBaseImage">
19+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.baseImage}}</argument>
20+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.baseImage}}</argument>
21+
</helper>
22+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copySmallImage">
23+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.smallImage}}</argument>
24+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.smallImage}}</argument>
25+
</helper>
26+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyThumbnailImage">
27+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.thumbnailImage}}</argument>
28+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.thumbnailImage}}</argument>
29+
</helper>
30+
31+
<!-- Copy Images to Import Directory for Downloadable Links -->
32+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="createDirectory" stepKey="createDirectoryForImportDownloadableLinkFiles">
33+
<argument name="path">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}"}</argument>
34+
</helper>
35+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyImportFile">
36+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.fileName}}</argument>
37+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.fileName}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.fileName}}"}</argument>
38+
</helper>
39+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyBaseImage2">
40+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.baseImage}}</argument>
41+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.baseImage}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.baseImage}}"}</argument>
42+
</helper>
43+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copySmallImage2">
44+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.smallImage}}</argument>
45+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.smallImage}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.smallImage}}"}</argument>
46+
</helper>
47+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyThumbnailImage3">
48+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_FileLinks.thumbnailImage}}</argument>
49+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.thumbnailImage}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}/{{ImportProduct_Downloadable_FileLinks.thumbnailImage}}"}</argument>
50+
</helper>
51+
</before>
52+
53+
<after>
54+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="deleteDirectory" stepKey="deleteProductImageDirectory">
55+
<argument name="path">var/import/images/{{ImportProduct_Downloadable_FileLinks.name}}</argument>
56+
</helper>
57+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="deleteDirectory" stepKey="deleteDownloadableLinkFilesDirectory">
58+
<argument name="path">{"local":"pub/media/import/{{ImportProduct_Downloadable_FileLinks.name}}","s3":"media/import/{{ImportProduct_Downloadable_FileLinks.name}}"}</argument>
59+
</helper>
60+
</after>
61+
62+
</test>
63+
</tests>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
9+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
10+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
11+
<test name="AdminImportDownloadableProductsWithUrlLinksTest">
12+
13+
<before>
14+
<!-- Copy Images to Import Directory for Product Images -->
15+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="createDirectory" stepKey="createDirectoryForImportImages">
16+
<argument name="path">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}</argument>
17+
</helper>
18+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyBaseImage">
19+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.baseImage}}</argument>
20+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.baseImage}}</argument>
21+
</helper>
22+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copySmallImage">
23+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.smallImage}}</argument>
24+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.smallImage}}</argument>
25+
</helper>
26+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyThumbnailImage">
27+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.thumbnailImage}}</argument>
28+
<argument name="destination">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.thumbnailImage}}</argument>
29+
</helper>
30+
31+
<!-- Copy Images to Import Directory for Downloadable Links -->
32+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="createDirectory" stepKey="createDirectoryForImportDownloadableLinkFiles">
33+
<argument name="path">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}"}</argument>
34+
</helper>
35+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyImportFile">
36+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.fileName}}</argument>
37+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.fileName}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.fileName}}"}</argument>
38+
</helper>
39+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyBaseImage2">
40+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.baseImage}}</argument>
41+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.baseImage}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.baseImage}}"}</argument>
42+
</helper>
43+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copySmallImage2">
44+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.smallImage}}</argument>
45+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.smallImage}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.smallImage}}"}</argument>
46+
</helper>
47+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="copyFromLocal" stepKey="copyThumbnailImage3">
48+
<argument name="source">dev/tests/acceptance/tests/_data/{{ImportProduct_Downloadable_UrlLinks.thumbnailImage}}</argument>
49+
<argument name="destination">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.thumbnailImage}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}/{{ImportProduct_Downloadable_UrlLinks.thumbnailImage}}"}</argument>
50+
</helper>
51+
</before>
52+
53+
<after>
54+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="deleteDirectory" stepKey="deleteProductImageDirectory">
55+
<argument name="path">var/import/images/{{ImportProduct_Downloadable_UrlLinks.name}}</argument>
56+
</helper>
57+
<helper class="Magento\AwsS3\Test\Mftf\Helper\FileAssertions" method="deleteDirectory" stepKey="deleteDownloadableLinkFilesDirectory">
58+
<argument name="path">{"local":"pub/media/import/{{ImportProduct_Downloadable_UrlLinks.name}}","s3":"media/import/{{ImportProduct_Downloadable_UrlLinks.name}}"}</argument>
59+
</helper>
60+
</after>
61+
</test>
62+
</tests>

0 commit comments

Comments
 (0)