You are here

public function EditorIntegrationLoadingTest::testUserWithPermission in Drupal 9

Same name and namespace in other branches
  1. 10 core/modules/quickedit/tests/src/Functional/EditorIntegrationLoadingTest.php \Drupal\Tests\quickedit\Functional\EditorIntegrationLoadingTest::testUserWithPermission()

Tests loading of untransformed text when a user does have access to it.

File

core/modules/quickedit/tests/src/Functional/EditorIntegrationLoadingTest.php, line 122

Class

EditorIntegrationLoadingTest
Tests Quick Edit module integration endpoints.

Namespace

Drupal\Tests\quickedit\Functional

Code

public function testUserWithPermission() {
  $user = $this
    ->drupalCreateUser(array_merge(static::$basicPermissions, [
    'edit any article content',
    'access in-place editing',
  ]));
  $this
    ->drupalLogin($user);
  $this
    ->drupalGet('node/1');

  // Ensure the text is transformed.
  $this
    ->assertSession()
    ->responseContains('<p>Do you also love Drupal?</p><figure role="group" class="caption caption-img"><img src="druplicon.png" /><figcaption>Druplicon</figcaption></figure>');
  $client = $this
    ->getHttpClient();
  $response = $client
    ->post($this
    ->buildUrl('editor/node/1/body/en/full'), [
    'query' => http_build_query([
      MainContentViewSubscriber::WRAPPER_FORMAT => 'drupal_ajax',
    ]),
    'cookies' => $this
      ->getSessionCookies(),
    'headers' => [
      'Accept' => 'application/json',
      'Content-Type' => 'application/x-www-form-urlencoded',
    ],
    'http_errors' => FALSE,
  ]);
  $this
    ->assertEquals(200, $response
    ->getStatusCode());
  $ajax_commands = Json::decode($response
    ->getBody());
  $this
    ->assertCount(1, $ajax_commands, 'The untransformed text POST request results in one AJAX command.');
  $this
    ->assertSame('editorGetUntransformedText', $ajax_commands[0]['command'], 'The first AJAX command is an editorGetUntransformedText command.');
  $this
    ->assertSame('<p>Do you also love Drupal?</p><img src="druplicon.png" data-caption="Druplicon" />', $ajax_commands[0]['data'], 'The editorGetUntransformedText command contains the expected data.');
}