protected function ViewsBulkOperationsKernelTestBase::createTestNodes in Views Bulk Operations (VBO) 8.3
Same name and namespace in other branches
- 8.2 tests/src/Kernel/ViewsBulkOperationsKernelTestBase.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase::createTestNodes()
- 4.0.x tests/src/Kernel/ViewsBulkOperationsKernelTestBase.php \Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsKernelTestBase::createTestNodes()
Create some test nodes.
Parameters
array $test_node_data: Describes test node bundles and properties.
See also
Drupal\Tests\views_bulk_operations\Kernel\ViewsBulkOperationsDataServiceTest::setUp()
2 calls to ViewsBulkOperationsKernelTestBase::createTestNodes()
- ViewsBulkOperationsActionProcessorTest::setUp in tests/
src/ Kernel/ ViewsBulkOperationsActionProcessorTest.php - ViewsBulkOperationsDataServiceTest::setUp in tests/
src/ Kernel/ ViewsBulkOperationsDataServiceTest.php
File
- tests/
src/ Kernel/ ViewsBulkOperationsKernelTestBase.php, line 119
Class
- ViewsBulkOperationsKernelTestBase
- Base class for Views Bulk Operations kernel tests.
Namespace
Drupal\Tests\views_bulk_operations\KernelCode
protected function createTestNodes(array $test_node_data) {
$this->testNodesData = [];
foreach ($test_node_data as $type_name => $type_data) {
$type = NodeType::create([
'type' => $type_name,
'name' => $type_name,
]);
$type
->save();
$count_languages = isset($type_data['languages']) ? count($type_data['languages']) : 0;
if ($count_languages) {
for ($i = 0; $i < $count_languages; $i++) {
$language = ConfigurableLanguage::createFromLangcode($type_data['languages'][$i]);
$language
->save();
}
$this->container
->get('content_translation.manager')
->setEnabled('node', $type_name, TRUE);
// $this->container->get('entity_type.manager')->clearCachedDefinitions();
}
// Create some test nodes.
$time = $this->time
->getRequestTime();
if (!isset($type_data['count'])) {
$type_data['count'] = 10;
}
for ($i = 0; $i < $type_data['count']; $i++) {
$time -= $i;
$title = 'Title ' . $i;
$node = $this
->drupalCreateNode([
'type' => $type_name,
'title' => $title,
'sticky' => FALSE,
'created' => $time,
'changed' => $time,
]);
$this->testNodesData[$node
->id()]['en'] = $title;
if ($count_languages) {
// It doesn't really matter to which languages we translate
// from the API point of view so some randomness should be fine.
$langcode = $type_data['languages'][rand(0, $count_languages - 1)];
$title = 'Translated title ' . $langcode . ' ' . $i;
$translation = $node
->addTranslation($langcode, [
'title' => $title,
]);
$translation
->save();
$this->testNodesData[$node
->id()][$langcode] = $title;
}
}
}
}