You are here

protected function AjaxRendererTest::setUp in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest::setUp()

Overrides UnitTestCase::setUp

File

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

Class

AjaxRendererTest
@coversDefaultClass \Drupal\Core\Render\MainContent\AjaxRenderer @group Ajax

Namespace

Drupal\Tests\Core\Controller

Code

protected function setUp() : void {
  $element_info_manager = $this
    ->createMock('Drupal\\Core\\Render\\ElementInfoManagerInterface');
  $element_info_manager
    ->expects($this
    ->any())
    ->method('getInfo')
    ->with('ajax')
    ->willReturn([
    '#header' => TRUE,
    '#commands' => [],
    '#error' => NULL,
  ]);
  $renderer = $this
    ->createMock(RendererInterface::class);
  $renderer
    ->expects($this
    ->any())
    ->method('renderRoot')
    ->willReturnCallback(function (&$elements, $is_root_call = FALSE) {
    $elements += [
      '#attached' => [],
    ];
    if (isset($elements['#markup'])) {
      return $elements['#markup'];
    }
    elseif (isset($elements['#type'])) {
      return $elements['#type'];
    }
    else {
      return 'Markup';
    }
  });
  $this->ajaxRenderer = new AjaxRenderer($element_info_manager, $renderer);
}