Skip to content

Commit

Permalink
Network site connection remote get test added, #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Kolnik committed Oct 24, 2016
1 parent eb55dfc commit 8be66f4
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/php/NetworkSiteConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,39 @@ public function test_pull(){

}

/**
* Verifies that when passed no id the request can still return items
* @since 0.8
*/
public function test_remote_get_empty_id(){

$this->connection_obj->site->blog_id = 321;

\WP_Mock::userFunction( 'get_option' );

$this->assertArrayHasKey( 'total_items', $this->connection_obj->remote_get() );

}

/**
* Verifies that the remote_get method returns an array containing the post title.
*
* @since 0.8
*/
public function test_remote_get(){

$this->connection_obj->site->blog_id = 321;

\WP_Mock::userFunction( 'get_post', [
'return' => (object) [
'post_title' => 'my title',
]
] );

$this->assertArrayHasKey( 'post_title', (array) $this->connection_obj->remote_get( [

This comment has been minimized.

Copy link
@zanematthew

zanematthew Oct 24, 2016

@tlovett1 I feel a better test would be to check if this is an instance of WP_Post, if so, can you let me know what the code would be to check and possibly mock whats needed?

'id' => 123
] ) );

}

}
40 changes: 40 additions & 0 deletions tests/php/includes/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,46 @@ public function __construct( $code = '', $message = '' ) {
}
}

/**
* Hollowed out WP_Query class for mocking
*
* @since 0.8
*/
class WP_Query {
public function __construct( $args = array() ){

$items = [
[
'ID' => 2,
'title' => 'my title a',
'content' => 'my content a',
],
[
'ID' => 188,
'title' => 'my title b',
'content' => 'my content b',
],
[
'ID' => 198,
'title' => 'my title c',
'content' => 'my content c',
]
];

foreach( $items as $item ){
foreach( $item as $key => $value ){
$tmp[ $key ] = $value;
}
$posts[] = (object) $tmp;
}

$this->found_posts = count( $items );
$this->posts = $posts;

}

}

/**
* Check if object is WP_Error
*
Expand Down

0 comments on commit 8be66f4

Please sign in to comment.