View source
<?php
namespace Drupal\Tests\aggregator\Functional;
use Drupal\views\Entity\View;
class AggregatorRenderingTest extends AggregatorTestBase {
protected static $modules = [
'block',
'test_page_test',
];
protected $defaultTheme = 'stark';
protected function setUp() : void {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
public function testBlockLinks() {
$this
->createSampleNodes();
$feed = $this
->createFeed();
$this
->updateFeedItems($feed, $this
->getDefaultFeedItemCount());
$admin_user = $this
->drupalCreateUser([
'administer blocks',
'access administration pages',
'administer news feeds',
'access news feeds',
]);
$this
->drupalLogin($admin_user);
$block = $this
->drupalPlaceBlock("aggregator_feed_block", [
'label' => 'feed-' . $feed
->label(),
]);
$block
->getPlugin()
->setConfigurationValue('feed', $feed
->id());
$block
->getPlugin()
->setConfigurationValue('block_count', 2);
$block
->save();
$this
->drupalGet('test-page');
$this
->assertSession()
->pageTextContains($block
->label());
$items = $this->container
->get('entity_type.manager')
->getStorage('aggregator_item')
->loadByFeed($feed
->id(), 1);
$this
->assertSession()
->linkByHrefExists(reset($items)
->getLink());
$this
->assertSession()
->linkByHrefExists($feed
->toUrl()
->toString());
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed
->id());
$this
->drupalGet($feed
->toUrl()
->getInternalPath());
$this
->assertSession()
->elementTextContains('xpath', '//h1', $feed
->label());
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed
->id());
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
$block
->getPlugin()
->setConfigurationValue('block_count', 0);
$block
->save();
$this
->drupalGet('test-page');
$this
->assertSession()
->pageTextNotContains($block
->label());
}
public function testFeedPage() {
$view = View::load('frontpage');
$display =& $view
->getDisplay('feed_1');
$display['display_options']['pager']['options']['items_per_page'] = 30;
$view
->save();
$this
->createSampleNodes(30);
$feed = $this
->createFeed();
$this
->updateFeedItems($feed, 30);
$this
->drupalGet('aggregator');
$this
->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
$this
->drupalGet('aggregator/sources');
$this
->assertSession()
->elementTextContains('xpath', '//h1', 'Sources');
$href = $feed
->toUrl()
->toString();
$this
->assertSession()
->linkByHrefExists($href);
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed
->id());
$this
->drupalLogout();
$this
->drupalGet('aggregator/rss');
$this
->assertSession()
->statusCodeEquals(403);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('aggregator/rss');
$this
->assertSession()
->statusCodeEquals(200);
$this
->assertSession()
->responseHeaderEquals('Content-Type', 'application/rss+xml; charset=utf-8');
$this
->drupalGet('aggregator/opml');
$content = $this
->getSession()
->getPage()
->getContent();
$xml = simplexml_load_string($content);
$attributes = $xml
->xpath('//outline[1]')[0]
->attributes();
$this
->assertEquals('rss', $attributes->type);
$this
->assertEquals($feed
->label(), $attributes->text);
$this
->assertEquals($feed
->getUrl(), $attributes->xmlUrl);
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$this
->assertSession()
->elementExists('xpath', '//ul[contains(@class, "pager__items")]');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed:' . $feed
->id());
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_feed_view');
$this
->assertSession()
->responseHeaderContains('X-Drupal-Cache-Tags', 'aggregator_item_view');
}
}