Skip to content

Commit

Permalink
test implemented and completed
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Jul 23, 2020
1 parent ee14576 commit 47d2460
Showing 1 changed file with 60 additions and 30 deletions.
90 changes: 60 additions & 30 deletions tests/tests/connectors/test-class-connector-bbpress.php
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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' ) );
}
}

0 comments on commit 47d2460

Please sign in to comment.