public function DevelGenerateBrowserTest::testDevelGenerateBatchContent in Devel 8.3
Same name and namespace in other branches
- 4.x devel_generate/tests/src/Functional/DevelGenerateBrowserTest.php \Drupal\Tests\devel_generate\Functional\DevelGenerateBrowserTest::testDevelGenerateBatchContent()
Tests generating content in batch mode.
File
- devel_generate/
tests/ src/ Functional/ DevelGenerateBrowserTest.php, line 311
Class
- DevelGenerateBrowserTest
- Tests the logic to generate data.
Namespace
Drupal\Tests\devel_generate\FunctionalCode
public function testDevelGenerateBatchContent() {
// For 50 or more nodes, the processing will be done via batch.
$edit = [
'num' => 55,
'kill' => TRUE,
'node_types[article]' => TRUE,
'node_types[page]' => TRUE,
];
$this
->drupalPostForm('admin/config/development/generate/content', $edit, 'Generate');
$this
->assertSession()
->pageTextContains('Finished 55 elements created successfully.');
$this
->assertSession()
->pageTextContains('Generate process complete.');
// Tests that the expected number of nodes have been created.
$count = count(Node::loadMultiple());
$this
->assertEquals(55, $count, sprintf('The expected total number of nodes is %s, found %s', 55, $count));
// Create nodes with translations via batch.
$edit = [
'num' => 52,
'kill' => TRUE,
'node_types[article]' => TRUE,
'node_types[page]' => TRUE,
'add_language[]' => [
'en',
],
'translate_language[]' => [
'de',
'ca',
],
];
$this
->drupalPostForm('admin/config/development/generate/content', $edit, 'Generate');
$this
->assertCount(52, \Drupal::entityQuery('node')
->execute());
// Only aticles will have translations so get that number.
$articles = \Drupal::entityQuery('node')
->condition('type', 'article')
->execute();
$this
->assertSession()
->pageTextContains(sprintf('Finished 52 elements and %s translations created successfully.', 2 * count($articles)));
// Generate only articles.
$edit = [
'num' => 60,
'kill' => TRUE,
'node_types[article]' => TRUE,
'node_types[page]' => FALSE,
];
$this
->drupalPostForm('admin/config/development/generate/content', $edit, 'Generate');
// Tests that all the created nodes were of the node type selected.
$nodeStorage = $this->container
->get('entity_type.manager')
->getStorage('node');
$type = 'article';
$count = $nodeStorage
->getQuery()
->condition('type', $type)
->count()
->execute();
$this
->assertEquals(60, $count, sprintf('The expected number of %s is %s, found %s', $type, 60, $count));
}