From 28b43ff1e44dbd5b4fe0d7ea316dd8571fa8c1b0 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Thu, 30 Jul 2020 14:11:04 -0400 Subject: [PATCH 1/4] Installer connector test implemented. --- .../test-class-connector-installer.php | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) create mode 100644 tests/tests/connectors/test-class-connector-installer.php diff --git a/tests/tests/connectors/test-class-connector-installer.php b/tests/tests/connectors/test-class-connector-installer.php new file mode 100644 index 000000000..657946da9 --- /dev/null +++ b/tests/tests/connectors/test-class-connector-installer.php @@ -0,0 +1,208 @@ +mock = $this->getMockBuilder( Connector_Installer::class ) + ->setMethods( array( 'log' ) ) + ->getMock(); + + // Register connector. + $this->mock->register(); + } + + public function test_callback_upgrader_process_complete() { + // Prepare scenario + + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + + ); + + // Do stuff. + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_upgrader_process_complete' ) ); + } + + public function test_callback_activate_plugin() { + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '"%1$s" plugin activated %2$s', + '1: Plugin name, 2: Single site or network wide', + 'stream' + ) + ), + $this->equalTo( + array( + 'name' => 'Hello Dolly', + 'network_wide' => null + ) + ), + $this->equalTo( null ), + $this->equalTo( 'plugins' ), + $this->equalTo( 'activated' ) + ); + + // Do stuff. + \activate_plugin( 'hello.php' ); + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_activate_plugin' ) ); + } + + public function test_callback_deactivate_plugin() { + // Prepare scenario + \activate_plugin( 'hello.php' ); + + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '"%1$s" plugin deactivated %2$s', + '1: Plugin name, 2: Single site or network wide', + 'stream' + ) + ), + $this->equalTo( + array( + 'name' => 'Hello Dolly', + 'network_wide' => null, + ) + ), + $this->equalTo( null ), + $this->equalTo( 'plugins' ), + $this->equalTo( 'deactivated' ) + ); + + // Do stuff. + \deactivate_plugins( array( 'hello.php' ) ); + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_deactivate_plugin' ) ); + } + + public function test_callback_switch_theme() { + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( __( '"%s" theme activated', 'stream' ) ), + $this->equalTo( array( 'name' => 'Twenty Twenty' ) ), + $this->equalTo( null ), + $this->equalTo( 'themes' ), + $this->equalTo( 'activated' ) + ); + + // Do stuff. + switch_theme( 'twentytwenty' ); + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_switch_theme' ) ); + } + + public function test_callback_delete_site_transient_update_themes() { + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( __( '"%s" theme deleted', 'stream' ) ), + $this->equalTo( array( 'name' => 'twentyninteen' ) ), + $this->equalTo( null ), + $this->equalTo( 'themes' ), + $this->equalTo( 'deleted' ) + ); + + // Do stuff. + delete_theme( 'twentyninteen' ); + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_site_transient_update_themes' ) ); + } + + public function test_callback_pre_set_site_transient_update_plugins() { + // Prepare scenario + + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( __( '"%s" plugin deleted', 'stream' ) ), + $this->equalTo( + array( + 'name' => 'Hello Dolly', + 'plugin' => 'hello.php', + 'network_wide' => null, + ) + ), + $this->equalTo( null ), + $this->equalTo( 'plugins' ), + $this->equalTo( 'deleted' ) + ); + + // Do stuff. + + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_pre_set_site_transient_update_plugins' ) ); + } + + public function test_callback__core_updated_successfully() { + // Prepare scenario + + // Expected log calls. + $this->mock->expects( $this->exactly( 2 ) ) + ->method( 'log' ) + ->withConsecutive( + array( + $this->equalTo( esc_html__( 'WordPress auto-updated to %s', 'stream' ) ), + $this->equalTo( + array( + 'new_version' => '', + 'old_version' => '', + 'auto_updated' => true, + ) + ), + $this->equalTo( null ), + $this->equalTo( 'WordPress' ), + $this->equalTo( 'updated' ) + ), + array( + $this->equalTo( esc_html__( 'WordPress updated to %s', 'stream' ) ), + $this->equalTo( + array( + 'new_version' => '', + 'old_version' => '', + 'auto_updated' => false, + ) + ), + $this->equalTo( null ), + $this->equalTo( 'WordPress' ), + $this->equalTo( 'updated' ) + ) + ); + + // Do stuff. + + // Check callback test action. + $this->assertFalse( 0 === did_action( 'wp_stream_test_callback__core_updated_successfully' ) ); + } +} From 26724d6e0a8c2738a5f8b0abef5c891740abfcf1 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 21 Aug 2020 11:56:40 -0400 Subject: [PATCH 2/4] 3 tests skipped until scenarios can be simulated. --- .../test-class-connector-installer.php | 48 +++++++++++++++++-- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-installer.php b/tests/tests/connectors/test-class-connector-installer.php index 657946da9..10622feee 100644 --- a/tests/tests/connectors/test-class-connector-installer.php +++ b/tests/tests/connectors/test-class-connector-installer.php @@ -23,15 +23,53 @@ public function setUp() { public function test_callback_upgrader_process_complete() { // Prepare scenario + $this->markTestSkipped( 'This test skipped until the needed scenario can be properly simulated.' ); // Expected log calls. $this->mock->expects( $this->once() ) ->method( 'log' ) - ->with( - + ->withConsecutive( + array( + _x( + 'Installed %1$s: %2$s %3$s', + 'Plugin/theme installation. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', + 'stream' + ), + array( + 'type' => 'plugin', + 'name' => 'Hello Dolly', + 'version' => '', + 'slug' => 'hello_dolly.php', + 'success' => true, + 'error' => null, + 'old_version' => '', + ), + null, + 'plugins', + 'installed' + ), + array( + _x( + 'Updated %1$s: %2$s %3$s', + 'Plugin/theme update. 1: Type (plugin/theme), 2: Plugin/theme name, 3: Plugin/theme version', + 'stream' + ), + array( + 'type' => 'theme', + 'name' => 'Twenty Twenty', + 'version' => '', + 'slug' => 'twentytwenty', + 'success' => true, + 'error' => null, + 'old_version' => '', + ), + null, + 'themes', + 'updated' + ) ); - // Do stuff. + // Simulate installing plugin and updating theme to trigger callback. // Check callback test action. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_upgrader_process_complete' ) ); @@ -47,7 +85,7 @@ public function test_callback_activate_plugin() { '"%1$s" plugin activated %2$s', '1: Plugin name, 2: Single site or network wide', 'stream' - ) + ), ), $this->equalTo( array( @@ -140,6 +178,7 @@ public function test_callback_delete_site_transient_update_themes() { public function test_callback_pre_set_site_transient_update_plugins() { // Prepare scenario + $this->markTestSkipped( 'This test skipped until the needed scenario can be properly simulated.' ); // Expected log calls. $this->mock->expects( $this->once() ) @@ -167,6 +206,7 @@ public function test_callback_pre_set_site_transient_update_plugins() { public function test_callback__core_updated_successfully() { // Prepare scenario + $this->markTestSkipped( 'This test skipped until the needed scenario can be properly simulated.' ); // Expected log calls. $this->mock->expects( $this->exactly( 2 ) ) From 22292cecb16b409a9d086e7815a05c9429e3852c Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 21 Aug 2020 12:02:10 -0400 Subject: [PATCH 3/4] Syntax error fixed. --- tests/tests/connectors/test-class-connector-installer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/connectors/test-class-connector-installer.php b/tests/tests/connectors/test-class-connector-installer.php index 10622feee..ef067876c 100644 --- a/tests/tests/connectors/test-class-connector-installer.php +++ b/tests/tests/connectors/test-class-connector-installer.php @@ -85,7 +85,7 @@ public function test_callback_activate_plugin() { '"%1$s" plugin activated %2$s', '1: Plugin name, 2: Single site or network wide', 'stream' - ), + ) ), $this->equalTo( array( From dfca9852f77fb3f63e1a7efe36e9da4e23bb82be Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 5 Jan 2021 18:22:22 -0500 Subject: [PATCH 4/4] Installer connector test cleaned up. --- .../connectors/test-class-connector-installer.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-installer.php b/tests/tests/connectors/test-class-connector-installer.php index ef067876c..761578423 100644 --- a/tests/tests/connectors/test-class-connector-installer.php +++ b/tests/tests/connectors/test-class-connector-installer.php @@ -72,7 +72,7 @@ public function test_callback_upgrader_process_complete() { // Simulate installing plugin and updating theme to trigger callback. // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_upgrader_process_complete' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_upgrader_process_complete' ) ); } public function test_callback_activate_plugin() { @@ -102,7 +102,7 @@ public function test_callback_activate_plugin() { \activate_plugin( 'hello.php' ); // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_activate_plugin' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_activate_plugin' ) ); } public function test_callback_deactivate_plugin() { @@ -135,7 +135,7 @@ public function test_callback_deactivate_plugin() { \deactivate_plugins( array( 'hello.php' ) ); // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_deactivate_plugin' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_deactivate_plugin' ) ); } public function test_callback_switch_theme() { @@ -154,7 +154,7 @@ public function test_callback_switch_theme() { switch_theme( 'twentytwenty' ); // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_switch_theme' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_switch_theme' ) ); } public function test_callback_delete_site_transient_update_themes() { @@ -173,7 +173,7 @@ public function test_callback_delete_site_transient_update_themes() { delete_theme( 'twentyninteen' ); // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_site_transient_update_themes' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_delete_site_transient_update_themes' ) ); } public function test_callback_pre_set_site_transient_update_plugins() { @@ -201,7 +201,7 @@ public function test_callback_pre_set_site_transient_update_plugins() { // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_pre_set_site_transient_update_plugins' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback_pre_set_site_transient_update_plugins' ) ); } public function test_callback__core_updated_successfully() { @@ -243,6 +243,6 @@ public function test_callback__core_updated_successfully() { // Do stuff. // Check callback test action. - $this->assertFalse( 0 === did_action( 'wp_stream_test_callback__core_updated_successfully' ) ); + $this->assertFalse( 0 === did_action( $this->action_prefix . 'callback__core_updated_successfully' ) ); } }