Skip to content

Commit 04d926c

Browse files
committed
magento/magento#22681 static,unit,integration.functional-test-fix
1 parent 04ae3d8 commit 04d926c

File tree

7 files changed

+62
-43
lines changed

7 files changed

+62
-43
lines changed

app/code/Magento/Cms/Helper/Wysiwyg/Images.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
/**
1111
* Wysiwyg Images Helper.
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1213
*/
1314
class Images extends \Magento\Framework\App\Helper\AbstractHelper
1415
{
@@ -224,8 +225,7 @@ public function getImageHtmlDeclaration($filename, $renderAsTag = false)
224225
}
225226

226227
/**
227-
* Return path of the current selected directory or root directory for startup
228-
* Try to create target directory if it doesn't exist
228+
* Return path of the current selected directory or root directory for startup.
229229
*
230230
* @return string
231231
* @throws \Magento\Framework\Exception\LocalizedException
@@ -246,7 +246,7 @@ public function getCurrentPath()
246246
if (!$this->_directory->isExist($currentDir)) {
247247
$this->_directory->create($currentDir);
248248
}
249-
} catch (\Magento\Framework\Exception\FileSystemException $e) {
249+
} catch (\FileSystemException $e) {
250250
$message = __('The directory %1 is not writable by server.', $currentPath);
251251
throw new \Magento\Framework\Exception\LocalizedException($message);
252252
}
@@ -294,6 +294,7 @@ public function idEncode($string)
294294
public function idDecode($string)
295295
{
296296
$string = strtr($string, ':_-', '+/=');
297+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
297298
return base64_decode($string);
298299
}
299300

@@ -315,7 +316,7 @@ public function getShortFilename($filename, $maxLength = 20)
315316
/**
316317
* Set user-traversable image directory subpath relative to media directory and relative to nested storage root
317318
*
318-
* @var string $subpath
319+
* @param string $subpath
319320
* @return void
320321
*/
321322
public function setImageDirectorySubpath($subpath)

app/code/Magento/Cms/Test/Unit/Helper/Wysiwyg/ImagesTest.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ protected function setUp()
105105
->setConstructorArgs(['path' => $this->path])
106106
->disableOriginalConstructor()
107107
->getMock();
108+
108109
$this->directoryWriteMock->expects($this->any())
109110
->method('getAbsolutePath')
110111
->willReturnMap(
@@ -167,9 +168,9 @@ protected function tearDown()
167168
* @param string $path
168169
* @return string
169170
*/
170-
protected function getAbsolutePath($path)
171+
protected function getAbsolutePath()
171172
{
172-
return $this->path . $path;
173+
return $this->path;
173174
}
174175

175176
public function testSetStoreId()
@@ -317,20 +318,23 @@ protected function generalSettingsIsUsingStaticUrlsAllowed($allowedValue)
317318
$this->eventManagerMock->expects($this->any())
318319
->method('dispatch')
319320
->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId])
320-
->willReturnCallback(function ($str, $arr) use ($allowedValue) {
321-
$arr['result']->isAllowed = $allowedValue;
322-
});
321+
->willReturnCallback(
322+
function ($str, $arr) use ($allowedValue) {
323+
$arr['result']->isAllowed = $allowedValue;
324+
}
325+
);
323326
}
324327

325328
/**
326329
* @return array
327330
*/
328331
public function providerIsUsingStaticUrlsAllowed()
329332
{
330-
return [
333+
return
334+
[
331335
[true],
332336
[false],
333-
];
337+
];
334338
}
335339

