You are here

public function QuickEditIntegrationTest::testGetUntransformedTextCommand in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/editor/src/Tests/QuickEditIntegrationTest.php \Drupal\editor\Tests\QuickEditIntegrationTest::testGetUntransformedTextCommand()

Tests GetUntransformedTextCommand AJAX command.

File

core/modules/editor/src/Tests/QuickEditIntegrationTest.php, line 199
Contains \Drupal\editor\Tests\QuickEditIntegrationTest.

Class

QuickEditIntegrationTest
Tests Edit module integration (Editor module's inline editing support).

Namespace

Drupal\editor\Tests

Code

public function testGetUntransformedTextCommand() {

  // Create an entity with values for the field.
  $entity = entity_create('entity_test');
  $entity->{$this->fieldName}->value = 'Test';
  $entity->{$this->fieldName}->format = 'full_html';
  $entity
    ->save();
  $entity = entity_load('entity_test', $entity
    ->id());

  // Verify AJAX response.
  $controller = new EditorController();
  $request = new Request();
  $response = $controller
    ->getUntransformedText($entity, $this->fieldName, LanguageInterface::LANGCODE_DEFAULT, 'default');
  $expected = array(
    array(
      'command' => 'editorGetUntransformedText',
      'data' => 'Test',
    ),
  );
  $ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
  $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
  $event = new FilterResponseEvent(\Drupal::service('http_kernel'), $request, HttpKernelInterface::MASTER_REQUEST, $response);
  $subscriber
    ->onResponse($event);
  $this
    ->assertEqual(Json::encode($expected), $response
    ->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.');
}