public function ContentHubEntityDependencyTest::testDependencyChain in Acquia Content Hub 8
Test Dependency Chain.
@covers ::appendDependencyChain @covers ::isInDependencyChain @covers ::getDependencyChain
File
- tests/
src/ Unit/ ContentHubEntityDependencyTest.php, line 115
Class
- ContentHubEntityDependencyTest
- PHPUnit for the ContentHubEntityDependency class.
Namespace
Drupal\Tests\acquia_contenthub\UnitCode
public function testDependencyChain() {
$this->entity = $this
->createContentHubEntity();
$ch_entity_dependency = new ContentHubEntityDependency($this->entity);
// Adding dependency.
$entity1 = $this
->createContentHubEntity([
'uuid' => '00000000-2222-0000-0000-000000000000',
]);
$ch_entity_dependency1 = new ContentHubEntityDependency($entity1);
$ch_entity_dependency
->appendDependencyChain($ch_entity_dependency1);
$expected_dependency_chain = [];
$expected_dependency_chain[] = $entity1
->getUuid();
$this
->assertEquals($expected_dependency_chain, $ch_entity_dependency
->getDependencyChain());
// Adding another dependency.
$entity2 = $this
->createContentHubEntity([
'uuid' => '00000000-3333-0000-0000-000000000000',
]);
$ch_entity_dependency2 = new ContentHubEntityDependency($entity2);
$ch_entity_dependency
->appendDependencyChain($ch_entity_dependency2);
$expected_dependency_chain[] = $entity2
->getUuid();
$this
->assertEquals($expected_dependency_chain, $ch_entity_dependency
->getDependencyChain());
// $entity1 and $entity2 should be in the dependency chain.
$this
->assertTrue($ch_entity_dependency
->isInDependencyChain($ch_entity_dependency1));
$this
->assertTrue($ch_entity_dependency
->isInDependencyChain($ch_entity_dependency2));
// This entity should not be in the dependency chain.
$entity3 = $this
->createContentHubEntity([
'uuid' => '00000000-4444-0000-0000-000000000000',
]);
$ch_entity_dependency3 = new ContentHubEntityDependency($entity3);
$this
->assertFalse($ch_entity_dependency
->isInDependencyChain($ch_entity_dependency3));
}