Newer
Older
<?php
/**
* @file
* Definition of Drupal\aggregator\Tests\AggregatorRenderingTest.
*/
namespace Drupal\aggregator\Tests;
catch
committed
use Drupal\Component\Utility\String;
Jennifer Hodgdon
committed
/**
* Tests display of aggregator items on the page.
*
* @group aggregator
Jennifer Hodgdon
committed
*/
class AggregatorRenderingTest extends AggregatorTestBase {
Dries Buytaert
committed
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block', 'test_page_test');
Dries Buytaert
committed
Jennifer Hodgdon
committed
* Adds a feed block to the page and checks its links.
*/
public function testBlockLinks() {
// Create feed.
$this->createSampleNodes();
$feed = $this->createFeed();
$this->updateFeedItems($feed, $this->getDefaultFeedItemCount());
// Need admin user to be able to access block admin.
Dries Buytaert
committed
$admin_user = $this->drupalCreateUser(array(
'administer blocks',
'access administration pages',
'administer news feeds',
'access news feeds',
));
Dries Buytaert
committed
$this->drupalLogin($admin_user);
catch
committed
$block = $this->drupalPlaceBlock("aggregator_feed_block", array('label' => 'feed-' . $feed->label()));
// Configure the feed that should be displayed.
$block->getPlugin()->setConfigurationValue('feed', $feed->id());
$block->getPlugin()->setConfigurationValue('block_count', 2);
$block->save();
Dries Buytaert
committed
// Confirm that the block is now being displayed on pages.
$this->drupalGet('test-page');
Angie Byron
committed
$this->assertText($block->label(), 'Feed block is displayed on the page.');
// Find the expected read_more link.
Angie Byron
committed
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
Dries Buytaert
committed
$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('block_plugin:aggregator_feed_block', $cache_tags));
$this->assertTrue(in_array('aggregator_feed:' . $feed->id(), $cache_tags));
// Visit that page.
Angie Byron
committed
$this->drupalGet($feed->urlInfo()->getInternalPath());
$correct_titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => $feed->label()));
Dries Buytaert
committed
$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));
// Set the number of news items to 0 to test that the block does not show
// up.
catch
committed
$block->getPlugin()->setConfigurationValue('block_count', 0);
$block->save();
// Check that the block is no longer displayed.
$this->drupalGet('test-page');
Angie Byron
committed
$this->assertNoText($block->label(), 'Feed block is not displayed on the page when number of items is set to 0.');
}
/**
Jennifer Hodgdon
committed
* Creates a feed and checks that feed's page.
*/
public function testFeedPage() {
// Increase the number of items published in the rss.xml feed so we have
// enough articles to test paging.
Angie Byron
committed
$view = entity_load('view', 'frontpage');
$display = &$view->getDisplay('feed_1');
$display['display_options']['pager']['options']['items_per_page'] = 30;
$view->save();
// Create a feed with 30 items.
$this->createSampleNodes(30);
$feed = $this->createFeed();
$this->updateFeedItems($feed, 30);
// Check for presence of an aggregator pager.
$this->drupalGet('aggregator');
$elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager'));
$this->assertTrue(!empty($elements), 'Individual source page contains a pager.');
catch
committed
// Check for sources page title.
$this->drupalGet('aggregator/sources');
$titles = $this->xpath('//h1[normalize-space(text())=:title]', array(':title' => 'Sources'));
$this->assertTrue(!empty($titles), 'Source page contains correct title.');
// Find the expected read_more link on the sources page.
Angie Byron
committed
$href = $feed->url();
$links = $this->xpath('//a[@href = :href]', array(':href' => $href));
catch
committed
$this->assertTrue(isset($links[0]), String::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));
catch
committed
catch
committed
// Check the rss aggregator page.
$this->drupalGet('aggregator/rss');
$this->assertResponse(200);
$this->assertEqual($this->drupalGetHeader('Content-type'), 'application/rss+xml; charset=utf-8');
// Check the opml aggregator page.
$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.');
// Check for the presence of a pager.
$this->drupalGet('aggregator/sources/' . $feed->id());
$elements = $this->xpath("//ul[@class=:class]", array(':class' => 'pager'));
Dries Buytaert
committed
$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));