Passed
Push — master ( 0c4770...bd90a5 )
by Damian
32:36 queued 21:07
created

TinyMCEConfigTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 52
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLanguagesValid() 0 21 4
A testGetContentCSS() 0 21 1
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
     * Ensure that all TinyMCEConfig.tinymce_lang are valid
14
     */
15
    public function testLanguagesValid()
16
    {
17
        $configDir = TinyMCEConfig::config()->get('base_dir');
18
        if (!$configDir) {
19
            $this->markTestSkipped("Test skipped without TinyMCE resources folder being installed");
20
        }
21
22
        $langs = Director::baseFolder() . '/' . ModuleResourceLoader::resourcePath($configDir) . '/langs';
23
24
        // Test all langs exist as real files
25
        foreach (TinyMCEConfig::config()->get('tinymce_lang') as $locale => $resource) {
26
            // Check valid
27
            $this->assertFileExists(
28
                "{$langs}/{$resource}.js",
29
                "Locale code {$locale} maps to {$resource}.js which exists"
30
            );
31
            // Check we don't simplify to locale when a specific version exists
32
            if (strpos($resource, '_') === false) {
33
                $this->assertFileNotExists(
34
                    "{$langs}/{$locale}.js",
35
                    "Locale code {$locale} doesn't map to simple {$resource}.js when a better {$locale}.js is available"
36
                );
37
            }
38
        }
39
    }
40
41
    public function testGetContentCSS()
42
    {
43
        TinyMCEConfig::config()->set('editor_css', [
44
            'silverstripe/framework:tests/php/Forms/HTMLEditor.css'
45
        ]);
46
47
        // Test default config
48
        $config = new TinyMCEConfig();
49
        $this->assertContains('silverstripe/framework:tests/php/Forms/HTMLEditor.css', $config->getContentCSS());
50
51
        // Test manual disable
52
        $config->setContentCSS([]);
53
        $this->assertEmpty($config->getContentCSS());
54
55
        // Test replacement config
56
        $config->setContentCSS([
57
            'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'
58
        ]);
59
        $this->assertEquals(
60
            [ 'silverstripe/framework:tests/php/Forms/HTMLEditor_another.css'],
61
            $config->getContentCSS()
62
        );
63
    }
64
}
65