diff options
author | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-29 04:53:32 +0000 |
---|---|---|
committer | Angie Byron <webchick@24967.no-reply.drupal.org> | 2010-11-29 04:53:32 +0000 |
commit | 14779b97e1a051b68e2977ba6f48932e54da7b25 (patch) | |
tree | 0d79c0a340a92e5d7f2d3587ec59d1dc7171e4dc /modules | |
parent | 1a685474e698ce3e90dbae87f6a1f83966d9ef63 (diff) | |
download | brdo-14779b97e1a051b68e2977ba6f48932e54da7b25.tar.gz brdo-14779b97e1a051b68e2977ba6f48932e54da7b25.tar.bz2 |
#917730 by rfay, David_Rothstein: Fixed various RSS feed links (with tests).
Diffstat (limited to 'modules')
-rw-r--r-- | modules/forum/forum.module | 2 | ||||
-rw-r--r-- | modules/node/node.module | 4 | ||||
-rw-r--r-- | modules/simpletest/tests/common.test | 82 |
3 files changed, 85 insertions, 3 deletions
diff --git a/modules/forum/forum.module b/modules/forum/forum.module index 10076a9cd..fffd0c76d 100644 --- a/modules/forum/forum.module +++ b/modules/forum/forum.module @@ -990,7 +990,7 @@ function template_preprocess_forums(&$variables) { if ($variables['tid'] && !in_array($variables['tid'], variable_get('forum_containers', array()))) { $variables['topics'] = theme('forum_topic_list', $variables); - drupal_add_feed('taxonomy/term/' . $variables['tid'] . '/0/feed', 'RSS - ' . $title); + drupal_add_feed('taxonomy/term/' . $variables['tid'] . '/feed', 'RSS - ' . $title); } else { $variables['topics'] = ''; diff --git a/modules/node/node.module b/modules/node/node.module index 9a5651350..44a2274d1 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -2537,8 +2537,8 @@ function node_page_default() { $nodes = node_load_multiple($nids); $build = node_view_multiple($nodes); - $feed_url = url('rss.xml', array('absolute' => TRUE)); - drupal_add_feed($feed_url, variable_get('site_name', 'Drupal') . ' ' . t('RSS')); + // 'rss.xml' is a path, not a file, registered in node_menu(). + drupal_add_feed('rss.xml', variable_get('site_name', 'Drupal') . ' ' . t('RSS')); $build['pager'] = array( '#theme' => 'pager', '#weight' => 5, diff --git a/modules/simpletest/tests/common.test b/modules/simpletest/tests/common.test index 6c1492e75..5fca979d9 100644 --- a/modules/simpletest/tests/common.test +++ b/modules/simpletest/tests/common.test @@ -2277,3 +2277,85 @@ class DrupalGetRdfNamespacesTestCase extends DrupalWebTestCase { $this->assertTrue(!isset($ns['dc']), t('A prefix with conflicting namespaces is discarded.')); } } + +/** + * Basic tests for drupal_add_feed(). + */ +class DrupalAddFeedTestCase extends DrupalWebTestCase { + public static function getInfo() { + return array( + 'name' => 'drupal_add_feed() tests', + 'description' => 'Make sure that drupal_add_feed() works correctly with various constructs.', + 'group' => 'System', + ); + } + + /** + * Test drupal_add_feed() with paths, URLs, and titles. + */ + function testBasicFeedAddNoTitle() { + $path = $this->randomName(12); + $external_url = 'http://' . $this->randomName(12) . '/' . $this->randomName(12); + $fully_qualified_local_url = url($this->randomName(12), array('absolute' => TRUE)); + + $path_for_title = $this->randomName(12); + $external_for_title = 'http://' . $this->randomName(12) . '/' . $this->randomName(12); + $fully_qualified_for_title = url($this->randomName(12), array('absolute' => TRUE)); + + // Possible permutations of drupal_add_feed() to test. + // - 'input_url': the path passed to drupal_add_feed(), + // - 'output_url': the expected URL to be found in the header. + // - 'title' == the title of the feed as passed into drupal_add_feed(). + $urls = array( + 'path without title' => array( + 'input_url' => $path, + 'output_url' => url($path, array('absolute' => TRUE)), + 'title' => '', + ), + 'external url without title' => array( + 'input_url' => $external_url, + 'output_url' => $external_url, + 'title' => '', + ), + 'local url without title' => array( + 'input_url' => $fully_qualified_local_url, + 'output_url' => $fully_qualified_local_url, + 'title' => '', + ), + 'path with title' => array( + 'input_url' => $path_for_title, + 'output_url' => url($path_for_title, array('absolute' => TRUE)), + 'title' => $this->randomName(12), + ), + 'external url with title' => array( + 'input_url' => $external_for_title, + 'output_url' => $external_for_title, + 'title' => $this->randomName(12), + ), + 'local url with title' => array( + 'input_url' => $fully_qualified_for_title, + 'output_url' => $fully_qualified_for_title, + 'title' => $this->randomName(12), + ), + ); + + foreach ($urls as $description => $feed_info) { + drupal_add_feed($feed_info['input_url'], $feed_info['title']); + } + + $this->drupalSetContent(drupal_get_html_head()); + foreach ($urls as $description => $feed_info) { + $this->assertPattern($this->urlToRSSLinkPattern($feed_info['output_url'], $feed_info['title']), t('Found correct feed header for %description', array('%description' => $description))); + } + } + + /** + * Create a pattern representing the RSS feed in the page. + */ + function urlToRSSLinkPattern($url, $title = '') { + // Escape any regular expression characters in the url ('?' is the worst). + $url = preg_replace('/([+?.*])/', '[$0]', $url); + $generated_pattern = '%<link +rel="alternate" +type="application/rss.xml" +title="' . $title . '" +href="' . $url . '" */>%'; + return $generated_pattern; + } +} |