diff --git a/docker-compose.yml b/docker-compose.yml index 5f9933e42..e93efe5b5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -14,7 +14,7 @@ services: XDEBUG_MODE: "develop, debug" PHP_IDE_CONFIG: "serverName=Docker" # Enable step debugging for all PHP request. See ./README.md#step-debugging for more information. - XDEBUG_SESSION: 1 + # XDEBUG_SESSION: 1 mysql: image: percona/percona-server:5.7 command: --innodb-log-file-size=1G --max_allowed_packet=1G --innodb-buffer-pool-size=512M --wait_timeout=3000 --net_write_timeout=3000 --log_error_verbosity=3 diff --git a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml index 031243316..97aef784b 100644 --- a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml +++ b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.full.yml @@ -2,11 +2,15 @@ langcode: en status: true dependencies: config: + - core.entity_view_mode.node.full - field.field.node.oe_news.body - field.field.node.oe_news.oe_author + - field.field.node.oe_news.oe_departments - field.field.node.oe_news.oe_news_contacts - field.field.node.oe_news.oe_news_featured_media + - field.field.node.oe_news.oe_news_last_updated - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_sources - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date - field.field.node.oe_news.oe_reference_code @@ -16,7 +20,6 @@ dependencies: - field.field.node.oe_news.oe_teaser - node.type.oe_news module: - - datetime - entity_reference_revisions - field_group - link @@ -28,11 +31,12 @@ third_party_settings: group_details: children: - oe_reference_code - - oe_publication_date + - extra_field_oe_theme_content_news_date - oe_author + - oe_departments - oe_news_location parent_name: '' - weight: 1 + weight: 3 format_type: oe_theme_helper_field_list_pattern region: content format_settings: @@ -50,14 +54,10 @@ content: settings: { } third_party_settings: { } region: content - oe_news_contacts: - type: entity_reference_revisions_entity_view - weight: 2 + extra_field_oe_theme_content_news_date: + weight: 13 region: content - label: above - settings: - view_mode: full - link: '' + settings: { } third_party_settings: { } oe_author: type: skos_concept_entity_reference_label @@ -67,7 +67,7 @@ content: settings: link: false third_party_settings: { } - oe_news_location: + oe_departments: type: skos_concept_entity_reference_label weight: 15 region: content @@ -75,14 +75,34 @@ content: settings: link: false third_party_settings: { } - oe_publication_date: - type: datetime_default - weight: 13 + oe_news_contacts: + type: entity_reference_revisions_entity_view + weight: 4 region: content label: above settings: - timezone_override: '' - format_type: oe_theme_news_date + view_mode: full + link: '' + third_party_settings: { } + oe_news_location: + type: skos_concept_entity_reference_label + weight: 16 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' third_party_settings: { } oe_reference_code: type: string @@ -94,7 +114,7 @@ content: third_party_settings: { } oe_related_links: type: link - weight: 3 + weight: 5 region: content label: hidden settings: @@ -113,7 +133,9 @@ hidden: oe_content_navigation_title: true oe_content_short_title: true oe_news_featured_media: true + oe_news_last_updated: true oe_news_types: true + oe_publication_date: true oe_subject: true oe_summary: true oe_teaser: true diff --git a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml index 6d935aed6..90dc8cbb9 100644 --- a/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml +++ b/modules/oe_theme_content_news/config/install/core.entity_view_display.node.oe_news.teaser.yml @@ -5,10 +5,15 @@ dependencies: - core.entity_view_mode.node.teaser - field.field.node.oe_news.body - field.field.node.oe_news.oe_author + - field.field.node.oe_news.oe_departments + - field.field.node.oe_news.oe_news_contacts - field.field.node.oe_news.oe_news_featured_media + - field.field.node.oe_news.oe_news_last_updated - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_sources - field.field.node.oe_news.oe_news_types - field.field.node.oe_news.oe_publication_date + - field.field.node.oe_news.oe_reference_code - field.field.node.oe_news.oe_related_links - field.field.node.oe_news.oe_subject - field.field.node.oe_news.oe_summary @@ -65,6 +70,7 @@ content: third_party_settings: { } hidden: body: true + extra_field_oe_theme_content_news_date: true langcode: true links: true oe_author: true @@ -72,7 +78,12 @@ hidden: oe_content_legacy_link: true oe_content_navigation_title: true oe_content_short_title: true + oe_departments: true + oe_news_contacts: true + oe_news_last_updated: true oe_news_location: true + oe_news_sources: true + oe_reference_code: true oe_related_links: true oe_subject: true oe_summary: true diff --git a/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml new file mode 100644 index 000000000..97aef784b --- /dev/null +++ b/modules/oe_theme_content_news/config/post_updates/00009_update_full_view_display/core.entity_view_display.node.oe_news.full.yml @@ -0,0 +1,141 @@ +langcode: en +status: true +dependencies: + config: + - core.entity_view_mode.node.full + - field.field.node.oe_news.body + - field.field.node.oe_news.oe_author + - field.field.node.oe_news.oe_departments + - field.field.node.oe_news.oe_news_contacts + - field.field.node.oe_news.oe_news_featured_media + - field.field.node.oe_news.oe_news_last_updated + - field.field.node.oe_news.oe_news_location + - field.field.node.oe_news.oe_news_sources + - field.field.node.oe_news.oe_news_types + - field.field.node.oe_news.oe_publication_date + - field.field.node.oe_news.oe_reference_code + - field.field.node.oe_news.oe_related_links + - field.field.node.oe_news.oe_subject + - field.field.node.oe_news.oe_summary + - field.field.node.oe_news.oe_teaser + - node.type.oe_news + module: + - entity_reference_revisions + - field_group + - link + - rdf_skos + - text + - user +third_party_settings: + field_group: + group_details: + children: + - oe_reference_code + - extra_field_oe_theme_content_news_date + - oe_author + - oe_departments + - oe_news_location + parent_name: '' + weight: 3 + format_type: oe_theme_helper_field_list_pattern + region: content + format_settings: + variant: horizontal + label: Details +id: node.oe_news.full +targetEntityType: node +bundle: oe_news +mode: full +content: + body: + label: hidden + type: text_default + weight: 0 + settings: { } + third_party_settings: { } + region: content + extra_field_oe_theme_content_news_date: + weight: 13 + region: content + settings: { } + third_party_settings: { } + oe_author: + type: skos_concept_entity_reference_label + weight: 14 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_departments: + type: skos_concept_entity_reference_label + weight: 15 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_news_contacts: + type: entity_reference_revisions_entity_view + weight: 4 + region: content + label: above + settings: + view_mode: full + link: '' + third_party_settings: { } + oe_news_location: + type: skos_concept_entity_reference_label + weight: 16 + region: content + label: above + settings: + link: false + third_party_settings: { } + oe_news_sources: + type: link + weight: 1 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + third_party_settings: { } + oe_reference_code: + type: string + weight: 12 + region: content + label: above + settings: + link_to_entity: false + third_party_settings: { } + oe_related_links: + type: link + weight: 5 + region: content + label: hidden + settings: + trim_length: null + url_only: false + url_plain: false + rel: '0' + target: '0' + third_party_settings: { } +hidden: + extra_field_oe_theme_helper_short_title_with_fallback: true + langcode: true + links: true + oe_content_content_owner: true + oe_content_legacy_link: true + oe_content_navigation_title: true + oe_content_short_title: true + oe_news_featured_media: true + oe_news_last_updated: true + oe_news_types: true + oe_publication_date: true + oe_subject: true + oe_summary: true + oe_teaser: true diff --git a/modules/oe_theme_content_news/oe_theme_content_news.module b/modules/oe_theme_content_news/oe_theme_content_news.module index 35bc55296..869f11423 100644 --- a/modules/oe_theme_content_news/oe_theme_content_news.module +++ b/modules/oe_theme_content_news/oe_theme_content_news.module @@ -57,12 +57,21 @@ function oe_theme_content_news_node_view_alter(array &$build, EntityInterface $e // Rename field labels based on number of items. $plural_label_overrides = [ 'oe_author' => t('Authors'), + 'oe_departments' => t('Departments'), + ]; + + $singular_label_overrides = [ + 'oe_departments' => t('Department'), ]; foreach ($plural_label_overrides as $name => $label_override) { if (!$entity->get($name)->isEmpty() && $entity->get($name)->count() > 1 && isset($build[$name]['#title'])) { $build[$name]['#title'] = $label_override; } + // Override singular labels if defined. + elseif (!$entity->get($name)->isEmpty() && $entity->get($name)->count() == 1 && isset($build[$name]['#title']) && isset($singular_label_overrides[$name])) { + $build[$name]['#title'] = $singular_label_overrides[$name]; + } } } } diff --git a/modules/oe_theme_content_news/oe_theme_content_news.post_update.php b/modules/oe_theme_content_news/oe_theme_content_news.post_update.php index 82105ef58..a4627b945 100644 --- a/modules/oe_theme_content_news/oe_theme_content_news.post_update.php +++ b/modules/oe_theme_content_news/oe_theme_content_news.post_update.php @@ -131,3 +131,23 @@ function oe_theme_content_news_post_update_00008(): void { $display = $storage->createFromStorageRecord($display_values); $display->save(); } + +/** + * Updates the full view display. + */ +function oe_theme_content_news_post_update_00009(): void { + $storage = new FileStorage(drupal_get_path('module', 'oe_theme_content_news') . '/config/post_updates/00009_update_full_view_display'); + + $display_values = $storage->read('core.entity_view_display.node.oe_news.full'); + $storage = \Drupal::entityTypeManager()->getStorage('entity_view_display'); + + $view_display = EntityViewDisplay::load($display_values['id']); + if ($view_display) { + $display = $storage->updateFromStorageRecord($view_display, $display_values); + $display->save(); + return; + } + + $display = $storage->createFromStorageRecord($display_values); + $display->save(); +} diff --git a/modules/oe_theme_content_news/src/Plugin/ExtraField/Display/PublicationDate.php b/modules/oe_theme_content_news/src/Plugin/ExtraField/Display/PublicationDate.php new file mode 100644 index 000000000..3e65ee6ca --- /dev/null +++ b/modules/oe_theme_content_news/src/Plugin/ExtraField/Display/PublicationDate.php @@ -0,0 +1,31 @@ +renderPublicationDateExtraField($entity, 'oe_theme_news_date'); + } + +} diff --git a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php b/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php index 2be896326..d04cac246 100644 --- a/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php +++ b/modules/oe_theme_content_publication/src/Plugin/ExtraField/Display/PublicationDate.php @@ -5,11 +5,7 @@ namespace Drupal\oe_theme_content_publication\Plugin\ExtraField\Display; use Drupal\Core\Entity\ContentEntityInterface; -use Drupal\Core\Plugin\ContainerFactoryPluginInterface; -use Drupal\Core\Datetime\DateFormatterInterface; -use Drupal\Core\StringTranslation\StringTranslationTrait; -use Drupal\extra_field\Plugin\ExtraFieldDisplayFormattedBase; -use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\oe_theme_helper\Plugin\ExtraField\Display\PublicationDateExtraFieldBase; /** * Displays publication date and last update date fields. @@ -23,74 +19,13 @@ * visible = true * ) */ -class PublicationDate extends ExtraFieldDisplayFormattedBase implements ContainerFactoryPluginInterface { - - use StringTranslationTrait; - - /** - * Date formatter service instance. - * - * @var \Drupal\Core\Datetime\DateFormatterInterface - */ - protected $dateFormatter; - - /** - * PublicationDate constructor. - * - * @param array $configuration - * A configuration array containing information about the plugin instance. - * @param string $plugin_id - * The plugin_id for the plugin instance. - * @param mixed $plugin_definition - * The plugin implementation definition. - * @param \Drupal\Core\Datetime\DateFormatterInterface $date_formatter - * Date formatter. - */ - public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatterInterface $date_formatter) { - parent::__construct($configuration, $plugin_id, $plugin_definition); - $this->dateFormatter = $date_formatter; - } +class PublicationDate extends PublicationDateExtraFieldBase { /** * {@inheritdoc} */ - public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { - return new static( - $configuration, - $plugin_id, - $plugin_definition, - $container->get('date.formatter') - ); - } - - /** - * {@inheritdoc} - */ - public function getLabel() { - return $this->t('Publication date'); - } - - /** - * {@inheritdoc} - */ - public function viewElements(ContentEntityInterface $entity) { - $publication_date_timestamp = $entity->get('oe_publication_date')->date->getTimestamp(); - $publication_date = $this->dateFormatter->format($publication_date_timestamp, 'oe_theme_publication_date'); - if ($entity->get('oe_publication_last_updated')->isEmpty()) { - return [ - '#markup' => $publication_date, - ]; - } - - $last_update_timestamp = $entity->get('oe_publication_last_updated')->date->getTimestamp(); - return [ - '#type' => 'inline_template', - '#template' => "{{ publication_date }} ({{'Last updated on: @date'|t({'@date': last_update}) }})", - '#context' => [ - 'publication_date' => $publication_date, - 'last_update' => $this->dateFormatter->format($last_update_timestamp, 'oe_theme_publication_date'), - ], - ]; + public function viewElements(ContentEntityInterface $entity): array { + return $this->renderPublicationDateExtraField($entity, 'oe_theme_publication_date'); } } diff --git a/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php new file mode 100644 index 000000000..133f6bfb4 --- /dev/null +++ b/modules/oe_theme_helper/src/Plugin/ExtraField/Display/PublicationDateExtraFieldBase.php @@ -0,0 +1,96 @@ +dateFormatter = $date_formatter; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + return new static( + $configuration, + $plugin_id, + $plugin_definition, + $container->get('date.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function getLabel() { + return $this->t('Publication date'); + } + + /** + * Render the publication date field with the specified date format. + * + * @param \Drupal\Core\Entity\ContentEntityInterface $entity + * The entity the field is being rendered on. + * @param string $date_format + * The date format to use. + * + * @return array + * The render array. + */ + protected function renderPublicationDateExtraField(ContentEntityInterface $entity, string $date_format): array { + $bundle = $entity->bundle(); + $publication_date_timestamp = $entity->get('oe_publication_date')->date->getTimestamp(); + $publication_date = $this->dateFormatter->format($publication_date_timestamp, $date_format); + if ($entity->get($bundle . '_last_updated')->isEmpty()) { + return [ + '#markup' => $publication_date, + ]; + } + + $last_update_timestamp = $entity->get($bundle . '_last_updated')->date->getTimestamp(); + return [ + '#type' => 'inline_template', + '#template' => "{{ publication_date }} ({{'Last updated on: @date'|t({'@date': last_update}) }})", + '#context' => [ + 'publication_date' => $publication_date, + 'last_update' => $this->dateFormatter->format($last_update_timestamp, $date_format), + ], + ]; + } + +} diff --git a/oe_theme.theme b/oe_theme.theme index 871c7a0ae..a5a4d7a49 100644 --- a/oe_theme.theme +++ b/oe_theme.theme @@ -430,20 +430,6 @@ function oe_theme_preprocess_field(&$variables, $hook): void { $item['content']['#attributes']['class'][] = 'ecl-u-height-auto'; } } - - if ($variables['field_name'] === 'oe_related_links') { - foreach ($variables['items'] as $delta => $item) { - $variables['items'][$delta]['content'] = [ - '#type' => 'pattern', - '#id' => 'list_item', - '#variant' => 'default', - '#fields' => [ - 'url' => $item['content']['#url'], - 'title' => $item['content']['#title'], - ], - ]; - } - } } /** diff --git a/templates/field/field--node--oe-departments--oe-news--full.html.twig b/templates/field/field--node--oe-departments--oe-news--full.html.twig new file mode 100644 index 000000000..22aa0b583 --- /dev/null +++ b/templates/field/field--node--oe-departments--oe-news--full.html.twig @@ -0,0 +1,9 @@ +{# +/** + * @file + * Theme override for the Related department field template of the News content type. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +{%- include 'field--multiple-values--pipe-separated.html.twig' -%} diff --git a/templates/field/field--node--oe-news-sources--oe-news--full.html.twig b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig new file mode 100644 index 000000000..32e1aa1ed --- /dev/null +++ b/templates/field/field--node--oe-news-sources--oe-news--full.html.twig @@ -0,0 +1,23 @@ +{# +/** + * @file + * News sources field template. + * + * @see ./core/themes/stable/templates/field/field.html.twig + */ +#} +

