Skip to content

Commit

Permalink
Add mocked functions required for updated Gutenberg detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc committed Aug 16, 2022
1 parent 958538f commit 7ab4015
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 11 deletions.
7 changes: 7 additions & 0 deletions tests/php/NetworkSiteConnectionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ public function test_push() {
\WP_Mock::userFunction( 'remove_filter' );
\WP_Mock::userFunction( 'get_option' );
\WP_Mock::passthruFunction( 'wp_slash' );
\WP_Mock::passthruFunction( 'absint' );

$this->connection_obj->site->blog_id = 2;

$original_url = 'original url';
$new_post_id = 123;

\WP_Mock::userFunction(
'use_block_editor_for_post_type', [
'return' => true,
]
);

\WP_Mock::userFunction(
'wp_insert_post', [
'return' => $new_post_id,
Expand Down
57 changes: 52 additions & 5 deletions tests/php/SubscriptionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Distributor;

use WP_Mock\Tools\TestCase;
use WP_Mock\Functions;

class SubscriptionsTest extends TestCase {

Expand Down Expand Up @@ -178,16 +179,32 @@ public function test_delete_subscribing_post() {
*/
public function test_send_notifications_none() {

$post = new \stdClass();
$post->ID = 1;
$post = (object) [
'ID' => 1,
'post_type' => 'post',
];

\WP_Mock::passthruFunction( 'absint' );
\WP_Mock::userFunction(
'get_post', [
'args' => [ $post->ID ],
'args' => [ Functions::anyOf( $post->ID, $post ) ],
'return' => $post,
]
);

\WP_Mock::userFunction(
'get_option', [
'args' => [ 'page_for_posts' ],
'return' => 0,
]
);

\WP_Mock::userFunction(
'use_block_editor_for_post_type', [
'return' => false,
]
);

\WP_Mock::userFunction(
'wp_is_post_revision', [
'return' => false,
Expand Down Expand Up @@ -315,11 +332,26 @@ public function test_send_notifications_no_remote_post() {

\WP_Mock::userFunction(
'get_post', [
'args' => [ $post_id ],
'args' => [ Functions::anyOf( $post->ID, $post ) ],
'return' => $post,
]
);

\WP_Mock::passthruFunction( 'absint' );

\WP_Mock::userFunction(
'get_option', [
'args' => [ 'page_for_posts' ],
'return' => 0,
]
);

\WP_Mock::userFunction(
'use_block_editor_for_post_type', [
'return' => false,
]
);

\WP_Mock::userFunction(
'wp_remote_post', [
'times' => 1,
Expand Down Expand Up @@ -488,11 +520,26 @@ public function test_send_notifications_remote_post_exists() {

\WP_Mock::userFunction(
'get_post', [
'args' => [ $post_id ],
'args' => [ Functions::anyOf( $post->ID, $post ) ],
'return' => $post,
]
);

\WP_Mock::passthruFunction( 'absint' );

\WP_Mock::userFunction(
'get_option', [
'args' => [ 'page_for_posts' ],
'return' => 0,
]
);

\WP_Mock::userFunction(
'use_block_editor_for_post_type', [
'return' => false,
]
);

\WP_Mock::userFunction(
'wp_remote_post', [
'times' => 1,
Expand Down
32 changes: 26 additions & 6 deletions tests/php/WordPressExternalConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
namespace Distributor\ExternalConnections;

use \Distributor\Authentications\WordPressBasicAuth as WordPressBasicAuth;
use WP_Mock\Functions;
use WP_Mock\Tools\TestCase;

class WordPressExternalConnectionTest extends TestCase {
Expand Down Expand Up @@ -57,6 +58,20 @@ public function test_push() {
\WP_Mock::userFunction( 'wp_remote_post' );
\WP_Mock::userFunction( 'esc_html__' );
\WP_Mock::userFunction( 'get_bloginfo' );
\WP_Mock::passthruFunction( 'absint' );

\WP_Mock::userFunction(
'get_option', [
'args' => [ 'page_for_posts' ],
'return' => 0,
]
);

\WP_Mock::userFunction(
'use_block_editor_for_post_type', [
'return' => false,
]
);

$post_type = 'foo';

Expand All @@ -75,14 +90,19 @@ public function test_push() {
]
);

$post = (object) [
'post_content' => 'my post content',
'post_type' => $post_type,
'post_excerpt' => 'post excerpt',
'post_name' => 'slug',
'post_type' => $post_type,
'ID' => 1,
];

\WP_Mock::userFunction(
'get_post', [
'return' => (object) [
'post_content' => 'my post content',
'post_type' => $post_type,
'post_excerpt' => 'post excerpt',
'post_name' => 'slug',
],
'args' => [ Functions::anyOf( $post->ID, $post ) ],
'return' => $post,
]
);

Expand Down

0 comments on commit 7ab4015

Please sign in to comment.