View source
<?php
namespace Drupal\Tests\colorbutton\FunctionalJavascript;
use Drupal\Component\Serialization\Json;
use Drupal\field\Entity\FieldConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\NodeType;
class ColorbuttonTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
protected static $modules = [
'colorbutton',
'colorbutton_test',
'node',
'filter',
'field_ui',
];
protected function setUp() {
parent::setUp();
NodeType::create([
'type' => 'article',
'name' => 'Article',
])
->save();
FieldConfig::create([
'field_name' => 'body',
'entity_type' => 'node',
'bundle' => 'article',
'format' => 'full_html',
])
->save();
$display_repository = \Drupal::service('entity_display.repository');
$display_repository
->getViewDisplay('node', 'article')
->setComponent('body')
->save();
$display_repository
->getFormDisplay('node', 'article')
->setComponent('body')
->save();
$this
->drupalCreateNode([
'type' => 'article',
'title' => 'Article colorbutton',
'nid' => 1,
'body' => [
[
'value' => $this
->randomMachineName(32),
'format' => 'full_html',
],
],
])
->save();
$permissions = [
'bypass node access',
'administer site configuration',
'use text format full_html',
'administer filters',
];
$user = $this
->createUser($permissions);
$this
->drupalLogin($user);
}
public function testColorbutton() {
$this
->drupalGet('/node/1');
$this
->assertSession()
->pageTextContains('Article colorbutton');
$this
->drupalGet('/admin/config/content/formats/manage/full_html');
$this
->assertSession()
->elementExists('css', '.ckeditor-button');
$json_encode = function ($html) {
return trim(Json::encode($html), '"');
};
$markup = $json_encode(file_url_transform_relative(file_create_url('libraries/colorbutton/icons/textcolor.png')));
$this
->assertSession()
->responseContains($markup);
$this
->drupalGet('/node/1/edit');
$this
->assertSession()
->elementExists('css', '#cke_edit-body-0-value .cke_button__textcolor');
$this
->assertSession()
->elementExists('css', '#cke_edit-body-0-value .cke_button__bgcolor');
$this
->assertSession()
->elementNotExists('css', '.cke_panel');
$this
->click('.cke_button__textcolor');
$this
->assertNotNull($this
->assertSession()
->waitForElement('css', '.cke_panel'));
$this
->assertJsCondition("jQuery('.cke_panel').length > 0");
$this
->assertJsCondition("jQuery('.cke_panel').height() > 100");
$this
->click('.cke_button__bgcolor');
$this
->assertNotNull($this
->assertSession()
->waitForElement('css', '.cke_panel'));
}
}