You are here

public function FootnotesFilterPluginTest::testDefaultFunctionality in Footnotes 8.2

Tests CKEditor Filter plugin functionality.

File

tests/src/Functional/FootnotesFilterPluginTest.php, line 65

Class

FootnotesFilterPluginTest
Contains Footnotes Filter plugin functionality tests.

Namespace

Drupal\Tests\footnotes\Functional

Code

public function testDefaultFunctionality() {

  // Verify a title with HTML entities is properly escaped.
  $text1 = 'This is the note one.';
  $note1 = '[fn]' . $text1 . '[/fn]';
  $text2 = 'And this is the note two.';
  $note2 = "<fn>{$text2}</fn>";
  $body = '<p>' . $this
    ->randomMachineName(100) . $note1 . '</p><p>' . $this
    ->randomMachineName(100) . $note2 . '</p>';

  // Create a node.
  $node = $this
    ->drupalCreateNode([
    'title' => $this
      ->randomString(),
    'body' => [
      0 => [
        'value' => $body,
        'format' => $this->formatName,
      ],
    ],
  ]);
  $this
    ->drupalGet('node/' . $node
    ->id());

  // Footnote with [fn].
  $this
    ->assertNoRaw($note1);
  $this
    ->assertText($text1);

  // Footnote with <fn>.
  $this
    ->assertNoRaw($note2);
  $this
    ->assertText($text2);

  // Css file:
  $this
    ->assertRaw('/assets/css/footnotes.css');

  // @todo currently additional settings doesn't work as expected.
  // So we don't check additional settings for now.
  // $this->createTextFormat(TRUE);
  $text1 = 'This is the note one.';
  $note1 = "[fn value='1']{$text1}[/fn]";
  $text2 = 'And this is the note two.';
  $note2 = "<fn value='1'>{$text2}</fn>";
  $body = '<p>' . $this
    ->randomMachineName(100) . $note1 . '</p><p>' . $this
    ->randomMachineName(100) . $note2 . '</p>';

  // Create a node.
  $node = $this
    ->drupalCreateNode([
    'title' => $this
      ->randomString(),
    'body' => [
      0 => [
        'value' => $body,
        'format' => $this->formatName,
      ],
    ],
  ]);
  $this
    ->drupalGet('node/' . $node
    ->id());

  // Footnote with [fn].
  $this
    ->assertNoRaw($note1);
  $this
    ->assertText($text1);

  // Elements with the same value should be collapsed.
  // @todo This should work only if footnotes_collapse setting is enabled.
  $this
    ->assertNoRaw($note2);
  $this
    ->assertNoText($text2);
}