View source
<?php
namespace Drupal\Tests\footnotes\Functional;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\Tests\BrowserTestBase;
class FootnotesFilterPluginTest extends BrowserTestBase {
use StringTranslationTrait;
protected static $modules = [
'fakeobjects',
'footnotes',
'node',
];
protected $adminUser;
protected $formatName;
protected function setUp() {
parent::setUp();
$permissions = [
'administer filters',
'administer nodes',
'access administration pages',
'administer site configuration',
];
$this->adminUser = $this
->drupalCreateUser($permissions);
$this->formatName = strtolower($this
->randomMachineName());
$this
->drupalLogin($this->adminUser);
$this
->createTextFormat();
$this
->drupalCreateContentType([
'type' => 'page',
]);
}
public function testDefaultFunctionality() {
$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>';
$node = $this
->drupalCreateNode([
'title' => $this
->randomString(),
'body' => [
0 => [
'value' => $body,
'format' => $this->formatName,
],
],
]);
$this
->drupalGet('node/' . $node
->id());
$this
->assertNoRaw($note1);
$this
->assertText($text1);
$this
->assertNoRaw($note2);
$this
->assertText($text2);
$this
->assertRaw('/assets/css/footnotes.css');
$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>';
$node = $this
->drupalCreateNode([
'title' => $this
->randomString(),
'body' => [
0 => [
'value' => $body,
'format' => $this->formatName,
],
],
]);
$this
->drupalGet('node/' . $node
->id());
$this
->assertNoRaw($note1);
$this
->assertText($text1);
$this
->assertNoRaw($note2);
$this
->assertNoText($text2);
}
protected function createTextFormat($additional_settings = FALSE) {
$button_groups = json_encode([
[
[
'name' => 'Tools',
'items' => [
'Source',
'footnotes',
],
],
],
]);
$edit = [
'format' => $this->formatName,
'name' => $this->formatName,
'roles[' . AccountInterface::AUTHENTICATED_ROLE . ']' => TRUE,
'editor[editor]' => 'ckeditor',
'filters[filter_footnotes][status]' => TRUE,
];
$this
->drupalGet("admin/config/content/formats/add");
$this
->drupalPostForm(NULL, $edit, 'editor_configure');
$edit['editor[settings][toolbar][button_groups]'] = $button_groups;
$edit['filters[filter_footnotes][settings][footnotes_collapse]'] = $button_groups;
if ($additional_settings) {
$edit['filters[filter_footnotes][settings][footnotes_collapse]'] = 1;
$edit['filters[filter_footnotes][settings][footnotes_html]'] = 1;
}
$this
->drupalPostForm(NULL, $edit, $this
->t('Save configuration'));
$this
->assertText($this
->t('Added text format @format.', [
'@format' => $this->formatName,
]));
}
}