View source
<?php
namespace Drupal\Tests\quickedit\FunctionalJavascript;
use Drupal\editor\Entity\Editor;
use Drupal\filter\Entity\FilterFormat;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\contextual\FunctionalJavascript\ContextualLinkClickTrait;
class FieldTest extends WebDriverTestBase {
use ContextualLinkClickTrait;
protected static $modules = [
'node',
'ckeditor',
'contextual',
'quickedit',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$filtered_html_format = FilterFormat::create([
'format' => 'filtered_html',
'name' => 'Filtered HTML',
'weight' => 0,
]);
$filtered_html_format
->save();
Editor::create([
'format' => 'filtered_html',
'editor' => 'ckeditor',
])
->save();
$node_type = NodeType::create([
'type' => 'page',
'name' => 'Page',
]);
$node_type
->save();
node_add_body_field($node_type);
$account = $this
->drupalCreateUser([
'access content',
'administer nodes',
'edit any page content',
'use text format filtered_html',
'access contextual links',
'access in-place editing',
]);
$this
->drupalLogin($account);
}
public function testFieldWithCkeditor() {
$body_value = '<p>Dare to be wise</p>';
$node = Node::create([
'type' => 'page',
'title' => 'Page node',
'body' => [
[
'value' => $body_value,
'format' => 'filtered_html',
],
],
]);
$node
->save();
$page = $this
->getSession()
->getPage();
$assert = $this
->assertSession();
$this
->drupalGet('node/' . $node
->id());
$this
->assertSession()
->waitForElement('css', '[data-quickedit-entity-id="node/' . $node
->id() . '"] .contextual .quickedit');
$this
->clickContextualLink('[data-quickedit-entity-id="node/' . $node
->id() . '"]', 'Quick edit');
$page
->find('css', '[data-quickedit-field-id="node/' . $node
->id() . '/body/en/full"]')
->click();
$this
->assertSession()
->waitForElementVisible('css', '.cke_button.cke_button__blockquote')
->click();
$this
->assertSession()
->waitForElementVisible('css', '.quickedit-toolgroup.ops [type="submit"][aria-hidden="false"]')
->click();
$this
->assertSession()
->assertNoElementAfterWait('css', '.cke_button.cke_button__blockquote');
$assert
->responseMatches("|<blockquote>\\s*{$body_value}\\s*</blockquote>|");
}
}