View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\depcalc\DependencyStack;
use Drupal\depcalc\DependentEntityWrapper;
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\path_alias\Entity\PathAlias;
use Drupal\Tests\field\Traits\EntityReferenceTestTrait;
use Drupal\Tests\taxonomy\Traits\TaxonomyTestTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
use Symfony\Component\DependencyInjection\Reference;
class RePublishDependencyChangesTest extends QueueingTestBase {
use UserCreationTrait;
use TaxonomyTestTrait;
use EntityReferenceTestTrait;
public static $modules = [
'field',
'filter',
'node',
'path_alias',
'system',
'taxonomy',
'text',
'user',
];
protected $vocabulary;
protected $term;
public function register(ContainerBuilder $container) {
parent::register($container);
$container
->register('cache_factory', 'Drupal\\Core\\Cache\\CacheFactory')
->addArgument(new Reference('settings'))
->addMethodCall('setContainer', [
new Reference('service_container'),
]);
}
protected function setUp() : void {
parent::setUp();
$this
->installEntitySchema('node');
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('taxonomy_term');
$this
->installEntitySchema('user');
$this
->installSchema('node', [
'node_access',
]);
$this
->installEntitySchema('field_config');
$this->vocabulary = $this
->createVocabulary();
NodeType::create([
'type' => 'bundle_test',
])
->save();
$this
->createEntityReferenceField('node', 'bundle_test', 'taxonomy_reference', 'taxonomy_reference', 'taxonomy_term');
$this->term = $this
->createTerm($this->vocabulary, [
'name' => 'Test',
]);
}
public function testIsAlreadyEnqueued() {
$user = $this
->setUpCurrentUser();
$node = Node::create([
'type' => 'bundle_test',
'uid' => $user
->id(),
'taxonomy_reference' => $this->term
->id(),
'title' => 'Title',
]);
$node
->setPublished();
$node
->save();
$path = PathAlias::create([
'path' => '/node/' . $node
->id(),
'alias' => 'new_test_path',
]);
$path
->save();
$publisher_tracker = \Drupal::service('acquia_contenthub_publisher.tracker');
$this
->assertNotFalse($publisher_tracker
->getQueueId($node
->uuid()), 'Node queued for export');
$this
->assertNotFalse($publisher_tracker
->getQueueId($path
->uuid()), 'Path alias queued for export');
$this
->assertNotFalse($publisher_tracker
->getQueueId($this->term
->uuid()), 'Term queued for export');
$this->contentHubQueue
->purgeQueues();
$wrapper = new DependentEntityWrapper($node);
$stack = new DependencyStack();
$calculator = \Drupal::service('entity.dependency.calculator');
$calculator
->calculateDependencies($wrapper, $stack);
$this->term
->delete();
$this
->assertNotFalse($publisher_tracker
->getQueueId($node
->uuid()), 'Node queued again after term reference delete');
$this
->assertNotFalse($publisher_tracker
->getQueueId($path
->uuid()), 'Path queued again after term reference delete');
$this
->assertFalse($publisher_tracker
->getQueueId($this->term
->uuid()), 'Term not queued for export anymore');
}
}