Skip to content

Commit 22b2587

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into MC-38620
2 parents e3ae222 + 9a655bb commit 22b2587

23 files changed

+814
-39
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminCategoryOpenDesignSectionActionGroup">
11+
<waitForElementVisible selector="{{CategoryDesignSection.DesignTab}}" stepKey="waitForDesignSection"/>
12+
<conditionalClick selector="{{CategoryDesignSection.DesignTab}}" dependentSelector="{{CategoryDesignSection.LayoutDropdown}}" visible="false" stepKey="openDesignSection"/>
13+
<waitForPageLoad stepKey="waitForDesignSectionLoad"/>
14+
</actionGroup>
15+
</actionGroups>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
<actionGroups xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/actionGroupSchema.xsd">
10+
<actionGroup name="AdminCategoryOpenScheduleDesignUpdateSectionActionGroup">
11+
<waitForElementVisible selector="{{AdminCategoryScheduleDesignUpdateSection.sectionHeader}}" stepKey="waitForScheduleDesignUpdateSection"/>
12+
<conditionalClick selector="{{AdminCategoryScheduleDesignUpdateSection.sectionHeader}}" dependentSelector="{{AdminCategoryScheduleDesignUpdateSection.customDesignFrom}}" visible="false" stepKey="openScheduleDesignUpdateSection"/>
13+
<waitForPageLoad stepKey="waitForScheduleDesignUpdateSectionLoad"/>
14+
</actionGroup>
15+
</actionGroups>

app/code/Magento/Catalog/Test/Mftf/Section/AdminCategoryScheduleDesignUpdateSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<section name="AdminCategoryScheduleDesignUpdateSection">
1111
<element name="sectionHeader" type="button" selector="div[data-index='schedule_design_update'] .fieldset-wrapper-title" timeout="30"/>
1212
<element name="sectionBody" type="text" selector="div[data-index='schedule_design_update'] .admin__fieldset-wrapper-content"/>
13+
<element name="customDesignFrom" type="input" selector="div[data-index='schedule_design_update'] input[name='custom_design_from']"/>
1314
</section>
1415
</sections>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
<tests xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:mftf:Test/etc/testSchema.xsd">
10+
<test name="AdminUploadCategoryImageTest">
11+
<annotations>
12+
<features value="Catalog"/>
13+
<stories value="Add/remove images and videos for all product types and category"/>
14+
<title value="Upload Category Image"/>
15+
<description value="The test verifies uploading images including a special case of image name with spaces"/>
16+
<severity value="MAJOR"/>
17+
<testCaseId value="MC-26112"/>
18+
<group value="catalog"/>
19+
</annotations>
20+
21+
<before>
22+
<createData entity="_defaultCategory" stepKey="createCategory"/>
23+
<actionGroup ref="AdminLoginActionGroup" stepKey="loginAsAdmin"/>
24+
</before>
25+
26+
<after>
27+
<deleteData createDataKey="createCategory" stepKey="deleteCategory"/>
28+
<actionGroup ref="AdminLogoutActionGroup" stepKey="adminLogout"/>
29+
</after>
30+
31+
<!--Go to created category admin page and upload image-->
32+
<actionGroup ref="GoToAdminCategoryPageByIdActionGroup" stepKey="goToAdminCategoryPage">
33+
<argument name="id" value="$createCategory.id$"/>
34+
</actionGroup>
35+
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImage"/>
36+
<actionGroup ref="CheckCategoryImageInAdminActionGroup" stepKey="checkCategoryImageInAdmin"/>
37+
<!--Remove and upload new image-->
38+
<actionGroup ref="RemoveCategoryImageActionGroup" stepKey="removeCategoryImage"/>
39+
<actionGroup ref="AddCategoryImageActionGroup" stepKey="addCategoryImageAgain">
40+
<argument name="image" value="ImageUploadPngTwo"/>
41+
</actionGroup>
42+
<actionGroup ref="CheckCategoryImageInAdminActionGroup" stepKey="checkCategoryImageInAdminAgain"/>
43+
</test>
44+
</tests>

app/code/Magento/MediaGalleryUi/Test/Mftf/Data/AdminEnhancedMediaGalleryImageData.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,8 @@
4040
<data key="extension">jpg</data>
4141
<data key="keywords">magento, mediagallerymetadata</data>
4242
</entity>
43+
<entity name="ImageUploadPngTwo" type="image">
44+
<data key="file">magento-logo_2.png</data>
45+
<data key="extension">png</data>
46+
</entity>
4347
</entities>

