init
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Cms\Helper;
|
||||
|
||||
use Magento\Customer\Model\Context;
|
||||
|
||||
/**
|
||||
* @magentoAppArea frontend
|
||||
*/
|
||||
class PageTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @magentoAppIsolation enabled
|
||||
* @magentoDataFixture Magento/Cms/_files/pages.php
|
||||
*/
|
||||
public function testRenderPage()
|
||||
{
|
||||
/** @var $objectManager \Magento\TestFramework\ObjectManager */
|
||||
$objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
$httpContext = $objectManager->get(\Magento\Framework\App\Http\Context::class);
|
||||
$httpContext->setValue(Context::CONTEXT_AUTH, false, false);
|
||||
$objectManager->get(\Magento\Framework\App\State::class)->setAreaCode('frontend');
|
||||
$arguments = [
|
||||
'request' => $objectManager->get(\Magento\TestFramework\Request::class),
|
||||
'response' => $objectManager->get(\Magento\TestFramework\Response::class),
|
||||
];
|
||||
$context = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Action\Context::class,
|
||||
$arguments
|
||||
);
|
||||
$page = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Cms\Model\Page::class);
|
||||
$page->load('page_design_blank', 'identifier');
|
||||
// fixture
|
||||
/** @var $pageHelper \Magento\Cms\Helper\Page */
|
||||
$pageHelper = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(\Magento\Cms\Helper\Page::class);
|
||||
$result = $pageHelper->prepareResultPage(
|
||||
\Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\App\Test\Unit\Action\Stub\ActionStub::class,
|
||||
['context' => $context]
|
||||
),
|
||||
$page->getId()
|
||||
);
|
||||
$design = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
|
||||
\Magento\Framework\View\DesignInterface::class
|
||||
);
|
||||
$this->assertEquals('Magento/blank', $design->getDesignTheme()->getThemePath());
|
||||
$this->assertInstanceOf(\Magento\Framework\View\Result\Page::class, $result);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Cms\Helper\Wysiwyg;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\App\Helper\Context;
|
||||
use Magento\Framework\Event\ManagerInterface;
|
||||
use Magento\Framework\Filesystem;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use Magento\TestFramework\ObjectManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use stdClass;
|
||||
|
||||
class ImagesTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var ObjectManager
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = Bootstrap::getObjectManager();
|
||||
}
|
||||
|
||||
public function testGetStorageRoot()
|
||||
{
|
||||
/** @var Filesystem $filesystem */
|
||||
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
|
||||
$mediaPath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath();
|
||||
/** @var Images $helper */
|
||||
$helper = $this->objectManager->create(
|
||||
Images::class
|
||||
);
|
||||
$this->assertStringStartsWith($mediaPath, $helper->getStorageRoot());
|
||||
}
|
||||
|
||||
/**
|
||||
* @magentoConfigFixture current_store web/unsecure/base_url http://example.com/
|
||||
*/
|
||||
public function testGetCurrentUrl()
|
||||
{
|
||||
/** @var Images $helper */
|
||||
$helper = $this->objectManager->create(Images::class);
|
||||
|
||||
$this->assertStringStartsWith('http://example.com/', $helper->getCurrentUrl());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $isStaticUrlsAllowed
|
||||
* @param string $filename
|
||||
* @param bool $renderAsTag
|
||||
* @param string|callable $expectedResult - string or callable to make unique assertions on $expectedResult
|
||||
* @magentoConfigFixture current_store web/unsecure/base_url http://example.com/
|
||||
* @dataProvider providerGetImageHtmlDeclaration
|
||||
*/
|
||||
public function testGetImageHtmlDeclaration(
|
||||
$isStaticUrlsAllowed,
|
||||
$filename,
|
||||
$renderAsTag,
|
||||
$expectedResult
|
||||
) {
|
||||
$helper = $this->generateHelper($isStaticUrlsAllowed);
|
||||
|
||||
$actualResult = $helper->getImageHtmlDeclaration($filename, $renderAsTag);
|
||||
|
||||
if (is_callable($expectedResult)) {
|
||||
$expectedResult($actualResult);
|
||||
} else {
|
||||
$this->assertEquals(
|
||||
$expectedResult,
|
||||
$actualResult
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify image html declaration renders correctly with custom admin url.
|
||||
*
|
||||
* @magentoConfigFixture default/admin/url/use_custom 1
|
||||
* @magentoConfigFixture admin_store web/unsecure/base_url http://example-admin.com/
|
||||
*/
|
||||
public function testGetImageHtmlDeclarationCustomBackendUrl()
|
||||
{
|
||||
$helper = $this->generateHelper(false, 0);
|
||||
$actualResult = $helper->getImageHtmlDeclaration('wysiwyg/hello.png', true);
|
||||
|
||||
$this->assertEquals('<img src="{{media url="wysiwyg/hello.png"}}" alt="" />', $actualResult);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetImageHtmlDeclaration
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function providerGetImageHtmlDeclaration()
|
||||
{
|
||||
return [
|
||||
[true, 'wysiwyg/hello.png', true, '<img src="http://example.com/media/wysiwyg/hello.png" alt="" />'],
|
||||
[
|
||||
false,
|
||||
'wysiwyg/hello.png',
|
||||
false,
|
||||
function ($actualResult) {
|
||||
$expectedResult = (
|
||||
'/backend/cms/wysiwyg/directive/___directive/' .
|
||||
'e3ttZWRpYSB1cmw9Ind5c2l3eWcvaGVsbG8ucG5nIn19/'
|
||||
);
|
||||
|
||||
$this->assertStringContainsString($expectedResult, parse_url($actualResult, PHP_URL_PATH));
|
||||
},
|
||||
],
|
||||
[true, 'wysiwyg/hello.png', false, 'http://example.com/media/wysiwyg/hello.png'],
|
||||
[false, 'wysiwyg/hello.png', true, '<img src="{{media url="wysiwyg/hello.png"}}" alt="" />'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate instance of Images Helper
|
||||
*
|
||||
* @param bool $isStaticUrlsAllowed - mock is created to override value of isUsingStaticUrlsAllowed method in class
|
||||
* @param int $storeId
|
||||
* @return Images
|
||||
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
private function generateHelper($isStaticUrlsAllowed = false, int $storeId = 1)
|
||||
{
|
||||
$eventManagerMock = $this->createMock(ManagerInterface::class);
|
||||
|
||||
$contextMock = $this->objectManager->create(Context::class, [
|
||||
'eventManager' => $eventManagerMock,
|
||||
]);
|
||||
|
||||
$helper = $this->objectManager->create(Images::class, [
|
||||
'context' => $contextMock,
|
||||
]);
|
||||
|
||||
$checkResult = new stdClass();
|
||||
$checkResult->isAllowed = false;
|
||||
|
||||
$eventManagerMock->expects($this->any())
|
||||
->method('dispatch')
|
||||
->with('cms_wysiwyg_images_static_urls_allowed', ['result' => $checkResult, 'store_id' => $storeId])
|
||||
->willReturnCallback(function ($_, $arr) use ($isStaticUrlsAllowed) {
|
||||
$arr['result']->isAllowed = $isStaticUrlsAllowed;
|
||||
});
|
||||
|
||||
$helper->setStoreId($storeId);
|
||||
|
||||
return $helper;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user