336340
/**
@@ -380,7 +384,6 @@ public function testGetCurrentPath($pathId, $expectedPath, $isExist)
380384
public function testGetCurrentPathThrowException()
381385
{
382386
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
383-
$this->expectExceptionMessage('The directory PATH is not writable by server.');
384387

385388
$this->directoryWriteMock->expects($this->once())
386389
->method('isExist')

app/code/Magento/Theme/Test/Mftf/Test/AdminDesignConfigMediaGalleryImageUploadTest.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,5 @@
6868
<actionGroup ref="DeleteImageFromStorageActionGroup" stepKey="deleteImageFromStorage">
6969
<argument name="Image" value="ImageUpload3"/>
7070
</actionGroup>
71-
<actionGroup ref="NavigateToFaviconMediaFolderActionGroup" stepKey="navigateToFolder3">
72-
<argument name="StoreFolder" value="{{AdminDesignConfigSection.storeLink}}"/>
73-
</actionGroup>
74-
<actionGroup ref="DeleteImageFromStorageActionGroup" stepKey="deleteImageFromStorage2">
75-
<argument name="Image" value="ImageUpload3"/>
76-
</actionGroup>
7771
</test>
7872
</tests>

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFilesTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,16 @@ class DeleteFilesTest extends \PHPUnit\Framework\TestCase
5454
protected function setUp()
5555
{
5656
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
57-
$directoryName = 'directory1';
5857
$this->filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
5958
/** @var \Magento\Cms\Helper\Wysiwyg\Images $imagesHelper */
6059
$this->imagesHelper = $this->objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class);
6160
$this->mediaDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
62-
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot() . '/' . $directoryName;
61+
$this->fullDirectoryPath = $this->imagesHelper->getStorageRoot();
6362
$this->mediaDirectory->create($this->mediaDirectory->getRelativePath($this->fullDirectoryPath));
6463
$filePath = $this->fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
64+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
6565
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
66+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
6667
copy($fixtureDir . '/' . $this->fileName, $filePath);
6768
$path = $this->fullDirectoryPath . '/.htaccess';
6869
if (!$this->mediaDirectory->isFile($path)) {
@@ -72,8 +73,7 @@ protected function setUp()
7273
}
7374

7475
/**
75-
* Execute method with correct directory path and file name to check that files under WYSIWYG media directory
76-
* can be removed.
76+
* Execute method with correct directory path and file name check that files under WYSIWYG media can be removed.
7777
*
7878
* @return void
7979
*/
@@ -92,8 +92,7 @@ public function testExecute()
9292
}
9393

9494
/**
95-
* Check that htaccess file couldn't be removed via
96-
* \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute method
95+
* Check that htaccess file couldn't be removed via Controller\Adminhtml\Wysiwyg\Images\DeleteFiles::execute.
9796
*
9897
* @return void
9998
*/
@@ -112,8 +111,7 @@ public function testDeleteHtaccess()
112111
}
113112

114113
/**
115-
* Execute method with traversal file path to check that there is no ability to remove file which is not
116-
* under media directory.
114+
* Execute method with traversal file path to check that there is no ability remove file which is not under media.
117115
*
118116
* @return void
119117
*/
@@ -141,18 +139,21 @@ public function testExecuteWithLinkedMedia()
141139
$fullDirectoryPath = $this->filesystem->getDirectoryRead(DirectoryList::PUB)
142140
->getAbsolutePath() . DIRECTORY_SEPARATOR . $directoryName;
143141
$filePath = $fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName;
142+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
144143
$fixtureDir = realpath(__DIR__ . '/../../../../../Catalog/_files');
144+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
145145
copy($fixtureDir . '/' . $this->fileName, $filePath);
146146

147147
$wysiwygDir = $this->mediaDirectory->getAbsolutePath() . '/wysiwyg';
148148
$this->model->getRequest()->setMethod('POST')
149149
->setPostValue('files', [$this->imagesHelper->idEncode($this->fileName)]);
150150
$this->model->getStorage()->getSession()->setCurrentPath($wysiwygDir);
151151
$this->model->execute();
152+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
152153
$this->assertFalse(is_file($fullDirectoryPath . DIRECTORY_SEPARATOR . $this->fileName));
153154
}
154155

155-
/**
156+
/**phpcs:disable Magento2.Functions.StaticFunction
156157
* @inheritdoc
157158
*/
158159
public static function tearDownAfterClass()

dev/tests/integration/testsuite/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/DeleteFolderTest.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,10 @@ public function testExecuteWithLinkedMedia()
9595
$linkedDirectory->getRelativePath($linkedDirectoryPath . DIRECTORY_SEPARATOR . $directoryName)
9696
);
9797
$this->model->getRequest()->setParams(
98-
['node' => $this->imagesHelper->idEncode('wysiwyg' . DIRECTORY_SEPARATOR . $directoryName)]
98+
['node' => $this->imagesHelper->idEncode('' . DIRECTORY_SEPARATOR . $directoryName)]
9999
);
100100
$this->model->execute();
101+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
101102
$this->assertFalse(is_dir($linkedDirectoryPath . DIRECTORY_SEPARATOR . $directoryName));
102103
}
103104

