Skip to content

Commit 33a003c

Browse files
committed
MAGETWO-88232: Images from WYSIWYG (Text, Slider) do not show up on admin preview nor storefront
Refactor ImagesTest
1 parent 128eea3 commit 33a003c

File tree

1 file changed

+32
-29
lines changed
  • dev/tests/integration/testsuite/Magento/Cms/Helper/Wysiwyg

1 file changed

+32
-29
lines changed

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

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,32 +27,34 @@ public function testGetStorageRoot()
2727
\Magento\Framework\Filesystem::class
2828
);
2929
$mediaPath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
30-
$helper = $this->generateHelper();
30+
$helper = $this->generateHelper(null);
3131
$this->assertStringStartsWith($mediaPath, $helper->getStorageRoot());
3232
}
3333

34+
/**
35+
* @magentoConfigFixture current_store web/unsecure/base_url http://example.com/
36+
*/
3437
public function testGetCurrentUrl()
3538
{
36-
$helper = $this->generateHelper();
37-
$this->assertStringStartsWith('http://localhost/', $helper->getCurrentUrl());
39+
$helper = $this->generateHelper(null);
40+
$this->assertStringStartsWith('http://example.com/', $helper->getCurrentUrl());
3841
}
3942

4043
/**
41-
* @param bool $staticUrlsAllowed
44+
* @param bool $isStaticUrlsAllowed
4245
* @param string $filename
4346
* @param bool $renderAsTag
4447
* @param string|callable $expectedResult - string or callable to make unique assertions on $expectedResult
45-
*
4648
* @magentoConfigFixture current_store web/unsecure/base_url http://example.com/
4749
* @dataProvider providerGetImageHtmlDeclaration
4850
*/
4951
public function testGetImageHtmlDeclaration(
50-
$staticUrlsAllowed,
52+
$isStaticUrlsAllowed,
5153
$filename,
5254
$renderAsTag,
5355
$expectedResult
5456
) {
55-
$helper = $this->generateHelper($staticUrlsAllowed);
57+
$helper = $this->generateHelper($isStaticUrlsAllowed);
5658

5759
$actualResult = $helper->getImageHtmlDeclaration($filename, $renderAsTag);
5860

@@ -96,38 +98,39 @@ function ($actualResult) {
9698
/**
9799
* Generate instance of Images Helper
98100
*
99-
* @param bool|null $staticUrlsAllowed - if boolean, mock is created to override value of isUsingStaticUrlsAllowed
101+
* @param bool|null $isStaticUrlsAllowed - if boolean, mock is created to override value of isUsingStaticUrlsAllowed
100102
* @return \Magento\Cms\Helper\Wysiwyg\Images
101103
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
102104
*/
103-
private function generateHelper($staticUrlsAllowed = null)
105+
private function generateHelper($isStaticUrlsAllowed = false)
104106
{
105-
if (!is_bool($staticUrlsAllowed)) {
106-
return $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class);
107-
}
107+
$storeId = 1;
108108

109-
$eventManagerMock = $this->createMock(\Magento\Framework\Event\ManagerInterface::class);
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);
110113

111-
$contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [
112-
'eventManager' => $eventManagerMock,
113-
]);
114+
$contextMock = $this->objectManager->create(\Magento\Framework\App\Helper\Context::class, [
115+
'eventManager' => $eventManagerMock,
116+
]);
114117

115-
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [
116-
'context' => $contextMock
117-
]);
118+
$helper = $this->objectManager->create(\Magento\Cms\Helper\Wysiwyg\Images::class, [
119+
'context' => $contextMock
120+
]);
118121

119-
$storeId = 1;
120-
$helper->setStoreId($storeId);
122+
$checkResult = new \stdClass();
123+
$checkResult->isAllowed = false;
121124

122-
$checkResult = new \stdClass();
123-
$checkResult->isAllowed = false;
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+
}
124132

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 ($staticUrlsAllowed) {
129-
$arr['result']->isAllowed = $staticUrlsAllowed;
130-
});
133+
$helper->setStoreId($storeId);
131134

132135
return $helper;
133136
}

0 commit comments

Comments
 (0)