You are here

public function ExporterIntegrationTest::testModuleExport in Default Content for D8 2.0.x

Same name and namespace in other branches
  1. 8 tests/src/Kernel/ExporterIntegrationTest.php \Drupal\Tests\default_content\Kernel\ExporterIntegrationTest::testModuleExport()

Tests exportModuleContent().

File

tests/src/Kernel/ExporterIntegrationTest.php, line 201

Class

ExporterIntegrationTest
Tests export functionality.

Namespace

Drupal\Tests\default_content\Kernel

Code

public function testModuleExport() {
  \Drupal::service('module_installer')
    ->install([
    'node',
    'default_content',
    'default_content_export_test',
  ]);
  $this->exporter = \Drupal::service('default_content.exporter');
  $test_uuid = '0e45d92f-1919-47cd-8b60-964a8a761292';
  $node_type = NodeType::create([
    'type' => 'test',
  ]);
  $node_type
    ->save();
  $user = User::create([
    'name' => 'owner',
  ]);
  $user
    ->save();
  $node = Node::create([
    'type' => $node_type
      ->id(),
    'title' => 'test node',
    'uid' => $user
      ->id(),
  ]);
  $node->uuid = $test_uuid;
  $node
    ->save();

  /** @var \Drupal\node\NodeInterface $node */
  $node = Node::load($node
    ->id());
  $expected_node = [
    '_meta' => [
      'version' => '1.0',
      'entity_type' => 'node',
      'uuid' => '0e45d92f-1919-47cd-8b60-964a8a761292',
      'bundle' => 'test',
      'default_langcode' => 'en',
    ],
    'default' => [
      'revision_uid' => [
        0 => [
          'target_id' => $node
            ->getOwner()
            ->id(),
        ],
      ],
      'status' => [
        0 => [
          'value' => TRUE,
        ],
      ],
      'uid' => [
        0 => [
          'target_id' => $node
            ->getOwner()
            ->id(),
        ],
      ],
      'title' => [
        0 => [
          'value' => 'test node',
        ],
      ],
      'created' => [
        0 => [
          'value' => $node
            ->getCreatedTime(),
        ],
      ],
      'promote' => [
        0 => [
          'value' => TRUE,
        ],
      ],
      'sticky' => [
        0 => [
          'value' => FALSE,
        ],
      ],
      'revision_translation_affected' => [
        0 => [
          'value' => TRUE,
        ],
      ],
    ],
  ];
  $content = $this->exporter
    ->exportModuleContent('default_content_export_test');
  $this
    ->assertEquals($expected_node, Yaml::decode($content['node'][$test_uuid]));
}