Skip to content

Commit fe3f23b

Browse files
committed
MAGETWO-88232: Images from WYSIWYG (Text, Slider) do not show up on admin preview nor storefront
Refactor ImagesTest to prevent calling of generateHelper on previously existing tests
1 parent 33a003c commit fe3f23b

File tree

1 file changed

+24
-22
lines changed
  • dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg

1 file changed

+24
-22
lines changed

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

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,10 @@ public function testGetStorageRoot()
2727
\Magento\Framework\Filesystem::class
2828
);
2929
$mediaPath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
30-
$helper = $this->generateHelper(null);
30+
/** @var \Magento\Cms\Helper\Wysiwyg\Images $helper */
31+
$helper = $this->objectManager->create(
32+
\Magento\Cms\Helper\Wysiwyg\Images::class
33+
);
3134
$this->assertStringStartsWith($mediaPath, $helper->getStorageRoot());
3235
}
3336

@@ -36,7 +39,10 @@ public function testGetStorageRoot()
3639
*/
3740
public function testGetCurrentUrl()
3841
{
39-
$helper = $this->generateHelper(null);
42+
/** @var \Magento\Cms\Helper\Wysiwyg\Images $helper */
43+
$helper = $this->objectManager->create(
44+
\Magento\Cms\Helper\Wysiwyg\Images::class
45+
);
4046
$this->assertStringStartsWith('http://example.com/', $helper->getCurrentUrl());
4147
}
4248

@@ -98,37 +104,33 @@ function ($actualResult) {
98104
/**
99105
* Generate instance of Images Helper
100106
*
101-
* @param bool|null $isStaticUrlsAllowed - if boolean, mock is created to override value of isUsingStaticUrlsAllowed
107+
* @param bool $isStaticUrlsAllowed - mock is created to override value of isUsingStaticUrlsAllowed method in class
102108
* @return \Magento\Cms\Helper\Wysiwyg\Images
103109
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
104110
*/
105111
private function generateHelper($isStaticUrlsAllowed = false)
106112
{
107113
$storeId = 1;
108114

109-
if (!is_bool($isStaticUrlsAllowed)) {
110-
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class);
111-
} else {
112-
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
115+
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
113116

114-
$contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [
115-
'eventManager' => $eventManagerMock,
116-
]);
117+
$contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [
118+
'eventManager' => $eventManagerMock,
119+
]);
117120

118-
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [
119-
'context' => $contextMock
120-
]);
121+
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [
122+
'context' => $contextMock
123+
]);
121124

122-
$checkResult = new \stdClass();
123-
$checkResult->isAllowed = false;
125+
$checkResult = new \stdClass();
126+
$checkResult->isAllowed = false;
124127

125-
$eventManagerMock->expects($this->any())
126-
->method('dispatch')
127-
->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId])
128-
->willReturnCallback(function ($_, $arr) use ($isStaticUrlsAllowed) {
129-
$arr['result']->isAllowed = $isStaticUrlsAllowed;
130-
});
131-
}
128+
$eventManagerMock->expects($this->any())
129+
->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+
});
132134

133135
$helper->setStoreId($storeId);
134136

0 commit comments

Comments
 (0)