WordPress.org

Make WordPress Core

Changeset 12 in tests


Ignore:
Timestamp:
09/20/07 09:06:36 (7 years ago)
Author:
tellyworth
Message:

fairly complete rss2 tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_includes_feed_rss2.php

    r11 r12  
    44 
    55// test the RSS 2.0 feed by generating a feed, parsing it, and checking that the 
    6 // contents are correct.  Since we're using a real XML parser, this also ensures 
    7 // that the feed is valid XML, and that the contents are correctly escaped and 
    8 // encoded. 
     6// parsed contents match the contents of the posts stored in the database.  Since 
     7// we're using a real XML parser, this confirms that the feed is valid, well formed, 
     8// and contains the right stuff. 
    99 
    1010class TestFeedRss2 extends _WPMediumBlog { 
    1111 
     12    function setUp() { 
     13        parent::setUp(); 
     14        $this->post_count = get_option('posts_per_rss'); 
     15        $this->excerpt_only = get_option('rss_use_excerpt'); 
     16        // this seems to break something 
     17        update_option('use_smilies', false); 
     18    } 
     19 
    1220    function do_rss2() { 
    1321        ob_start(); 
     22        // nasty hack 
     23        global $post; 
    1424        require(ABSPATH.'wp-includes/feed-rss2.php'); 
    1525        $out = ob_get_clean(); 
     
    6474        $this->http('/feed/'); 
    6575        $feed = $this->do_rss2(); 
    66         $data = xml_to_array($feed); 
     76        $xml = xml_to_array($feed); 
    6777 
    68         // get all the rss -> channel -> item -> title elements 
    69         $titles = xml_find($data, 'rss', 'channel', 'item', 'title'); 
     78        // get all the rss -> channel -> item elements 
     79        $items = xml_find($xml, 'rss', 'channel', 'item'); 
     80        $posts = get_posts('numberposts='.$this->post_count); 
    7081 
    71         $this->assertEquals('post title 24', $titles[0]['content']); 
    72         $this->assertEquals('post title 23', $titles[1]['content']); 
    73         $this->assertEquals('post title 22', $titles[2]['content']); 
    74         $this->assertEquals('post title 21', $titles[3]['content']); 
    75         $this->assertEquals('post title 20', $titles[4]['content']); 
    76         $this->assertEquals('post title 19', $titles[5]['content']); 
    77         $this->assertEquals('post title 18', $titles[6]['content']); 
    78         $this->assertEquals('post title 17', $titles[7]['content']); 
    79         $this->assertEquals('post title 16', $titles[8]['content']); 
    80         $this->assertEquals('post title 15', $titles[9]['content']); 
     82        // check each of the items against the known post data 
     83        for ($i=0; $i < $this->post_count; $i++) { 
     84 
     85            // title 
     86            $title = xml_find($items[$i]['child'], 'title'); 
     87            $this->assertEquals($posts[$i]->post_title, $title[0]['content']); 
     88 
     89            // link 
     90            $link = xml_find($items[$i]['child'], 'link'); 
     91            $this->assertEquals(get_permalink($posts[$i]->ID), $link[0]['content']); 
     92 
     93            // comment link 
     94            $comments_link = xml_find($items[$i]['child'], 'comments'); 
     95            $this->assertEquals(get_permalink($posts[$i]->ID) . '#comments', $comments_link[0]['content']); 
     96 
     97            // pub date 
     98            $pubdate = xml_find($items[$i]['child'], 'pubDate'); 
     99            $this->assertEquals(strtotime($posts[$i]->post_date), strtotime($pubdate[0]['content'])); 
     100 
     101            // author 
     102            $creator = xml_find($items[$i]['child'], 'dc:creator'); 
     103            $this->assertEquals($this->author->user_nicename, $creator[0]['content']); 
     104 
     105            // categories (perhaps multiple) 
     106            $categories = xml_find($items[$i]['child'], 'category'); 
     107            $cat_ids = wp_get_post_categories($post->ID); 
     108            if (empty($cat_ids))    $cat_ids = array(1); 
     109            // should be the same number of categories 
     110            $this->assertEquals(count($cat_ids), count($categories)); 
     111            // ..with the same names 
     112            for ($j=0; $j < count($cat_ids); $j++) 
     113                $this->assertEquals(get_cat_name($cat_ids[$j]), $categories[$j]['content']); 
     114 
     115            // GUID 
     116            $guid = xml_find($items[$i]['child'], 'guid'); 
     117            $this->assertEquals('false', $guid[0]['attributes']['isPermaLink']); 
     118            $this->assertEquals($posts[$i]->guid, $guid[0]['content']); 
     119 
     120            // description/excerpt 
     121            $description = xml_find($items[$i]['child'], 'description'); 
     122            $this->assertEquals(trim($posts[$i]->post_excerpt), trim($description[0]['content'])); 
     123 
     124            // post content 
     125            if (!$this->excerpt_only) { 
     126                $content = xml_find($items[$i]['child'], 'content:encoded'); 
     127                $this->assertEquals(trim(apply_filters('the_content', $posts[$i]->post_content)), trim($content[0]['content'])); 
     128            } 
     129 
     130            // comment rss 
     131            $comment_rss = xml_find($items[$i]['child'], 'wfw:commentRss'); 
     132            $this->assertEquals(html_entity_decode(get_post_comments_feed_link($posts[$i]->ID)), $comment_rss[0]['content']); 
     133        } 
     134 
    81135    } 
    82136} 
Note: See TracChangeset for help on using the changeset viewer.