Skip to content

Commit d93f3d2

Browse files
committed
#29677: Fixed static tests
1 parent 10bd41f commit d93f3d2

File tree

3 files changed

+66
-77
lines changed

3 files changed

+66
-77
lines changed

app/code/Magento/Cms/Controller/Adminhtml/Wysiwyg/Images/OnInsert.php

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,62 @@
11
<?php
22
/**
3-
*
43
* Copyright © Magento, Inc. All rights reserved.
54
* See COPYING.txt for license details.
65
*/
76
namespace Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
87

9-
class OnInsert extends \Magento\Cms\Controller\Adminhtml\Wysiwyg\Images
8+
use Magento\Backend\App\Action\Context;
9+
use Magento\Cms\Controller\Adminhtml\Wysiwyg\Images;
10+
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent;
11+
use Magento\Framework\App\Action\HttpGetActionInterface;
12+
use Magento\Framework\Controller\Result\RawFactory;
13+
use Magento\Framework\Controller\ResultInterface;
14+
use Magento\Framework\Registry;
15+
16+
class OnInsert extends Images implements HttpGetActionInterface
1017
{
1118
/**
12-
* @var \Magento\Framework\Controller\Result\RawFactory
19+
* @var RawFactory
1320
*/
1421
protected $resultRawFactory;
1522

1623
/**
17-
* @var \Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent
24+
* @var GetInsertImageContent
1825
*/
1926
protected $getInsertImageContent;
2027

2128
/**
22-
* @param \Magento\Backend\App\Action\Context $context
23-
* @param \Magento\Framework\Registry $coreRegistry
24-
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
25-
* @param \Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent $getInsertImageContent
29+
* @param Context $context
30+
* @param Registry $coreRegistry
31+
* @param RawFactory $resultRawFactory
32+
* @param GetInsertImageContent $getInsertImageContent
2633
*/
2734
public function __construct(
28-
\Magento\Backend\App\Action\Context $context,
29-
\Magento\Framework\Registry $coreRegistry,
30-
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
31-
?\Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent $getInsertImageContent = null
35+
Context $context,
36+
Registry $coreRegistry,
37+
RawFactory $resultRawFactory,
38+
?GetInsertImageContent $getInsertImageContent = null
3239
) {
3340
$this->resultRawFactory = $resultRawFactory;
3441
parent::__construct($context, $coreRegistry);
3542
$this->getInsertImageContent = $getInsertImageContent ?: $this->_objectManager
36-
->get(\Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent::class);
43+
->get(GetInsertImageContent::class);
3744
}
3845

3946
/**
40-
* Fire when select image
47+
* Return a content (just a link or an html block) for inserting image to the content
4148
*
42-
* @return \Magento\Framework\Controller\ResultInterface
49+
* @return ResultInterface
4350
*/
4451
public function execute()
4552
{
4653
$data = $this->getRequest()->getParams();
47-
48-
$fileName = $data['filename'];
49-
$forceStaticPath = $data['force_static_path'];
50-
$renderAsTag = $data['as_is'];
51-
$storeId = isset($data['store_id']) ? (int) $data['store_id'] : null;
52-
53-
/** @var \Magento\Framework\Controller\Result\Raw $resultRaw */
54-
$resultRaw = $this->resultRawFactory->create();
55-
56-
return $resultRaw->setContents(
54+
return $this->resultRawFactory->create()->setContents(
5755
$this->getInsertImageContent->execute(
58-
$fileName,
59-
$forceStaticPath,
60-
$renderAsTag,
61-
$storeId
56+
$data['filename'],
57+
$data['force_static_path'],
58+
$data['as_is'],
59+
isset($data['store']) ? (int) $data['store'] : null
6260
)
6361
);
6462
}

app/code/Magento/Cms/Model/Wysiwyg/Images/GetInsertImageContent.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function __construct(ImagesHelper $imagesHelper)
2828
}
2929

3030
/**
31-
* Prepare Image Contents for Insert
31+
* Create a content (just a link or an html block) for inserting image to the content
3232
*
3333
* @param string $encodedFilename
3434
* @param bool $forceStaticPath
@@ -48,10 +48,7 @@ public function execute(
4848

4949
if ($forceStaticPath) {
5050
// phpcs:ignore Magento2.Functions.DiscouragedFunction
51-
return parse_url(
52-
$this->imagesHelper->getCurrentUrl() . $filename,
53-
PHP_URL_PATH
54-
);
51+
return parse_url($this->imagesHelper->getCurrentUrl() . $filename, PHP_URL_PATH);
5552
}
5653

5754
return $this->imagesHelper->getImageHtmlDeclaration($filename, $renderAsTag);

app/code/Magento/Cms/Test/Integration/Model/Wysiwyg/Images/GetInsertImageContentTest.php renamed to dev/tests/integration/testsuite/Magento/Cms/Model/Wysiwyg/Images/GetInsertImageContentTest.php

Lines changed: 37 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66

77
declare(strict_types=1);
88

9-
namespace Magento\Cms\Test\Integration\Model\Wysiwyg\Images;
9+
namespace Magento\Cms\Model\Wysiwyg\Images;
1010

11-
use Magento\Backend\Helper\Data as BackendHelper;
11+
use Magento\Backend\Model\UrlInterface;
1212
use Magento\Cms\Helper\Wysiwyg\Images as ImagesHelper;
13-
use Magento\Cms\Model\Wysiwyg\Images\GetInsertImageContent;
1413
use Magento\Framework\Url\EncoderInterface;
1514
use Magento\TestFramework\Helper\Bootstrap;
1615
use PHPUnit\Framework\TestCase;
1716

1817
class GetInsertImageContentTest extends TestCase
1918
{
20-
private const TEST_IMAGE_FILE = '/test-image.jpg';
21-
2219
/**
2320
* @var GetInsertImageContent
2421
*/
@@ -35,9 +32,9 @@ class GetInsertImageContentTest extends TestCase
3532
private $urlEncoder;
3633

3734
/**
38-
* @var BackendHelper
35+
* @var UrlInterface
3936
*/
40-
protected $_backendData;
37+
protected $url;
4138

4239
/**
4340
* @inheritdoc
@@ -47,48 +44,45 @@ protected function setUp(): void
4744
$this->getInsertImageContent = Bootstrap::getObjectManager()->get(GetInsertImageContent::class);
4845
$this->imagesHelper = Bootstrap::getObjectManager()->get(ImagesHelper::class);
4946
$this->urlEncoder = Bootstrap::getObjectManager()->get(EncoderInterface::class);
50-
$this->_backendData = Bootstrap::getObjectManager()->get(BackendHelper::class);
47+
$this->url = Bootstrap::getObjectManager()->get(UrlInterface::class);
5148
}
5249

5350
/**
5451
* Test for GetInsertImageContent::execute
5552
*
5653
* @dataProvider imageDataProvider
57-
* @param string $encodedFilename
54+
* @param string $filename
5855
* @param bool $forceStaticPath
5956
* @param bool $renderAsTag
6057
* @param int|null $storeId
61-
* @param string|null $expectedResult
58+
* @param string $expectedResult
6259
*/
6360
public function testExecute(
64-
string $encodedFilename,
61+
string $filename,
6562
bool $forceStaticPath,
6663
bool $renderAsTag,
67-
?int $storeId = null,
68-
?string $expectedResult = null
64+
?int $storeId,
65+
string $expectedResult
6966
): void {
70-
$getImageForInsert = $this->getInsertImageContent->execute(
71-
$encodedFilename,
72-
$forceStaticPath,
73-
$renderAsTag,
74-
$storeId
75-
);
76-
77-
if (!$forceStaticPath && !$renderAsTag) {
78-
if (!$this->imagesHelper->isUsingStaticUrlsAllowed()) {
79-
80-
$encodedDirective = $this->urlEncoder->encode($expectedResult);
81-
$expectedResult = $this->_backendData->getUrl(
82-
'cms/wysiwyg/directive',
83-
[
84-
'___directive' => $encodedDirective,
85-
'_escape_params' => false,
86-
]
87-
);
88-
}
67+
if (!$forceStaticPath && !$renderAsTag && !$this->imagesHelper->isUsingStaticUrlsAllowed()) {
68+
$expectedResult = $this->url->getUrl(
69+
'cms/wysiwyg/directive',
70+
[
71+
'___directive' => $this->urlEncoder->encode($expectedResult),
72+
'_escape_params' => false
73+
]
74+
);
8975
}
9076

91-
$this->assertEquals($getImageForInsert, $expectedResult);
77+
$this->assertEquals(
78+
$expectedResult,
79+
$this->getInsertImageContent->execute(
80+
$this->imagesHelper->idEncode($filename),
81+
$forceStaticPath,
82+
$renderAsTag,
83+
$storeId
84+
)
85+
);
9286
}
9387

9488
/**
@@ -100,39 +94,39 @@ public function imageDataProvider(): array
10094
{
10195
return [
10296
[
103-
'L3Rlc3QtaW1hZ2UuanBn',
97+
'test-image.jpg',
10498
false,
10599
true,
106100
1,
107-
'<img src="{{media url=&quot;' . self::TEST_IMAGE_FILE . '&quot;}}" alt="" />'
101+
'<img src="{{media url=&quot;test-image.jpg&quot;}}" alt="" />'
108102
],
109103
[
110-
'L3Rlc3QtaW1hZ2UuanBn',
104+
'catalog/category/test-image.jpg',
111105
true,
112106
false,
113107
1,
114-
'/pub/media/' . self::TEST_IMAGE_FILE
108+
'/pub/media/catalog/category/test-image.jpg'
115109
],
116110
[
117-
'L3Rlc3QtaW1hZ2UuanBn',
111+
'test-image.jpg',
118112
false,
119113
false,
120114
1,
121-
'{{media url="' . self::TEST_IMAGE_FILE . '"}}'
115+
'{{media url="test-image.jpg"}}'
122116
],
123117
[
124-
'L3Rlc3QtaW1hZ2UuanBn',
118+
'/test-image.jpg',
125119
false,
126120
true,
127121
2,
128-
'<img src="{{media url=&quot;' . self::TEST_IMAGE_FILE . '&quot;}}" alt="" />'
122+
'<img src="{{media url=&quot;/test-image.jpg&quot;}}" alt="" />'
129123
],
130124
[
131-
'L3Rlc3QtaW1hZ2UuanBn',
125+
'test-image.jpg',
132126
false,
133127
true,
134128
null,
135-
'<img src="{{media url=&quot;' . self::TEST_IMAGE_FILE . '&quot;}}" alt="" />'
129+
'<img src="{{media url=&quot;test-image.jpg&quot;}}" alt="" />'
136130
],
137131
];
138132
}

0 commit comments

Comments
 (0)