View source
<?php
namespace Drupal\Tests\panelizer_quickedit\FunctionalJavascript;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
class PanelizerQuickEditTest extends JavascriptTestBase {
public static $modules = [
'contextual',
'quickedit',
'field_ui',
'node',
'panelizer_quickedit',
];
protected function setUp() {
parent::setUp();
$this
->drupalCreateContentType([
'type' => 'article',
'name' => 'Article',
]);
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' => 'article',
'required' => FALSE,
'settings' => [],
'description' => '',
])
->save();
$entity_form_display = \Drupal::entityTypeManager()
->getStorage('entity_form_display')
->load('node.article.default');
$entity_form_display
->setComponent('test_field')
->save();
$entity_display = \Drupal::entityTypeManager()
->getStorage('entity_view_display')
->load('node.article.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 article content',
'edit any article content',
]);
$this
->drupalLogin($user);
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertResponse(200);
$edit = [
'panelizer[enable]' => TRUE,
];
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertResponse(200);
}
public function testPanelizerQuickEdit() {
$panelizer = \Drupal::service('panelizer');
$displays = $panelizer
->getDefaultPanelsDisplays('node', 'article', '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' => 'article',
'test_field' => [
'value' => 'Change me',
],
]);
$this
->drupalGet('node/' . $node
->id());
$this
->assertResponse(200);
$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/' . $node
->id());
$this
->assertResponse(200);
$this
->assertSession()
->pageTextContains('Hello world');
}
protected function triggerClick($css_selector) {
$this
->getSession()
->executeScript("jQuery('" . $css_selector . "')[0].click()");
}
}