silverstripe-autotoc 

silverstripe-autotoc Commit Details

Date:2017-12-30 09:52:06 (3 years 20 days ago)
Author:Nicola Fontana
Branch:dev, master
Commit:ff53845f5c8735b54bdfd967c20e7c01d357b4c1
Parents: c866cde26462ee7b679185f709e1f1659baa46bb
Message:Fix content field overriding only "Content"

Changes:
Msrc/Autotoc.php (1 diff)
Mtests/AutotocTest.php (1 diff)

File differences

src/Autotoc.php
8888
8989
9090
91
91
9292
9393
9494
if ($owner) {
Hacks::addCallbackMethodToInstance(
$owner,
'getContent',
'get'.$this->contentField(),
function() use ($owner) {
return $owner->getContentField();
}
tests/AutotocTest.php
107107
108108
109109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
110140
$this->assertEquals(5, $toc->Children->count());
$this->assertStringEqualsFile(__DIR__.'/html2', $obj->Content);
}
public function testOverriding()
{
$html = file_get_contents(__DIR__.'/test1');
// The content field is not expected to be changed dynamically:
// we need to set it *before* creating the test instance
Config::inst()->update(TestObject::class, 'content_field', 'Something');
$obj = new TestObject;
$obj->Content = $html;
$obj->Test2 = $html;
$this->assertEquals($html, $obj->Content);
$this->assertEquals($html, $obj->Test2);
Config::inst()->update(TestObject::class, 'content_field', 'Content');
$obj = new TestObject;
$obj->Content = $html;
$obj->Test2 = $html;
$this->assertNotEquals($html, $obj->Content);
$this->assertEquals($html, $obj->Test2);
Config::inst()->update(TestObject::class, 'content_field', 'Test2');
$obj = new TestObject;
$obj->Content = $html;
$obj->Test2 = $html;
// The overriding works on a class basis, so the Content field
// will still be overriden
$this->assertNotEquals($html, $obj->Content);
$this->assertNotEquals($html, $obj->Test2);
}
}

Archive Download the corresponding diff file