Skip to content

Commit

Permalink
EWPP-2072: Update test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
22Alexandra committed Apr 19, 2022
1 parent a05393a commit a8d4046
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 15 deletions.
7 changes: 6 additions & 1 deletion tests/src/Functional/ContentConsultationRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,20 @@ 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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#corner-arrow"></use>', $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',
])->save();
$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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $icon->getHtml());

// Assert status "Closed".
$static_time = new DrupalDateTime('2020-04-20 14:00:00', DateTimeItemInterface::STORAGE_TIMEZONE);
Expand Down
34 changes: 26 additions & 8 deletions tests/src/Functional/ContentEventRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $event_website_link_icon->getHtml());

// Assert "Registration capacity" field.
$node->set('oe_event_registration_capacity', 'event registration capacity')->save();
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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', DateTimeItemInterface::STORAGE_TIMEZONE);
$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.
Expand All @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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());
Expand All @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $more_media_link_icon->getHtml());
$this->assertSession()->pageTextContainsOnce('More media links');

// Assert that summary and description fields are not displayed anymore.
Expand Down Expand Up @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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'));
}

Expand Down
4 changes: 4 additions & 0 deletions tests/src/Functional/ContentPersonRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $second_link_icon->getHtml());

// Assert Biography introduction field.
$node->set('oe_person_biography_intro', 'Biography introduction text')->save();
Expand Down
33 changes: 27 additions & 6 deletions tests/src/Functional/ContentProjectRenderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => [
Expand Down Expand Up @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $project_website_icon->getHtml());

// Assert documents file.
$file_wrapper = $this->assertSession()->elementExists('css', 'div#project-documents');
Expand All @@ -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');
Expand Down Expand Up @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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());
Expand All @@ -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,
Expand All @@ -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('<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="/build/themes/custom/oe_theme/dist/ec/images/icons/sprites/icons.svg#external"></use>', $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'));
}
}
Expand Down

0 comments on commit a8d4046

Please sign in to comment.