app/code/Magento/Theme/Test/Mftf/Section/StorefrontHeaderSection.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<section name="StorefrontHeaderSection">
1111
<element name="welcomeMessage" type="text" selector=".greet.welcome"/>
1212
<element name="logoLink" type="button" selector=".header .logo"/>
13+
<element name="logoImage" type="button" selector=".header .logo > img[src*='{{filename}}']" parameterized="true"/>
1314
</section>
1415
</sections>
Loading

dev/tests/integration/testsuite/Magento/Catalog/Model/ImageUploaderTest.php

Lines changed: 60 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,62 +8,77 @@
88
namespace Magento\Catalog\Model;
99

1010
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Exception\LocalizedException;
12+
use Magento\Framework\Filesystem;
13+
use Magento\Framework\Filesystem\Directory\WriteInterface;
14+
use Magento\Framework\ObjectManagerInterface;
15+
use Magento\TestFramework\Helper\Bootstrap;
16+
use PHPUnit\Framework\TestCase;
1117

1218
/**
1319
* Tests for the \Magento\Catalog\Model\ImageUploader class
1420
*/
15-
class ImageUploaderTest extends \PHPUnit\Framework\TestCase
21+
class ImageUploaderTest extends TestCase
1622
{
23+
private const BASE_TMP_PATH = 'catalog/tmp/category';
24+
25+
private const BASE_PATH = 'catalog/category';
26+
1727
/**
18-
* @var \Magento\Framework\ObjectManagerInterface
28+
* @var ObjectManagerInterface
1929
*/
2030
private $objectManager;
2131

2232
/**
23-
* @var \Magento\Catalog\Model\ImageUploader
33+
* @var ImageUploader
2434
*/
2535
private $imageUploader;
2636

2737
/**
28-
* @var \Magento\Framework\Filesystem
38+
* @var Filesystem
2939
*/
3040
private $filesystem;
3141

3242
/**
33-
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
43+
* @var WriteInterface
3444
*/
3545
private $mediaDirectory;
3646

47+
/**
48+
* @var WriteInterface
49+
*/
50+
private $tmpDirectory;
51+
3752
/**
3853
* @inheritdoc
3954
*/
4055
protected function setUp(): void
4156
{
42-
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
43-
/** @var \Magento\Framework\Filesystem $filesystem */
44-
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
57+
$this->objectManager = Bootstrap::getObjectManager();
58+
$this->filesystem = $this->objectManager->get(Filesystem::class);
4559
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
46-
/** @var $uploader \Magento\MediaStorage\Model\File\Uploader */
60+
$this->tmpDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::SYS_TMP);
4761
$this->imageUploader = $this->objectManager->create(
48-
\Magento\Catalog\Model\ImageUploader::class,
62+
ImageUploader::class,
4963
[
50-
'baseTmpPath' => 'catalog/tmp/category',
51-
'basePath' => 'catalog/category',
64+
'baseTmpPath' => self::BASE_TMP_PATH,
65+
'basePath' => self::BASE_PATH,
5266
'allowedExtensions' => ['jpg', 'jpeg', 'gif', 'png'],
5367
'allowedMimeTypes' => ['image/jpg', 'image/jpeg', 'image/gif', 'image/png']
5468
]
5569
);
5670
}
5771

5872
/**
73+
* @dataProvider saveFileToTmpDirProvider
74+
* @param string $fileName
75+
* @param string $expectedName
5976
* @return void
6077
*/
61-
public function testSaveFileToTmpDir(): void
78+
public function testSaveFileToTmpDir(string $fileName, string $expectedName): void
6279
{
63-
$fileName = 'magento_small_image.jpg';
64-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
6580
$fixtureDir = realpath(__DIR__ . '/../_files');
66-
$filePath = $tmpDirectory->getAbsolutePath($fileName);
81+
$filePath = $this->tmpDirectory->getAbsolutePath($fileName);
6782
copy($fixtureDir . DIRECTORY_SEPARATOR . $fileName, $filePath);
6883

6984
$_FILES['image'] = [
@@ -75,10 +90,27 @@ public function testSaveFileToTmpDir(): void
7590
];
7691

7792
$this->imageUploader->saveFileToTmpDir('image');
78-
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR. $fileName;
93+
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR . $expectedName;
7994
$this->assertTrue(is_file($this->mediaDirectory->getAbsolutePath($filePath)));
8095
}
8196

