function ViewsConfigDependenciesIntegrationTest::testConfigRemovalRole

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php \Drupal\Tests\views\Kernel\ViewsConfigDependenciesIntegrationTest::testConfigRemovalRole()
  2. 10 core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php \Drupal\Tests\views\Kernel\ViewsConfigDependenciesIntegrationTest::testConfigRemovalRole()
  3. 11.x core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php \Drupal\Tests\views\Kernel\ViewsConfigDependenciesIntegrationTest::testConfigRemovalRole()

Tests removing a config dependency that deletes the View.

File

core/modules/views/tests/src/Kernel/ViewsConfigDependenciesIntegrationTest.php, line 111

Class

ViewsConfigDependenciesIntegrationTest
Tests integration of views with other modules.

Namespace

Drupal\Tests\views\Kernel

Code

public function testConfigRemovalRole() {
    // Create a role we can add to the View and delete.
    $role = Role::create([
        'id' => 'dummy',
        'label' => 'dummy',
    ]);
    $role->save();
    
    /** @var \Drupal\views\ViewEntityInterface $view */
    $view = View::load('entity_test_fields');
    $display =& $view->getDisplay('default');
    // Set the access to be restricted by the dummy role.
    $display['display_options']['access'] = [
        'type' => 'role',
        'options' => [
            'role' => [
                $role->id() => $role->id(),
            ],
        ],
    ];
    $view->save();
    // Check that the View now has a dependency on the Role.
    $dependencies = $view->getDependencies() + [
        'config' => [],
    ];
    $this->assertContains('user.role.dummy', $dependencies['config']);
    // Delete the role.
    $role->delete();
    $view = View::load('entity_test_fields');
    // Checks that the view has been deleted too.
    $this->assertNull($view);
}

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