EntityReferenceDependencyManagerTest.php in Entity Reference Integrity 8
File
tests/src/Kernel/EntityReferenceDependencyManagerTest.php
View source
<?php
namespace Drupal\Tests\entity_reference_integrity\Kernel;
use Drupal\KernelTests\KernelTestBase;
use Drupal\node\Entity\Node;
use Drupal\user\Entity\User;
class EntityReferenceDependencyManagerTest extends KernelTestBase {
public static $modules = [
'system',
'node',
'user',
'entity_reference_integrity',
];
protected $dependencyManager;
protected $testUser;
protected $testNode;
protected function setUp() {
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();
}
protected function setUserAsNodeAuthor() {
$this->testNode->uid = $this->testUser
->id();
$this->testNode
->save();
}
public function testHasDependents() {
$this
->assertFalse($this->dependencyManager
->hasDependents($this->testUser));
$this
->setUserAsNodeAuthor();
$this
->assertTrue($this->dependencyManager
->hasDependents($this->testUser));
}
public function testGetDependentEntityIds() {
$this
->assertEquals([], $this->dependencyManager
->getDependentEntityIds($this->testUser));
$this
->setUserAsNodeAuthor();
$this
->assertEquals($this->testNode
->id(), $this->dependencyManager
->getDependentEntityIds($this->testUser)['node'][0]);
}
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());
}
}