View source
<?php
namespace Drupal\Tests\acquia_contenthub\Functional;
class NodeReferenceTest extends ContentHubTestBase {
public static $modules = [
'node',
'acquia_contenthub',
'node_with_references',
];
public function testNodeReferences() {
$this
->drupalLogin($this->adminUser);
$entity1 = $this
->drupalCreateNode([
'type' => 'node_with_references',
'title' => 'Title 1',
]);
$entity2 = $this
->drupalCreateNode([
'type' => 'node_with_references',
'title' => 'Title 2',
'field_reference' => [
[
'target_id' => $entity1
->id(),
],
],
]);
$entity3 = $this
->drupalCreateNode([
'type' => 'node_with_references',
'title' => 'Title 3',
'field_reference' => [
[
'target_id' => $entity2
->id(),
],
],
]);
$entity4 = $this
->drupalCreateNode([
'type' => 'node_with_references',
'title' => 'Title 4',
'field_reference' => [
[
'target_id' => $entity3
->id(),
],
],
]);
$entity5 = $this
->drupalCreateNode([
'type' => 'node_with_references',
'title' => 'Title 5',
'field_reference' => [
[
'target_id' => $entity4
->id(),
],
],
]);
$this
->configureContentHubContentTypes('node', [
'node_with_references',
]);
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity5
->getEntityTypeId() . '/' . $entity5
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['1']['uuid'], $entity4
->uuid());
$this
->assertEqual($output['entities']['2']['uuid'], $entity3
->uuid());
$this
->assertEqual($output['entities']['3']['uuid'], $entity2
->uuid());
$this
->assertFalse($this
->findEntityUuid($entity1
->uuid(), $output), $entity1
->uuid() . ' not found.');
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity4
->getEntityTypeId() . '/' . $entity4
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['1']['uuid'], $entity3
->uuid());
$this
->assertEqual($output['entities']['2']['uuid'], $entity2
->uuid());
$this
->assertEqual($output['entities']['3']['uuid'], $entity1
->uuid());
$config = \Drupal::configFactory()
->getEditable('acquia_contenthub.entity_config');
$config
->set('dependency_depth', 4);
$config
->save();
drupal_flush_all_caches();
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity5
->getEntityTypeId() . '/' . $entity5
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['1']['uuid'], $entity4
->uuid());
$this
->assertEqual($output['entities']['2']['uuid'], $entity3
->uuid());
$this
->assertEqual($output['entities']['3']['uuid'], $entity2
->uuid());
$this
->assertEqual($output['entities']['4']['uuid'], $entity1
->uuid());
$config
->set('dependency_depth', 2);
$config
->save();
drupal_flush_all_caches();
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/' . $entity5
->getEntityTypeId() . '/' . $entity5
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
$this
->assertEqual($output['entities']['1']['uuid'], $entity4
->uuid());
$this
->assertEqual($output['entities']['2']['uuid'], $entity3
->uuid());
$this
->assertFalse($this
->findEntityUuid($entity2
->uuid(), $output), $entity2
->uuid() . ' not found.');
$this
->assertFalse($this
->findEntityUuid($entity1
->uuid(), $output), $entity1
->uuid() . ' not found.');
}
protected function findEntityUuid($uuid, array $entities) {
foreach ($entities['entities'] as $entity) {
if ($entity['uuid'] == $uuid) {
return TRUE;
}
}
return FALSE;
}
}