public function TaxonomyTermTest::testTaxonomyTermHierarchy in Acquia Content Hub 8
Test terms in a single and multiple hierarchy.
File
- tests/
src/ Functional/ TaxonomyTermTest.php, line 130
Class
- TaxonomyTermTest
- Test that Acquia Content Hub respects Taxonomy Term.
Namespace
Drupal\Tests\acquia_contenthub\FunctionalCode
public function testTaxonomyTermHierarchy() {
// Create two taxonomy terms.
$term1 = $this
->createTerm($this->vocabulary);
$term2 = $this
->createTerm($this->vocabulary);
// Edit $term2, setting $term1 as parent.
$edit = [];
$edit['parent[]'] = [
$term1
->id(),
];
$this
->drupalPostForm('taxonomy/term/' . $term2
->id() . '/edit', $edit, $this
->t('Save'));
// Check CH cdf response.
$output = $this
->drupalGetCdf('acquia-contenthub-cdf/taxonomy/term/' . $term2
->id(), [
'query' => [
'include_references' => 'true',
],
]);
$this
->assertResponse(200);
// Check cdf format.
$this
->assertTrue(isset($output['entities']['0']['attributes']['parent']), 'Parent field is present.');
$this
->assertTrue(is_array($output['entities']['0']['attributes']['parent']), 'Parent field is array.');
// Collect data about parent entity.
$type = $output['entities']['0']['attributes']['parent']['type'];
$value = $output['entities']['0']['attributes']['parent']['value'];
// Check parent field format mapping.
$this
->assertEqual($type, 'array<reference>', 'Field type looks correct.');
// Extract first uuid from parent field.
$parent_uuid = '';
if ($value) {
$parent_lang = array_pop($value);
$parent_uuid = array_pop($parent_lang);
}
// Compare first uuid from response with term1 uuid.
$this
->assertEqual($term1
->uuid(), $parent_uuid, 'Parent term looks correct.');
// Check that the parent is included in the CDF.
$this
->assertEqual($term1
->uuid(), $output['entities']['1']['uuid'], 'Parent Entity included in the CDF as a dependency.');
$this
->assertEqual($term1
->label(), $output['entities']['1']['attributes']['name']['value'][LANGUAGE_NONE][0], 'Parent Name coincides with expected name.');
}