public function ContentEntityTest::testMediaSource in Drupal 8
Same name and namespace in other branches
- 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testMediaSource()
- 10 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testMediaSource()
Tests media source plugin.
@dataProvider migrationConfigurationProvider
File
- core/
modules/ migrate_drupal/ tests/ src/ Kernel/ Plugin/ migrate/ source/ ContentEntityTest.php, line 385
Class
- ContentEntityTest
- Tests the entity content source plugin.
Namespace
Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\sourceCode
public function testMediaSource(array $configuration) {
$values = [
'id' => 'image',
'label' => 'Image',
'source' => 'test',
'new_revision' => FALSE,
];
$media_type = $this
->createMediaType('test', $values);
$media = Media::create([
'name' => 'Foo media',
'uid' => $this->user
->id(),
'bundle' => $media_type
->id(),
]);
$media
->save();
$configuration += [
'bundle' => 'image',
];
$migration = $this->migrationPluginManager
->createStubMigration($this
->migrationDefinition('content_entity:media', $configuration));
$media_source = $migration
->getSourcePlugin();
$this
->assertSame('media items', $media_source
->__toString());
if (!$configuration['include_translations']) {
$this
->assertEquals(1, $media_source
->count());
}
$this
->assertIds($media_source, $configuration);
$fields = $media_source
->fields();
$this
->assertArrayHasKey('bundle', $fields);
$this
->assertArrayHasKey('mid', $fields);
$this
->assertArrayHasKey('vid', $fields);
$this
->assertArrayHasKey('name', $fields);
$this
->assertArrayHasKey('status', $fields);
$media_source
->rewind();
$values = $media_source
->current()
->getSource();
$this
->assertEquals(1, $values['mid']);
if ($configuration['add_revision_id']) {
$this
->assertEquals(1, $values['vid']);
}
else {
$this
->assertEquals([
[
'value' => 1,
],
], $values['vid']);
}
$this
->assertEquals('Foo media', $values['name'][0]['value']);
$this
->assertNull($values['thumbnail'][0]['title']);
$this
->assertEquals(1, $values['uid'][0]['target_id']);
$this
->assertEquals('image', $values['bundle'][0]['target_id']);
}