public static function ViewTestData::importTestViews

Imports test views from config.

Parameters

string $class: The name of the test class.

array $modules: (optional) The module directories to look in for test views. Defaults to an empty array.

See also

config_install_default_config()

17 calls to ViewTestData::importTestViews()
AccessTest::setUp in drupal/core/modules/views/lib/Drupal/views/Tests/Plugin/AccessTest.php
Sets up a Drupal site for running functional and integration tests.
CommentTestBase::setUp in drupal/core/modules/comment/lib/Drupal/comment/Tests/Views/CommentTestBase.php
Sets up a Drupal site for running functional and integration tests.
DisplayBlockTest::setUp in drupal/core/modules/block/lib/Drupal/block/Tests/Views/DisplayBlockTest.php
Sets up a Drupal site for running functional and integration tests.
ExtensionViewsFieldTest::setUp in drupal/core/modules/file/lib/Drupal/file/Tests/Views/ExtensionViewsFieldTest.php
Sets up Drupal unit test environment.
FieldTestBase::setUp in drupal/core/modules/field/lib/Drupal/field/Tests/Views/FieldTestBase.php
Sets up a Drupal site for running functional and integration tests.

... See full list

File

drupal/core/modules/views/lib/Drupal/views/Tests/ViewTestData.php, line 34
Contains \Drupal\views\Tests\ViewTestData.

Class

ViewTestData
Provides tests view data and the base test schema with sample data records.

Namespace

Drupal\views\Tests

Code

public static function importTestViews($class, $modules = array()) {
  $views = array();
  while ($class) {
    if (property_exists($class, 'testViews')) {
      $views = array_merge($views, $class::$testViews);
    }
    $class = get_parent_class($class);
  }
  if (!empty($views)) {
    $module_handler = \Drupal::moduleHandler();
    foreach ($modules as $module) {
      $config_dir = drupal_get_path('module', $module) . '/test_views';
      if (!is_dir($config_dir) || !$module_handler
        ->moduleExists($module)) {
        continue;
      }
      $source_storage = new FileStorage($config_dir);

      // Only import views used by test.
      $views_to_import = array();
      foreach ($source_storage
        ->listAll('views.view.') as $config_name) {
        $id = str_replace('views.view.', '', $config_name);
        if (in_array($id, $views)) {
          $views_to_import[] = $config_name;
        }
      }
      $storage_comparer = new StorageComparer($source_storage, \Drupal::service('config.storage'));
      $storage_comparer
        ->addChangelist('create', $views_to_import);
      $installer = new ViewTestConfigInstaller($storage_comparer, \Drupal::service('event_dispatcher'), \Drupal::service('config.factory'), \Drupal::entityManager(), \Drupal::lock());
      $installer
        ->import();
    }
  }
}