View source
<?php
namespace Drupal\Tests\panelizer_quickedit\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
class PanelizerQuickEditTest extends WebDriverTestBase {
protected $defaultTheme = 'stark';
public static $modules = [
'contextual',
'field_ui',
'node',
'panelizer_quickedit',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'page',
'name' => 'Page',
]);
FieldStorageConfig::create([
'field_name' => 'test_field',
'entity_type' => 'node',
'type' => 'string',
])
->save();
FieldConfig::create([
'field_name' => 'test_field',
'label' => 'Test Field',
'entity_type' => 'node',
'bundle' => 'page',
'required' => FALSE,
'settings' => [],
'description' => '',
])
->save();
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('node.page.default');
$entity_form_display
->setComponent('test_field')
->save();
$entity_display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.page.default');
$entity_display
->setComponent('test_field')
->save();
$user = $this
->drupalCreateUser([
'access contextual links',
'access in-place editing',
'access content',
'administer node display',
'administer panelizer',
'create page content',
'edit any page content',
]);
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/types/manage/page/display');
$this->container
->get('panelizer')
->setPanelizerSettings('node', 'page', 'default', [
'enable' => TRUE,
'allow' => FALSE,
'custom' => FALSE,
'default' => 'default',
]);
}
public function testPanelizerQuickEdit() {
$panelizer = \Drupal::service('panelizer');
$displays = $panelizer
->getDefaultPanelsDisplays('node', 'page', 'default');
$display = $displays['default'];
$block_id = FALSE;
foreach ($display
->getConfiguration()['blocks'] as $block) {
if ($block['id'] === 'entity_field:node:test_field') {
$block_id = $block['uuid'];
}
}
$this
->assertNotFalse($block_id);
$node = $this
->drupalCreateNode([
'type' => 'page',
'test_field' => [
'value' => 'Change me',
],
]);
$this
->drupalGet($node
->toUrl());
$panelizer_id = 'panelizer-full-block-id-' . $block_id;
$entity_selector = '[data-quickedit-entity-id="node/' . $node
->id() . '"]';
$field_selector = '[data-quickedit-field-id="node/' . $node
->id() . '/test_field/' . $node
->language()
->getId() . '/' . $panelizer_id . '"]';
$condition = "jQuery('" . $entity_selector . " .quickedit').length > 0";
$this
->assertJsCondition($condition, 10000);
$this
->triggerClick($entity_selector . ' [data-contextual-id] > button');
$this
->click($entity_selector . ' [data-contextual-id] .quickedit > a');
$this
->triggerClick($field_selector);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->executeScript("jQuery('" . $field_selector . "').text('Hello world').trigger('keyup');");
$this
->prepareRequest();
$this
->triggerClick('.quickedit-button.action-save');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->drupalGet($node
->toUrl());
$this
->assertSession()
->pageTextContains('Hello world');
}
protected function triggerClick($css_selector) {
$this
->getSession()
->executeScript("jQuery('" . $css_selector . "')[0].click()");
}
}