function DevelGenerateCommandsTest::testDrushGenerateMedia
Same name in other branches
- 4.x devel_generate/tests/src/Functional/DevelGenerateCommandsTest.php \Drupal\Tests\devel_generate\Functional\DevelGenerateCommandsTest::testDrushGenerateMedia()
Tests generating media.
File
-
devel_generate/
tests/ src/ Functional/ DevelGenerateCommandsTest.php, line 291
Class
- DevelGenerateCommandsTest
- Test class for the Devel Generate drush commands.
Namespace
Drupal\Tests\devel_generate\FunctionalCode
public function testDrushGenerateMedia() : void {
// Create two media types.
$media_type1 = $this->createMediaType('image');
$media_type2 = $this->createMediaType('audio_file');
// Make sure media items gets created with batch process.
$this->drush(DevelGenerateCommands::MEDIA, [
'53',
], [
'kill' => NULL,
'base-fields' => 'phish',
]);
$this->assertCount(53, \Drupal::entityQuery('media')->accessCheck(FALSE)
->execute());
$messages = $this->getErrorOutput();
$this->assertStringContainsStringIgnoringCase('Finished 53 elements created successfully.', $messages, 'devel-generate-media batch ending message not found');
$medias = \Drupal::entityQuery('media')->accessCheck(FALSE)
->execute();
$media = Media::load(end($medias));
// Verify that base field populates.
$this->assertNotEmpty($media->get('phish')
->getString());
// Test also with a non-batch process. We're testing also --kill here.
$this->drush(DevelGenerateCommands::MEDIA, [
'7',
], [
'media-types' => $media_type1->id() . ',' . $media_type2->id(),
'kill' => NULL,
]);
$this->assertCount(7, \Drupal::entityQuery('media')->accessCheck(FALSE)
->execute());
}