|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* @package elemental |
|
5
|
|
|
* @subpackage tests |
|
6
|
|
|
*/ |
|
7
|
|
|
class ElementAnchorTests extends FunctionalTest { |
|
|
|
|
|
|
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))); |
|
|
|
|
|
|
20
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 2))); |
|
|
|
|
|
|
21
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 3))); |
|
|
|
|
|
|
22
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 4))); |
|
|
|
|
|
|
23
|
|
|
$area->write(); |
|
24
|
|
|
|
|
25
|
|
|
$recordSet = $area->Elements()->toArray(); |
|
26
|
|
|
$this->assertEquals('e'.$recordSet[0]->ID, $recordSet[0]->getAnchor()); |
|
|
|
|
|
|
27
|
|
|
$this->assertEquals('e'.$recordSet[1]->ID, $recordSet[1]->getAnchor()); |
|
|
|
|
|
|
28
|
|
|
$this->assertEquals('e'.$recordSet[2]->ID, $recordSet[2]->getAnchor()); |
|
|
|
|
|
|
29
|
|
|
$this->assertEquals('e'.$recordSet[3]->ID, $recordSet[3]->getAnchor()); |
|
|
|
|
|
|
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))); |
|
|
|
|
|
|
40
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 2))); |
|
|
|
|
|
|
41
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 3))); |
|
|
|
|
|
|
42
|
|
|
$area->Widgets()->add(BaseElement::create(array('Title' => 'Element 1', 'Sort' => 4))); |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
52
|
|
|
$this->assertEquals('element-1-2', $recordSet[1]->getAnchor()); |
|
|
|
|
|
|
53
|
|
|
$this->assertEquals('element-1-3', $recordSet[2]->getAnchor()); |
|
|
|
|
|
|
54
|
|
|
$this->assertEquals('element-1-4', $recordSet[3]->getAnchor()); |
|
|
|
|
|
|
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); |
|
|
|
|
|
|
76
|
|
|
$area->Widgets()->add($virtElement1); |
|
|
|
|
|
|
77
|
|
|
$area->Widgets()->add($virtElement2); |
|
|
|
|
|
|
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()); |
|
|
|
|
|
|
88
|
|
|
$this->assertEquals('element-2-2', $recordSet[1]->getAnchor()); |
|
|
|
|
|
|
89
|
|
|
$this->assertEquals('element-2-3', $recordSet[2]->getAnchor()); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.