From 47d2460634c593e32474f0210197ce7208b117f1 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 29 Jun 2020 20:39:02 -0400 Subject: [PATCH] test implemented and completed --- .../test-class-connector-bbpress.php | 90 ++++++++++++------- 1 file changed, 60 insertions(+), 30 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-bbpress.php b/tests/tests/connectors/test-class-connector-bbpress.php index e47d95d9b..dd727484b 100644 --- a/tests/tests/connectors/test-class-connector-bbpress.php +++ b/tests/tests/connectors/test-class-connector-bbpress.php @@ -2,14 +2,18 @@ namespace WP_Stream; class Test_WP_Stream_Connector_BbPress extends WP_StreamTestCase { - public function setUp() { parent::setUp(); + $post_connector = new Connector_Posts(); + $post_connector->register(); + // Make partial of Connector_ACF class, with mocked "log" function. $this->mock = $this->getMockBuilder( Connector_BbPress::class ) - ->setMethods( [ 'log', 'log_override' ] ) + ->setMethods( [ 'log' ] ) ->getMock(); + + $this->mock->register(); } public function tearDown() { @@ -21,49 +25,75 @@ public function test_bbpress_installed_and_activated() { } public function test_log_override() { - $this->mock->expects( $this->atLeastOnce() ) - ->method( 'log_override' ) - ->willReturn( - 'bbpress', - _x( - '"%1$s" %2$s published', + $asserted = false; + + add_action( + 'wp_stream_log_data', + function( $data ) use( &$asserted ) { + $message = _x( + '"%1$s" %2$s updated', '1: Post title, 2: Post type singular name', 'stream' - ), - array( - 'post_title' => 'Test Forum', - 'singular_name' => $post_type_name, - 'post_date' => $post->post_date, - 'post_date_gmt' => $post->post_date_gmt, - 'new_status' => $new, - 'old_status' => $old, - 'revision_id' => $revision_id, - ), - $this->greaterThan( 0 ), - 'forum', - 'publish', - null - ); + ); - bbp_insert_forum( [ 'post_title' => 'Test Forum' ] ); + $this->assertSame( 'bbpress', $data['connector'] ); + $this->assertSame( $message, $data['message'] ); + $this->assertSame( 'Test Forum', $data['args']['post_title'] ); + $this->assertSame( 'forum', $data['context'] ); + $this->assertSame( 'updated', $data['action'] ); + $asserted = true; + + return $data; + }, + 99 + ); + + $forum_id = bbp_insert_forum( [ 'post_title' => 'Test Forum' ] ); + + $this->assertGreaterThan( 0, $forum_id ); + $this->assertTrue( $asserted ); } public function test_callback_bbp_toggle_topic_admin() { - $this->markTestIncomplete( - 'Not implemented yet.' + $forum_id = bbp_insert_forum( [ 'post_title' => 'Test Forum' ] ); + $topic_id = bbp_insert_topic( + [ + 'post_title' => 'Test Topic', + 'post_parent' => $forum_id, + ] ); + $topic = get_post( $topic_id ); // Expected log calls. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) - ->withConsecutive( - + ->with( + $this->equalTo( _x( '%1$s "%2$s" topic', '1: Action, 2: Topic title', 'stream' ) ), + $this->equalTo( + array( + 'action_title' => esc_html_x( 'Closed', 'bbpress', 'stream' ), + 'topic_title' => $topic->post_title, + 'action' => 'closed', + ) + ), + $this->equalTo( $topic_id ), + $this->equalTo( 'topic' ), + $this->equalTo( 'closed' ) ); // Do stuff - + do_action( + 'bbp_toggle_topic_admin', + bbp_close_topic( $topic_id ), + array( 'ID' => $topic_id ), + 'bbp_toggle_topic_close', + array( + 'bbp_topic_toggle_notice' => 'closed', + 'topic_id' => $topic_id + ) + ); // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_save_post' ) ); + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_bbp_toggle_topic_admin' ) ); } }