Skip to content
This repository has been archived by the owner on Nov 28, 2019. It is now read-only.

Commit

Permalink
Assert that the new post ID is passed to the ImportPost #57
Browse files Browse the repository at this point in the history
  • Loading branch information
dnaber-de committed Feb 12, 2016
1 parent 3652c4c commit f599551
Showing 1 changed file with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public function test_import_post( Array $post_data, Array $meta_data, Array $id_
->method( 'action_fired' )
->with( $text_action );

/**
* Todo: #57
* Instantiate the new actors here, and bind them to the action.
* The tests should still pass then.
*/
add_action(
$text_action,
/**
Expand All @@ -77,6 +82,10 @@ function( $wp_post, $import_post )
$import_post_mock,
$import_post
);
$this->assertSame(
$wp_post->ID,
$import_post->id()
);
$this->make_post_assertions( $wp_post, $import_post, $id_map );
$this->make_meta_assertions( $wp_post, $meta_data );
$this->make_term_assertions( $wp_post, $import_post, $term_data );
Expand Down Expand Up @@ -260,7 +269,30 @@ public function build_import_post_mock( Array $post_data, Array $meta_data, $ter
);
}

return $this->mock_builder->type_wp_import_post( [], $post_data );
$post_mock = $this->mock_builder->type_wp_import_post( [], $post_data );

/**
* WpPostImporter MUST pass the new wp-post id to the import post object.
* Its used as a one-time setter. Each ensuing call will return this new post id.
* This is asserted in test_import_post()
*/
$post_mock->expects( $this->atLeast( 1 ) )
->method( 'id' )
->willReturnCallback(
function( $id = NULL ) {
static $local_id;
if ( ! $local_id ) {
$local_id = 0;
}
if ( ! $id || $local_id )
return $local_id;

$local_id = (int) $id;
return $local_id;
}
);

return $post_mock;
}

/**
Expand Down

0 comments on commit f599551

Please sign in to comment.