function ContentImportTest::testDirectContentImport

Same name in other branches
  1. 11.x core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php \Drupal\FunctionalTests\DefaultContent\ContentImportTest::testDirectContentImport()

Tests importing content directly, via the API.

File

core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php, line 140

Class

ContentImportTest
@covers \Drupal\Core\DefaultContent\Importer @group DefaultContent @group Recipe

Namespace

Drupal\FunctionalTests\DefaultContent

Code

public function testDirectContentImport() : void {
    $logger = new TestLogger();
    
    /** @var \Drupal\Core\DefaultContent\Importer $importer */
    $importer = $this->container
        ->get(Importer::class);
    $importer->setLogger($logger);
    $importer->importContent(new Finder($this->contentDir));
    $this->assertContentWasImported();
    // We should see a warning about importing a file entity associated with a
    // file that doesn't exist.
    $predicate = function (array $record) : bool {
        return $record['message'] === 'File entity %name was imported, but the associated file (@path) was not found.' && $record['context']['%name'] === 'dce9cdc3-d9fc-4d37-849d-105e913bb5ad.png' && $record['context']['@path'] === $this->contentDir . '/file/dce9cdc3-d9fc-4d37-849d-105e913bb5ad.png';
    };
    $this->assertTrue($logger->hasRecordThatPasses($predicate, LogLevel::WARNING));
}

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