View source
<?php
namespace Drupal\Tests\acquia_contenthub\Kernel;
use Drupal\acquia_contenthub_publisher\Event\ContentHubEntityEligibilityEvent;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
use Drupal\Tests\user\Traits\UserCreationTrait;
class OptionalDependencyCalculationTest extends KernelTestBase {
use NodeCreationTrait;
use ContentTypeCreationTrait;
use UserCreationTrait;
public static $modules = [
'system',
'user',
'field',
'filter',
'node',
'text',
'depcalc',
'path_alias',
'acquia_contenthub',
'acquia_contenthub_server_test',
'acquia_contenthub_publisher',
];
private $commonActionService;
public function setUp() {
parent::setUp();
$this
->installSchema('acquia_contenthub_publisher', [
'acquia_contenthub_publisher_export_tracking',
]);
$this
->installConfig('node');
$this
->installConfig('field');
$this
->installConfig('filter');
$this
->installSchema('node', 'node_access');
$this
->installSchema('user', 'users_data');
$this
->installEntitySchema('user');
$this
->installEntitySchema('node');
$this
->installEntitySchema('path_alias');
$this
->installEntitySchema('user');
$this->commonActionService = $this->container
->get('acquia_contenthub_common_actions');
}
public function testDependencyCalculation() : void {
$bundle = 'dummy_content_type';
$contentType = $this
->createContentType([
'type' => $bundle,
'name' => 'Dummy content type',
]);
$contentType
->save();
$node = $this
->createNode([
'type' => $bundle,
]);
$node
->save();
$queue = \Drupal::queue('acquia_contenthub_publish_export');
$queue_item = $queue
->claimItem();
$this
->assertFalse(property_exists($queue_item->data, 'calculate_dependencies'));
$queue
->deleteQueue();
$event = new ContentHubEntityEligibilityEvent($node, 'insert');
$event
->setCalculateDependencies(FALSE);
$item = new \stdClass();
$item->type = $node
->getEntityTypeId();
$item->uuid = $node
->uuid();
if ($event
->getCalculateDependencies() === FALSE) {
$item->calculate_dependencies = FALSE;
}
$queue
->createItem($item);
$queue_item = $queue
->claimItem();
$this
->assertFalse($queue_item->data->calculate_dependencies);
$entities = [];
$cdf_objects = $this->commonActionService
->getEntityCdf($node, $entities, TRUE, FALSE);
$this
->assertEqual(1, count($cdf_objects), 'There is only 1 CDF object.');
$cdf = reset($cdf_objects);
$this
->assertEqual($node
->uuid(), $cdf
->getUuid());
$this
->assertEmpty($cdf
->getDependencies());
$this
->assertEmpty($cdf
->getModuleDependencies());
$entities = [];
$cdf_objects = $this->commonActionService
->getEntityCdf($node, $entities);
$this
->assertGreaterThan(1, count($cdf_objects));
foreach ($cdf_objects as $cdf) {
if ($node
->uuid() === $cdf
->getUuid()) {
$this
->assertNotEmpty($cdf
->getDependencies());
}
$this
->assertNotEmpty($cdf
->getModuleDependencies());
}
}
}