Skip to content

Commit

Permalink
Issue #402: Use code element for field_related_document without URL
Browse files Browse the repository at this point in the history
  • Loading branch information
lkmorlan committed Apr 24, 2024
1 parent 021e122 commit 3299e5a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function viewElements(FieldItemListInterface $items, $langcode): array {
'@label' => $title,
':uri' => $uri,
];
$links[] = $this->t('<div>@label:</div><div class="text-break">:uri</div>', $args);
$links[] = $this->t('<div>@label:</div><code class="text-break">:uri</code>', $args);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"]');
Expand All @@ -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"]');
Expand Down

0 comments on commit 3299e5a

Please sign in to comment.