View source
<?php
namespace Drupal\aggregator\Tests;
use Drupal\Component\Utility\SafeMarkup;
class AggregatorRenderingTest extends AggregatorTestBase {
public static $modules = array(
'block',
'test_page_test',
);
protected function setUp() {
parent::setUp();
$this
->drupalPlaceBlock('page_title_block');
}
public function testBlockLinks() {
$this
->createSampleNodes();
$feed = $this
->createFeed();
$this
->updateFeedItems($feed, $this
->getDefaultFeedItemCount());
$admin_user = $this
->drupalCreateUser(array(
'administer blocks',
'access administration pages',
'administer news feeds',
'access news feeds',
));
$this
->drupalLogin($admin_user);
$block = $this
->drupalPlaceBlock("aggregator_feed_block", array(
'label' => 'feed-' . $feed
->label(),
));
$block
->getPlugin()
->setConfigurationValue('feed', $feed
->id());
$block
->getPlugin()
->setConfigurationValue('block_count', 2);
$block
->save();
$this
->drupalGet('test-page');
$this
->assertText($block
->label(), 'Feed block is displayed on the page.');
$items = $this->container
->get('entity.manager')
->getStorage('aggregator_item')
->loadByFeed($feed
->id(), 1);
$links = $this
->xpath('//a[@href = :href]', array(
':href' => reset($items)
->getLink(),
));
$this
->assert(isset($links[0]), 'Item link found.');
$href = $feed
->url();
$links = $this
->xpath('//a[@href = :href]', array(
':href' => $href,
));
$this
->assert(isset($links[0]), format_string('Link to href %href found.', array(
'%href' => $href,
)));
$cache_tags_header = $this
->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
$this
->assertTrue(in_array('aggregator_feed:' . $feed
->id(), $cache_tags));
$this
->drupalGet($feed
->urlInfo()
->getInternalPath());
$correct_titles = $this
->xpath('//h1[normalize-space(text())=:title]', array(
':title' => $feed
->label(),
));
$this
->assertFalse(empty($correct_titles), 'Aggregator feed page is available and has the correct title.');
$cache_tags = explode(' ', $this
->drupalGetHeader('X-Drupal-Cache-Tags'));
$this
->assertTrue(in_array('aggregator_feed:' . $feed
->id(), $cache_tags));
$this
->assertTrue(in_array('aggregator_feed_view', $cache_tags));
$this
->assertTrue(in_array('aggregator_item_view', $cache_tags));
$block
->getPlugin()
->setConfigurationValue('block_count', 0);
$block
->save();
$this
->drupalGet('test-page');
$this
->assertNoText($block
->label(), 'Feed block is not displayed on the page when number of items is set to 0.');
}
public function testFeedPage() {
$view = entity_load('view', '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');
$elements = $this
->xpath("//ul[contains(@class, :class)]", array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Individual source page contains a pager.');
$this
->drupalGet('aggregator/sources');
$titles = $this
->xpath('//h1[normalize-space(text())=:title]', array(
':title' => 'Sources',
));
$this
->assertTrue(!empty($titles), 'Source page contains correct title.');
$href = $feed
->url();
$links = $this
->xpath('//a[@href = :href]', array(
':href' => $href,
));
$this
->assertTrue(isset($links[0]), SafeMarkup::format('Link to href %href found.', array(
'%href' => $href,
)));
$cache_tags_header = $this
->drupalGetHeader('X-Drupal-Cache-Tags');
$cache_tags = explode(' ', $cache_tags_header);
$this
->assertTrue(in_array('aggregator_feed:' . $feed
->id(), $cache_tags));
$this
->drupalLogout();
$this
->drupalGet('aggregator/rss');
$this
->assertResponse(403);
$this
->drupalLogin($this->adminUser);
$this
->drupalGet('aggregator/rss');
$this
->assertResponse(200);
$this
->assertEqual($this
->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');
$this
->drupalGet('aggregator/opml');
$outline = $this
->xpath('//outline[1]');
$this
->assertEqual($outline[0]['type'], 'rss', 'The correct type attribute is used for rss OPML.');
$this
->assertEqual($outline[0]['text'], $feed
->label(), 'The correct text attribute is used for rss OPML.');
$this
->assertEqual($outline[0]['xmlurl'], $feed
->getUrl(), 'The correct xmlUrl attribute is used for rss OPML.');
$this
->drupalGet('aggregator/sources/' . $feed
->id());
$elements = $this
->xpath("//ul[contains(@class, :class)]", array(
':class' => 'pager__items',
));
$this
->assertTrue(!empty($elements), 'Individual source page contains a pager.');
$cache_tags = explode(' ', $this
->drupalGetHeader('X-Drupal-Cache-Tags'));
$this
->assertTrue(in_array('aggregator_feed:' . $feed
->id(), $cache_tags));
$this
->assertTrue(in_array('aggregator_feed_view', $cache_tags));
$this
->assertTrue(in_array('aggregator_item_view', $cache_tags));
}
}