function ContentImportTest::testEntityValidationIsTriggered
Same name in other branches
- 11.x core/tests/Drupal/FunctionalTests/DefaultContent/ContentImportTest.php \Drupal\FunctionalTests\DefaultContent\ContentImportTest::testEntityValidationIsTriggered()
Tests that the importer validates entities before saving them.
File
-
core/
tests/ Drupal/ FunctionalTests/ DefaultContent/ ContentImportTest.php, line 164
Class
- ContentImportTest
- @covers \Drupal\Core\DefaultContent\Importer @group DefaultContent @group Recipe
Namespace
Drupal\FunctionalTests\DefaultContentCode
public function testEntityValidationIsTriggered() : void {
$dir = uniqid('public://');
mkdir($dir);
/** @var string $data */
$data = file_get_contents($this->contentDir . '/node/2d3581c3-92c7-4600-8991-a0d4b3741198.yml');
$data = Yaml::decode($data);
/** @var array{default: array{sticky: array<int, array{value: mixed}>}} $data */
$data['default']['sticky'][0]['value'] = 'not a boolean!';
file_put_contents($dir . '/invalid.yml', Yaml::encode($data));
$this->expectException(InvalidEntityException::class);
$this->expectExceptionMessage("{$dir}/invalid.yml: sticky.0.value=This value should be of the correct primitive type.");
$this->container
->get(Importer::class)
->importContent(new Finder($dir));
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.