class DiscoveryCachedTraitTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/tests/Drupal/Tests/Component/Plugin/Discovery/DiscoveryCachedTraitTest.php \Drupal\Tests\Component\Plugin\Discovery\DiscoveryCachedTraitTest
@coversDefaultClass Drupal\Component\Plugin\Discovery\DiscoveryCachedTrait @uses Drupal\Component\Plugin\Discovery\DiscoveryTrait @group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \Drupal\Tests\PHPUnit_Framework_TestCase
- class \Drupal\Tests\Component\Plugin\Discovery\DiscoveryCachedTraitTest
Expanded class hierarchy of DiscoveryCachedTraitTest
File
- core/
tests/ Drupal/ Tests/ Component/ Plugin/ Discovery/ DiscoveryCachedTraitTest.php, line 17 - Contains \Drupal\Tests\Component\Plugin\Discovery\DiscoveryCachedTraitTest.
Namespace
Drupal\Tests\Component\Plugin\DiscoveryView source
class DiscoveryCachedTraitTest extends UnitTestCase {
/**
* Data provider for testGetDefinition().
*
* @return array
* - Expected result from getDefinition().
* - Cached definitions to be placed into self::$definitions
* - Definitions to be returned by getDefinitions().
* - Plugin name to query for.
*/
public function providerGetDefinition() {
return array(
[
'definition',
[],
[
'plugin_name' => 'definition',
],
'plugin_name',
],
[
'definition',
[
'plugin_name' => 'definition',
],
[],
'plugin_name',
],
[
NULL,
[
'plugin_name' => 'definition',
],
[],
'bad_plugin_name',
],
);
}
/**
* @covers ::getDefinition
* @dataProvider providerGetDefinition
*/
public function testGetDefinition($expected, $cached_definitions, $get_definitions, $plugin_id) {
// Mock a DiscoveryCachedTrait.
$trait = $this
->getMockForTrait('Drupal\\Component\\Plugin\\Discovery\\DiscoveryCachedTrait');
$reflection_definitions = new \ReflectionProperty($trait, 'definitions');
$reflection_definitions
->setAccessible(TRUE);
// getDefinition() needs the ::$definitions property to be set in one of two
// ways: 1) As existing cached data, or 2) as a side-effect of calling
// getDefinitions().
// If there are no cached definitions, then we have to fake the side-effect
// of getDefinitions().
if (count($cached_definitions) < 1) {
$trait
->expects($this
->once())
->method('getDefinitions')
->willReturnCallback(function () use ($reflection_definitions, $trait, $get_definitions) {
$reflection_definitions
->setValue($trait, $get_definitions);
return $get_definitions;
});
}
else {
// Put $cached_definitions into our mocked ::$definitions.
$reflection_definitions
->setValue($trait, $cached_definitions);
}
// Call getDefinition(), with $exception_on_invalid always FALSE.
$this
->assertSame($expected, $trait
->getDefinition($plugin_id, FALSE));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DiscoveryCachedTraitTest:: |
public | function | Data provider for testGetDefinition(). | |
DiscoveryCachedTraitTest:: |
public | function | @covers ::getDefinition @dataProvider providerGetDefinition | |
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. | |
UnitTestCase:: |
protected | function | 259 |