ConfigTest.php 2.8 KB

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