{{ 'Sources'|t }}

+{% for item in items %} + {% set bubble_cache = item.content|render %} +
+ {% include '@ecl-twig/link' with { + link: { + type: 'standalone', + label: item.content['#title'], + path: item.content['#url'], + icon_position: 'after' + }, + icon: get_link_icon(item.content['#url'].toString(), 'xs') + } %} +
+{% endfor %} diff --git a/templates/field/field--oe-related-links.html.twig b/templates/field/field--oe-related-links.html.twig index 7b128027d..de33b5e5b 100644 --- a/templates/field/field--oe-related-links.html.twig +++ b/templates/field/field--oe-related-links.html.twig @@ -1,6 +1,14 @@ -

{{ 'Related links'|t }}

-
- {% for item in items %} - {{ item.content }} - {% endfor %} -
+

{{ 'Related links'|t }}

+{% for item in items %} + {% set bubble_cache = item.content|render %} +
+ {% include '@ecl-twig/link' with { + link: { + type: 'standalone', + label: item.content['#title'], + path: item.content['#url'], + icon_position: 'after' + } + } %} +
+{% endfor %} diff --git a/templates/patterns/list_item/list_item.ui_patterns.yml b/templates/patterns/list_item/list_item.ui_patterns.yml index 9da13b124..542332d60 100644 --- a/templates/patterns/list_item/list_item.ui_patterns.yml +++ b/templates/patterns/list_item/list_item.ui_patterns.yml @@ -90,3 +90,8 @@ list_item: preview: src: "https://placeimg.com/1200/900/arch" alt: "Alternative text for image" + icon: + type: "text" + label: "Icon" + description: "An optional icon to be used with the link." + preview: "external" diff --git a/templates/patterns/list_item/pattern-list-item.html.twig b/templates/patterns/list_item/pattern-list-item.html.twig index fe67948d4..1770b5659 100644 --- a/templates/patterns/list_item/pattern-list-item.html.twig +++ b/templates/patterns/list_item/pattern-list-item.html.twig @@ -12,6 +12,7 @@ - "image_position" (string) (default: ''): Image before of after the item. - "length" (int) (default: 0): Max length of detail field. - "additional_information" (array): Additional information to be displayed right below the 'Detail' field. + - "icon" (string) (default: ''): Icon used for the link item. #} {# Create macro #} @@ -48,13 +49,23 @@ {% block title %}
{%- if url %} - {% include '@ecl-twig/link' with { + {% set _link = { link: { type: 'standalone', label: title, - path: url + path: url, } - } only %} + } %} + {% if icon %} + {% set _link = _link|merge({ + icon: { + 'path': ecl_icon_path, + 'name': icon, + 'size': 's', + } + }) %} + {% endif %} + {% include '@ecl-twig/link' with _link only %} {% else %} {{ title }} {%- endif -%} diff --git a/tests/Functional/ContentNewsRenderTest.php b/tests/Functional/ContentNewsRenderTest.php index 72a02303a..2e58e5848 100644 --- a/tests/Functional/ContentNewsRenderTest.php +++ b/tests/Functional/ContentNewsRenderTest.php @@ -5,7 +5,6 @@ namespace Drupal\Tests\oe_theme\Functional; use Drupal\Tests\oe_theme\PatternAssertions\FieldListAssert; -use Drupal\Tests\oe_theme\PatternAssertions\ListItemAssert; use Drupal\Tests\oe_theme\PatternAssertions\PatternPageHeaderAssert; use Drupal\user\Entity\Role; use Drupal\user\RoleInterface; @@ -59,6 +58,7 @@ public function testNewsRendering(): void { 'value' => '2020-09-18', ], 'oe_author' => 'http://publications.europa.eu/resource/authority/corporate-body/ACJHR', + 'oe_departments' => 'http://publications.europa.eu/resource/authority/corporate-body/AASM', 'oe_content_content_owner' => 'http://publications.europa.eu/resource/authority/corporate-body/COMMU', 'uid' => 0, 'status' => 1, @@ -85,6 +85,23 @@ public function testNewsRendering(): void { $this->assertEquals('http://www.example.org', $header_link->getAttribute('href')); $this->assertEquals('http://www.example.org', $header_link->getText()); + // Assert Sources field content. + $node->set('oe_news_sources', [ + [ + 'uri' => 'internal:/node', + 'title' => 'Internal source link', + ], [ + 'uri' => 'https://example.com', + 'title' => 'External source link', + ], + ])->save(); + $this->drupalGet($node->toUrl()); + $this->assertEquals('Sources', $this->assertSession()->elementExists('css', 'h3.ecl-u-type-heading-3')->getText()); + $internal_source_link = $this->assertSession()->elementExists('css', 'div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-pt-m.ecl-u-pb-m:nth-child(3)'); + $this->assertLinkIcon($internal_source_link, 'Internal source link', '/build/node', FALSE, 'xs'); + $external_source_link = $this->assertSession()->elementExists('css', 'div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-pt-m.ecl-u-pb-m:nth-child(4)'); + $this->assertLinkIcon($external_source_link, 'External source link', 'https://example.com', TRUE, 'xs'); + $node->set('oe_news_location', 'http://publications.europa.eu/resource/authority/place/ARE_AUH'); $node->set('oe_news_types', 'http://publications.europa.eu/resource/authority/resource-type/PUB_GEN'); $node->save(); @@ -114,6 +131,10 @@ public function testNewsRendering(): void { 'label' => 'Author', 'body' => 'African Court of Justice and Human Rights', ], + [ + 'label' => 'Department', + 'body' => 'Associated African States and Madagascar', + ], [ 'label' => 'Location', 'body' => 'Abu Dhabi', @@ -124,6 +145,14 @@ public function testNewsRendering(): void { $field_list_assert->assertPattern($details_expected_values, $details_html); $field_list_assert->assertVariant('horizontal', $details_html); + // Assert Last update date field. + $node->set('oe_news_last_updated', '2021-08-04')->save(); + $this->drupalGet($node->toUrl()); + + $details_expected_values['items'][1]['body'] = '18 September 2020 (Last updated on: 4 August 2021)'; + $details_html = $details->getHtml(); + $field_list_assert->assertPattern($details_expected_values, $details_html); + // Assert Author field label. $node->set('oe_author', [ ['target_id' => 'http://publications.europa.eu/resource/authority/corporate-body/ACJHR'], @@ -136,6 +165,18 @@ public function testNewsRendering(): void { $details_html = $details->getHtml(); $field_list_assert->assertPattern($details_expected_values, $details_html); + // Assert Departments field label. + $node->set('oe_departments', [ + ['target_id' => 'http://publications.europa.eu/resource/authority/corporate-body/AASM'], + ['target_id' => 'http://publications.europa.eu/resource/authority/corporate-body/ABEC'], + ]); + $node->save(); + $this->drupalGet($node->toUrl()); + $details_expected_values['items'][3]['label'] = 'Departments'; + $details_expected_values['items'][3]['body'] = 'Associated African States and Madagascar | Audit Board of the European Communities'; + $details_html = $details->getHtml(); + $field_list_assert->assertPattern($details_expected_values, $details_html); + // Assert Body field. $body = $this->assertSession()->elementExists('css', 'article[role=article] .ecl'); $this->assertEquals('News body', $body->getText()); @@ -192,25 +233,13 @@ public function testNewsRendering(): void { ], ])->save(); $this->drupalGet($node->toUrl()); - - $related_links_header = $this->assertSession()->elementExists('css', 'article[role=article] > div > h2'); - $this->assertContentHeader($related_links_header, 'Related links'); - $related_links_content = $this->assertSession()->elementExists('css', 'article[role=article] > div > div.ecl-list article.ecl-content-item:nth-child(1)'); - $link_assert = new ListItemAssert(); - $link_expected_values = [ - 'url' => '/build/node', - 'title' => 'Node listing', - ]; - $link_assert->assertPattern($link_expected_values, $related_links_content->getOuterHtml()); - $link_assert->assertVariant('default', $related_links_content->getOuterHtml()); - - $related_links_content = $this->assertSession()->elementExists('css', 'article[role=article] > div > div.ecl-list article.ecl-content-item:nth-child(2)'); - $link_expected_values = [ - 'url' => 'https://example.com', - 'title' => 'External link', - ]; - $link_assert->assertPattern($link_expected_values, $related_links_content->getOuterHtml()); - $link_assert->assertVariant('default', $related_links_content->getOuterHtml()); + $this->assertEquals('Related links', $this->assertSession()->elementExists('css', 'h2.ecl-u-type-heading-2:nth-child(8)')->getText()); + $first_related_link = $this->assertSession()->elementExists('css', 'div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-pt-m.ecl-u-pb-m:nth-child(9) a'); + $this->assertEquals('/build/node', $first_related_link->getAttribute('href')); + $this->assertEquals('Node listing', $first_related_link->getText()); + $second_related_link = $this->assertSession()->elementExists('css', 'div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-pt-m.ecl-u-pb-m:nth-child(10) a'); + $this->assertEquals('https://example.com', $second_related_link->getAttribute('href')); + $this->assertEquals('External link', $second_related_link->getText()); } } diff --git a/tests/Functional/ContentRenderTestBase.php b/tests/Functional/ContentRenderTestBase.php index d4c56523e..88ef0cd27 100644 --- a/tests/Functional/ContentRenderTestBase.php +++ b/tests/Functional/ContentRenderTestBase.php @@ -357,9 +357,11 @@ protected function assertContentHeader(NodeElement $element, string $title, stri * @param string $href * Link URL. * @param bool $is_external - * Defines whether it is extrernal link or internal. + * Defines whether it is external link or internal. + * @param string $icon_size + * Icon size. */ - protected function assertLinkIcon(NodeElement $element, string $title, string $href, bool $is_external = TRUE): void { + protected function assertLinkIcon(NodeElement $element, string $title, string $href, bool $is_external = TRUE, string $icon_size = 's'): void { $link = $element->findAll('css', 'a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after'); $this->assertCount(1, $link); $this->assertEquals($href, $link[0]->getAttribute('href')); @@ -368,10 +370,10 @@ protected function assertLinkIcon(NodeElement $element, string $title, string $h $this->assertCount(1, $label); $this->assertEquals($title, $label[0]->getText()); - $svg_locator = 'svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'; + $svg_locator = 'svg.ecl-icon.ecl-icon--' . $icon_size . '.ecl-icon--primary.ecl-link__icon'; $icon_type = 'external'; if (!$is_external) { - $svg_locator = 'svg.ecl-icon.ecl-icon--s.ecl-icon--rotate-90.ecl-icon--primary.ecl-link__icon'; + $svg_locator = 'svg.ecl-icon.ecl-icon--' . $icon_size . '.ecl-icon--rotate-90.ecl-icon--primary.ecl-link__icon'; $icon_type = 'corner-arrow'; } $svg = $link[0]->findAll('css', $svg_locator); diff --git a/tests/Kernel/LegacyContentRenderTest.php b/tests/Kernel/LegacyContentRenderTest.php index b664eaa06..22f678a80 100644 --- a/tests/Kernel/LegacyContentRenderTest.php +++ b/tests/Kernel/LegacyContentRenderTest.php @@ -55,7 +55,7 @@ public function testPage(): void { // Related links. $related_links_heading = $crawler->filter('.ecl-u-type-heading-2'); $this->assertContains('Related links', $related_links_heading->text()); - $related_links = $crawler->filter('.ecl-list .ecl-link.ecl-link--standalone'); + $related_links = $crawler->filter('div.ecl-u-border-bottom.ecl-u-border-color-grey-15.ecl-u-pt-m.ecl-u-pb-m a'); $this->assertCount(2, $related_links); // Test short title fallback. diff --git a/tests/Kernel/fixtures/rendering.yml b/tests/Kernel/fixtures/rendering.yml index 570717503..a187b2a56 100644 --- a/tests/Kernel/fixtures/rendering.yml +++ b/tests/Kernel/fixtures/rendering.yml @@ -849,6 +849,7 @@ 'div.ecl-content-item__additional_information .ecl-description-list.ecl-description-list--horizontal': 1 'div.ecl-content-item__additional_information .ecl-description-list__term': 2 'div.ecl-content-item__additional_information .ecl-description-list__definition': 2 + 'svg.ecl-icon.ecl-icon--s.ecl-link__icon': 0 equals: 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" 'div.ecl-content-item__additional_information .ecl-description-list .ecl-description-list__term:nth-child(1)': "When" @@ -867,6 +868,7 @@ meta: - "Meta 1" - "Meta 2" + icon: "check" assertions: count: 'article.ecl-content-item div.ecl-content-item__title a.ecl-link[href="http://example.com"]': 1 @@ -874,8 +876,9 @@ 'article.ecl-content-item div.ecl-content-item__image__before': 0 'article.ecl-content-item div.ecl-content-item__image__after': 0 equals: + 'a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after svg.ecl-icon.ecl-icon--s.ecl-link__icon' : '' 'article.ecl-content-item div.ecl-content-item__meta': "Meta 1 | Meta 2" - 'article.ecl-content-item div.ecl-content-item__title .ecl-link': "Item title" + 'article.ecl-content-item div.ecl-content-item__title .ecl-link span.ecl-link__label': "Item title" 'article.ecl-content-item div.ecl-content-item__description': "
This is the detail. It...
" - array: '#type': pattern diff --git a/tests/PatternAssertions/ListItemAssert.php b/tests/PatternAssertions/ListItemAssert.php index 3bedc2a78..778991374 100644 --- a/tests/PatternAssertions/ListItemAssert.php +++ b/tests/PatternAssertions/ListItemAssert.php @@ -66,6 +66,9 @@ protected function getAssertions($variant): array { 'additional_information' => [ [$this, 'assertAdditionalInformation'], ], + 'icon' => [ + [$this, 'assertIcon'], + ], ]; } @@ -256,6 +259,24 @@ protected function assertAdditionalInformation($expected, Crawler $crawler): voi } } + /** + * Asserts the icon of the list item link. + * + * @param string|null $expected + * The expected icon. + * @param \Symfony\Component\DomCrawler\Crawler $crawler + * The DomCrawler where to check the element. + */ + protected function assertIcon($expected, Crawler $crawler): void { + $icon_selector = 'a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after svg.ecl-icon.ecl-icon--s.ecl-link__icon use'; + if (is_null($expected)) { + $this->assertElementNotExists($icon_selector, $crawler); + return; + } + $icon = $crawler->filter($icon_selector); + self::assertContains($expected, $icon->attr('xlink:href')); + } + /** * Returns the base CSS selector for a list item depending on the variant. *