public static function ViewTestData::createTestViews in Drupal 10
Same name and namespace in other branches
- 8 core/modules/views/src/Tests/ViewTestData.php \Drupal\views\Tests\ViewTestData::createTestViews()
- 9 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.
62 calls to ViewTestData::createTestViews()
- AccessPermissionTest::setUp in core/
modules/ user/ tests/ src/ Kernel/ Views/ AccessPermissionTest.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.
- ArgumentNodeRevisionIdTest::setUp in core/
modules/ node/ tests/ src/ Kernel/ Views/ ArgumentNodeRevisionIdTest.php - 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::service('extension.list.module')
->getPath($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();
}