function AjaxRendererTest::testRenderWithFragmentObject

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest::testRenderWithFragmentObject()
  2. 10 core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest::testRenderWithFragmentObject()
  3. 11.x core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest::testRenderWithFragmentObject()

Tests the content method.

@covers ::renderResponse

File

core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php, line 67

Class

AjaxRendererTest
@coversDefaultClass <a href="/api/drupal/core%21lib%21Drupal%21Core%21Render%21MainContent%21AjaxRenderer.php/class/AjaxRenderer/9" title="Default main content renderer for Ajax requests." class="local">\Drupal\Core\Render\MainContent\AjaxRenderer</a> @group Ajax

Namespace

Drupal\Tests\Core\Controller

Code

public function testRenderWithFragmentObject() {
    $main_content = [
        '#markup' => 'example content',
    ];
    $request = new Request();
    $route_match = $this->createMock('Drupal\\Core\\Routing\\RouteMatchInterface');
    
    /** @var \Drupal\Core\Ajax\AjaxResponse $result */
    $result = $this->ajaxRenderer
        ->renderResponse($main_content, $request, $route_match);
    $this->assertInstanceOf('Drupal\\Core\\Ajax\\AjaxResponse', $result);
    $commands = $result->getCommands();
    $this->assertEquals('insert', $commands[0]['command']);
    $this->assertEquals('example content', $commands[0]['data']);
    $this->assertEquals('insert', $commands[1]['command']);
    $this->assertEquals('status_messages', $commands[1]['data']);
}

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