<!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>[2169] 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php: Add tests for process_posts() and using a real WXR file; see #332.</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/2169">2169</a></dd>
<dt>Author</dt> <dd>frederick.ding</dd>
<dt>Date</dt> <dd>2013-07-29 05:24:08 +0000 (Mon, 29 Jul 2013)</dd>
</dl>

<h3>Log Message</h3>
<pre>Add tests for process_posts() and using a real WXR file; see <a href="http://gsoc.trac.wordpress.org/ticket/332">#332</a>.

- Very incomplete at the moment, but necessary</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 (2168 => 2169)</h4>
<pre class="diff"><span>
<span class="info">--- 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php        2013-07-29 05:23:58 UTC (rev 2168)
+++ 2013/frederickding/importer/trunk/tests/test-class-wordpress-importer.php   2013-07-29 05:24:08 UTC (rev 2169)
</span><span class="lines">@@ -26,6 +26,8 @@
</span><span class="cx">                           '/class-wp-importer-cron.php';
</span><span class="cx">          require_once dirname( dirname( __FILE__ ) ) .
</span><span class="cx">                           '/class-wordpress-importer.php';
</span><ins>+               require_once dirname( dirname( __FILE__ ) ) .
+                                '/class-wxr-parser.php';
</ins><span class="cx">           
</span><span class="cx">          global $wpdb;
</span><span class="cx">          // crude but effective: make sure there's no residual data in the main
</span><span class="lines">@@ -86,13 +88,13 @@
</span><span class="cx">          // hack it into submission; nothing else will function without a
</span><span class="cx">          // properly defined wxr_file
</span><span class="cx">          self::set( $instance, 'wxr_file', 'test-nonexistent.xml' );
</span><del>-
</del><ins>+                
</ins><span class="cx">           // with no step defined
</span><span class="cx">          $this->assertEquals( 'start', $instance->advance() );
</span><span class="cx">          
</span><span class="cx">          // non-existent step
</span><span class="cx">          $this->assertWPError( $instance->advance( rand_str( 10 ) ) );
</span><del>-
</del><ins>+                        
</ins><span class="cx">           // if on a terms step, the next step is posts
</span><span class="cx">          $this->assertEquals( 'terms', $instance->advance( 'terms' ) );
</span><span class="cx">          $this->assertEquals( 'terms', $instance->get_step() );
</span><span class="lines">@@ -150,6 +152,7 @@
</span><span class="cx"> 
</span><span class="cx">  /**
</span><span class="cx">   * @depends test_get_error
</span><ins>+        * @depends test_get_warnings
</ins><span class="cx">    * @depends test_params
</span><span class="cx">   */
</span><span class="cx">  public function test_process_author_mappings_standalone() {
</span><span class="lines">@@ -224,6 +227,90 @@
</span><span class="cx">  }
</span><span class="cx"> 
</span><span class="cx">  /**
</span><ins>+        * @depends test_get_error
+        * @depends test_get_warnings
+        * @depends test_params
+        * @depends test_advance
+        */
+       public function test_process_posts_standalone() {
+               /*
+                * An empty posts array causes the process to advance
+                */
+               $instance = new WordPress_Importer();
+               
+               // hack it into submission; nothing else will function without a
+               // properly defined wxr_file
+               self::set( $instance, 'wxr_file', 'test-nonexistent.xml' );
+               
+               self::set( $instance, 'posts', array() );
+               $this->assertEquals( 'posts', $instance->advance( 'posts' ) );
+               $this->assertTrue( self::call( $instance, 'process_posts' ) );
+               $this->assertEmpty( $instance->get_error() );
+               $this->assertEmpty( $instance->get_warnings() );
+               $this->assertEquals( 'backfill_parents', 
+                               current( self::get( $instance, 'progress' ) ) );
+               
+               /*
+                * START OVER to test a post with non-existent post type
+                */
+               $instance2 = new WordPress_Importer();
+               
+               // hack it into submission; nothing else will function without a
+               // properly defined wxr_file
+               self::set( $instance2, 'wxr_file', 'test-nonexistent.xml' );
+               
+               self::set( $instance2, 'posts', 
+                               array(
+                                               array(
+                                                               'post_type' => rand_str( 12 )
+                                               )
+                               ) );
+               $this->assertEquals( 'posts', $instance2->advance( 'posts' ) );
+               $this->assertTrue( self::call( $instance2, 'process_posts' ) );
+               $this->assertEmpty( $instance2->get_error() );
+               $this->assertNotEmpty( $instance2->get_warnings() );
+               $this->assertWPError(current($instance2->get_warnings()));
+               $this->assertEquals('import_process_posts_post_type_warning', 
+                       current($instance2->get_warnings())->get_error_code());
+
+       }
+
+       /**
+        * Tiny test case of a valid 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_smallest() {
+               $instance = new WordPress_Importer();
+               
+               // use the WordPress core test case
+               $authors = array(
+                               'admin' => false,
+                               'editor' => false,
+                               'author' => false
+               );
+               $wxr_file = DIR_TESTDATA . '/export/valid-wxr-1.1.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( 'user_new', $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());
+               
+               $instance->do_cleanup();
+               
+       }
+
+       /**
</ins><span class="cx">    * Uses Reflection to call otherwise inaccessible methods.
</span><span class="cx">   *
</span><span class="cx">   * Although typically this wouldn't be used, the importer being tested uses
</span></span></pre>
</div>
</div>

</body>
</html>