function ContentImportTest::testDirectContentImport
Same name and namespace in other branches
- 11.x core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php \Drupal\FunctionalTests\DefaultContent\ContentImportTest::testDirectContentImport()
- 10 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 100
Class
- ContentImportTest
- Tests Content Import.
Namespace
Drupal\FunctionalTests\DefaultContentCode
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($this->adminAccount);
// 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));
// Visit a page that is published in a non-live workspace; we should not be
// able to see it, because we don't have permission.
$node_in_workspace = $this->container
->get(EntityRepositoryInterface::class)
->loadEntityByUuid('node', '48475954-e878-439c-9d3d-226724a44269');
$this->assertInstanceOf(NodeInterface::class, $node_in_workspace);
$node_url = $node_in_workspace->toUrl();
$this->drupalGet($node_url);
$assert_session = $this->assertSession();
$assert_session->statusCodeEquals(403);
// If we log in with administrative privileges (i.e., we can look at any
// workspace), we should be able to see it.
$this->drupalLogin($this->adminAccount);
$this->drupalGet($node_url);
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains($node_in_workspace->label());
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.