You are here

public function QuickEditIntegrationLoadingTest::testUserWithPermission in Drupal 8

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

File

core/modules/editor/tests/src/Functional/QuickEditIntegrationLoadingTest.php, line 122

Class

QuickEditIntegrationLoadingTest
Tests Quick Edit module integration endpoints.

Namespace

Drupal\Tests\editor\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
    ->assertRaw('<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
    ->assertIdentical('editorGetUntransformedText', $ajax_commands[0]['command'], 'The first AJAX command is an editorGetUntransformedText command.');
  $this
    ->assertIdentical('<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.');
}