Changeset 42343 for trunk/tests/phpunit/tests/feed/atom.php
- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/feed/atom.php
r38927 r42343 19 19 public static function wpSetUpBeforeClass( $factory ) { 20 20 // Create a user 21 self::$user_id = $factory->user->create( array( 22 'role' => 'author', 23 'user_login' => 'test_author', 24 'display_name' => 'Test A. Uthor', 25 ) ); 21 self::$user_id = $factory->user->create( 22 array( 23 'role' => 'author', 24 'user_login' => 'test_author', 25 'display_name' => 'Test A. Uthor', 26 ) 27 ); 26 28 27 29 // Create a taxonomy 28 self::$category = self::factory()->category->create_and_get( array( 29 'name' => 'Test Category', 30 'slug' => 'test-cat', 31 ) ); 30 self::$category = self::factory()->category->create_and_get( 31 array( 32 'name' => 'Test Category', 33 'slug' => 'test-cat', 34 ) 35 ); 32 36 33 37 $count = get_option( 'posts_per_rss' ) + 1; 34 38 35 39 // Create a few posts 36 self::$posts = $factory->post->create_many( $count, array( 37 'post_author' => self::$user_id, 38 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.', 39 'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 40 ) ); 40 self::$posts = $factory->post->create_many( 41 $count, array( 42 'post_author' => self::$user_id, 43 'post_content' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec velit massa, ultrices eu est suscipit, mattis posuere est. Donec vitae purus lacus. Cras vitae odio odio.', 44 'post_excerpt' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', 45 ) 46 ); 41 47 42 48 // Assign a category to those posts … … 53 59 parent::setUp(); 54 60 55 $this->post_count = (int) get_option( 'posts_per_rss' );61 $this->post_count = (int) get_option( 'posts_per_rss' ); 56 62 $this->excerpt_only = get_option( 'rss_use_excerpt' ); 57 63 } … … 81 87 $this->go_to( '/?feed=atom' ); 82 88 $feed = $this->do_atom(); 83 $xml = xml_to_array( $feed );89 $xml = xml_to_array( $feed ); 84 90 85 91 // Get the <feed> child element of <xml>. … … 92 98 $this->assertEquals( 'http://www.w3.org/2005/Atom', $atom[0]['attributes']['xmlns'] ); 93 99 $this->assertEquals( 'http://purl.org/syndication/thread/1.0', $atom[0]['attributes']['xmlns:thr'] ); 94 $this->assertEquals( site_url( '/wp-atom.php' ) 100 $this->assertEquals( site_url( '/wp-atom.php' ), $atom[0]['attributes']['xml:base'] ); 95 101 96 102 // Verify the <feed> element is present and contains a <title> child element. … … 125 131 $this->go_to( '/?feed=atom' ); 126 132 $feed = $this->do_atom(); 127 $xml = xml_to_array( $feed );133 $xml = xml_to_array( $feed ); 128 134 129 135 // Get all the <entry> child elements of the <feed> element. … … 140 146 141 147 // Get post for comparison 142 $id = xml_find( $entries[ $key]['child'], 'id' );148 $id = xml_find( $entries[ $key ]['child'], 'id' ); 143 149 preg_match( '/\?p=(\d+)/', $id[0]['content'], $matches ); 144 150 $post = get_post( $matches[1] ); 145 151 146 152 // Author 147 $author = xml_find( $entries[ $key]['child'], 'author', 'name' );148 $user = new WP_User( $post->post_author );153 $author = xml_find( $entries[ $key ]['child'], 'author', 'name' ); 154 $user = new WP_User( $post->post_author ); 149 155 $this->assertEquals( $user->display_name, $author[0]['content'] ); 150 156 151 157 // Title 152 $title = xml_find( $entries[ $key]['child'], 'title' );158 $title = xml_find( $entries[ $key ]['child'], 'title' ); 153 159 $this->assertEquals( $post->post_title, $title[0]['content'] ); 154 160 155 161 // Link rel="alternate" 156 $link_alts = xml_find( $entries[ $key]['child'], 'link' );162 $link_alts = xml_find( $entries[ $key ]['child'], 'link' ); 157 163 foreach ( $link_alts as $link_alt ) { 158 164 if ( 'alternate' == $link_alt['attributes']['rel'] ) { … … 162 168 163 169 // Id 164 $guid = xml_find( $entries[ $key]['child'], 'id' );170 $guid = xml_find( $entries[ $key ]['child'], 'id' ); 165 171 $this->assertEquals( $post->guid, $id[0]['content'] ); 166 172 167 173 // Updated 168 $updated = xml_find( $entries[ $key]['child'], 'updated' );174 $updated = xml_find( $entries[ $key ]['child'], 'updated' ); 169 175 $this->assertEquals( strtotime( $post->post_modified_gmt ), strtotime( $updated[0]['content'] ) ); 170 176 171 177 // Published 172 $published = xml_find( $entries[ $key]['child'], 'published' );178 $published = xml_find( $entries[ $key ]['child'], 'published' ); 173 179 $this->assertEquals( strtotime( $post->post_date_gmt ), strtotime( $published[0]['content'] ) ); 174 180 … … 177 183 $terms[] = $term->name; 178 184 } 179 $categories = xml_find( $entries[ $key]['child'], 'category' );185 $categories = xml_find( $entries[ $key ]['child'], 'category' ); 180 186 foreach ( $categories as $category ) { 181 187 $this->assertTrue( in_array( $category['attributes']['term'], $terms ) ); … … 185 191 // Content 186 192 if ( ! $this->excerpt_only ) { 187 $content = xml_find( $entries[ $key]['child'], 'content' );193 $content = xml_find( $entries[ $key ]['child'], 'content' ); 188 194 $this->assertEquals( trim( apply_filters( 'the_content', $post->post_content ) ), trim( $content[0]['content'] ) ); 189 195 } 190 196 191 197 // Link rel="replies" 192 $link_replies = xml_find( $entries[ $key]['child'], 'link' );198 $link_replies = xml_find( $entries[ $key ]['child'], 'link' ); 193 199 foreach ( $link_replies as $link_reply ) { 194 200 if ( 'replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type'] ) {
Note: See TracChangeset
for help on using the changeset viewer.