View source
<?php
namespace Drupal\Tests\boxout\Functional;
use Drupal\Tests\BrowserTestBase;
use Drupal\filter\Entity\FilterFormat;
use Drupal\Core\StringTranslation\StringTranslationTrait;
class BoxoutTest extends BrowserTestBase {
use StringTranslationTrait;
protected $defaultTheme = 'stark';
protected $profile = 'minimal';
protected static $modules = [
'node',
'filter',
'editor',
'boxout',
];
protected $adminUser;
protected $privilegedUser;
protected function setUp() {
parent::setUp();
$this->adminUser = $this
->drupalCreateUser([
'administer filters',
], 'Boxout Admin', TRUE);
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
$filtered_html_format = FilterFormat::create([
'format' => 'boxout_filter',
'name' => 'Boxout Filter',
'weight' => 0,
'roles' => $this->adminUser
->getRoles(),
'filters' => [
'filter_html' => [
'status' => 1,
'settings' => [
'allowed_html' => '<h2> <p> <div class="boxout default plain">',
],
],
],
]);
$filtered_html_format
->save();
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('admin/config/content/formats/manage/boxout_filter');
$this
->submitForm([
'editor[editor]' => 'ckeditor',
], $this
->t('editor_configure'));
$buttons = [
[
[
'name' => 'Tools',
'items' => [
'Boxout',
],
],
],
];
$this
->submitForm([
'editor[settings][toolbar][button_groups]' => json_encode($buttons),
], $this
->t('Save configuration'));
}
function testBoxoutArticle() {
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('boxout/dialog');
$this
->assertResponse(200, "Boxout Dialog works");
$this
->xpath('//select[@id=:id]/option', [
':id' => 'boxout-style',
]);
$this
->assertOption('boxout-style', 'default');
$this
->assertOption('boxout-style', 'plain');
$this
->xpath('//select[@name=:id]/option', [
':id' => 'boxout-element-type',
]);
$this
->assertOption('boxout-element-type', 'p');
$this
->assertOption('boxout-element-type', 'h2');
$this
->assertOption('boxout-element-type', 'h3');
$this
->assertOption('boxout-element-type', 'h4');
$this
->assertOption('boxout-element-type', 'h5');
$field_header = $this
->xpath('//input[@name="attributes[header]"]');
$this
->assertTrue(count($field_header) === 1, 'Header field is present');
$field_body = $this
->xpath('//textarea[@name="attributes[body]"]');
$this
->assertTrue(count($field_body) === 1, 'Body field is present');
$this
->drupalGet('node/add/article');
$editor_settings = $this
->getDrupalSettings()['editor']['formats']['boxout_filter']['editorSettings'];
$this
->assertTrue($editor_settings['allowedContent']['div']['classes'] == 'boxout,default,plain');
$this
->assertTrue($editor_settings['boxout_dialog_title_insert'] == 'Insert Boxout');
$this
->assertTrue($editor_settings['toolbar'][0]['items'][0] == 'Boxout');
$markup = '<div class="boxout default"><h2>Title</h2><p>Content</p></div>';
$this
->submitForm([
'title[0][value]' => 'Boxout test node ' . $this
->randomMachineName(10),
'body[0][value]' => $markup,
], $this
->t('Save'));
$this
->assertRaw($markup);
}
}