class YamlDirectoryDiscoveryTest
Same name in this branch
- 11.x core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
Same name in other branches
- 9 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest
- 9 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
- 8.9.x core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest
- 8.9.x core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
- 10 core/tests/Drupal/Tests/Core/Plugin/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest
- 10 core/tests/Drupal/Tests/Component/Discovery/YamlDirectoryDiscoveryTest.php \Drupal\Tests\Component\Discovery\YamlDirectoryDiscoveryTest
@coversDefaultClass \Drupal\Core\Plugin\Discovery\YamlDirectoryDiscovery
@group Plugin
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Drupal\Tests\PhpUnitCompatibilityTrait, \Prophecy\PhpUnit\ProphecyTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\RandomGeneratorTrait
- class \Drupal\Tests\Core\Plugin\Discovery\YamlDirectoryDiscoveryTest extends \Drupal\Tests\UnitTestCase
Expanded class hierarchy of YamlDirectoryDiscoveryTest
File
-
core/
tests/ Drupal/ Tests/ Core/ Plugin/ Discovery/ YamlDirectoryDiscoveryTest.php, line 18
Namespace
Drupal\Tests\Core\Plugin\DiscoveryView source
class YamlDirectoryDiscoveryTest extends UnitTestCase {
/**
* @covers ::getDefinitions
*/
public function testGetDefinitions() : void {
vfsStream::setup('modules', NULL, [
'module_a' => [
'subdir1' => [
'plugin1.yml' => "id: plugin1\ntest_provider: module_a",
'plugin2.yml' => "id: plugin2\ntest_provider: module_a",
],
'subdir2' => [
'plugin3.yml' => "id: plugin3\ntest_provider: module_a",
],
'subdir3' => [],
],
'module_b' => [
'subdir1' => [
'plugin4.yml' => "id: plugin4\ntest_provider: module_b",
],
],
]);
$directories = [
'module_a' => [
vfsStream::url('modules/module_a/subdir1'),
vfsStream::url('modules/module_a/subdir2'),
// Empty directory.
vfsStream::url('modules/module_a/subdir3'),
// Directory does not exist.
vfsStream::url('modules/module_a/subdir4'),
],
'module_b' => vfsStream::url('modules/module_b/subdir1'),
];
$discovery = new YamlDirectoryDiscovery($directories, 'test');
$definitions = $discovery->getDefinitions();
$this->assertIsArray($definitions);
$this->assertCount(4, $definitions);
foreach ($definitions as $id => $definition) {
foreach ([
'id',
'provider',
ComponentYamlDirectoryDiscovery::FILE_KEY,
] as $key) {
$this->assertArrayHasKey($key, $definition);
}
$this->assertEquals($id, $definition['id']);
$this->assertEquals($definition['test_provider'], $definition['provider']);
}
}
/**
* @covers ::getDefinitions
*/
public function testGetDefinitionsWithTranslatableDefinitions() : void {
vfsStream::setup('modules', NULL, [
'module_a' => [
'subdir1' => [
'plugin1.yml' => "id: plugin1\ntest_provider: module_a\ntitle: 'test title'",
'plugin2.yml' => "id: plugin2\ntest_provider: module_a\ntitle: 'test title'\ntitle_context: test-context",
],
],
]);
$directories = [
'module_a' => vfsStream::url('modules/module_a/subdir1'),
];
$discovery = new YamlDirectoryDiscovery($directories, 'test');
$discovery->addTranslatableProperty('title', 'title_context');
$definitions = $discovery->getDefinitions();
$this->assertCount(2, $definitions);
$plugin_1 = $definitions['plugin1'];
$plugin_2 = $definitions['plugin2'];
$this->assertInstanceOf(TranslatableMarkup::class, $plugin_1['title']);
$this->assertEquals([], $plugin_1['title']->getOptions());
$this->assertInstanceOf(TranslatableMarkup::class, $plugin_2['title']);
$this->assertEquals([
'context' => 'test-context',
], $plugin_2['title']->getOptions());
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overrides |
---|---|---|---|---|
ExpectDeprecationTrait::expectDeprecation | public | function | Adds an expected deprecation. | |
ExpectDeprecationTrait::getCallableName | private static | function | Returns a callable as a string suitable for inclusion in a message. | |
ExpectDeprecationTrait::setUpErrorHandler | public | function | Sets up the test error handler. | |
ExpectDeprecationTrait::tearDownErrorHandler | public | function | Tears down the test error handler. | |
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::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::setUp | protected | function | 367 | |
UnitTestCase::setUpBeforeClass | public static | function | ||
YamlDirectoryDiscoveryTest::testGetDefinitions | public | function | @covers ::getDefinitions | |
YamlDirectoryDiscoveryTest::testGetDefinitionsWithTranslatableDefinitions | public | function | @covers ::getDefinitions |
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.