You are here

public function EntityReferenceFilterTrait::createTestViews in Views Reference Filter 8

Create test views from config.

Parameters

array $views: Views to create.

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Component\Plugin\Exception\PluginNotFoundException

\Drupal\Core\Entity\EntityStorageException

2 calls to EntityReferenceFilterTrait::createTestViews()
EntityReferenceFunctionalJavascriptTestBase::setUp in tests/src/FunctionalJavascript/EntityReferenceFunctionalJavascriptTestBase.php
EntityReferenceFunctionalTestBase::setUp in tests/src/Functional/EntityReferenceFunctionalTestBase.php

File

tests/src/Traits/EntityReferenceFilterTrait.php, line 118

Class

EntityReferenceFilterTrait
Provides common helper methods for Entityreference filter module tests.

Namespace

Drupal\Tests\entityreference_filter\Traits

Code

public function createTestViews(array $views) {
  $storage = \Drupal::entityTypeManager()
    ->getStorage('view');
  $module_handler = \Drupal::moduleHandler();
  $config_dir = drupal_get_path('module', 'entityreference_filter_test_config') . '/test_views';
  if (!is_dir($config_dir) || !$module_handler
    ->moduleExists('entityreference_filter_test_config')) {
    return;
  }
  $file_storage = new FileStorage($config_dir);
  $available_views = $file_storage
    ->listAll('views.view.');
  foreach ($views as $id) {
    $config_name = 'views.view.' . $id;
    if (in_array($config_name, $available_views, TRUE)) {
      $storage
        ->create($file_storage
        ->read($config_name))
        ->save();
    }
  }

  // Rebuild the router once.
  \Drupal::service('router.builder')
    ->rebuild();
}