From 1397573b09e7823b08dce16dacc49f095976fea2 Mon Sep 17 00:00:00 2001 From: 22Alexandra Date: Mon, 4 Apr 2022 17:47:32 +0300 Subject: [PATCH] EWPP-2072: Update test coverage. --- .../ContentConsultationRenderTest.php | 7 +++- .../src/Functional/ContentEventRenderTest.php | 34 ++++++++++++++----- .../Functional/ContentPersonRenderTest.php | 4 +++ .../Functional/ContentProjectRenderTest.php | 33 ++++++++++++++---- 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/tests/src/Functional/ContentConsultationRenderTest.php b/tests/src/Functional/ContentConsultationRenderTest.php index 185e25452e..439a7344a0 100644 --- a/tests/src/Functional/ContentConsultationRenderTest.php +++ b/tests/src/Functional/ContentConsultationRenderTest.php @@ -554,8 +554,11 @@ public function testConsultationRendering(): void { ])->save(); $this->drupalGet($node->toUrl()); $respond_button = $content_items[3]->find('css', '.ecl-link.ecl-link--cta'); + $icon = $respond_button->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-icon--rotate-90.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $icon->getHtml()); $this->assertEquals('Respond to the questionnaire', $respond_button->getText()); - // Add a link to respond button and assert default label. + // Add a link with title to respond button and assert the label is updated + // and the external icon is rendered. $node->set('oe_consultation_response_button', [ 'uri' => 'https://example.com', 'title' => 'Link text', @@ -563,6 +566,8 @@ public function testConsultationRendering(): void { $this->drupalGet($node->toUrl()); $respond_button = $content_items[3]->find('css', '.ecl-link.ecl-link--cta'); $this->assertEquals('Link text', $respond_button->getText()); + $icon = $respond_button->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $icon->getHtml()); // Assert status "Closed". $static_time = new DrupalDateTime('2020-04-20 14:00:00', DateTimeItemInterface::STORAGE_TIMEZONE); diff --git a/tests/src/Functional/ContentEventRenderTest.php b/tests/src/Functional/ContentEventRenderTest.php index 44a7c56928..3c0cd50dbf 100644 --- a/tests/src/Functional/ContentEventRenderTest.php +++ b/tests/src/Functional/ContentEventRenderTest.php @@ -449,6 +449,8 @@ public function testEventRendering(): void { 'body' => 'Event website', ]; $field_list_assert->assertPattern($field_list_expected_values, $practical_list_content->getOuterHtml()); + $event_website_link_icon = $this->assertSession()->elementExists('css', 'dl.ecl-description-list dd a.ecl-link svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $event_website_link_icon->getHtml()); // Assert "Registration capacity" field. $node->set('oe_event_registration_capacity', 'event registration capacity')->save(); @@ -476,7 +478,7 @@ public function testEventRendering(): void { $this->drupalGet($node->toUrl()); $registration_content = $this->assertSession()->elementExists('css', '#event-registration-block'); - $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation'); + $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation', TRUE); // Report or media content are not shown when event is still ongoing. $node->set('oe_event_report_summary', 'Event report summary'); @@ -556,17 +558,20 @@ public function testEventRendering(): void { $this->cronRun(); $this->drupalGet($node->toUrl()); - $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation'); + $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation', TRUE); $this->assertEquals('Book your seat, 1 day left to register, registration will end on 21 February 2020, 15:00 CET', $registration_info_content->getText()); // Assert "Registration date" field when registration will finish today in // one hour. + // Set the Registration URL to an internal path. + $node->set('oe_event_registration_url', 'https://www.europa.eu.com/registation'); + $node->save(); $static_time = new DrupalDateTime('2020-02-21 13:00:00', 'Europe/Brussels'); $this->freezeTime($static_time); $this->cronRun(); $this->drupalGet($node->toUrl()); - $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'http://www.example.com/registation'); + $this->assertRegistrationButtonEnabled($registration_content, 'Register here', 'https://www.europa.eu.com/registation', FALSE); $this->assertEquals('Book your seat, the registration will end today, 21 February 2020, 15:00 CET', $registration_info_content->getText()); // Assert "Registration date" field in the past. @@ -590,9 +595,10 @@ public function testEventRendering(): void { $this->assertEquals('Livestream', $online_heading->getText()); $online_description = $this->assertSession()->elementExists('css', 'div > div:nth-of-type(1) > .ecl', $details_content); $this->assertEquals('Online event description', $online_description->getText()); - $online_button = $this->assertSession()->elementExists('css', 'a.ecl-u-mt-l.ecl-u-mb-l.ecl-link.ecl-link--cta.ecl-u-d-inline-block', $details_content); - $this->assertEquals('Link to online event', $online_button->getText()); + $online_button = $this->assertSession()->elementExists('css', 'span.ecl-u-mt-l.ecl-u-mb-l.ecl-u-d-inline-block a.ecl-link.ecl-link--cta.ecl-link--icon.ecl-link--icon-after', $details_content); + $this->assertEquals('Link to online event', $online_button->find('css', 'span.ecl-link__label')->getText()); $this->assertEquals('http://www.example.com/online_link', $online_button->getAttribute('href')); + $this->assertEquals('', $online_button->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon')->getHtml()); $description_summary = $this->assertSession()->elementExists('css', 'div > div:nth-of-type(2) .ecl', $details_content); $this->assertEquals('Event report summary', $description_summary->getText()); @@ -615,6 +621,8 @@ public function testEventRendering(): void { $this->assertEmpty($caption->find('css', '.ecl-gallery__meta')->getText()); // Assert media links. $this->assertSession()->linkExistsExact('Main link for media items'); + $more_media_link_icon = $this->assertSession()->elementExists('css', 'div#event-media a.ecl-link svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $more_media_link_icon->getHtml()); $this->assertSession()->pageTextContainsOnce('More media links'); // Assert that summary and description fields are not displayed anymore. @@ -1078,10 +1086,20 @@ public function testEventRendering(): void { * Button text. * @param string $link * Button link. + * @param bool $external + * Whether the registration link is external or not. */ - protected function assertRegistrationButtonEnabled(NodeElement $parent_element, string $text, string $link): void { - $rendered_button = $this->assertSession()->elementExists('css', 'a.ecl-u-mt-2xl.ecl-link.ecl-link--cta', $parent_element); - $this->assertEquals($text, $rendered_button->getText()); + protected function assertRegistrationButtonEnabled(NodeElement $parent_element, string $text, string $link, bool $external): void { + if ($external) { + $rendered_button = $this->assertSession()->elementExists('css', 'span.ecl-u-mt-2xl.ecl-u-d-inline-block a.ecl-link.ecl-link--cta.ecl-link--icon.ecl-link--icon-after', $parent_element); + $this->assertEquals($text, $rendered_button->find('css', 'span.ecl-link__label')->getText()); + $this->assertEquals('', $rendered_button->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon')->getHtml()); + } + else { + $this->assertSession()->elementNotExists('css', 'span.ecl-u-mt-2xl.ecl-u-d-inline-block a.ecl-link.ecl-link--cta.ecl-link--icon.ecl-link--icon-after', $parent_element); + $rendered_button = $this->assertSession()->elementExists('css', 'a.ecl-link.ecl-link--cta', $parent_element); + $this->assertEquals($text, $rendered_button->getText()); + } $this->assertEquals($link, $rendered_button->getAttribute('href')); } diff --git a/tests/src/Functional/ContentPersonRenderTest.php b/tests/src/Functional/ContentPersonRenderTest.php index 56b4fb6be9..711481f0ae 100644 --- a/tests/src/Functional/ContentPersonRenderTest.php +++ b/tests/src/Functional/ContentPersonRenderTest.php @@ -347,8 +347,12 @@ public function testPersonRendering(): void { $this->assertCount(2, $transparency_links_items); $this->assertEquals('http://example.com/link_1', $transparency_links_items[0]->getAttribute('href')); $this->assertEquals('Person link 1', $transparency_links_items[0]->getText()); + $first_link_icon = $transparency_links_items[0]->find('css', 'a.ecl-link svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $first_link_icon->getHtml()); $this->assertEquals('http://example.com/link_2', $transparency_links_items[1]->getAttribute('href')); $this->assertEquals('http://example.com/link_2', $transparency_links_items[1]->getText()); + $second_link_icon = $transparency_links_items[0]->find('css', 'a.ecl-link svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $second_link_icon->getHtml()); // Assert Biography introduction field. $node->set('oe_person_biography_intro', 'Biography introduction text')->save(); diff --git a/tests/src/Functional/ContentProjectRenderTest.php b/tests/src/Functional/ContentProjectRenderTest.php index de30d85c45..3dd8eb1f11 100644 --- a/tests/src/Functional/ContentProjectRenderTest.php +++ b/tests/src/Functional/ContentProjectRenderTest.php @@ -85,6 +85,10 @@ public function testProjectRendering(): void { [ 'uri' => 'http://proposal-call-no-title.com', ], + [ + 'uri' => 'http://ec.europa.eu/info', + 'title' => 'Internal Call for proposal', + ], ], 'oe_project_results' => 'Project results...', 'oe_project_result_files' => [ @@ -223,6 +227,8 @@ public function testProjectRendering(): void { $field_list_html = $description_lists[2]->getHtml(); $field_list_assert->assertPattern($third_field_list_expected_values, $field_list_html); $field_list_assert->assertVariant('featured_horizontal', $field_list_html); + $project_website_icon = $this->assertSession()->elementExists('css', 'dl.ecl-description-list dd a.ecl-link svg.ecl-icon.ecl-icon--s.ecl-icon--primary.ecl-link__icon'); + $this->assertEquals('', $project_website_icon->getHtml()); // Assert documents file. $file_wrapper = $this->assertSession()->elementExists('css', 'div#project-documents'); @@ -249,9 +255,10 @@ public function testProjectRendering(): void { $this->assertListItem($funding_items[0], 'Anti Fraud Information System (AFIS)', 'Funding programme'); $proposal_items = $unordered_list_items[1]->findAll('css', '.ecl-unordered-list__item'); - $this->assertCount(2, $proposal_items); - $this->assertListItem($proposal_items[0], 'Test call for proposal', 'Call for proposals', 'http://proposal-call.com'); - $this->assertListItem($proposal_items[1], 'http://proposal-call-no-title.com', 'Call for proposals', 'http://proposal-call-no-title.com'); + $this->assertCount(3, $proposal_items); + $this->assertListItem($proposal_items[0], 'Test call for proposal', 'Call for proposals', 'http://proposal-call.com', TRUE); + $this->assertListItem($proposal_items[1], 'http://proposal-call-no-title.com', 'Call for proposals', 'http://proposal-call-no-title.com', TRUE); + $this->assertListItem($proposal_items[2], 'Internal Call for proposal', 'Call for proposals', 'http://ec.europa.eu/info'); // Assert bottom region - Stakeholders. $project_stakeholders = $this->assertSession()->elementExists('css', 'div#project-stakeholders'); @@ -375,11 +382,16 @@ protected function assertStakeholderOrganisationRendering(NodeElement $rendered_ $field_list_html = $field_list_wrapper->getHtml(); $field_list_assert->assertPattern($first_field_list_expected_values, $field_list_html); $field_list_assert->assertVariant('horizontal', $field_list_html); + // Assert contact website's icon. + $website_icon = $field_list_wrapper->find('css', 'dl.ecl-description-list dd a.ecl-link'); + $this->assertEquals('', $website_icon->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon')->getHtml()); // Assert contact link. - $contact_links = $rendered_stakeholder_element->findAll('css', 'div.ecl-u-mt-l.ecl-u-type-bold a.ecl-link'); + $contact_links = $rendered_stakeholder_element->findAll('css', 'div.ecl-u-mt-l.ecl-u-type-bold a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after'); $this->assertCount(1, $contact_links); $this->assertStringContainsString("http://example.com/contact_$name", $contact_links[0]->getAttribute('href')); + // Assert contact link's icon. + $this->assertEquals('', $contact_links[0]->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon')->getHtml()); $contact_link_labels = $rendered_stakeholder_element->findAll('css', 'div.ecl-u-mt-l.ecl-u-type-bold span.ecl-link__label'); $this->assertCount(1, $contact_link_labels); $this->assertEquals('Contact organisation', $contact_link_labels[0]->getText()); @@ -396,10 +408,12 @@ protected function assertStakeholderOrganisationRendering(NodeElement $rendered_ * Meta value of the list item. * @param string $link * Link that is used. + * @param bool $external_link + * Whether the link is external or not. * * @throws \Behat\Mink\Exception\ElementNotFoundException */ - protected function assertListItem(NodeElement $rendered_element, string $title, string $meta, $link = ''): void { + protected function assertListItem(NodeElement $rendered_element, string $title, string $meta, $link = '', bool $external_link = FALSE): void { $list_item_assert = new ListItemAssert(); $expected_values = [ 'meta' => $meta, @@ -414,7 +428,14 @@ protected function assertListItem(NodeElement $rendered_element, string $title, $this->assertEquals($meta, $field_meta->getText()); if (!empty($link)) { - $link_tag = $rendered_element->find('css', '.ecl-link'); + if ($external_link) { + $link_tag = $rendered_element->find('css', 'a.ecl-link.ecl-link--standalone.ecl-link--icon.ecl-link--icon-after'); + $this->assertEquals('', $link_tag->find('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon')->getHtml()); + } + else { + $this->assertSession()->elementNotExists('css', 'svg.ecl-icon.ecl-icon--s.ecl-link__icon', $rendered_element); + $link_tag = $rendered_element->find('css', '.ecl-link'); + } $this->assertEquals($link, $link_tag->getAttribute('href')); } }