function GenerateCommandsKernelTest::testContentBatch

A large number of nodes is generated by a batch, in this process.

File

devel_generate/tests/src/Kernel/GenerateCommandsKernelTest.php, line 138

Class

GenerateCommandsKernelTest
Tests the devel_generate commands.

Namespace

Drupal\Tests\devel_generate\Kernel

Code

public function testContentBatch() : void {
  // Nodes need an author.
  User::create([
    'name' => 'author',
  ])->save();
  $this->runCommand(GenerateContentCommand::class, [
    'num' => '3',
    '--bundles' => 'page',
  ]);
  $display = $this->runCommand(GenerateContentCommand::class, [
    'num' => '55',
    '--bundles' => 'page',
    '--kill' => TRUE,
  ])
    ->getDisplay();
  $this->assertSame(55, $this->countEntities('node'));
  $this->assertStringContainsString('Finished 55 elements created successfully.', $display);
  // The batch is spent, so that a later command does not run it again.
  $this->assertEmpty(batch_get());
}