| Conditions | 10 |
| Paths | 73 |
| Total Lines | 77 |
| Code Lines | 39 |
| Lines | 4 |
| Ratio | 5.19 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 135 | function test_entry_elements() |
||
| 136 | { |
||
| 137 | $this->go_to('/?feed=atom'); |
||
| 138 | $feed = $this->do_atom(); |
||
| 139 | $xml = xml_to_array($feed); |
||
| 140 | |||
| 141 | // Get all the <entry> child elements of the <feed> element. |
||
| 142 | $entries = xml_find($xml, 'feed', 'entry'); |
||
| 143 | |||
| 144 | // Verify we are displaying the correct number of posts. |
||
| 145 | $this->assertCount($this->post_count, $entries); |
||
| 146 | |||
| 147 | // We Really only need to test X number of entries unless the content is different |
||
| 148 | $entries = array_slice($entries, 1); |
||
| 149 | |||
| 150 | // Check each of the desired entries against the known post data. |
||
| 151 | foreach ( $entries as $key => $entry ) { |
||
| 152 | |||
| 153 | // Get post for comparison |
||
| 154 | $id = xml_find($entries[$key]['child'], 'id'); |
||
| 155 | preg_match('/\?p=(\d+)/', $id[0]['content'], $matches); |
||
| 156 | $post = get_post($matches[1]); |
||
| 157 | |||
| 158 | // Author |
||
| 159 | $author = xml_find($entries[$key]['child'], 'author', 'name'); |
||
| 160 | $user = new WP_User($post->post_author); |
||
| 161 | $this->assertEquals($user->display_name, $author[0]['content']); |
||
| 162 | |||
| 163 | // Title |
||
| 164 | $title = xml_find($entries[$key]['child'], 'title'); |
||
| 165 | $this->assertEquals($post->post_title, $title[0]['content']); |
||
| 166 | |||
| 167 | // Link rel="alternate" |
||
| 168 | $link_alts = xml_find($entries[$key]['child'], 'link'); |
||
| 169 | foreach ( $link_alts as $link_alt ) { |
||
| 170 | if ('alternate' == $link_alt['attributes']['rel'] ) { |
||
| 171 | $this->assertEquals(get_permalink($post), $link_alt['attributes']['href']); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | |||
| 175 | // Id |
||
| 176 | $guid = xml_find($entries[$key]['child'], 'id'); |
||
| 177 | $this->assertEquals($post->guid, $id[0]['content']); |
||
| 178 | |||
| 179 | // Updated |
||
| 180 | $updated = xml_find($entries[$key]['child'], 'updated'); |
||
| 181 | $this->assertEquals(strtotime($post->post_modified_gmt), strtotime($updated[0]['content'])); |
||
| 182 | |||
| 183 | // Published |
||
| 184 | $published = xml_find($entries[$key]['child'], 'published'); |
||
| 185 | $this->assertEquals(strtotime($post->post_date_gmt), strtotime($published[0]['content'])); |
||
| 186 | |||
| 187 | // Category |
||
| 188 | foreach ( get_the_category($post->ID) as $term ) { |
||
| 189 | $terms[] = $term->name; |
||
| 190 | } |
||
| 191 | $categories = xml_find($entries[$key]['child'], 'category'); |
||
| 192 | foreach ( $categories as $category ) { |
||
| 193 | $this->assertTrue(in_array($category['attributes']['term'], $terms)); |
||
| 194 | } |
||
| 195 | unset($terms); |
||
| 196 | |||
| 197 | // Content |
||
| 198 | View Code Duplication | if (! $this->excerpt_only ) { |
|
| 199 | $content = xml_find($entries[$key]['child'], 'content'); |
||
| 200 | $this->assertEquals(trim(apply_filters('the_content', $post->post_content)), trim($content[0]['content'])); |
||
| 201 | } |
||
| 202 | |||
| 203 | // Link rel="replies" |
||
| 204 | $link_replies = xml_find($entries[$key]['child'], 'link'); |
||
| 205 | foreach ( $link_replies as $link_reply ) { |
||
| 206 | if ('replies' == $link_reply['attributes']['rel'] && 'application/atom+xml' == $link_reply['attributes']['type'] ) { |
||
| 207 | $this->assertEquals(get_post_comments_feed_link($post->ID, 'atom'), $link_reply['attributes']['href']); |
||
| 208 | } |
||
| 209 | } |
||
| 210 | } |
||
| 211 | } |
||
| 212 | } |
||
| 213 |