97+
/**
98+
* @return array
99+
*/
100+
public function saveFileToTmpDirProvider(): array
101+
{
102+
return [
103+
'image_default_name' => [
104+
'file_name' => 'magento_small_image.jpg',
105+
'expected_name' => 'magento_small_image.jpg',
106+
],
107+
'image_with_space_in_name' => [
108+
'file_name' => 'magento_image with space in name.jpg',
109+
'expected_name' => 'magento_image_with_space_in_name.jpg',
110+
],
111+
];
112+
}
113+
82114
/**
83115
* Test that method rename files when move it with the same name into base directory.
84116
*
@@ -90,7 +122,7 @@ public function testMoveFileFromTmp(): void
90122
{
91123
$expectedFilePath = $this->imageUploader->getBasePath() . DIRECTORY_SEPARATOR . 'magento_small_image_1.jpg';
92124

93-
$this->assertFileNotExists($this->mediaDirectory->getAbsolutePath($expectedFilePath));
125+
$this->assertFileDoesNotExist($this->mediaDirectory->getAbsolutePath($expectedFilePath));
94126

95127
$this->imageUploader->moveFileFromTmp('magento_small_image.jpg');
96128

@@ -102,12 +134,11 @@ public function testMoveFileFromTmp(): void
102134
*/
103135
public function testSaveFileToTmpDirWithWrongExtension(): void
104136
{
105-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
137+
$this->expectException(LocalizedException::class);
106138
$this->expectExceptionMessage('File validation failed.');
107139

108140
$fileName = 'text.txt';
109-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
110-
$filePath = $tmpDirectory->getAbsolutePath($fileName);
141+
$filePath = $this->tmpDirectory->getAbsolutePath($fileName);
111142
$file = fopen($filePath, "wb");
112143
fwrite($file, 'just a text');
113144

@@ -120,7 +151,7 @@ public function testSaveFileToTmpDirWithWrongExtension(): void
120151
];
121152

122153
$this->imageUploader->saveFileToTmpDir('image');
123-
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR. $fileName;
154+
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR . $fileName;
124155
$this->assertFalse(is_file($this->mediaDirectory->getAbsolutePath($filePath)));
125156
}
126157

@@ -129,12 +160,11 @@ public function testSaveFileToTmpDirWithWrongExtension(): void
129160
*/
130161
public function testSaveFileToTmpDirWithWrongFile(): void
131162
{
132-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
163+
$this->expectException(LocalizedException::class);
133164
$this->expectExceptionMessage('File validation failed.');
134165

135166
$fileName = 'file.gif';
136-
$tmpDirectory = $this->filesystem->getDirectoryWrite(\Magento\Framework\App\Filesystem\DirectoryList::SYS_TMP);
137-
$filePath = $tmpDirectory->getAbsolutePath($fileName);
167+
$filePath = $this->tmpDirectory->getAbsolutePath($fileName);
138168
$file = fopen($filePath, "wb");
139169
fwrite($file, 'just a text');
140170

@@ -147,7 +177,7 @@ public function testSaveFileToTmpDirWithWrongFile(): void
147177
];
148178

149179
$this->imageUploader->saveFileToTmpDir('image');
150-
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR. $fileName;
180+
$filePath = $this->imageUploader->getBaseTmpPath() . DIRECTORY_SEPARATOR . $fileName;
151181
$this->assertFalse(is_file($this->mediaDirectory->getAbsolutePath($filePath)));
152182
}
153183

@@ -157,11 +187,10 @@ public function testSaveFileToTmpDirWithWrongFile(): void
157187
public static function tearDownAfterClass(): void
158188
{
159189
parent::tearDownAfterClass();
160-
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
161-
\Magento\Framework\Filesystem::class
162-
);
163-
/** @var \Magento\Framework\Filesystem\Directory\WriteInterface $mediaDirectory */
190+
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
191+
/** @var WriteInterface $mediaDirectory */
164192
$mediaDirectory = $filesystem->getDirectoryWrite(DirectoryList::MEDIA);
165-
$mediaDirectory->delete('tmp');
193+
$mediaDirectory->delete(self::BASE_TMP_PATH);
194+
$mediaDirectory->delete(self::BASE_PATH);
166195
}
167196
}

0 commit comments

Comments
 (0)