1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Cms\Model\Wysiwyg;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestModuleWysiwygConfig\Model\Config as TestModuleWysiwygConfig;
/**
* @magentoAppArea adminhtml
*/
class ConfigTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Cms\Model\Wysiwyg\Config
*/
private $model;
/**
* {@inheritdoc}
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->model = $objectManager->create(\Magento\Cms\Model\Wysiwyg\Config::class);
}
/**
* Tests that config returns valid config array in it
*
* @return void
*/
public function testGetConfig()
{
$config = $this->model->getConfig();
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $config);
}
/**
* Tests that config returns right urls going to the published library path
*
* @return void
*/
public function testGetConfigCssUrls()
{
$config = $this->model->getConfig();
$publicPathPattern = 'http://localhost/pub/static/%s/adminhtml/Magento/backend/en_US/%s';
$tinyMce4Config = $config->getData('tinymce4');
$contentCss = $tinyMce4Config['content_css'];
if (is_array($contentCss)) {
foreach ($contentCss as $url) {
$this->assertStringMatchesFormat($publicPathPattern, $url);
}
} else {
$this->assertStringMatchesFormat($publicPathPattern, $contentCss);
}
}
/**
* Test enabled module is able to modify WYSIWYG config
*
* @return void
*
* @magentoConfigFixture default/cms/wysiwyg/editor Magento_TestModuleWysiwygConfig/wysiwyg/tinymce4TestAdapter
*/
public function testTestModuleEnabledModuleIsAbleToModifyConfig()
{
$objectManager = Bootstrap::getObjectManager();
$compositeConfigProvider = $objectManager->create(\Magento\Cms\Model\Wysiwyg\CompositeConfigProvider::class);
$model = $objectManager->create(
\Magento\Cms\Model\Wysiwyg\Config::class,
['configProvider' => $compositeConfigProvider]
);
$config = $model->getConfig();
$this->assertEquals(TestModuleWysiwygConfig::CONFIG_HEIGHT, $config['height']);
$this->assertEquals(TestModuleWysiwygConfig::CONFIG_CONTENT_CSS, $config['content_css']);
$this->assertArrayHasKey('tinymce4', $config);
$this->assertArrayHasKey('toolbar', $config['tinymce4']);
$this->assertNotContains(
'charmap',
$config['tinymce4']['toolbar'],
'Failed to address that the custom test module removes "charmap" button from the toolbar'
);
}
}