class ContentImportAlreadyExistsTest
Tests Content Import.
Attributes
#[Group('DefaultContent')]
#[Group('Recipe')]
#[Group('#slow')]
#[CoversClass(Importer::class)]
#[RunTestsInSeparateProcesses]
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\PhpUnitCompatibilityTrait, \Drupal\TestTools\Extension\DeprecationBridge\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\FunctionalTests\DefaultContent\ContentImportAlreadyExistsTest uses \Drupal\FunctionalTests\Core\Recipe\RecipeTestTrait extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of ContentImportAlreadyExistsTest
File
-
core/
tests/ Drupal/ FunctionalTests/ DefaultContent/ ContentImportAlreadyExistsTest.php, line 23
Namespace
Drupal\FunctionalTests\DefaultContentView source
class ContentImportAlreadyExistsTest extends BrowserTestBase {
use RecipeTestTrait;
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* {@inheritdoc}
*/
protected static $modules = [
'block_content',
'content_translation',
'entity_test',
'layout_builder',
'media',
'menu_link_content',
'node',
'path',
'path_alias',
'system',
'taxonomy',
'user',
'workspaces',
];
/**
* The directory with the source data.
*/
private readonly string $contentDir;
/**
* The admin account.
*/
private UserInterface $adminAccount;
/**
* {@inheritdoc}
*/
protected function setUp() : void {
parent::setUp();
$this->adminAccount = $this->setUpCurrentUser(admin: TRUE);
// Apply the recipe that sets up the fields and configuration for our
// default content.
$fixtures_dir = $this->getDrupalRoot() . '/core/tests/fixtures';
$this->applyRecipe($fixtures_dir . '/recipes/default_content_base');
$this->contentDir = $fixtures_dir . '/default_content';
\Drupal::service('file_system')->copy($this->contentDir . '/file/druplicon_copy.png', $this->publicFilesDirectory . '/druplicon_copy.png', FileExists::Error);
}
/**
* @return array<array<mixed>>
* An array of test cases, each containing an existing entity handling mode.
*/
public static function providerImportEntityThatAlreadyExists() : array {
return [
[
Existing::Error,
],
[
Existing::Skip,
],
];
}
/**
* Tests import entity that already exists.
*/
public function testImportEntityThatAlreadyExists(Existing $existing) : void {
$this->drupalCreateUser(values: [
'uuid' => '94503467-be7f-406c-9795-fc25baa22203',
]);
if ($existing === Existing::Error) {
$this->expectException(ImportException::class);
$this->expectExceptionMessage('user 94503467-be7f-406c-9795-fc25baa22203 already exists.');
}
$this->container
->get(Importer::class)
->importContent(new Finder($this->contentDir), $existing);
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.