diff --git a/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/BcDcRelatedDocuments.php b/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/BcDcRelatedDocuments.php index b98a004f..496a99a0 100644 --- a/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/BcDcRelatedDocuments.php +++ b/html/modules/custom/bc_dc/src/Plugin/Field/FieldFormatter/BcDcRelatedDocuments.php @@ -106,7 +106,7 @@ public function viewElements(FieldItemListInterface $items, $langcode): array { '@label' => $title, ':uri' => $uri, ]; - $links[] = $this->t('
@label:
:uri
', $args); + $links[] = $this->t('
@label:
:uri', $args); } } } diff --git a/html/modules/custom/bc_dc/tests/src/Functional/BcDcFunctionalTest.php b/html/modules/custom/bc_dc/tests/src/Functional/BcDcFunctionalTest.php index f31a7b1d..8b4d8a9e 100644 --- a/html/modules/custom/bc_dc/tests/src/Functional/BcDcFunctionalTest.php +++ b/html/modules/custom/bc_dc/tests/src/Functional/BcDcFunctionalTest.php @@ -1339,9 +1339,16 @@ public function test(): void { 'edit-field-related-document-0-subform-field-paragraph-document-title-0-value' => $related_document_title, 'edit-field-related-document-0-subform-field-paragraph-document-link-0-value' => $related_document_uri, ]; + $this->submitForm($edit, 'Add Document'); + // Add a second document and save. + $related_document_local_uri = '//local/' . $this->randomMachineName(); + $edit = [ + 'edit-field-related-document-1-subform-field-paragraph-document-type' => $document_type_1->id(), + 'edit-field-related-document-1-subform-field-paragraph-document-link-0-value' => $related_document_local_uri, + ]; $this->submitForm($edit, 'Save'); // There is now a related document. - $this->assertSession()->elementExists('xpath', '//div[contains(@class, "field--name-field-related-document")]//div[@class = "field__item"][text() = "1"]'); + $this->assertSession()->elementExists('xpath', '//div[contains(@class, "field--name-field-related-document")]//div[@class = "field__item"][text() = "2"]'); // field_data_sets_used is not empty. This demonstrates that the Build page // is showing the latest version not the default version. $this->assertSession()->elementNotExists('xpath', '//div[contains(@class, "field--name-field-data-sets-used")]/div[@class = "field__item"]/em[text() = "Optional"]'); @@ -1367,6 +1374,15 @@ public function test(): void { ]; $xpath = $this->assertSession()->buildXPathQuery('//div[contains(@class, "field--name-field-related-document")]//ul/li/a[@href = :href][text() = :text]', $args); $this->assertSession()->elementExists('xpath', $xpath); + // Related document without a URL appears. + $args = [ + ':text' => $document_type_1->label() . ':', + ':uri' => $related_document_local_uri, + ]; + $xpath = $this->assertSession()->buildXPathQuery('//div[contains(@class, "field--name-field-related-document")]//ul/li + [div[text() = :text]] + [code[text() = :uri]]', $args); + $this->assertSession()->elementExists('xpath', $xpath); // Page has "Assets used" with link to node/2. $dc_lineage = $this->assertSession()->elementExists('xpath', '//details[@class = "dc-lineage"]');