Passed
Push — fix-1683 ( 00f5cf )
by Sam
08:14
created

TinyMCEConfigTest::testEditorIdentifier()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Forms\Tests\HTMLEditor;
4
5
use SilverStripe\Control\Director;
6
use SilverStripe\Core\Manifest\ModuleResourceLoader;
7
use SilverStripe\Dev\SapphireTest;
8
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
9
10
class TinyMCEConfigTest extends SapphireTest
11
{
12
13
    public function testEditorIdentifier()
14
    {
15
        $config = TinyMCEConfig::get('myconfig');
16
        $this->assertEquals('myconfig', $config->getOption('editorIdentifier'));
17
    }
18
19
    /**
20
     * Ensure that all TinyMCEConfig.tinymce_lang are valid
21
     */
22
    public function testLanguagesValid()
23
    {
24
        $configDir = TinyMCEConfig::config()->get('base_dir');
25
        if (!$configDir) {
26
            $this->markTestSkipped("Test skipped without TinyMCE resources folder being installed");
27
        }
28
29
        $langs = Director::baseFolder() . '/' . ModuleResourceLoader::resourcePath($configDir) . '/langs';
30
31
        // Test all langs exist as real files
32
        foreach (TinyMCEConfig::config()->get('tinymce_lang') as $locale => $resource) {
33
            // Check valid
34
            $this->assertFileExists(
35
                "{$langs}/{$resource}.js",
36
                "Locale code {$locale} maps to {$resource}.js which exists"
37
            );
38
            // Check we don't simplify to locale when a specific version exists
39
            if (strpos($resource, '_') === false) {
40
                $this->assertFileNotExists(
41
                    "{$langs}/{$locale}.js",
42
                    "Locale code {$locale} doesn't map to simple {$resource}.js when a better {$locale}.js is available"
43
                );
44
            }
45
        }
46
    }
47
48
    public function testGetContentCSS()
49
    {
50
        TinyMCEConfig::config()->set('editor_css', [
51
            'silverstripe/framework:tests/php/Forms/HTMLEditor.css'
52
        ]);
53
54
        // Test default config
55
        $config = new TinyMCEConfig();
56
        $this->assertContains('silverstripe/framework:tests/php/Forms/HTMLEditor.css', $config->getContentCSS());
57
58
        // Test manual disable
59
        $config->setContentCSS([]);
60
        $this->assertEmpty($config->getContentCSS());
61
62
        // Test replacement config
63
        $config->setContentCSS([
64
            'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'
65
        ]);
66
        $this->assertEquals(
67
            [ 'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'],
68
            $config->getContentCSS()
69
        );
70
    }
71
}
72