function AjaxRendererTest::testRenderWithoutAttached

Tests renderResponse() when the render array has no #attached key.

File

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

Class

AjaxRendererTest
Tests Drupal\Core\Render\MainContent\AjaxRenderer.

Namespace

Drupal\Tests\Core\Controller

Code

public function testRenderWithoutAttached() : void {
  $element_info_manager = $this->createStub(ElementInfoManagerInterface::class);
  $renderer = $this->createStub(RendererInterface::class);
  $renderer->method('renderRoot')
    ->willReturnCallback(function (array &$elements, $is_root_call = FALSE) {
    if (isset($elements['#markup'])) {
      return $elements['#markup'];
    }
    elseif (isset($elements['#type'])) {
      return $elements['#type'];
    }
    else {
      return 'Markup';
    }
  });
  $ajax_renderer = new AjaxRenderer($element_info_manager, $renderer);
  $main_content = [
    '#markup' => 'example content',
  ];
  $request = new Request();
  $route_match = $this->createStub(RouteMatchInterface::class);
  $result = $ajax_renderer->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']);
}

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