function EditorIntegrationTest::testGetUntransformedTextCommand

Tests GetUntransformedTextCommand AJAX command.

File

core/modules/quickedit/tests/src/Kernel/EditorIntegrationTest.php, line 219

Class

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

Namespace

Drupal\Tests\quickedit\Kernel

Code

public function testGetUntransformedTextCommand() {
    $this->accessChecker = new MockQuickEditEntityFieldAccessCheck();
    $this->editorSelector = $this->container
        ->get('quickedit.editor.selector');
    $this->editorManager = $this->container
        ->get('plugin.manager.quickedit.editor');
    $this->metadataGenerator = new MetadataGenerator($this->accessChecker, $this->editorSelector, $this->editorManager);
    // Create an entity with values for the field.
    $entity = EntityTest::create();
    $entity->{$this->fieldName}->value = 'Test';
    $entity->{$this->fieldName}->format = 'full_html';
    $entity->save();
    $entity = EntityTest::load($entity->id());
    // Verify AJAX response.
    $controller = new QuickEditController($this->container
        ->get('tempstore.private'), $this->metadataGenerator, $this->editorSelector, $this->container
        ->get('renderer'), $this->container
        ->get('entity_display.repository'), $this->container
        ->get('entity.repository'));
    $request = new Request();
    $response = $controller->getUntransformedText($entity, $this->fieldName, LanguageInterface::LANGCODE_DEFAULT, 'default');
    $expected = [
        [
            'command' => 'editorGetUntransformedText',
            'data' => 'Test',
        ],
    ];
    $ajax_response_attachments_processor = \Drupal::service('ajax_response.attachments_processor');
    $subscriber = new AjaxResponseSubscriber($ajax_response_attachments_processor);
    $event = new ResponseEvent(\Drupal::service('http_kernel'), $request, HttpKernelInterface::MASTER_REQUEST, $response);
    $subscriber->onResponse($event);
    $this->assertEquals(Json::encode($expected), $response->getContent(), 'The GetUntransformedTextCommand AJAX command works correctly.');
}

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