function DevelGenerateCommandsTest::testDrushGenerateMedia

Same name in other branches
  1. 5.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 211

Class

DevelGenerateCommandsTest
Test class for the Devel Generate drush commands.

Namespace

Drupal\Tests\devel_generate\Functional

Code

public function testDrushGenerateMedia() {
    // 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('devel-generate-media', [
        53,
    ], [
        'kill' => NULL,
    ]);
    $this->assertCount(53, \Drupal::entityQuery('media')->execute());
    $messages = $this->getErrorOutput();
    $this->assertStringContainsStringIgnoringCase('Finished 53 elements created successfully.', $messages, 'devel-generate-media batch ending message not found');
    // Test also with a non-batch process. We're testing also --kill here.
    $this->drush('devel-generate-media', [
        7,
    ], [
        'media-types' => $media_type1->id() . ',' . $media_type2->id(),
        'kill' => NULL,
    ]);
    $this->assertCount(7, \Drupal::entityQuery('media')->execute());
}