From 7ab401517e30e6906fe7d95a2b68e3438b623a5e Mon Sep 17 00:00:00 2001 From: Peter Wilson <519727+peterwilsoncc@users.noreply.github.com> Date: Tue, 16 Aug 2022 14:30:17 +1000 Subject: [PATCH] Add mocked functions required for updated Gutenberg detection. --- tests/php/NetworkSiteConnectionsTest.php | 7 +++ tests/php/SubscriptionsTest.php | 57 +++++++++++++++++-- tests/php/WordPressExternalConnectionTest.php | 32 +++++++++-- 3 files changed, 85 insertions(+), 11 deletions(-) diff --git a/tests/php/NetworkSiteConnectionsTest.php b/tests/php/NetworkSiteConnectionsTest.php index 7dc6f86c4..2e889db4d 100644 --- a/tests/php/NetworkSiteConnectionsTest.php +++ b/tests/php/NetworkSiteConnectionsTest.php @@ -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, diff --git a/tests/php/SubscriptionsTest.php b/tests/php/SubscriptionsTest.php index f6dff1373..0453d57b8 100644 --- a/tests/php/SubscriptionsTest.php +++ b/tests/php/SubscriptionsTest.php @@ -3,6 +3,7 @@ namespace Distributor; use WP_Mock\Tools\TestCase; +use WP_Mock\Functions; class SubscriptionsTest extends TestCase { @@ -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, @@ -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, @@ -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, diff --git a/tests/php/WordPressExternalConnectionTest.php b/tests/php/WordPressExternalConnectionTest.php index 537b492ef..343974dbc 100644 --- a/tests/php/WordPressExternalConnectionTest.php +++ b/tests/php/WordPressExternalConnectionTest.php @@ -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 { @@ -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'; @@ -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, ] );