class AjaxRendererTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest
- 8.9.x core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest
- 11.x core/tests/Drupal/Tests/Core/Controller/AjaxRendererTest.php \Drupal\Tests\Core\Controller\AjaxRendererTest
@coversDefaultClass \Drupal\Core\Render\MainContent\AjaxRenderer @group Ajax
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Controller\AjaxRendererTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of AjaxRendererTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Controller/ AjaxRendererTest.php, line 16
Namespace
Drupal\Tests\Core\ControllerView source
class AjaxRendererTest extends UnitTestCase {
/**
* The tested ajax controller.
*
* @var \Drupal\Core\Render\MainContent\AjaxRenderer
*/
protected $ajaxRenderer;
/**
* The renderer.
*
* @var \Drupal\Core\Render\RendererInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $renderer;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$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);
}
/**
* Tests the content method.
*
* @covers ::renderResponse
*/
public function testRenderWithFragmentObject() : void {
$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']);
}
}
Members
Title Sort descending | Deprecated | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|---|
AjaxRendererTest::$ajaxRenderer | protected | property | The tested ajax controller. | |||
AjaxRendererTest::$renderer | protected | property | The renderer. | |||
AjaxRendererTest::setUp | protected | function | Overrides UnitTestCase::setUp | |||
AjaxRendererTest::testRenderWithFragmentObject | public | function | Tests the content method. | |||
PhpUnitWarnings::$deprecationWarnings | private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |||
PhpUnitWarnings::addWarning | public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |||
RandomGeneratorTrait::getRandomGenerator | protected | function | Gets the random generator for the utility methods. | |||
RandomGeneratorTrait::randomMachineName | protected | function | Generates a unique random string containing letters and numbers. | |||
RandomGeneratorTrait::randomObject | public | function | Generates a random PHP object. | |||
RandomGeneratorTrait::randomString | public | function | Generates a pseudo-random string of ASCII characters of codes 32 to 126. | |||
RandomGeneratorTrait::randomStringValidate | Deprecated | public | function | Callback for random string validation. | ||
UnitTestCase::$root | protected | property | The app root. | 1 | ||
UnitTestCase::getClassResolverStub | protected | function | Returns a stub class resolver. | |||
UnitTestCase::getConfigFactoryStub | public | function | Returns a stub config factory that behaves according to the passed array. | |||
UnitTestCase::getConfigStorageStub | public | function | Returns a stub config storage that returns the supplied configuration. | |||
UnitTestCase::getContainerWithCacheTagsInvalidator | protected | function | Sets up a container with a cache tags invalidator. | |||
UnitTestCase::getStringTranslationStub | public | function | Returns a stub translation manager that just returns the passed string. | |||
UnitTestCase::setUpBeforeClass | public static | function | ||||
UnitTestCase::__get | public | function |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.