You are here

protected function DefaultContentYamlImportTest::doPostInstallTests in Default Content for D8 2.0.x

Makes assertions post the install of the default_content_test module.

2 calls to DefaultContentYamlImportTest::doPostInstallTests()
DefaultContentYamlImportTest::testImport in tests/src/Kernel/DefaultContentYamlImportTest.php
Test importing default content.
DefaultContentYamlImportTest::testImportViaConfigImporter in tests/src/Kernel/DefaultContentYamlImportTest.php
Test importing default content via ConfigImporter.

File

tests/src/Kernel/DefaultContentYamlImportTest.php, line 118

Class

DefaultContentYamlImportTest
Test import of default content.

Namespace

Drupal\Tests\default_content\Kernel

Code

protected function doPostInstallTests() {

  // Ensure the content contained in the default_content_test module has been
  // created correctly.
  $node = $this
    ->getNodeByTitle('Imported node');
  $this
    ->assertEquals('Crikey it works!', $node
    ->get('body')->value);
  $this
    ->assertEquals('page', $node
    ->getType());
  $this
    ->assertSame('2', $node
    ->getOwnerId(), 'The node created is owned by user 2');
  $node = $this
    ->getNodeByTitle('Imported node with owned by user that does not exist');
  $this
    ->assertSame('1', $node
    ->getOwnerId(), 'The node created is owned by user 1');
  $terms = \Drupal::entityTypeManager()
    ->getStorage('taxonomy_term')
    ->loadMultiple();
  $term = reset($terms);
  $this
    ->assertInstanceOf(TermInterface::class, $term);
  $this
    ->assertEquals('A tag', $term
    ->label());
  $this
    ->assertEquals($term
    ->id(), $node
    ->get('field_tags')->target_id);

  // Assert the files, since a file already existed at that location, one has
  // been renamed and the URI adjusted.
  $files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'filename' => 'test-file.txt',
  ]);
  $this
    ->assertCount(1, $files);

  /** @var \Drupal\file\FileInterface $file */
  $file = reset($files);
  $this
    ->assertEquals('public://test-file_0.txt', $file
    ->getFileUri());
  $this
    ->assertFileExists($file
    ->getFileUri());
  $files = \Drupal::entityTypeManager()
    ->getStorage('file')
    ->loadByProperties([
    'filename' => 'test-file1.txt',
  ]);
  $this
    ->assertCount(1, $files);

  /** @var \Drupal\file\FileInterface $file */
  $file = reset($files);
  $this
    ->assertEquals('public://example/test-file1.txt', $file
    ->getFileUri());
  $this
    ->assertFileExists($file
    ->getFileUri());
}