Test Setup Failed
Pull Request — master (#197)
by Gorrie
01:07
created

tests/ElementalPageExtensionTests.php (1 issue)

Checks if used types are declared or listed as dependencies.

Bug Major
1
<?php
2
3
namespace DNADesign\Elemental\Tests;
4
5
use DNADesign\Elemental\Extensions\ElementalPageExtension;
6
use Page;
0 ignored issues
show
The type Page was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SilverStripe\CMS\Model\RedirectorPage;
8
use SilverStripe\Dev\FunctionalTest;
9
10
class ElementalPageExtensionTests extends FunctionalTest
11
{
12
    protected static $fixture_file = 'ElementalPageExtensionTests.yml';
13
14
    protected static $required_extensions = [
15
        Page::class => [
16
            ElementalPageExtension::class,
17
        ],
18
    ];
19
20
    public function testUpdateCmsFields()
21
    {
22
        $page = $this->objFromFixture(Page::class, 'elementaldemo');
23
24
        $elementalArea = $page->getCMSFields()->dataFieldByName('ElementalArea');
25
        $this->assertNotNull($elementalArea);
26
27
        $content = $page->getCMSFields()->dataFieldByName('Content');
28
        $this->assertNull($content);
29
30
        $redirect = $this->objFromFixture(RedirectorPage::class, 'elementredirectpage');
31
        $elementalArea = $redirect->getCMSFields()->dataFieldByName('ElementalArea');
32
33
        $this->assertNull($elementalArea);
34
    }
35
36
    public function testGetElementalTypes()
37
    {
38
        $page = $this->objFromFixture(Page::class, 'elementaldemo');
39
        $types = $page->getElementalTypes();
40
41
        $this->assertArrayHasKey(ElementContent::class, $types);
42
        $this->assertArrayNotHasKey(BaseElement::class, $type, 'Base class should not appear');
43
44
        // if we disallow a type then it should remove it
45
        Config::modify()->set(Page::class, 'disallowed_elements', [
46
            ElementContent::class
47
        ]);
48
49
        $types = $page->getElementalTypes();
50
        $this->assertArrayNotHasKey(ElementContent::class, $type, 'Disallowed items should not appear');
51
52
        // conversely, if we set allowed items to a number of classes then they
53
        // should be the only ones to appear.
54
        Config::modify()->set(Page::class, 'allowed_elements', [
55
            TestElement::class
56
        ]);
57
58
        Config::modify()->remove(Page::class, 'disallowed_elements');
59
        $types = $page->getElementalTypes();
60
61
        $this->assertArrayNotHasKey(ElementContent::class, $type, 'Disallowed items should not appear');
62
        $this->assertArrayHasKey(TestElement::class, $types);
63
64
        $this->assertEquals('A test element', $types[TestElement::class], 'Types should use their i18n name');
65
    }
66
}
67