Changeset 86 in tests
- Timestamp:
- 11/17/2007 08:26:04 PM (19 years ago)
- File:
-
- 1 edited
-
wp-testlib/base.php (modified) (5 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
wp-testlib/base.php
-
Property
svn:eol-style
set to
native
r75 r86 174 174 175 175 // insert a given number of trivial posts, each with predictable title, content and excerpt 176 function _insert_quick_posts($num, $type='post' ) {176 function _insert_quick_posts($num, $type='post', $more = array()) { 177 177 for ($i=0; $i<$num; $i++) 178 $this->post_ids[] = wp_insert_post(array (178 $this->post_ids[] = wp_insert_post(array_merge(array( 179 179 'post_author' => $this->author->ID, 180 180 'post_status' => 'publish', … … 182 182 'post_content' => "{$type} content {$i}", 183 183 'post_excerpt' => "{$type} excerpt {$i}", 184 ), $more)); 185 } 186 187 function _insert_quick_comments($post_id, $num=3) { 188 for ($i=0; $i<$num; $i++) { 189 wp_insert_comment(array( 190 'comment_post_ID' => $post_id, 191 'comment_author' => "Commenter $i", 192 'comment_author_url' => "http://example.com/$i/", 193 'comment_approved' => 1, 184 194 )); 195 } 185 196 } 186 197 … … 196 207 assert('!empty($path)'); 197 208 assert('is_file($path)'); 198 199 $_POST = array('user'=>$users, 'userselect'=>array()); 209 210 $userselect = array(); 211 foreach ($users as $k=>$v) 212 $userselect[$k] = '#NONE#'; 213 214 $_POST = array('user'=>$users, 'userselect'=>$userselect); 200 215 201 216 // this is copied from WP_Import::import() 202 217 // we can't call that function directly because it expects a file ID 203 218 $importer->file = realpath($filename); 204 $importer->get_ entries();205 var_dump($importer->get_wp_authors());219 $importer->get_authors_from_post(); 220 $importer->get_entries(array(&$importer, 'process_post')); 206 221 $importer->process_categories(); 222 $importer->process_tags(); 207 223 $importer->process_posts(); 208 224 … … 213 229 // When run, the tests will check that the content of the blog exactly matches what it is now, 214 230 // with a separate test function for each post. 215 function _generate_post_content_test(&$posts ) {231 function _generate_post_content_test(&$posts, $separate_funcs = true) { 216 232 $out = ''; 233 if (!$separate_funcs) 234 $out .= "\n\tfunction test_all_posts() {\n"; 217 235 foreach ($posts as $i=>$post) { 218 $out .= "\n\tfunction test_post_{$i}() {\n"; 236 if ($separate_funcs) 237 $out .= "\n\tfunction test_post_{$i}() {\n"; 219 238 $out .= "\t\t\$post = \$this->posts[{$i}];\n"; 220 239 foreach (array_keys(get_object_vars($post)) as $field) { 221 240 if ($field == 'guid') 222 241 $out .= "\t\t".'$this->assertEquals(get_permalink($post->ID), $post->guid);'."\n"; 242 elseif ($field == 'post_parent' and !empty($post->post_parent)) 243 $out .= "\t\t".'$this->assertEquals("'.get_permalink($post->post_parent).'", get_permalink($post->post_parent));'."\n"; 223 244 elseif ($field != 'ID') 224 $out .= "\t\t".'$this->assertEquals("'.addcslashes($post->$field, "\$\n\r\t '\"\\").'", $post->'.$field.');'."\n";245 $out .= "\t\t".'$this->assertEquals("'.addcslashes($post->$field, "\$\n\r\t\"\\").'", $post->'.$field.');'."\n"; 225 246 } 226 247 $cat_ids = wp_get_post_categories($post->ID); … … 231 252 $out .= "\t\t".'$this->assertEquals(\''.addslashes(get_cat_name($cat_id)).'\', get_cat_name($cats['.$j.']));'."\n"; 232 253 } 254 255 $tags = wp_get_post_tags($post->ID); 256 $out .= "\t\t".'$tags = wp_get_post_tags($post->ID);'."\n"; 257 $out .= "\t\t".'$this->assertEquals('.count($tags).', count($tags));'."\n"; 258 if ($tags) { 259 foreach ($tags as $j=>$tag) { 260 $out .= "\t\t".'$this->assertEquals(\''.addslashes($tag->name).'\', $tags['.$j.']->name);'."\n"; 261 $out .= "\t\t".'$this->assertEquals(\''.addslashes($tag->slug).'\', $tags['.$j.']->slug);'."\n"; 262 } 263 } 264 265 if ($separate_funcs) 266 $out .= "\t}\n\n"; 267 else 268 $out .= "\n\n"; 269 } 270 if (!$separate_funcs) 233 271 $out .= "\t}\n\n"; 234 }235 236 272 return $out; 237 273 } -
Property
svn:eol-style
set to
Note: See TracChangeset
for help on using the changeset viewer.