annotate core/modules/quickedit/tests/src/Kernel/QuickEditLoadingTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
rev   line source
Chris@5 1 <?php
Chris@5 2
Chris@5 3 namespace Drupal\Tests\quickedit\Kernel;
Chris@5 4
Chris@5 5 use Drupal\KernelTests\KernelTestBase;
Chris@5 6 use Drupal\node\Entity\Node;
Chris@5 7 use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
Chris@5 8 use Drupal\Tests\node\Traits\NodeCreationTrait;
Chris@5 9 use Drupal\Tests\user\Traits\UserCreationTrait;
Chris@5 10
Chris@5 11 /**
Chris@5 12 * Tests loading of in-place editing functionality and lazy loading of its
Chris@5 13 * in-place editors.
Chris@5 14 *
Chris@5 15 * @group quickedit
Chris@5 16 */
Chris@5 17 class QuickEditLoadingTest extends KernelTestBase {
Chris@5 18
Chris@5 19 use NodeCreationTrait;
Chris@5 20 use UserCreationTrait;
Chris@5 21 use ContentTypeCreationTrait;
Chris@5 22
Chris@5 23 /**
Chris@5 24 * {@inheritdoc}
Chris@5 25 */
Chris@5 26 protected static $modules = [
Chris@5 27 'user',
Chris@5 28 'system',
Chris@5 29 'field',
Chris@5 30 'node',
Chris@5 31 'text',
Chris@5 32 'filter',
Chris@5 33 'contextual',
Chris@5 34 'quickedit',
Chris@5 35 ];
Chris@5 36
Chris@5 37 /**
Chris@5 38 * A user with permissions to access in-place editor.
Chris@5 39 *
Chris@5 40 * @var \Drupal\user\UserInterface
Chris@5 41 */
Chris@5 42 protected $editorUser;
Chris@5 43
Chris@5 44 /**
Chris@5 45 * {@inheritdoc}
Chris@5 46 */
Chris@5 47 protected function setUp() {
Chris@5 48 parent::setUp();
Chris@5 49
Chris@5 50 $this->installSchema('system', 'sequences');
Chris@5 51 $this->installEntitySchema('user');
Chris@5 52 $this->installEntitySchema('node');
Chris@5 53 $this->installConfig(['field', 'filter', 'node']);
Chris@5 54
Chris@5 55 // Create a Content type and one test node.
Chris@5 56 $this->createContentType(['type' => 'page']);
Chris@5 57 $this->createNode();
Chris@5 58
Chris@5 59 $this->editorUser = $this->createUser([
Chris@5 60 'access content',
Chris@5 61 'create page content',
Chris@5 62 'edit any page content',
Chris@5 63 'access contextual links',
Chris@5 64 'access in-place editing',
Chris@5 65 ]);
Chris@5 66 }
Chris@5 67
Chris@5 68 /**
Chris@5 69 * Tests that Quick Edit doesn't make fields rendered with display options
Chris@5 70 * editable.
Chris@5 71 */
Chris@5 72 public function testDisplayOptions() {
Chris@5 73 $node = Node::load(1);
Chris@5 74 $renderer = $this->container->get('renderer');
Chris@5 75 $this->container->get('current_user')->setAccount($this->editorUser);
Chris@5 76
Chris@5 77 $build = $node->body->view(['label' => 'inline']);
Chris@5 78 $this->setRawContent($renderer->renderRoot($build));
Chris@5 79 $elements = $this->xpath('//div[@data-quickedit-field-id]');
Chris@5 80 $this->assertFalse(!empty($elements), 'data-quickedit-field-id attribute not added when rendering field using dynamic display options.');
Chris@5 81
Chris@5 82 $build = $node->body->view('default');
Chris@5 83 $this->setRawContent($renderer->renderRoot($build));
Chris@5 84 $elements = $this->xpath('//div[@data-quickedit-field-id="node/1/body/en/default"]');
Chris@5 85 $this->assertTrue(!empty($elements), 'Body with data-quickedit-field-id attribute found.');
Chris@5 86 }
Chris@5 87
Chris@5 88 }