class ElementInfoManagerTest
Same name and namespace in other branches
- 11.x core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest
- 10 core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest
- 9 core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest
- 8.9.x core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest
Tests Drupal\Core\Render\ElementInfoManager.
Attributes
#[CoversClass(ElementInfoManager::class)]
#[Group('Render')]
Hierarchy
- class \Drupal\Tests\UnitTestCase uses \Drupal\Tests\DrupalTestCaseTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\Tests\RandomGeneratorTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\Core\Render\ElementInfoManagerTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of ElementInfoManagerTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Render/ ElementInfoManagerTest.php, line 21
Namespace
Drupal\Tests\Core\RenderView source
class ElementInfoManagerTest extends UnitTestCase {
/**
* Tests the getInfo() method when render element plugins are used.
*
* @legacy-covers ::getInfo
* @legacy-covers ::buildInfo
*/
public function testGetInfoElementPlugin(string $plugin_class, $expected_info) : void {
// Override the module handler to set expectations.
$moduleHandler = $this->createMock(ModuleHandlerInterface::class);
$moduleHandler->expects($this->once())
->method('alter')
->with('element_info', $this->anything())
->willReturnArgument(0);
$plugin = $this->createMock($plugin_class);
$plugin->expects($this->once())
->method('getInfo')
->willReturn([
'#theme' => 'page',
]);
$themeManager = $this->createStub(ThemeManagerInterface::class);
$element_info = $this->getMockBuilder('Drupal\\Core\\Render\\ElementInfoManager')
->setConstructorArgs([
new \ArrayObject(),
$this->createStub(CacheBackendInterface::class),
$this->createStub(ThemeHandlerInterface::class),
$moduleHandler,
$themeManager,
])
->onlyMethods([
'getDefinitions',
'createInstance',
])
->getMock();
$themeManager->method('getActiveTheme')
->willReturn(new ActiveTheme([
'name' => 'test',
]));
$element_info->expects($this->once())
->method('createInstance')
->with('page')
->willReturn($plugin);
$element_info->expects($this->once())
->method('getDefinitions')
->willReturn([
'page' => [
'class' => 'TestElementPlugin',
],
]);
$this->assertEquals($expected_info, $element_info->getInfo('page'));
}
/**
* Provides tests data for testGetInfoElementPlugin().
*
* @return array
* An array of test data for testGetInfoElementPlugin().
*/
public static function providerTestGetInfoElementPlugin() : array {
$data = [];
$data[] = [
'Drupal\\Core\\Render\\Element\\ElementInterface',
[
'#type' => 'page',
'#theme' => 'page',
'#defaults_loaded' => TRUE,
],
];
$data[] = [
'Drupal\\Core\\Render\\Element\\FormElementInterface',
[
'#type' => 'page',
'#theme' => 'page',
'#input' => TRUE,
'#value_callback' => [
'TestElementPlugin',
'valueCallback',
],
'#defaults_loaded' => TRUE,
],
];
return $data;
}
/**
* Tests get info property.
*/
public function testGetInfoProperty() : void {
$themeManager = $this->createStub(ThemeManagerInterface::class);
$themeManager->method('getActiveTheme')
->willReturn(new ActiveTheme([
'name' => 'test',
]));
$element_info = new TestElementInfoManager(new \ArrayObject(), $this->createStub(CacheBackendInterface::class), $this->createStub(ThemeHandlerInterface::class), $this->createStub(ModuleHandlerInterface::class), $themeManager);
$this->assertSame('baz', $element_info->getInfoProperty('foo', '#bar'));
$this->assertNull($element_info->getInfoProperty('foo', '#non_existing_property'));
$this->assertSame('qux', $element_info->getInfoProperty('foo', '#non_existing_property', 'qux'));
}
}
Members
| Title Sort descending | Modifiers | Object type | Summary | Overrides |
|---|---|---|---|---|
| DrupalTestCaseTrait::checkErrorHandlerOnTearDown | public | function | Checks the test error handler after test execution. | 1 |
| ElementInfoManagerTest::providerTestGetInfoElementPlugin | public static | function | Provides tests data for testGetInfoElementPlugin(). | |
| ElementInfoManagerTest::testGetInfoElementPlugin | public | function | Tests the getInfo() method when render element plugins are used. | |
| ElementInfoManagerTest::testGetInfoProperty | public | function | Tests get info property. | |
| 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. | |
| UnitTestCase::$root | protected | property | The app root. | |
| 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::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::setDebugDumpHandler | public static | function | Registers the dumper CLI handler when the DebugDump extension is enabled. | |
| UnitTestCase::setUp | protected | function | 355 | |
| UnitTestCase::setupMockIterator | protected | function | Set up a traversable class mock to return specific items when iterated. |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.