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

tests/ElementalPageExtensionTests.php (2 issues)

1
<?php
2
3
namespace DNADesign\Elemental\Tests;
4
5
use DNADesign\Elemental\Extensions\ElementalPageExtension;
6
use Page;
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');
0 ignored issues
show
Comprehensibility Best Practice introduced by Will Rossiter
The variable $type does not exist. Did you maybe mean $types?
Loading history...
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();
0 ignored issues
show
The assignment to $types is dead and can be removed.
Loading history...
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