Skip to content

Commit

Permalink
Documentation added to Test_WP_Stream_Connector_Posts class
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Jul 23, 2020
1 parent 8c8a1bf commit 62c6d36
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions tests/tests/connectors/test-class-connector-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,31 @@
namespace WP_Stream;

class Test_WP_Stream_Connector_Posts extends WP_StreamTestCase {
/**
* Holds local timestamp in "Y-m-d H:i:s" format
*
* @var string
*/
private $date;

/**
* Holds GMT timestamp in "Y-m-d H:i:s" format
*
* @var string
*/
private $date_gmt;

/**
* Runs before each test.
*/
public function setUp() {
parent::setUp();

// Set static timestamps.
$this->date = '2007-07-04 12:30:00';
$this->date_gmt = get_gmt_from_date( $this->date );

// Make partial of Connector_ACF class, with mocked "log" function.
// Make partial of Connector_Posts class, with mocked "log" function.
$this->mock = $this->getMockBuilder( Connector_Posts::class )
->setMethods( [ 'log' ] )
->getMock();
Expand All @@ -20,8 +35,12 @@ public function setUp() {
$this->mock->register();
}

/**
* Tests "transition_post_status" callback function.
*/
public function test_callback_transition_post_status() {
$this->mock->expects( $this->atLeastOnce() )
// Set expected calls for the Mock.
$this->mock->expects( $this->once() )
->method( 'log' )
->with(
$this->equalTo(
Expand All @@ -47,7 +66,7 @@ public function test_callback_transition_post_status() {
$this->equalTo( 'updated' )
);

// Do stuff
// Create post and trigger mock.
wp_insert_post(
array(
'post_title' => 'Test post',
Expand All @@ -58,10 +77,15 @@ public function test_callback_transition_post_status() {
)
);

// Confirm callback execution.
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_transition_post_status' ) );
}

/**
* Tests "deleted_post" callback function.
*/
public function test_callback_deleted_post() {
// Create post for later use.
$post_id = wp_insert_post(
array(
'post_title' => 'Test post',
Expand All @@ -70,7 +94,8 @@ public function test_callback_deleted_post() {
)
);

$this->mock->expects( $this->atLeastOnce() )
// Set expected calls for the Mock.
$this->mock->expects( $this->once() )
->method( 'log' )
->with(
$this->equalTo(
Expand All @@ -91,9 +116,10 @@ public function test_callback_deleted_post() {
$this->equalTo( 'deleted' )
);

// Do stuff
// Delete post and trigger mock.
wp_delete_post( $post_id, true );

// Confirm callback execution.
$this->assertFalse( 0 === did_action( 'wp_stream_test_callback_deleted_post' ) );
}

Expand Down

0 comments on commit 62c6d36

Please sign in to comment.