function ContentEntityTest::testNodeSource

Same name in other branches
  1. 9 core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testNodeSource()
  2. 8.9.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testNodeSource()
  3. 11.x core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php \Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source\ContentEntityTest::testNodeSource()

Tests node source plugin.

@dataProvider migrationConfigurationProvider

File

core/modules/migrate_drupal/tests/src/Kernel/Plugin/migrate/source/ContentEntityTest.php, line 285

Class

ContentEntityTest
Tests the entity content source plugin.

Namespace

Drupal\Tests\migrate_drupal\Kernel\Plugin\migrate\source

Code

public function testNodeSource(array $configuration) : void {
    $configuration += [
        'bundle' => $this->bundle,
    ];
    $migration = $this->migrationPluginManager
        ->createStubMigration($this->migrationDefinition('content_entity:node', $configuration));
    $node_source = $migration->getSourcePlugin();
    $this->assertSame('content items', $node_source->__toString());
    $this->assertIds($node_source, $configuration);
    $fields = $node_source->fields();
    $this->assertArrayHasKey('nid', $fields);
    $this->assertArrayHasKey('vid', $fields);
    $this->assertArrayHasKey('title', $fields);
    $this->assertArrayHasKey('uid', $fields);
    $this->assertArrayHasKey('sticky', $fields);
    $node_source->rewind();
    $values = $node_source->current()
        ->getSource();
    $this->assertEquals($this->bundle, $values['type'][0]['target_id']);
    $this->assertEquals(1, $values['nid']);
    if ($configuration['add_revision_id']) {
        $this->assertEquals(1, $values['vid']);
    }
    else {
        $this->assertEquals([
            [
                'value' => '1',
            ],
        ], $values['vid']);
    }
    $this->assertEquals('en', $values['langcode']);
    $this->assertEquals(1, $values['status'][0]['value']);
    $this->assertEquals('Apples', $values['title'][0]['value']);
    $this->assertEquals(1, $values['default_langcode'][0]['value']);
    $this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
    if ($configuration['include_translations']) {
        $node_source->next();
        $values = $node_source->current()
            ->getSource();
        $this->assertEquals($this->bundle, $values['type'][0]['target_id']);
        $this->assertEquals(1, $values['nid']);
        if ($configuration['add_revision_id']) {
            $this->assertEquals(1, $values['vid']);
        }
        else {
            $this->assertEquals([
                0 => [
                    'value' => 1,
                ],
            ], $values['vid']);
        }
        $this->assertEquals('fr', $values['langcode']);
        $this->assertEquals(1, $values['status'][0]['value']);
        $this->assertEquals('fr - Apples', $values['title'][0]['value']);
        $this->assertEquals(0, $values['default_langcode'][0]['value']);
        $this->assertEquals(1, $values['field_entity_reference'][0]['target_id']);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.