function ViewTestData::createTestViews
Same name in other branches
- 9 core/modules/views/src/Tests/ViewTestData.php \Drupal\views\Tests\ViewTestData::createTestViews()
- 10 core/modules/views/src/Tests/ViewTestData.php \Drupal\views\Tests\ViewTestData::createTestViews()
- 11.x core/modules/views/src/Tests/ViewTestData.php \Drupal\views\Tests\ViewTestData::createTestViews()
Create test views from config.
Parameters
string $class: The name of the test class. Installs the listed test views *in order*.
array $modules: The module directories to look in for test views.
91 calls to ViewTestData::createTestViews()
- AccessPermissionTest::setUp in core/
modules/ user/ tests/ src/ Kernel/ Views/ AccessPermissionTest.php - AccessRoleUITest::setUp in core/
modules/ user/ tests/ src/ Functional/ AccessRoleUITest.php - AccessTest::setUp in core/
modules/ views/ tests/ src/ Functional/ Plugin/ AccessTest.php - ArgumentDefaultTest::testPluginArgumentDefaultCurrentUser in core/
modules/ user/ tests/ src/ Kernel/ Views/ ArgumentDefaultTest.php - Tests the current user with argument default.
- ArgumentUidRevisionTest::setUp in core/
modules/ node/ tests/ src/ Kernel/ Views/ ArgumentUidRevisionTest.php
File
-
core/
modules/ views/ src/ Tests/ ViewTestData.php, line 25
Class
- ViewTestData
- Provides tests view data and the base test schema with sample data records.
Namespace
Drupal\views\TestsCode
public static function createTestViews($class, array $modules) {
$views = [];
while ($class) {
if (property_exists($class, 'testViews')) {
$views = array_merge($views, $class::$testViews);
}
$class = get_parent_class($class);
}
if (!empty($views)) {
$storage = \Drupal::entityTypeManager()->getStorage('view');
$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;
}
$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)) {
$storage->create($file_storage->read($config_name))
->save();
}
}
}
}
// Rebuild the router once.
\Drupal::service('router.builder')->rebuild();
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.