View source
<?php
declare (strict_types=1);
namespace Drupal\Tests\announcements_feed\Kernel;
use GuzzleHttp\Psr7\Response;
class AnnounceFetcherTest extends AnnounceTestBase {
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'announcements_feed',
]);
}
public function testShowAnnouncements(array $feed_item) : void {
$this
->markTestSkipped('Skipped due to major version-specific logic. See https://www.drupal.org/project/drupal/issues/3359322');
$this
->setFeedItems([
$feed_item,
]);
$feeds = $this
->fetchFeedItems();
$this
->assertCount(1, $feeds);
$this
->assertSame('https://www.drupal.org/project/announce', $feeds[0]->url);
$this
->assertSame('Drupal security update Test', $feeds[0]->title);
$this
->assertSame('^10', $feeds[0]->version);
$this
->assertCount(1, $this->history);
}
public function testFeedFields() : void {
$this
->markTestSkipped('Skipped due to major version-specific logic. See https://www.drupal.org/project/drupal/issues/3359322');
$feed_item_1 = [
'id' => '1001',
'content_html' => 'Test teaser 1',
'url' => 'https://www.drupal.org/project/announce',
'_drupalorg' => [
'featured' => TRUE,
'version' => '^10',
],
'date_modified' => "2021-09-02T15:09:42+00:00",
'date_published' => "2021-09-01T15:09:42+00:00",
];
$this
->setFeedItems([
$feed_item_1,
]);
$feeds = $this
->fetchFeedItems();
$this
->assertCount(1, $feeds);
$this
->assertSame($feed_item_1['id'], $feeds[0]->id);
$this
->assertSame($feed_item_1['content_html'], $feeds[0]->content_html);
$this
->assertSame($feed_item_1['_drupalorg']['featured'], $feeds[0]->featured);
$this
->assertSame($feed_item_1['date_published'], $feeds[0]->date_published);
$this
->assertSame($feed_item_1['_drupalorg']['version'], $feeds[0]->version);
}
public static function providerShowAnnouncements() : array {
return [
'1' => [
'feed_item' => [
'id' => '1001',
'content_html' => 'Test teaser 1',
'_drupalorg' => [
'featured' => 1,
'version' => '^10',
],
'date_modified' => "2021-09-02T15:09:42+00:00",
'date_published' => "2021-09-01T15:09:42+00:00",
],
],
'2' => [
'feed_item' => [
'id' => '1002',
'content_html' => 'Test teaser 2',
'_drupalorg' => [
'featured' => 1,
'version' => '^10',
],
'date_modified' => "2021-09-02T15:09:42+00:00",
'date_published' => "2021-09-01T15:09:42+00:00",
],
],
'3' => [
'feed_item' => [
'id' => '1003',
'content_html' => 'Test teaser 3',
'_drupalorg' => [
'featured' => 1,
'version' => '^10',
],
'date_modified' => "2021-09-02T15:09:42+00:00",
'date_published' => "2021-09-01T15:09:42+00:00",
],
],
'4' => [
'feed_item' => [
'id' => '1004',
'content_html' => 'Test teaser 4',
'_drupalorg' => [
'featured' => 1,
'version' => '^10',
],
'date_modified' => "2021-09-02T15:09:42+00:00",
'date_published' => "2021-09-01T15:09:42+00:00",
],
],
];
}
protected function setFeedItems(array $feed_items) : void {
$responses = [];
foreach ($feed_items as $feed_item) {
$feed_item += [
'title' => 'Drupal security update Test',
'url' => 'https://www.drupal.org/project/announce',
];
$responses[] = new Response(200, [], json_encode([
'items' => [
$feed_item,
],
]));
}
$this
->setTestFeedResponses($responses);
}
protected function fetchFeedItems() : array {
return $this->container
->get('announcements_feed.fetcher')
->fetch();
}
}