class ElementInfoManagerTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Core/Render/ElementInfoManagerTest.php \Drupal\Tests\Core\Render\ElementInfoManagerTest
@coversDefaultClass \Drupal\Core\Render\ElementInfoManager @group Render
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Core\Render\ElementInfoManagerTest
Expanded class hierarchy of ElementInfoManagerTest
File
- core/
tests/ Drupal/ Tests/ Core/ Render/ ElementInfoManagerTest.php, line 18 - Contains \Drupal\Tests\Core\Render\ElementInfoManagerTest.
Namespace
Drupal\Tests\Core\RenderView source
class ElementInfoManagerTest extends UnitTestCase {
/**
* The mocked element_info.
*
* @var \Drupal\Core\Render\ElementInfoManagerInterface
*/
protected $elementInfo;
/**
* The cache backend to use.
*
* @var \Drupal\Core\Cache\CacheBackendInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cache;
/**
* The mocked module handler.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $moduleHandler;
/**
* The mocked theme manager.
*
* @var \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $themeManager;
/**
* The cache tags invalidator.
*
* @var \Drupal\Core\Cache\CacheTagsInvalidatorInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $cacheTagsInvalidator;
/**
* {@inheritdoc}
*
* @covers ::__construct
*/
protected function setUp() {
$this->cache = $this
->getMock('Drupal\\Core\\Cache\\CacheBackendInterface');
$this->cacheTagsInvalidator = $this
->getMock('Drupal\\Core\\Cache\\CacheTagsInvalidatorInterface');
$this->moduleHandler = $this
->getMock('Drupal\\Core\\Extension\\ModuleHandlerInterface');
$this->themeManager = $this
->getMock('Drupal\\Core\\Theme\\ThemeManagerInterface');
$this->elementInfo = new ElementInfoManager(new \ArrayObject(), $this->cache, $this->cacheTagsInvalidator, $this->moduleHandler, $this->themeManager);
}
/**
* Tests the getInfo() method when render element plugins are used.
*
* @covers ::getInfo
* @covers ::buildInfo
*
* @dataProvider providerTestGetInfoElementPlugin
*/
public function testGetInfoElementPlugin($plugin_class, $expected_info) {
$this->moduleHandler
->expects($this
->once())
->method('alter')
->with('element_info', $this
->anything())
->will($this
->returnArgument(0));
$plugin = $this
->getMock($plugin_class);
$plugin
->expects($this
->once())
->method('getInfo')
->willReturn(array(
'#theme' => 'page',
));
$element_info = $this
->getMockBuilder('Drupal\\Core\\Render\\ElementInfoManager')
->setConstructorArgs(array(
new \ArrayObject(),
$this->cache,
$this->cacheTagsInvalidator,
$this->moduleHandler,
$this->themeManager,
))
->setMethods(array(
'getDefinitions',
'createInstance',
))
->getMock();
$this->themeManager
->expects($this
->any())
->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(array(
'page' => array(
'class' => 'TestElementPlugin',
),
));
$this
->assertEquals($expected_info, $element_info
->getInfo('page'));
}
/**
* Provides tests data for testGetInfoElementPlugin().
*
* @return array
*/
public function providerTestGetInfoElementPlugin() {
$data = array();
$data[] = array(
'Drupal\\Core\\Render\\Element\\ElementInterface',
array(
'#type' => 'page',
'#theme' => 'page',
'#defaults_loaded' => TRUE,
),
);
$data[] = array(
'Drupal\\Core\\Render\\Element\\FormElementInterface',
array(
'#type' => 'page',
'#theme' => 'page',
'#input' => TRUE,
'#value_callback' => array(
'TestElementPlugin',
'valueCallback',
),
'#defaults_loaded' => TRUE,
),
);
return $data;
}
/**
* @covers ::getInfoProperty
*/
public function testGetInfoProperty() {
$this->themeManager
->method('getActiveTheme')
->willReturn(new ActiveTheme([
'name' => 'test',
]));
$element_info = new TestElementInfoManager(new \ArrayObject(), $this->cache, $this->cacheTagsInvalidator, $this->moduleHandler, $this->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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ElementInfoManagerTest:: |
protected | property | The cache backend to use. | |
ElementInfoManagerTest:: |
protected | property | The cache tags invalidator. | |
ElementInfoManagerTest:: |
protected | property | The mocked element_info. | |
ElementInfoManagerTest:: |
protected | property | The mocked module handler. | |
ElementInfoManagerTest:: |
protected | property | The mocked theme manager. | |
ElementInfoManagerTest:: |
public | function | Provides tests data for testGetInfoElementPlugin(). | |
ElementInfoManagerTest:: |
protected | function |
@covers ::__construct Overrides UnitTestCase:: |
|
ElementInfoManagerTest:: |
public | function | Tests the getInfo() method when render element plugins are used. | |
ElementInfoManagerTest:: |
public | function | @covers ::getInfoProperty | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed in 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. |