function ViewEntityDependenciesTest::testGetDependencies

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php \Drupal\Tests\views\Kernel\Entity\ViewEntityDependenciesTest::testGetDependencies()
  2. 10 core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php \Drupal\Tests\views\Kernel\Entity\ViewEntityDependenciesTest::testGetDependencies()
  3. 11.x core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php \Drupal\Tests\views\Kernel\Entity\ViewEntityDependenciesTest::testGetDependencies()

Tests the getDependencies method.

File

core/modules/views/tests/src/Kernel/Entity/ViewEntityDependenciesTest.php, line 92

Class

ViewEntityDependenciesTest
Tests the calculation of dependencies for views.

Namespace

Drupal\Tests\views\Kernel\Entity

Code

public function testGetDependencies() {
    $expected = [];
    $expected['test_field_get_entity'] = [
        'module' => [
            'comment',
            'node',
            'user',
        ],
    ];
    // Tests dependencies of relationships.
    $expected['test_relationship_dependency'] = [
        'module' => [
            'comment',
            'node',
            'user',
        ],
    ];
    $expected['test_plugin_dependencies'] = [
        'module' => [
            'comment',
            'views_test_data',
        ],
        'content' => [
            'RowTest',
            'StaticTest',
            'StyleTest',
        ],
    ];
    $expected['test_argument_dependency'] = [
        'config' => [
            'core.entity_view_mode.node.teaser',
            'field.storage.node.body',
        ],
        'content' => [
            'ArgumentDefaultTest',
            'ArgumentValidatorTest',
        ],
        'module' => [
            'node',
            // The argument handler is provided by the search module.
'search',
            'text',
            'user',
        ],
    ];
    foreach ($this::$testViews as $view_id) {
        $view = Views::getView($view_id);
        $dependencies = $view->getDependencies();
        $this->assertEquals($expected[$view_id], $dependencies);
        $config = $this->config('views.view.' . $view_id);
        \Drupal::service('config.storage.sync')->write($view_id, $config->get());
    }
    // Ensure that dependencies are calculated on the display level.
    $expected_display['default'] = [
        'config' => [
            'core.entity_view_mode.node.teaser',
        ],
        'content' => [
            'ArgumentDefaultTest',
            'ArgumentValidatorTest',
        ],
        'module' => [
            'core',
            'node',
            'search',
            'user',
            'views',
        ],
    ];
    $expected_display['page'] = [
        'config' => [
            'field.storage.node.body',
        ],
        'module' => [
            'core',
            'node',
            'text',
            'views',
        ],
    ];
    $view = Views::getView('test_argument_dependency');
    $view->initDisplay();
    foreach ($view->displayHandlers as $display) {
        // Calculate the dependencies each display has.
        $this->assertEquals($expected_display[$display->getPluginId()], $display->calculateDependencies());
    }
}

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