Skip to content

Commit

Permalink
WP_Stream_Importer unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel committed Nov 27, 2024
1 parent c803e59 commit eb33f20
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
41 changes: 22 additions & 19 deletions packages/playground/data-liberation/tests/WPStreamImporterTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,38 +24,41 @@ public function test_import_simple_wxr() {
/**
* @wip
*/
public function test_resume_frontloading() {
$wxr_path = __DIR__ . '/wxr/frontloading-1-attachment.xml';
$importer = WP_Stream_Importer::create_for_wxr_file( $wxr_path );
$this->skip_to_stage( $importer, WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS );
$this->assertTrue( $importer->advance_to_next_stage() );
for($i = 0; $i < 20; ++$i) {
$progress = $importer->get_frontloading_progress();
if( count( $progress ) === 0 ) {
continue;
}
var_dump( $importer->get_frontloading_events() );
var_dump( $importer->next_step() );
}
$this->assertFalse( true );
}
// public function test_resume_frontloading() {
// $wxr_path = __DIR__ . '/wxr/frontloading-1-attachment.xml';
// $importer = WP_Stream_Importer::create_for_wxr_file( $wxr_path );
// $this->skip_to_stage( $importer, WP_Stream_Importer::STAGE_FRONTLOAD_ASSETS );
// $this->assertTrue( $importer->advance_to_next_stage() );
// for($i = 0; $i < 20; ++$i) {
// $progress = $importer->get_frontloading_progress();
// if( count( $progress ) === 0 ) {
// continue;
// }
// var_dump( $importer->get_frontloading_events() );
// var_dump( $importer->next_step() );
// }
// $this->assertFalse( true );
// }

/**
* @wip
*
*/
public function test_resume_entity_import() {
$wxr_path = __DIR__ . '/wxr/entities-options-and-posts.xml';
$importer = WP_Stream_Importer::create_for_wxr_file( $wxr_path );
$this->skip_to_stage( $importer, WP_Stream_Importer::STAGE_IMPORT_ENTITIES );

for($i = 0; $i < 15; ++$i) {
for($i = 0; $i < 11; ++$i) {
$this->assertTrue( $importer->next_step() );
$cursor = $importer->get_reentrancy_cursor();
$importer = WP_Stream_Importer::create_for_wxr_file( $wxr_path, [], $cursor );
// Rewind back to the step we were on.
// Rewind back to the entity we were on.
// Note this means we may attempt to insert it twice. It's
// the importer's job to detect that and skip the duplicate
// insertion.
$this->assertTrue( $importer->next_step() );
}
$this->assertFalse( true );
$this->assertFalse( $importer->next_step() );
}

private function skip_to_stage( WP_Stream_Importer $importer, string $stage ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
},
{
"step": "runPHP",
"code": "<?php require_once '/wordpress/wp-load.php'; $base = '/wordpress/wp-content/plugins/data-liberation/';\nrequire $base . 'vendor/autoload.php';\ntry {\n$arguments = [\n'--stderr','--filter','test_resume_entity_import',\n'--configuration', $base . 'phpunit.xml'\n];\n$res = (new PHPUnit\\TextUI\\Application())->run($arguments);\nif ( $res !== 0 ) {\ntrigger_error('PHPUnit failed', E_USER_ERROR);\n}\n} catch (Throwable $e) {\ntrigger_error('PHPUnit failed: ' . $e->getMessage(), E_USER_ERROR);\n};"
"code": "<?php require_once '/wordpress/wp-load.php'; $base = '/wordpress/wp-content/plugins/data-liberation/';\nrequire $base . 'vendor/autoload.php';\ntry {\n$arguments = [\n'--stderr',\n'--configuration', $base . 'phpunit.xml'\n];\n$res = (new PHPUnit\\TextUI\\Application())->run($arguments);\nif ( $res !== 0 ) {\ntrigger_error('PHPUnit failed', E_USER_ERROR);\n}\n} catch (Throwable $e) {\ntrigger_error('PHPUnit failed: ' . $e->getMessage(), E_USER_ERROR);\n};"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<generator>https://wordpress.org/?v=6.5.4</generator>

<item>
<title><![CDATA["The Road Not Taken" by Robert Frost]]></title>
<title><![CDATA[The first imported post: "The Road Not Taken" by Robert Frost]]></title>
<link>https://playground.internal/path/?p=1</link>
<pubDate>Wed, 05 Jun 2024 16:04:48 +0000</pubDate>
<dc:creator><![CDATA[admin]]></dc:creator>
Expand All @@ -90,7 +90,7 @@
<wp:post_modified_gmt><![CDATA[2024-06-10 12:28:55]]></wp:post_modified_gmt>
<wp:comment_status><![CDATA[open]]></wp:comment_status>
<wp:ping_status><![CDATA[open]]></wp:ping_status>
<wp:post_name><![CDATA[hello-world]]></wp:post_name>
<wp:post_name><![CDATA[the-first-imported-post]]></wp:post_name>
<wp:status><![CDATA[publish]]></wp:status>
<wp:post_parent>0</wp:post_parent>
<wp:menu_order>0</wp:menu_order>
Expand Down

0 comments on commit eb33f20

Please sign in to comment.