class QuickEditLoadingTest

Same name in this branch
  1. 9 core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest
Same name and namespace in other branches
  1. 8.9.x core/modules/quickedit/tests/src/FunctionalJavascript/QuickEditLoadingTest.php \Drupal\Tests\quickedit\FunctionalJavascript\QuickEditLoadingTest
  2. 8.9.x core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php \Drupal\Tests\quickedit\Kernel\QuickEditLoadingTest

Tests loading of in-place editing and lazy loading of in-place editors.

@group quickedit @group legacy

Hierarchy

Expanded class hierarchy of QuickEditLoadingTest

File

core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php, line 17

Namespace

Drupal\Tests\quickedit\Kernel
View source
class QuickEditLoadingTest extends KernelTestBase {
  use NodeCreationTrait;
  use UserCreationTrait;
  use ContentTypeCreationTrait;
  
  /**
   * {@inheritdoc}
   */
  protected static $modules = [
    'user',
    'system',
    'field',
    'node',
    'text',
    'filter',
    'contextual',
    'quickedit',
  ];
  
  /**
   * A user with permissions to access in-place editor.
   *
   * @var \Drupal\user\UserInterface
   */
  protected $editorUser;
  
  /**
   * {@inheritdoc}
   */
  protected function setUp() : void {
    parent::setUp();
    $this->installSchema('system', 'sequences');
    $this->installEntitySchema('user');
    $this->installEntitySchema('node');
    $this->installConfig([
      'field',
      'filter',
      'node',
    ]);
    // Create a Content type and one test node.
    $this->createContentType([
      'type' => 'page',
    ]);
    $this->createNode();
    $this->editorUser = $this->createUser([
      'access content',
      'create page content',
      'edit any page content',
      'access contextual links',
      'access in-place editing',
    ]);
  }
  
  /**
   * Tests that fields rendered with display options are not editable.
   */
  public function testDisplayOptions() {
    $node = Node::load(1);
    $renderer = $this->container
      ->get('renderer');
    $this->container
      ->get('current_user')
      ->setAccount($this->editorUser);
    $build = $node->body
      ->view([
      'label' => 'inline',
    ]);
    $this->setRawContent($renderer->renderRoot($build));
    $elements = $this->xpath('//div[@data-quickedit-field-id]');
    $this->assertEmpty($elements, 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
    $build = $node->body
      ->view('default');
    $this->setRawContent($renderer->renderRoot($build));
    $elements = $this->xpath('//div[@data-quickedit-field-id="node/1/body/en/default"]');
    $this->assertNotEmpty($elements, 'Body with data-quickedit-field-id attribute found.');
  }

}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.