Make WordPress Core

Changeset 86 in tests


Ignore:
Timestamp:
11/17/2007 08:26:04 PM (19 years ago)
Author:
tellyworth
Message:

import test fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testlib/base.php

    • Property svn:eol-style set to native
    r75 r86  
    174174
    175175        // 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()) {
    177177                for ($i=0; $i<$num; $i++)
    178                         $this->post_ids[] = wp_insert_post(array(
     178                        $this->post_ids[] = wp_insert_post(array_merge(array(
    179179                                'post_author' => $this->author->ID,
    180180                                'post_status' => 'publish',
    … …  
    182182                                'post_content' => "{$type} content {$i}",
    183183                                '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,
    184194                                ));
     195                }
    185196        }
    186197
    … …  
    196207                assert('!empty($path)');
    197208                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);
    200215
    201216                // this is copied from WP_Import::import()
    202217                // we can't call that function directly because it expects a file ID
    203218                $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'));
    206221                $importer->process_categories();
     222                $importer->process_tags();
    207223                $importer->process_posts();
    208224
    … …  
    213229        // When run, the tests will check that the content of the blog exactly matches what it is now,
    214230        // 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) {
    216232                $out = '';
     233                if (!$separate_funcs)
     234                        $out .= "\n\tfunction test_all_posts() {\n";
    217235                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";
    219238                        $out .= "\t\t\$post = \$this->posts[{$i}];\n";
    220239                        foreach (array_keys(get_object_vars($post)) as $field) {
    221240                                if ($field == 'guid')
    222241                                        $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";
    223244                                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";
    225246                        }
    226247                        $cat_ids = wp_get_post_categories($post->ID);
    … …  
    231252                                        $out .= "\t\t".'$this->assertEquals(\''.addslashes(get_cat_name($cat_id)).'\', get_cat_name($cats['.$j.']));'."\n";
    232253                        }
     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)
    233271                        $out .= "\t}\n\n";
    234                 }
    235 
    236272                return $out;
    237273        }
Note: See TracChangeset for help on using the changeset viewer.