You are here

public function ViewEntityDependenciesTest::testGetDependencies in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php \Drupal\views\Tests\Entity\ViewEntityDependenciesTest::testGetDependencies()

Tests the getDependencies method.

File

core/modules/views/src/Tests/Entity/ViewEntityDependenciesTest.php, line 88
Contains \Drupal\views\Tests\Entity\ViewEntityDependenciesTest.

Class

ViewEntityDependenciesTest
Tests the calculation of dependencies for views.

Namespace

Drupal\views\Tests\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
      ->assertEqual($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',
      'text',
      'views',
    ],
  ];
  $view = Views::getView('test_argument_dependency');
  $view
    ->initDisplay();
  foreach ($view->displayHandlers as $display) {

    // Calculate the dependencies each display has.
    $this
      ->assertEqual($expected_display[$display
      ->getPluginId()], $display
      ->calculateDependencies());
  }
}