TermParentCdfAttributeTest.php in Acquia Content Hub 8.2
File
tests/src/Kernel/EventSubscriber/CdfAttributes/TermParentCdfAttributeTest.php
View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel\EventSubscriber\CdfAttributes;
use Drupal\acquia_contenthub\Event\CdfAttributesEvent;
use Drupal\acquia_contenthub\EventSubscriber\CdfAttributes\TermParentCdfAttribute;
use Drupal\depcalc\DependentEntityWrapper;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
class TermParentCdfAttributeTest extends EntityKernelTestBase {
use TaxonomyTestTrait;
public static $modules = [
'acquia_contenthub',
'depcalc',
'path_alias',
'taxonomy',
];
protected $termParentCdfAttribute;
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('taxonomy_term');
$this->termParentCdfAttribute = new TermParentCdfAttribute();
}
public function testTermParentCdfAttribute() : void {
$vocabulary = $this
->createVocabulary();
$parent_term = $this
->createTerm($vocabulary);
$child_term = $this
->createTerm($vocabulary, [
'vid' => $vocabulary
->id(),
'parent' => $parent_term
->id(),
]);
$cdf = $this->container
->get('acquia_contenthub_common_actions')
->getLocalCdfDocument($child_term)
->getCdfEntity($child_term
->uuid());
$wrapper = new DependentEntityWrapper($child_term);
$event = new CdfAttributesEvent($cdf, $child_term, $wrapper);
$this->termParentCdfAttribute
->onPopulateAttributes($event);
$this
->assertArrayHasKey('parent', $event
->getCdf()
->getAttributes());
}
}