<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[2174] 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php: Added standard test case (`small-export.xml`) from core unit tests.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://gsoc.trac.wordpress.org/changeset/2174">2174</a></dd>
<dt>Author</dt> <dd>frederick.ding</dd>
<dt>Date</dt> <dd>2013-07-29 18:37:33 +0000 (Mon, 29 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Added standard test case (`small-export.xml`) from core unit tests. Passes!

- See <a href="http://gsoc.trac.wordpress.org/ticket/332">#332</a></pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#2013frederickdingimportertrunkteststestclasswordpressimporterphp">2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="2013frederickdingimportertrunkteststestclasswordpressimporterphp"></a>
<div class="modfile"><h4>Modified: 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php (2173 => 2174)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php        2013-07-29 18:37:20 UTC (rev 2173)
+++ 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php   2013-07-29 18:37:33 UTC (rev 2174)
</span><span class="lines">@@ -56,7 +56,7 @@
</span><span class="cx">   */
</span><span class="cx">  public function test___construct() {
</span><span class="cx">          $instance = new WordPress_Importer();
</span><del>-               
</del><ins>+                        
</ins><span class="cx">           // check for hooks
</span><span class="cx">          $this->assertNotEquals( false, 
</span><span class="cx">                          has_filter( 'cron_schedules', 
</span><span class="lines">@@ -309,9 +309,6 @@
</span><span class="cx">          $this->assertTrue( $instance->do_import() );
</span><span class="cx">          $this->assertNull( $instance->get_error() );
</span><span class="cx">          
</span><del>-               // this specific import file was only meant for testing the parser, 
-               // so we DO expect an invalid taxonomy warning
-               
</del><span class="cx">           $instance->do_cleanup();
</span><span class="cx">          
</span><span class="cx">          // check author was imported correctly
</span><span class="lines">@@ -366,6 +363,208 @@
</span><span class="cx">          $this->assertEquals( 1, count($tags) );
</span><span class="cx">          $this->assertEquals( 'clippable', $tags[0]->slug );
</span><span class="cx">  }
</span><ins>+       
+       /**
+        * Standard test case of a WXR file, not utilizing cron scheduler.
+        *
+        * @depends test_save_vars
+        * @depends test_advance
+        * @depends test_get_error
+        * @depends test_get_warnings
+        * @depends test_params
+        */
+       public function test_wxr_standard() {
+           $instance = new WordPress_Importer();
+                       
+                       // use the WordPress core test case
+               $authors = array(
+                               'admin',
+                               'editor',
+                               'author'
+               );
+               $wxr_file = DIR_TESTDATA . '/export/small-export.xml';
+               $this->assertNotInstanceOf( 'WP_Error', 
+                               $parse = $instance->do_parse( $wxr_file ) );
+               
+               // set the parameters necessary for the process to run
+               $this->assertTrue( 
+                               $instance->set_param( 'imported_authors', $authors ) );
+               $this->assertEquals( 'start', $instance->advance( 'start' ) );
+               $this->assertTrue( $instance->is_allowed_user_creation() );
+               
+               // should be done in one cron run
+               $this->assertTrue( $instance->do_import() );
+               $this->assertNull( $instance->get_error() );
+               $this->assertEmpty( $instance->get_warnings() );
+               $instance->do_cleanup();
+               
+               // ensure that authors were imported correctly
+               $user_count = count_users();
+               $this->assertEquals( 3, $user_count['total_users'] );
+               $admin = get_user_by( 'login', 'admin' );
+               $this->assertEquals( 'admin', $admin->user_login );
+               $this->assertEquals( 'local@host.null', $admin->user_email );
+               $editor = get_user_by( 'login', 'editor' );
+               $this->assertEquals( 'editor', $editor->user_login );
+               $this->assertEquals( 'editor@example.org', $editor->user_email );
+               $this->assertEquals( 'FirstName', $editor->user_firstname );
+               $this->assertEquals( 'LastName', $editor->user_lastname );
+               $author = get_user_by( 'login', 'author' );
+               $this->assertEquals( 'author', $author->user_login );
+               $this->assertEquals( 'author@example.org', $author->user_email );
+               
+               // check that terms were imported correctly
+               $this->assertEquals( 30, wp_count_terms( 'category' ) );
+               $this->assertEquals( 3, wp_count_terms( 'post_tag' ) );
+               $foo = get_term_by( 'slug', 'foo', 'category' );
+               $this->assertEquals( 0, $foo->parent );
+               $bar = get_term_by( 'slug', 'bar', 'category' );
+               $foo_bar = get_term_by( 'slug', 'foo-bar', 'category' );
+               $this->assertEquals( $bar->term_id, $foo_bar->parent );
+               
+               // check that posts/pages were imported correctly
+               $post_count = wp_count_posts( 'post' );
+               $this->assertEquals( 5, $post_count->publish );
+               $this->assertEquals( 1, $post_count->private );
+               $page_count = wp_count_posts( 'page' );
+               $this->assertEquals( 4, $page_count->publish );
+               $this->assertEquals( 1, $page_count->draft );
+               $comment_count = wp_count_comments();
+               $this->assertEquals( 1, $comment_count->total_comments );
+               
+               $posts = get_posts( 
+                               array(
+                                               'numberposts' => 20,
+                                               'post_type' => 'any',
+                                               'post_status' => 'any',
+                                               'orderby' => 'ID'
+                               ) );
+               $this->assertEquals( 11, count( $posts ) );
+               
+               $post = $posts[0];
+               $this->assertEquals( 'Many Categories', $post->post_title );
+               $this->assertEquals( 'many-categories', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID );
+               $this->assertEquals( 27, count( $cats ) );
+               
+               $post = $posts[1];
+               $this->assertEquals( 'Non-standard post format', $post->post_title );
+               $this->assertEquals( 'non-standard-post-format', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID );
+               $this->assertEquals( 1, count( $cats ) );
+               $this->assertTrue( has_post_format( 'aside', $post->ID ) );
+               
+               $post = $posts[2];
+               $this->assertEquals( 'Top-level Foo', $post->post_title );
+               $this->assertEquals( 'top-level-foo', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID, 
+                               array(
+                                               'fields' => 'all'
+                               ) );
+               $this->assertEquals( 1, count( $cats ) );
+               $this->assertEquals( 'foo', $cats[0]->slug );
+               
+               $post = $posts[3];
+               $this->assertEquals( 'Foo-child', $post->post_title );
+               $this->assertEquals( 'foo-child', $post->post_name );
+               $this->assertEquals( $editor->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID, 
+                               array(
+                                               'fields' => 'all'
+                               ) );
+               $this->assertEquals( 1, count( $cats ) );
+               $this->assertEquals( 'foo-bar', $cats[0]->slug );
+               
+               $post = $posts[4];
+               $this->assertEquals( 'Private Post', $post->post_title );
+               $this->assertEquals( 'private-post', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'private', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID );
+               $this->assertEquals( 1, count( $cats ) );
+               $tags = wp_get_post_tags( $post->ID );
+               $this->assertEquals( 3, count( $tags ) );
+               $this->assertEquals( 'tag1', $tags[0]->slug );
+               $this->assertEquals( 'tag2', $tags[1]->slug );
+               $this->assertEquals( 'tag3', $tags[2]->slug );
+               
+               $post = $posts[5];
+               $this->assertEquals( '1-col page', $post->post_title );
+               $this->assertEquals( '1-col-page', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'page', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $this->assertEquals( 'onecolumn-page.php', 
+                               get_post_meta( $post->ID, '_wp_page_template', true ) );
+               
+               $post = $posts[6];
+               $this->assertEquals( 'Draft Page', $post->post_title );
+               $this->assertEquals( '', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'page', $post->post_type );
+               $this->assertEquals( 'draft', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $this->assertEquals( 'default', 
+                               get_post_meta( $post->ID, '_wp_page_template', true ) );
+               
+               $post = $posts[7];
+               $this->assertEquals( 'Parent Page', $post->post_title );
+               $this->assertEquals( 'parent-page', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'page', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $this->assertEquals( 'default', 
+                               get_post_meta( $post->ID, '_wp_page_template', true ) );
+               
+               $post = $posts[8];
+               $this->assertEquals( 'Child Page', $post->post_title );
+               $this->assertEquals( 'child-page', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'page', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( $posts[7]->ID, $post->post_parent );
+               $this->assertEquals( 'default', 
+                               get_post_meta( $post->ID, '_wp_page_template', true ) );
+               
+               $post = $posts[9];
+               $this->assertEquals( 'Sample Page', $post->post_title );
+               $this->assertEquals( 'sample-page', $post->post_name );
+               $this->assertEquals( $admin->ID, $post->post_author );
+               $this->assertEquals( 'page', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $this->assertEquals( 'default', 
+                               get_post_meta( $post->ID, '_wp_page_template', true ) );
+               
+               $post = $posts[10];
+               $this->assertEquals( 'Hello world!', $post->post_title );
+               $this->assertEquals( 'hello-world', $post->post_name );
+               $this->assertEquals( $author->ID, $post->post_author );
+               $this->assertEquals( 'post', $post->post_type );
+               $this->assertEquals( 'publish', $post->post_status );
+               $this->assertEquals( 0, $post->post_parent );
+               $cats = wp_get_post_categories( $post->ID );
+               $this->assertEquals( 1, count( $cats ) );
+       }
</ins><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * Uses Reflection to call otherwise inaccessible methods.
</span></span></pre>
</div>
</div>

</body>
</html>