You are here

public function TaxonomyImportTest::testCanCreateNode in YAML Content 8

Create a basic node.

File

tests/src/Functional/TaxonomyImportTest.php, line 62

Class

TaxonomyImportTest
Tests general Node creation functionality.

Namespace

Drupal\Tests\yaml_content\Functional

Code

public function testCanCreateNode() {

  /** @var \Drupal\Core\Entity\Entity[] $entities */
  $entities = $this->contentLoader
    ->loadContent('basic_taxonomy.content.yml');
  $this
    ->assertTrue(is_array($entities), 'An array was not returned from loadContent().');

  // 3 should have been created but references don't get returned.
  $this
    ->assertEquals(2, count($entities), 'No entity IDs were returned from loadContent().');
  $this
    ->assertTaxonomy($entities[0], 'Generated content', 'tags');
  $this
    ->assertEquals([
    'target_id' => 0,
  ], $entities[0]->parent
    ->get(0)
    ->getValue(), 'Unspecified parent should be root. (0)');
  $this
    ->assertTaxonomy($entities[1], 'Imported demo content', 'tags');

  // Parent will be created first as a dependency so it will have an id one less.
  $this
    ->assertEquals([
    'target_id' => $entities[1]
      ->id() - 1,
  ], $entities[1]->parent
    ->get(0)
    ->getValue(), 'Specified parent reference should be populated with a id.');
}