public function TocFilterBlockTest::testBlock in TOC filter 8.2
Test block.
File
- src/
Tests/ TocFilterBlockTest.php, line 80 - Definition of Drupal\toc_filter\Tests\TocFilterBlockTest.
Class
- TocFilterBlockTest
- Tests TOC filter block.
Namespace
Drupal\toc_filter\TestsCode
public function testBlock() {
$this->node->body->value = '<p>[toc]</p><h2>header 2</h2><h3>header 3</h3><h4>header 4</h4><h4>header 4</h4><h2>header 2</h2>';
$this->node->body->format = 'html';
$this->node
->save();
// Check table of contents displayed inline.
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertRaw('<h3>Table of Contents</h3>');
$this
->assertRaw('<a href="#header-2">header 2</a>');
$this
->assertRaw('<a href="#header-3">header 3</a>');
$this
->assertRaw('<a href="#header-4">header 4</a>');
$this
->assertRaw('<a href="#header-4-01">header 4</a>');
$this
->assertRaw('<a href="#header-2-01">header 2</a>');
$this
->assertRaw('<option value="">Table of Contents</option>');
$this
->assertRaw('<option value="#header-2">1) header 2</option>');
$this
->assertRaw('<option value="#header-3">1.1) header 3</option>');
$this
->assertRaw('<option value="#header-4">1.1.1) header 4</option>');
$this
->assertRaw('<option value="#header-4-01">1.1.2) header 4</option>');
$this
->assertRaw('<option value="#header-2-01">2) header 2</option>');
$this
->assertTrue($this
->cssSelect('.node__content .toc-tree'));
$this
->assertNoRaw('class="block block-toc-filter"');
$this
->assertNoRaw('<h2>Table of Contents</h2>');
// Check table of contents displayed in block.
$this->node->body->value = '<p>[toc block]</p><h2>header 2</h2><h3>header 3</h3><h4>header 4</h4><h4>header 4</h4><h2>header 2</h2>';
$this->node->body->format = 'html';
$this->node
->save();
$this
->drupalGet('node/' . $this->node
->id());
$this
->assertFalse($this
->cssSelect('.node__content .toc-tree'));
$this
->assertRaw('class="block block-toc-filter"');
$this
->assertRaw('<h2>Table of Contents</h2>');
}