Skip to content

Commit c68ccae

Browse files
author
Peter Sorensen
committed
add tests
1 parent f345b51 commit c68ccae

2 files changed

Lines changed: 48 additions & 0 deletions

File tree

tests/php/NetworkSiteConnectionsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,4 +500,28 @@ public function test_remote_get() {
500500

501501
}
502502

503+
/**
504+
* Test that dt_should_push_network_post filter prevents push when returning false.
505+
*
506+
* @since 2.0.0
507+
* @group NetworkSiteConnection
508+
* @runInSeparateProcess
509+
*/
510+
public function test_push_filtered_out_network_post() {
511+
$post = (object) [
512+
'ID' => 111,
513+
];
514+
515+
\WP_Mock::userFunction( 'get_post', [ 'return' => $post ] );
516+
517+
\WP_Mock::onFilter( 'dt_should_push_network_post' )
518+
->with( true, $post, array(), $this->connection_obj )
519+
->reply( false );
520+
521+
$result = $this->connection_obj->push( 1 );
522+
523+
$this->assertInstanceOf( \WP_Error::class, $result );
524+
$this->assertEquals( 'post-not-allowed-to-push', $result->get_error_code() );
525+
}
526+
503527
}

tests/php/WordPressExternalConnectionTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -455,4 +455,28 @@ public function test_check_connections_no_distributor() {
455455

456456
$this->assertTrue( empty( $this->connection->check_connections()['errors']['no_distributor'] ) );
457457
}
458+
459+
/**
460+
* Test that dt_should_push_external_post filter prevents push when returning false.
461+
*
462+
* @since 2.0.0
463+
* @group WordPressExternalConnection
464+
* @runInSeparateProcess
465+
*/
466+
public function test_push_filtered_out_external_post() {
467+
$post = (object) [
468+
'ID' => 1,
469+
];
470+
471+
\WP_Mock::userFunction( 'get_post', [ 'return' => $post ] );
472+
473+
\WP_Mock::onFilter( 'dt_should_push_external_post' )
474+
->with( true, $post, array(), $this->connection )
475+
->reply( false );
476+
477+
$result = $this->connection->push( 1 );
478+
479+
$this->assertInstanceOf( \WP_Error::class, $result );
480+
$this->assertEquals( 'post-not-allowed-to-push', $result->get_error_code() );
481+
}
458482
}

0 commit comments

Comments
 (0)