clean install

This commit is contained in:
2024-12-10 15:08:16 +01:00
commit e14eb2d8fd
31193 changed files with 3555714 additions and 0 deletions

View File

@@ -0,0 +1,116 @@
<?php
namespace Drupal\Tests\entity_reference_integrity\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
/**
* Test the EntityReferenceDependencyManager.
*
* @coversDefaultClass \Drupal\entity_reference_integrity\EntityReferenceDependencyManager
*
* @group entity_reference_integrity
*/
class EntityReferenceDependencyManagerTest extends KernelTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'system',
'node',
'user',
'entity_reference_integrity',
];
/**
* The entity dependency manager.
*
* @var \Drupal\entity_reference_integrity\EntityReferenceDependencyManagerInterface
*/
protected $dependencyManager;
/**
* A test user.
*
* @var \Drupal\user\UserInterface
*/
protected $testUser;
/**
* A test node.
*
* @var \Drupal\node\NodeInterface
*/
protected $testNode;
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
$this->installEntitySchema('node');
$this->installEntitySchema('user');
$this->installSchema('system', 'sequences');
$this->installSchema('node', 'node_access');
$this->dependencyManager = $this->container->get('entity_reference_integrity.dependency_manager');
$this->testUser = User::create([
'name' => 'Gerald',
]);
$this->testUser->save();
$this->testNode = Node::create([
'title' => 'foo',
'type' => 'bar',
]);
$this->testNode->save();
}
/**
* Test the test user as the author of the test node.
*/
protected function setUserAsNodeAuthor() {
$this->testNode->uid = $this->testUser->id();
$this->testNode->save();
}
/**
* Test the reference check method.
*
* @covers ::hasDependents
*/
public function testHasDependents() {
$this->assertFalse($this->dependencyManager->hasDependents($this->testUser));
$this->setUserAsNodeAuthor();
$this->assertTrue($this->dependencyManager->hasDependents($this->testUser));
}
/**
* Test the reference list method.
*
* @covers ::getDependentEntityIds
*/
public function testGetDependentEntityIds() {
$this->assertEquals([], $this->dependencyManager->getDependentEntityIds($this->testUser));
$this->setUserAsNodeAuthor();
$this->assertEquals($this->testNode->id(), $this->dependencyManager->getDependentEntityIds($this->testUser)['node'][0]);
}
/**
* Test the reference list method.
*
* @covers ::getDependentEntities
*/
public function testGetDependentEntities() {
$this->assertEquals([], $this->dependencyManager->getDependentEntities($this->testUser));
$this->setUserAsNodeAuthor();
$this->assertEquals($this->testNode->id(), $this->dependencyManager->getDependentEntities($this->testUser)['node'][0]->id());
}
}

View File

@@ -0,0 +1,119 @@
<?php
namespace Drupal\Tests\entity_reference_integrity\Unit;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\entity_reference_integrity\DependencyFieldMapGenerator;
use Drupal\Tests\UnitTestCase;
/**
* Test the field map generator.
*
* @group entity_reference_integrity
*/
class DependencyFieldMapGeneratorTest extends UnitTestCase {
/**
* Test the field map.
*
* @dataProvider fieldMapTestCases
*/
public function testFieldMap($has_custom_storage, $has_storage_definition, $revision_metadata_fields, $field_map, $expected_result) {
$target_entity_type_id = 'target_entity_type_id';
$entityFieldManager = $this->createMock(EntityFieldManagerInterface::class);
$entityFieldManager
->expects($this->any())
->method('getFieldMapByFieldType')
->willReturn($field_map);
$storage_definition = $this->createMock(FieldStorageDefinitionInterface::class);
$storage_definition
->expects($this->any())
->method('hasCustomStorage')
->willReturn($has_custom_storage);
$storage_definition
->expects($this->any())
->method('getSetting')
->willReturn($target_entity_type_id);
$entityFieldManager
->expects($this->any())
->method('getFieldStorageDefinitions')
->willReturn($has_storage_definition ? [
'field_name' => $storage_definition,
] : []);
$entityTypeManager = $this->createMock(EntityTypeManagerInterface::class);
$mockDefinition = $this->createMock(ContentEntityTypeInterface::class);
$mockDefinition->method('getRevisionMetadataKeys')->willReturn($revision_metadata_fields);
$entityTypeManager
->method('getDefinition')
->willReturn($mockDefinition);
$field_map = new DependencyFieldMapGenerator($entityFieldManager, $entityTypeManager, 'entity_reference', 'target_type');
$generated_map = $field_map->getReferencingFields($target_entity_type_id);
$this->assertEquals($expected_result, $generated_map);
}
/**
* Test cases for ::testFieldMap.
*/
public function fieldMapTestCases() {
return [
'Standard field' => [
FALSE,
TRUE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[
'foo_entity_type_id' => [
'field_name',
],
],
],
'Custom storage field' => [
TRUE,
TRUE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
'No storage definition' => [
FALSE,
FALSE,
[],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
'Field is revision metadata' => [
FALSE,
TRUE,
['field_name'],
[
'foo_entity_type_id' => [
'field_name' => [],
],
],
[],
],
];
}
}