Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function buildTeaser(array $build, NodeInterface $entity) {
*/
public function buildFeatured(array $build, NodeInterface $entity) {
$media = $this->getReferencedEntityFromField($entity, 'field_featured_image');
$image = $media instanceof MediaInterface ? $this->buildImageStyle($media, 'card', 'field_media_image') : NULL;
$image = $media instanceof MediaInterface ? $this->buildImageStyle($media, 'card', 'field_media_image') : [];
$title = $entity->label();
$url = $entity->toUrl();
$summary = $this->buildProcessedText($entity, 'field_body');
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

namespace Drupal\Tests\server_general\ExistingSite;

use Drupal\node\NodeInterface;
use Drupal\Tests\server_general\Traits\ParagraphCreationTrait;

/**
* Tests for the Related content carousel.
*/
class ServerGeneralRelatedContentFeaturedTest extends ServerGeneralSelenium2TestBase {

use ParagraphCreationTrait;

/**
* Test the featured content carousel.
*/
public function testFeaturedContent() {
$first_news_title = 'News item 1';
$second_news_title = 'News item 2';

$first_news = $this->createNode([
'type' => 'news',
'title' => $first_news_title,
'status' => NodeInterface::PUBLISHED,
'moderation_state' => 'published',
]);

$second_news = $this->createNode([
'type' => 'news',
'title' => $second_news_title,
'status' => NodeInterface::PUBLISHED,
'moderation_state' => 'published',
]);

$featured_content_paragraph = $this->createParagraph([
'type' => 'related_content',
'field_title' => 'Featured Content',
'field_is_featured' => 1,
'field_related_content' => [
['target_id' => $first_news->id()],
['target_id' => $second_news->id()],
],
]);

$landing_page = $this->createNode([
'type' => 'landing_page',
'title' => $this->randomString(),
'status' => NodeInterface::PUBLISHED,
'moderation_state' => 'published',
'field_paragraphs' => [
[
'target_id' => $featured_content_paragraph->id(),
'target_revision_id' => $featured_content_paragraph->getRevisionId(),
],
],
]);

$this->drupalGet($landing_page->toUrl());
/** @var \Drupal\FunctionalJavascriptTests\JSWebAssert $web_assert */
$web_assert = $this->assertSession();

$featured_content = $web_assert->waitForElement('css', '.paragraph--type--related-content');
$this->assertNotNull($featured_content);
$web_assert->elementTextContains('css', '.paragraph--type--related-content h2', 'Featured Content');
// Slick is initialized.
$carousel = $web_assert->waitForElement('css', '.paragraph--type--related-content .carousel-wrapper.slick-initialized');
$this->assertNotNull($carousel);

// Assert the current slide has the expected title.
$web_assert->elementTextContains('css', '.paragraph--type--related-content .carousel-slide.slick-current', $first_news_title);
// Click on the 2nd dot navigation.
$dots_2 = $carousel->find('css', '.slick-dots li:nth-child(2)');
$this->assertNotNull($dots_2);
$dots_2->click();
// Wait half sec for the JS and animation.
$this->getSession()->wait(500);
// Assert that the active slide is now different.
$web_assert->elementTextContains('css', '.paragraph--type--related-content .carousel-slide.slick-current', $second_news_title);
}
}