From 62c6d364193da31173b411b7531e3f1f6db54e5c Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Thu, 23 Jul 2020 16:36:32 -0400 Subject: [PATCH] Documentation added to Test_WP_Stream_Connector_Posts class --- .../connectors/test-class-connector-posts.php | 36 ++++++++++++++++--- 1 file changed, 31 insertions(+), 5 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-posts.php b/tests/tests/connectors/test-class-connector-posts.php index f9fc5bfc8..daf617359 100644 --- a/tests/tests/connectors/test-class-connector-posts.php +++ b/tests/tests/connectors/test-class-connector-posts.php @@ -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(); @@ -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( @@ -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', @@ -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', @@ -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( @@ -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' ) ); }