Completed
Push — master ( 961436...7b1539 )
by Will
11s
created

ElementAnchorTests::testVirtualElementAnchor()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 23
nc 2
nop 0
1
<?php
2
3
/**
4
 * @package elemental
5
 * @subpackage tests
6
 */
7
class ElementAnchorTests extends FunctionalTest {
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
8
    public function setUp() {
9
        parent::setUp();
10
    }
11
12
    /**
13
     * Test to ensure backwards compatibility with old Anchor IDs.
14
     */
15
    public function testDisablePrettyAnchor() {
16
        Config::inst()->update('BaseElement', 'disable_pretty_anchor_name', true);
17
18
        $area = ElementalArea::create();
19
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 1)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
20
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 2)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
21
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 3)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
22
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 4)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
23
        $area->write();
24
25
        $recordSet = $area->Elements()->toArray();
26
        $this->assertEquals('e'.$recordSet[0]->ID, $recordSet[0]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
        $this->assertEquals('e'.$recordSet[1]->ID, $recordSet[1]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
28
        $this->assertEquals('e'.$recordSet[2]->ID, $recordSet[2]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
29
        $this->assertEquals('e'.$recordSet[3]->ID, $recordSet[3]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
30
    }
31
32
    /**
33
     * Test the stop-clashing logic if two BaseElement classes have the same $Title.
34
     */
35
    public function testSameTitle() {
36
        Config::inst()->update('BaseElement', 'enable_title_in_template', true);
37
38
        $area = ElementalArea::create();
39
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 1)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
40
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 2)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
41
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 3)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
42
        $area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 4)));
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
43
        $area->write();
44
45
        $recordSet = $area->Elements()->toArray();
46
        foreach ($recordSet as $record) {
47
            // NOTE: This puts it into the $_anchor protected variable
48
            //       and caches it.
49
            $record->getAnchor();
50
        }
51
        $this->assertEquals('element-1', $recordSet[0]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
52
        $this->assertEquals('element-1-2', $recordSet[1]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        $this->assertEquals('element-1-3', $recordSet[2]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
        $this->assertEquals('element-1-4', $recordSet[3]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
55
    }
56
57
    /**
58
     * Test virtual element Anchor ID.
59
     */
60
    public function testVirtualElementAnchor() {
61
        Config::inst()->update('BaseElement', 'enable_title_in_template', true);
62
63
        $baseElement1 = BaseElement::create(array('Title' => 'Element 2', 'Sort' => 1));
64
        $baseElement1->write();
65
        $baseElement2 = BaseElement::create(array('Title' => 'Element 2', 'Sort' => 2));
66
        $baseElement2->write();
67
        $baseElement3 = BaseElement::create(array('Title' => 'Element 2', 'Sort' => 3));
68
        $baseElement3->write();
69
        $virtElement1 = ElementVirtualLinked::create(array('LinkedElementID' => $baseElement2->ID));
70
        $virtElement1->write();
71
        $virtElement2 = ElementVirtualLinked::create(array('LinkedElementID' => $baseElement3->ID));
72
        $virtElement2->write();
73
74
        $area = ElementalArea::create();
75
        $area->Widgets()->add($baseElement1);
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
76
        $area->Widgets()->add($virtElement1);
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
77
        $area->Widgets()->add($virtElement2);
0 ignored issues
show
Documentation Bug introduced by
The method Widgets does not exist on object<ElementalArea>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
78
        $area->write();
79
80
        $recordSet = $area->Elements()->toArray();
81
        foreach ($recordSet as $record) {
82
            // NOTE: This puts it into the $_anchor protected variable
83
            //       and caches it.
84
            $record->getAnchor();
85
        }
86
87
        $this->assertEquals('element-2', $recordSet[0]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
        $this->assertEquals('element-2-2', $recordSet[1]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
89
        $this->assertEquals('element-2-3', $recordSet[2]->getAnchor());
0 ignored issues
show
Bug introduced by
The method assertEquals() does not seem to exist on object<ElementAnchorTests>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
90
    }
91
92
}
93