@@ -103,7 +103,7 @@ |
||
| 103 | 103 | * (e.g. because of malformed content) no further attempts will be |
| 104 | 104 | * made. |
| 105 | 105 | * |
| 106 | - * @param DataObject $owner |
|
| 106 | + * @param \SilverStripe\ORM\DataObject $owner |
|
| 107 | 107 | * @return Tocifier|false|null |
| 108 | 108 | */ |
| 109 | 109 | private static function getTocifier($owner) |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | Hacks::addCallbackMethodToInstance( |
| 90 | 90 | $owner, |
| 91 | 91 | 'getContent', |
| 92 | - function () use ($owner) { |
|
| 92 | + function() use ($owner) { |
|
| 93 | 93 | return $owner->getContentField(); |
| 94 | 94 | } |
| 95 | 95 | ); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $callback = Config::inst()->get(self::class, 'augment_callback'); |
| 123 | 123 | } |
| 124 | 124 | $tocifier->setAugmentCallback(explode('::', $callback)); |
| 125 | - if (! $tocifier->process()) { |
|
| 125 | + if (!$tocifier->process()) { |
|
| 126 | 126 | $tocifier = false; |
| 127 | 127 | } |
| 128 | 128 | self::$tocifiers[$owner] = $tocifier; |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | public function getAutotoc() |
| 151 | 151 | { |
| 152 | 152 | $tocifier = self::getTocifier($this->owner); |
| 153 | - if (! $tocifier) { |
|
| 153 | + if (!$tocifier) { |
|
| 154 | 154 | return null; |
| 155 | 155 | } |
| 156 | 156 | |
@@ -171,15 +171,15 @@ discard block |
||
| 171 | 171 | public function getOriginalContentField() |
| 172 | 172 | { |
| 173 | 173 | $model = $this->owner->getCustomisedObj(); |
| 174 | - if (! $model) { |
|
| 174 | + if (!$model) { |
|
| 175 | 175 | $model = $this->owner->data(); |
| 176 | 176 | } |
| 177 | - if (! $model) { |
|
| 177 | + if (!$model) { |
|
| 178 | 178 | return null; |
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $field = $this->contentField(); |
| 182 | - if (! $model->hasField($field)) { |
|
| 182 | + if (!$model->hasField($field)) { |
|
| 183 | 183 | return null; |
| 184 | 184 | } |
| 185 | 185 | |
@@ -26,6 +26,10 @@ |
||
| 26 | 26 | ]; |
| 27 | 27 | } |
| 28 | 28 | |
| 29 | + /** |
|
| 30 | + * @param string $method |
|
| 31 | + * @param \Closure $callback |
|
| 32 | + */ |
|
| 29 | 33 | public static function addCallbackMethodToInstance($instance, $method, $callback) |
| 30 | 34 | { |
| 31 | 35 | // hasMethod() trigger the population of $extra_methods |
@@ -28,8 +28,8 @@ discard block |
||
| 28 | 28 | private function populatedTestObject() |
| 29 | 29 | { |
| 30 | 30 | $obj = new TestObject; |
| 31 | - $obj->Content = file_get_contents(__DIR__ . '/test1'); |
|
| 32 | - $obj->Test2 = file_get_contents(__DIR__ . '/test2'); |
|
| 31 | + $obj->Content = file_get_contents(__DIR__.'/test1'); |
|
| 32 | + $obj->Test2 = file_get_contents(__DIR__.'/test2'); |
|
| 33 | 33 | return $obj; |
| 34 | 34 | } |
| 35 | 35 | |
@@ -66,8 +66,8 @@ discard block |
||
| 66 | 66 | $toc = $obj->getAutotoc(); |
| 67 | 67 | $this->assertNull($toc); |
| 68 | 68 | |
| 69 | - $obj->Content = file_get_contents(__DIR__ . '/test1'); |
|
| 70 | - $obj->Test2 = file_get_contents(__DIR__ . '/test2'); |
|
| 69 | + $obj->Content = file_get_contents(__DIR__.'/test1'); |
|
| 70 | + $obj->Test2 = file_get_contents(__DIR__.'/test2'); |
|
| 71 | 71 | |
| 72 | 72 | // Old TOC should still be cached |
| 73 | 73 | $toc = $obj->getAutotoc(); |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | $toc = $obj->getAutotoc(); |
| 79 | 79 | $this->assertTrue($toc instanceof ArrayData); |
| 80 | 80 | $this->assertEquals(5, $toc->Children->count()); |
| 81 | - $this->assertStringEqualsFile(__DIR__ . '/test1', $obj->OriginalContentField); |
|
| 82 | - $this->assertStringEqualsFile(__DIR__ . '/html2', $obj->ContentField); |
|
| 83 | - $this->assertStringEqualsFile(__DIR__ . '/html2', $obj->Content); |
|
| 81 | + $this->assertStringEqualsFile(__DIR__.'/test1', $obj->OriginalContentField); |
|
| 82 | + $this->assertStringEqualsFile(__DIR__.'/html2', $obj->ContentField); |
|
| 83 | + $this->assertStringEqualsFile(__DIR__.'/html2', $obj->Content); |
|
| 84 | 84 | |
| 85 | 85 | // Change the content field |
| 86 | 86 | $obj->config()->update('content_field', 'Test2'); |
@@ -88,15 +88,15 @@ discard block |
||
| 88 | 88 | |
| 89 | 89 | $toc = $obj->getAutotoc(); |
| 90 | 90 | $this->assertNull($toc); |
| 91 | - $this->assertStringEqualsFile(__DIR__ . '/test2', $obj->OriginalContentField); |
|
| 92 | - $this->assertStringEqualsFile(__DIR__ . '/test2', $obj->ContentField); |
|
| 91 | + $this->assertStringEqualsFile(__DIR__.'/test2', $obj->OriginalContentField); |
|
| 92 | + $this->assertStringEqualsFile(__DIR__.'/test2', $obj->ContentField); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | public function testAugmentCallback() |
| 96 | 96 | { |
| 97 | 97 | $obj = new TestObject; |
| 98 | - $obj->Content = file_get_contents(__DIR__ . '/test1'); |
|
| 99 | - $obj->Test2 = file_get_contents(__DIR__ . '/test2'); |
|
| 98 | + $obj->Content = file_get_contents(__DIR__.'/test1'); |
|
| 99 | + $obj->Test2 = file_get_contents(__DIR__.'/test2'); |
|
| 100 | 100 | |
| 101 | 101 | // Change the augmenter at class level |
| 102 | 102 | Config::inst()->update( |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | |
| 109 | 109 | $toc = $obj->getAutotoc(); |
| 110 | 110 | $this->assertEquals(5, $toc->Children->count()); |
| 111 | - $this->assertStringEqualsFile(__DIR__ . '/html1', $obj->Content); |
|
| 111 | + $this->assertStringEqualsFile(__DIR__.'/html1', $obj->Content); |
|
| 112 | 112 | |
| 113 | 113 | // Change the augmenter at install level: should have higher |
| 114 | 114 | // precedence |
@@ -120,6 +120,6 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | $toc = $obj->getAutotoc(); |
| 122 | 122 | $this->assertEquals(5, $toc->Children->count()); |
| 123 | - $this->assertStringEqualsFile(__DIR__ . '/html2', $obj->Content); |
|
| 123 | + $this->assertStringEqualsFile(__DIR__.'/html2', $obj->Content); |
|
| 124 | 124 | } |
| 125 | 125 | } |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | public function testPrependAnchor() |
| 29 | 29 | { |
| 30 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
|
| 30 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
|
| 31 | 31 | $this->assertEquals('', $tocifier->getHtml()); |
| 32 | 32 | |
| 33 | 33 | $tocifier->setAugmentCallback(array('\eNTiDi\Autotoc\Tocifier', 'prependAnchor')); |
| 34 | 34 | $this->assertTrue($tocifier->process()); |
| 35 | - $this->assertStringEqualsFile(__DIR__ . '/html1', $tocifier->getHtml()); |
|
| 35 | + $this->assertStringEqualsFile(__DIR__.'/html1', $tocifier->getHtml()); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function testSetId() |
| 39 | 39 | { |
| 40 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
|
| 40 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
|
| 41 | 41 | $this->assertEquals('', $tocifier->getHtml()); |
| 42 | 42 | |
| 43 | 43 | // The default augmenting method should already be setId |
| 44 | 44 | $this->assertTrue($tocifier->process()); |
| 45 | - $this->assertStringEqualsFile(__DIR__ . '/html2', $tocifier->getHtml()); |
|
| 45 | + $this->assertStringEqualsFile(__DIR__.'/html2', $tocifier->getHtml()); |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | public function testTOC() |
| 49 | 49 | { |
| 50 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test1')); |
|
| 50 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test1')); |
|
| 51 | 51 | $this->assertEquals(array(), $tocifier->getTOC()); |
| 52 | 52 | $this->assertTrue($tocifier->process()); |
| 53 | 53 | $this->assertNotNull($tocifier->getTOC()); |
@@ -55,17 +55,17 @@ discard block |
||
| 55 | 55 | ob_start(); |
| 56 | 56 | $tocifier->dumpTOC(); |
| 57 | 57 | $returned = ob_get_clean(); |
| 58 | - $this->assertStringEqualsFile(__DIR__ . '/toc1', $returned); |
|
| 58 | + $this->assertStringEqualsFile(__DIR__.'/toc1', $returned); |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | public function testDataHideFromTOC() |
| 62 | 62 | { |
| 63 | - $tocifier = new Tocifier(file_get_contents(__DIR__ . '/test2')); |
|
| 63 | + $tocifier = new Tocifier(file_get_contents(__DIR__.'/test2')); |
|
| 64 | 64 | $this->assertEquals('', $tocifier->getHtml()); |
| 65 | 65 | $this->assertTrue($tocifier->process()); |
| 66 | 66 | |
| 67 | 67 | // Check the augmented HTML is equal to the original one |
| 68 | - $this->assertStringEqualsFile(__DIR__ . '/test2', $tocifier->getHtml()); |
|
| 68 | + $this->assertStringEqualsFile(__DIR__.'/test2', $tocifier->getHtml()); |
|
| 69 | 69 | |
| 70 | 70 | ob_start(); |
| 71 | 71 | $tocifier->dumpTOC(); |