|
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
|
|
|
|
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.