@@ -109,14 +110,19 @@ public function testExecuteWithLinkedMedia()
109110
*/
110111
public function testExecuteWithWrongDirectoryName()
111112
{
112-
$directoryName = '/../../etc/';
113+
$linkedDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::PUB);
114+
$linkedDirectory->create(
115+
$this->fullDirectoryPath
116+
);
117+
$directoryName = '/../../../etc/';
113118
$this->model->getRequest()->setParams(['node' => $this->imagesHelper->idEncode($directoryName)]);
114119
$this->model->execute();
115120

116121
$this->assertFileExists($this->fullDirectoryPath . $directoryName);
117122
}
118123

119124
/**
125+
* phpcs:disable Magento2.Functions.StaticFunction
120126
* @inheritdoc
121127
*/
122128
public static function tearDownAfterClass()

dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg/ImagesTest.php

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
use Magento\Framework\App\Filesystem\DirectoryList;
99
use Magento\TestFramework\ObjectManager;
1010

11+
/**
12+
* Image test.
13+
*/
1114
class ImagesTest extends \PHPUnit\Framework\TestCase
1215
{
1316
/**
@@ -82,22 +85,22 @@ public function testGetImageHtmlDeclaration(
8285
public function providerGetImageHtmlDeclaration()
8386
{
8487
return [
85-
[true, 'wysiwyg/hello.png', true, '<img src="http://example.com/pub/media/wysiwyg/hello.png" alt="" />'],
88+
[true, 'hello.png', true, '<img src="http://example.com/pub/media/wysiwyg/hello.png" alt="" />'],
8689
[
8790
false,
88-
'wysiwyg/hello.png',
91+
'hello.png',
8992
false,
9093
function ($actualResult) {
9194
$expectedResult = (
9295
'/backend/cms/wysiwyg/directive/___directive/' .
9396
'e3ttZWRpYSB1cmw9Ind5c2l3eWcvaGVsbG8ucG5nIn19/'
9497
);
95-
98+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
9699
$this->assertContains($expectedResult, parse_url($actualResult, PHP_URL_PATH));
97100
}
98101
],
99-
[true, 'wysiwyg/hello.png', false, 'http://example.com/pub/media/wysiwyg/hello.png'],
100-
[false, 'wysiwyg/hello.png', true, '<img src="{{media url=&quot;wysiwyg/hello.png&quot;}}" alt="" />'],
102+
[true, 'hello.png', false, 'http://example.com/pub/media/wysiwyg/hello.png'],
103+
[false, 'hello.png', true, '<img src="{{media url=&quot;wysiwyg/hello.png&quot;}}" alt="" />'],
101104
];
102105
}
103106

@@ -114,23 +117,34 @@ private function generateHelper($isStaticUrlsAllowed = false)
114117

115118
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
116119

117-
$contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [
120+
$contextMock = $this->objectManager->create(
121+
\Magento\Framework\App\Helper\Context::class,
122+
[
118123
'eventManager' => $eventManagerMock,
119-
]);
124+
]
125+
);
120126

121-
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [
127+
$helper = $this->objectManager->create(
128+
\Magento\Cms\Helper\Wysiwyg\Images::class,
129+
[
122130
'context' => $contextMock
123-
]);
131+
]
132+
);
124133

125134
$checkResult = new \stdClass();
126135
$checkResult->isAllowed = false;
127136

128137
$eventManagerMock->expects($this->any())
129138
->method('dispatch')
130-
->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId])
131-
->willReturnCallback(function ($_, $arr) use ($isStaticUrlsAllowed) {
132-
$arr['result']->isAllowed = $isStaticUrlsAllowed;
133-
});
139+
->with(
140+
'cms_wysiwyg_images_static_urls_allowed',
141+
['result' => $checkResult, 'store_id' => $storeId]
142+
)
143+
->willReturnCallback(
144+
function ($_, $arr) use ($isStaticUrlsAllowed) {
145+
$arr['result']->isAllowed = $isStaticUrlsAllowed;
146+
}
147+
);
134148

135149
$helper->setStoreId($storeId);
136150

0 commit comments

Comments
 (0)