Skip to content

Commit

Permalink
Documentation added.
Browse files Browse the repository at this point in the history
  • Loading branch information
kidunot89 committed Jul 23, 2020
1 parent 47d2460 commit b29dd02
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions tests/tests/connectors/test-class-connector-bbpress.php
Original file line number Diff line number Diff line change
@@ -1,32 +1,51 @@
<?php
/**
* WP Integration Test w/ bbPress
*
* Tests for bbPress Connector class callbacks.
*/
namespace WP_Stream;

class Test_WP_Stream_Connector_BbPress extends WP_StreamTestCase {
/**
* Runs before each test
*/
public function setUp() {
parent::setUp();

$post_connector = new Connector_Posts();
$post_connector->register();

// Make partial of Connector_ACF class, with mocked "log" function.
// Make partial of Connector_BbPress class, with mocked "log" function.
$this->mock = $this->getMockBuilder( Connector_BbPress::class )
->setMethods( [ 'log' ] )
->getMock();

$this->mock->register();
}

/**
* Runs after each test
*/
public function tearDown() {
parent::tearDown();
}

/**
* Confirm that bbPress is installed and active.
*/
public function test_bbpress_installed_and_activated() {
$this->assertTrue( class_exists( 'bbPress' ) );
}

/**
* Tests the "log_override" callback
*/
public function test_log_override() {
// Has asserted flag.
$asserted = false;

// Set assertion callback.
add_action(
'wp_stream_log_data',
function( $data ) use( &$asserted ) {
Expand All @@ -48,13 +67,21 @@ function( $data ) use( &$asserted ) {
99
);

// Do stuff.
$forum_id = bbp_insert_forum( [ 'post_title' => 'Test Forum' ] );

// Check ID.
$this->assertGreaterThan( 0, $forum_id );

// Confirm that assertion callback executed.
$this->assertTrue( $asserted );
}

/**
* Test "test_callback_bbp_toggle_topic_admin" callback.
*/
public function test_callback_bbp_toggle_topic_admin() {
// Create Forum and topic.
$forum_id = bbp_insert_forum( [ 'post_title' => 'Test Forum' ] );
$topic_id = bbp_insert_topic(
[
Expand All @@ -65,7 +92,7 @@ public function test_callback_bbp_toggle_topic_admin() {
$topic = get_post( $topic_id );

// Expected log calls.
$this->mock->expects( $this->atLeastOnce() )
$this->mock->expects( $this->once() )
->method( 'log' )
->with(
$this->equalTo( _x( '%1$s "%2$s" topic', '1: Action, 2: Topic title', 'stream' ) ),
Expand All @@ -81,7 +108,7 @@ public function test_callback_bbp_toggle_topic_admin() {
$this->equalTo( 'closed' )
);

// Do stuff
// Do stuff.
do_action(
'bbp_toggle_topic_admin',
bbp_close_topic( $topic_id ),
Expand Down

0 comments on commit b29dd02

Please sign in to comment.