class BlockPluginHasSettingsTrayFormAccessCheckTest

Same name in other branches
  1. 9 core/modules/settings_tray/tests/src/Unit/Access/BlockPluginHasSettingsTrayFormAccessCheckTest.php \Drupal\Tests\settings_tray\Unit\Access\BlockPluginHasSettingsTrayFormAccessCheckTest
  2. 8.9.x core/modules/settings_tray/tests/src/Unit/Access/BlockPluginHasSettingsTrayFormAccessCheckTest.php \Drupal\Tests\settings_tray\Unit\Access\BlockPluginHasSettingsTrayFormAccessCheckTest
  3. 11.x 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

Expanded class hierarchy of BlockPluginHasSettingsTrayFormAccessCheckTest

File

core/modules/settings_tray/tests/src/Unit/Access/BlockPluginHasSettingsTrayFormAccessCheckTest.php, line 22

Namespace

Drupal\Tests\settings_tray\Unit\Access
View source
class BlockPluginHasSettingsTrayFormAccessCheckTest extends UnitTestCase {
    
    /**
     * @covers ::access
     * @covers ::accessBlockPlugin
     * @dataProvider providerTestAccess
     */
    public function testAccess($with_forms, array $plugin_definition, AccessResultInterface $expected_access_result) : void {
        $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 static function providerTestAccess() {
        $annotation_forms_settings_tray_class = [
            'forms' => [
                'settings_tray' => Random::machineName(),
            ],
        ];
        $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

Title Sort descending Deprecated Modifiers Object type Summary Overrides
BlockPluginHasSettingsTrayFormAccessCheckTest::providerTestAccess public static function Provides test data for ::testAccess().
BlockPluginHasSettingsTrayFormAccessCheckTest::testAccess public function @covers ::access
@covers ::accessBlockPlugin
@dataProvider providerTestAccess
PhpUnitWarnings::$deprecationWarnings private static property Deprecation warnings from PHPUnit to raise with @trigger_error().
PhpUnitWarnings::addWarning public function Converts PHPUnit deprecation warnings to E_USER_DEPRECATED.
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.
RandomGeneratorTrait::randomStringValidate Deprecated public function Callback for random string validation.
UnitTestCase::$root protected property The app root. 1
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 358
UnitTestCase::setUpBeforeClass public static function
UnitTestCase::__get public function

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.