class RendererCallbackTest in Drupal 9
Same name and namespace in other branches
- 8 core/tests/Drupal/Tests/Core/Render/RendererCallbackTest.php \Drupal\Tests\Core\Render\RendererCallbackTest
@coversDefaultClass \Drupal\Core\Render\Renderer @group Render
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\Core\Render\RendererTestBase
- class \Drupal\Tests\Core\Render\RendererCallbackTest
- class \Drupal\Tests\Core\Render\RendererTestBase
Expanded class hierarchy of RendererCallbackTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ RendererCallbackTest.php, line 11
Namespace
Drupal\Tests\Core\RenderView source
class RendererCallbackTest extends RendererTestBase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->controllerResolver
->expects($this
->any())
->method('getControllerFromDefinition')
->willReturnArgument(0);
}
/**
* Tests the expected deprecations are triggered by Renderer::doCallback().
*
* @param array $render_array
* The render array with a callback.
* @param $expected_deprecation
* The expected deprecation message triggered whilst rendering.
*
* @dataProvider providerTestCallback
*/
public function testCallback(array $render_array, $expected_deprecation) {
$this
->expectException(UntrustedCallbackException::class);
$this
->expectExceptionMessage($expected_deprecation);
$this->renderer
->renderRoot($render_array);
}
/**
* Data provider for testCallback().
*/
public function providerTestCallback() {
return [
'Procedural function pre render' => [
[
'#pre_render' => [
'\\Drupal\\Tests\\Core\\Render\\callback',
],
'#type' => 'container',
],
'Render #pre_render callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was \\Drupal\\Tests\\Core\\Render\\callback. See https://www.drupal.org/node/2966725',
],
'Static object method post render' => [
[
'#post_render' => [
'\\Drupal\\Tests\\Core\\Render\\RendererCallbackTest::renderCallback',
],
'#type' => 'container',
],
'Render #post_render callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was \\Drupal\\Tests\\Core\\Render\\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725',
],
'Object method access callback' => [
[
'#access_callback' => [
$this,
'renderCallback',
],
'#type' => 'container',
],
'Render #access_callback callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\\Tests\\Core\\Render\\RendererCallbackTest::renderCallback. See https://www.drupal.org/node/2966725',
],
'Procedural function lazy builder' => [
[
'#lazy_builder' => [
'\\Drupal\\Tests\\Core\\Render\\callback',
[],
],
],
'Render #lazy_builder callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was \\Drupal\\Tests\\Core\\Render\\callback. See https://www.drupal.org/node/2966725',
],
'Invokable object access callback' => [
[
'#access_callback' => $this,
'#type' => 'container',
],
'Render #access_callback callbacks must be methods of a class that implements \\Drupal\\Core\\Security\\TrustedCallbackInterface or be an anonymous function. The callback was Drupal\\Tests\\Core\\Render\\RendererCallbackTest. See https://www.drupal.org/node/2966725',
],
];
}
/**
* A test render callback.
*/
public static function renderCallback($element = []) {
return $element;
}
/**
* Implements magic method as a render callback.
*/
public function __invoke($element = []) {
return $element;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
RendererCallbackTest:: |
public | function | Data provider for testCallback(). | |
RendererCallbackTest:: |
public static | function | A test render callback. | |
RendererCallbackTest:: |
protected | function |
Overrides RendererTestBase:: |
|
RendererCallbackTest:: |
public | function | Tests the expected deprecations are triggered by Renderer::doCallback(). | |
RendererCallbackTest:: |
public | function | Implements magic method as a render callback. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked controller resolver. | |
RendererTestBase:: |
protected | property | The simulated "current" user role, for use in tests with cache contexts. | |
RendererTestBase:: |
protected | property | The mocked element info. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The tested placeholder generator. | 1 |
RendererTestBase:: |
protected | property | The tested render cache. | |
RendererTestBase:: |
protected | property | The tested renderer. | |
RendererTestBase:: |
protected | property | The mocked renderer configuration. | |
RendererTestBase:: |
protected | property | ||
RendererTestBase:: |
protected | property | The mocked theme manager. | |
RendererTestBase:: |
protected | function | Asserts a render cache item. | |
RendererTestBase:: |
protected | function | Generates a random context value for the placeholder tests. | |
RendererTestBase:: |
protected | function | Sets up a memory-based render cache back-end. | |
RendererTestBase:: |
protected | function | Sets up a request object on the request stack. | |
RendererTestBase:: |
protected | function | Sets up a render cache back-end that is asserted to be never used. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. | |
UnitTestCase:: |
public static | function |