class BlockPluginHasSettingsTrayFormAccessCheckTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/settings_tray/tests/src/Unit/Access/BlockPluginHasSettingsTrayFormAccessCheckTest.php \Drupal\Tests\settings_tray\Unit\Access\BlockPluginHasSettingsTrayFormAccessCheckTest
- 10 core/modules/settings_tray/tests/src/Unit/Access/BlockPluginHasSettingsTrayFormAccessCheckTest.php \Drupal\Tests\settings_tray\Unit\Access\BlockPluginHasSettingsTrayFormAccessCheckTest
@coversDefaultClass \Drupal\settings_tray\Access\BlockPluginHasSettingsTrayFormAccessCheck @group settings_tray
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\settings_tray\Unit\Access\BlockPluginHasSettingsTrayFormAccessCheckTest
Expanded class hierarchy of BlockPluginHasSettingsTrayFormAccessCheckTest
File
- core/
modules/ settings_tray/ tests/ src/ Unit/ Access/ BlockPluginHasSettingsTrayFormAccessCheckTest.php, line 19
Namespace
Drupal\Tests\settings_tray\Unit\AccessView source
class BlockPluginHasSettingsTrayFormAccessCheckTest extends UnitTestCase {
/**
* @covers ::access
* @covers ::accessBlockPlugin
* @dataProvider providerTestAccess
*/
public function testAccess($with_forms, array $plugin_definition, AccessResultInterface $expected_access_result) {
$block_plugin = $this
->prophesize()
->willImplement(BlockPluginInterface::class);
if ($with_forms) {
$block_plugin
->willImplement(PluginWithFormsInterface::class);
$block_plugin
->hasFormClass(Argument::type('string'))
->will(function ($arguments) use ($plugin_definition) {
return !empty($plugin_definition['forms'][$arguments[0]]);
});
}
$block = $this
->prophesize(BlockInterface::class);
$block
->getPlugin()
->willReturn($block_plugin
->reveal());
$access_check = new BlockPluginHasSettingsTrayFormAccessCheck();
$this
->assertEquals($expected_access_result, $access_check
->access($block
->reveal()));
$this
->assertEquals($expected_access_result, $access_check
->accessBlockPlugin($block_plugin
->reveal()));
}
/**
* Provides test data for ::testAccess().
*/
public function providerTestAccess() {
$annotation_forms_settings_tray_class = [
'forms' => [
'settings_tray' => $this
->randomMachineName(),
],
];
$annotation_forms_settings_tray_not_set = [];
$annotation_forms_settings_tray_false = [
'forms' => [
'settings_tray' => FALSE,
],
];
return [
'block plugin with forms, forms[settings_tray] set to class' => [
TRUE,
$annotation_forms_settings_tray_class,
new AccessResultAllowed(),
],
'block plugin with forms, forms[settings_tray] not set' => [
TRUE,
$annotation_forms_settings_tray_not_set,
new AccessResultNeutral(),
],
'block plugin with forms, forms[settings_tray] set to FALSE' => [
TRUE,
$annotation_forms_settings_tray_false,
new AccessResultNeutral(),
],
// In practice, all block plugins extend BlockBase, which means they all
// implement PluginWithFormsInterface, but this may change in the future.
// This ensures Settings Tray will continue to work correctly.
'block plugin without forms, forms[settings_tray] set to class' => [
FALSE,
$annotation_forms_settings_tray_class,
new AccessResultNeutral(),
],
'block plugin without forms, forms[settings_tray] not set' => [
FALSE,
$annotation_forms_settings_tray_not_set,
new AccessResultNeutral(),
],
'block plugin without forms, forms[settings_tray] set to FALSE' => [
FALSE,
$annotation_forms_settings_tray_false,
new AccessResultNeutral(),
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BlockPluginHasSettingsTrayFormAccessCheckTest:: |
public | function | Provides test data for ::testAccess(). | |
BlockPluginHasSettingsTrayFormAccessCheckTest:: |
public | function | @covers ::access @covers ::accessBlockPlugin @dataProvider providerTestAccess | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
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 | Mocks a block with a block plugin. | 1 |
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:: |
protected | function | 340 |