diff --git a/composer.json b/composer.json index ee50c2353..9989fa6f3 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,8 @@ "wp-phpunit/wp-phpunit": "^5.4", "wpsh/local": "^0.2.3", "wpackagist-plugin/advanced-custom-fields": "5.8.12", - "wpackagist-plugin/easy-digital-downloads": "^2.9.23" + "wpackagist-plugin/easy-digital-downloads": "^2.9.23", + "wpackagist-plugin/user-switching": "^1.5.5" }, "config": { "process-timeout": 600, diff --git a/composer.lock b/composer.lock index d45b1aa6d..4e5401620 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "1d58819e7fbef294b0721f50a6564b19", + "content-hash": "9ea430268ec38a2b87542c340bc6f5fe", "packages": [ { "name": "composer/installers", @@ -183,16 +183,16 @@ }, { "name": "composer/ca-bundle", - "version": "1.2.7", + "version": "1.2.8", "source": { "type": "git", "url": "https://github.com/composer/ca-bundle.git", - "reference": "95c63ab2117a72f48f5a55da9740a3273d45b7fd" + "reference": "8a7ecad675253e4654ea05505233285377405215" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/ca-bundle/zipball/95c63ab2117a72f48f5a55da9740a3273d45b7fd", - "reference": "95c63ab2117a72f48f5a55da9740a3273d45b7fd", + "url": "https://api.github.com/repos/composer/ca-bundle/zipball/8a7ecad675253e4654ea05505233285377405215", + "reference": "8a7ecad675253e4654ea05505233285377405215", "shasum": "" }, "require": { @@ -235,7 +235,21 @@ "ssl", "tls" ], - "time": "2020-04-08T08:27:21+00:00" + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-08-23T12:54:47+00:00" }, { "name": "composer/composer", @@ -468,16 +482,16 @@ }, { "name": "composer/xdebug-handler", - "version": "1.4.2", + "version": "1.4.3", "source": { "type": "git", "url": "https://github.com/composer/xdebug-handler.git", - "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51" + "reference": "ebd27a9866ae8254e873866f795491f02418c5a5" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", - "reference": "fa2aaf99e2087f013a14f7432c1cd2dd7d8f1f51", + "url": "https://api.github.com/repos/composer/xdebug-handler/zipball/ebd27a9866ae8254e873866f795491f02418c5a5", + "reference": "ebd27a9866ae8254e873866f795491f02418c5a5", "shasum": "" }, "require": { @@ -508,7 +522,21 @@ "Xdebug", "performance" ], - "time": "2020-06-04T11:16:35+00:00" + "funding": [ + { + "url": "https://packagist.com", + "type": "custom" + }, + { + "url": "https://github.com/composer", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/composer/composer", + "type": "tidelift" + } + ], + "time": "2020-08-19T10:27:58+00:00" }, { "name": "cweagans/composer-patches", @@ -922,20 +950,20 @@ }, { "name": "johnpbloch/wordpress", - "version": "5.5.0", + "version": "5.5.1", "source": { "type": "git", "url": "https://github.com/johnpbloch/wordpress.git", - "reference": "d8a952dd4aa7f7d4d8be6fa145840fde4e248450" + "reference": "0973abd5c01ecce0b60bc1c81a6dd072827de930" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/johnpbloch/wordpress/zipball/d8a952dd4aa7f7d4d8be6fa145840fde4e248450", - "reference": "d8a952dd4aa7f7d4d8be6fa145840fde4e248450", + "url": "https://api.github.com/repos/johnpbloch/wordpress/zipball/0973abd5c01ecce0b60bc1c81a6dd072827de930", + "reference": "0973abd5c01ecce0b60bc1c81a6dd072827de930", "shasum": "" }, "require": { - "johnpbloch/wordpress-core": "5.5.0", + "johnpbloch/wordpress-core": "5.5.1", "johnpbloch/wordpress-core-installer": "^1.0 || ^2.0", "php": ">=5.6.20" }, @@ -957,20 +985,20 @@ "cms", "wordpress" ], - "time": "2020-08-11T18:47:19+00:00" + "time": "2020-09-01T19:07:41+00:00" }, { "name": "johnpbloch/wordpress-core", - "version": "5.5.0", + "version": "5.5.1", "source": { "type": "git", "url": "https://github.com/johnpbloch/wordpress-core.git", - "reference": "c49d46de4e4c8972b8ed2aebe3e850f4f218186f" + "reference": "fa5bcb1579eae33baef6c04355f8d6657e5bd349" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/johnpbloch/wordpress-core/zipball/c49d46de4e4c8972b8ed2aebe3e850f4f218186f", - "reference": "c49d46de4e4c8972b8ed2aebe3e850f4f218186f", + "url": "https://api.github.com/repos/johnpbloch/wordpress-core/zipball/fa5bcb1579eae33baef6c04355f8d6657e5bd349", + "reference": "fa5bcb1579eae33baef6c04355f8d6657e5bd349", "shasum": "" }, "require": { @@ -978,7 +1006,7 @@ "php": ">=5.6.20" }, "provide": { - "wordpress/core-implementation": "5.5.0" + "wordpress/core-implementation": "5.5.1" }, "type": "wordpress-core", "notification-url": "https://packagist.org/downloads/", @@ -998,7 +1026,7 @@ "cms", "wordpress" ], - "time": "2020-08-11T18:47:13+00:00" + "time": "2020-09-01T19:07:35+00:00" }, { "name": "johnpbloch/wordpress-core-installer", @@ -2727,16 +2755,16 @@ }, { "name": "seld/jsonlint", - "version": "1.8.1", + "version": "1.8.2", "source": { "type": "git", "url": "https://github.com/Seldaek/jsonlint.git", - "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd" + "reference": "590cfec960b77fd55e39b7d9246659e95dd6d337" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/3d5eb71705adfa34bd34b993400622932b2f62fd", - "reference": "3d5eb71705adfa34bd34b993400622932b2f62fd", + "url": "https://api.github.com/repos/Seldaek/jsonlint/zipball/590cfec960b77fd55e39b7d9246659e95dd6d337", + "reference": "590cfec960b77fd55e39b7d9246659e95dd6d337", "shasum": "" }, "require": { @@ -2782,7 +2810,7 @@ "type": "tidelift" } ], - "time": "2020-08-13T09:07:59+00:00" + "time": "2020-08-25T06:56:57+00:00" }, { "name": "seld/phar-utils", @@ -2881,16 +2909,16 @@ }, { "name": "symfony/config", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "9e2aa97f0d51f114983666f5aa362426d53e004a" + "reference": "801a3bbc17fb1ba44b0d7d41a6db7a0b74953595" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/9e2aa97f0d51f114983666f5aa362426d53e004a", - "reference": "9e2aa97f0d51f114983666f5aa362426d53e004a", + "url": "https://api.github.com/repos/symfony/config/zipball/801a3bbc17fb1ba44b0d7d41a6db7a0b74953595", + "reference": "801a3bbc17fb1ba44b0d7d41a6db7a0b74953595", "shasum": "" }, "require": { @@ -2955,20 +2983,20 @@ "type": "tidelift" } ], - "time": "2020-07-23T09:37:51+00:00" + "time": "2020-08-10T07:13:15+00:00" }, { "name": "symfony/console", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "afc7189694d2c59546cf24ea606a236fa46a966e" + "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/afc7189694d2c59546cf24ea606a236fa46a966e", - "reference": "afc7189694d2c59546cf24ea606a236fa46a966e", + "url": "https://api.github.com/repos/symfony/console/zipball/71da881ad579f0cd66aef8677e4cf6217d8ecd0c", + "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c", "shasum": "" }, "require": { @@ -3041,20 +3069,20 @@ "type": "tidelift" } ], - "time": "2020-07-06T08:57:31+00:00" + "time": "2020-08-09T08:16:57+00:00" }, { "name": "symfony/debug", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "7ce874f4432d8b11cc45a80cc5130a6e2609728d" + "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/7ce874f4432d8b11cc45a80cc5130a6e2609728d", - "reference": "7ce874f4432d8b11cc45a80cc5130a6e2609728d", + "url": "https://api.github.com/repos/symfony/debug/zipball/0893a0b07c499a1530614d65869ea6a7b1b8a164", + "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164", "shasum": "" }, "require": { @@ -3111,20 +3139,20 @@ "type": "tidelift" } ], - "time": "2020-07-16T09:41:49+00:00" + "time": "2020-08-09T08:13:48+00:00" }, { "name": "symfony/filesystem", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "0f625d0cb1e59c8c4ba61abb170125175218ff10" + "reference": "8e6eff546d0fe879996fa701ee2f312767e95e50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/0f625d0cb1e59c8c4ba61abb170125175218ff10", - "reference": "0f625d0cb1e59c8c4ba61abb170125175218ff10", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/8e6eff546d0fe879996fa701ee2f312767e95e50", + "reference": "8e6eff546d0fe879996fa701ee2f312767e95e50", "shasum": "" }, "require": { @@ -3175,11 +3203,11 @@ "type": "tidelift" } ], - "time": "2020-05-30T17:48:24+00:00" + "time": "2020-08-21T12:53:49+00:00" }, { "name": "symfony/finder", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", @@ -3711,7 +3739,7 @@ }, { "name": "symfony/process", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -3774,7 +3802,7 @@ }, { "name": "symfony/stopwatch", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -3837,16 +3865,16 @@ }, { "name": "symfony/yaml", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "e7fa05917ae931332a42d65b577ece4d497aad81" + "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/e7fa05917ae931332a42d65b577ece4d497aad81", - "reference": "e7fa05917ae931332a42d65b577ece4d497aad81", + "url": "https://api.github.com/repos/symfony/yaml/zipball/4152e36b0f305c2a57aa0233dee56ec27bca4f06", + "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06", "shasum": "" }, "require": { @@ -3906,7 +3934,7 @@ "type": "tidelift" } ], - "time": "2020-07-23T09:37:51+00:00" + "time": "2020-08-26T06:32:27+00:00" }, { "name": "webmozart/assert", @@ -5971,16 +5999,16 @@ }, { "name": "wp-phpunit/wp-phpunit", - "version": "5.5.0", + "version": "5.5.1", "source": { "type": "git", "url": "https://github.com/wp-phpunit/wp-phpunit.git", - "reference": "5cf5a40954b8c47941afdc08b0000ce42efe5993" + "reference": "763121e752594664c150643e05c991a0acf3800a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-phpunit/wp-phpunit/zipball/5cf5a40954b8c47941afdc08b0000ce42efe5993", - "reference": "5cf5a40954b8c47941afdc08b0000ce42efe5993", + "url": "https://api.github.com/repos/wp-phpunit/wp-phpunit/zipball/763121e752594664c150643e05c991a0acf3800a", + "reference": "763121e752594664c150643e05c991a0acf3800a", "shasum": "" }, "type": "library", @@ -6010,7 +6038,7 @@ "test", "wordpress" ], - "time": "2020-08-12T15:43:21+00:00" + "time": "2020-09-02T15:53:50+00:00" }, { "name": "wpackagist-plugin/advanced-custom-fields", @@ -6032,15 +6060,15 @@ }, { "name": "wpackagist-plugin/easy-digital-downloads", - "version": "2.9.23", + "version": "2.9.25", "source": { "type": "svn", "url": "https://plugins.svn.wordpress.org/easy-digital-downloads/", - "reference": "tags/2.9.23" + "reference": "tags/2.9.25" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/easy-digital-downloads.2.9.23.zip" + "url": "https://downloads.wordpress.org/plugin/easy-digital-downloads.2.9.25.zip" }, "require": { "composer/installers": "~1.0" @@ -6048,6 +6076,24 @@ "type": "wordpress-plugin", "homepage": "https://wordpress.org/plugins/easy-digital-downloads/" }, + { + "name": "wpackagist-plugin/user-switching", + "version": "1.5.5", + "source": { + "type": "svn", + "url": "https://plugins.svn.wordpress.org/user-switching/", + "reference": "tags/1.5.5" + }, + "dist": { + "type": "zip", + "url": "https://downloads.wordpress.org/plugin/user-switching.1.5.5.zip" + }, + "require": { + "composer/installers": "~1.0" + }, + "type": "wordpress-plugin", + "homepage": "https://wordpress.org/plugins/user-switching/" + }, { "name": "wpsh/local", "version": "0.2.3", diff --git a/connectors/class-connector-user-switching.php b/connectors/class-connector-user-switching.php index 78f792c59..8639a790e 100644 --- a/connectors/class-connector-user-switching.php +++ b/connectors/class-connector-user-switching.php @@ -219,13 +219,9 @@ public function callback_switch_back_user( $user_id, $old_user_id ) { public function callback_switch_off_user( $old_user_id ) { $old_user = get_userdata( $old_user_id ); - $message = __( - 'Switched off', - 'stream' - ); $this->log( - $message, + __( 'Switched off', 'stream' ), array(), $old_user->ID, 'sessions', diff --git a/phpunit.xml b/phpunit.xml index a982b0cc7..af2b1c44b 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -10,7 +10,7 @@ diff --git a/tests/tests/connectors/test-class-connector-user-switching.php b/tests/tests/connectors/test-class-connector-user-switching.php new file mode 100644 index 000000000..04f6b8944 --- /dev/null +++ b/tests/tests/connectors/test-class-connector-user-switching.php @@ -0,0 +1,165 @@ +plugin->connectors->unload_connectors(); + + // Make partial of Connector_User_Switching class, with mocked "log" function. + $this->mock = $this->getMockBuilder( Connector_User_Switching::class ) + ->setMethods( array( 'log' ) ) + ->getMock(); + + // Register connector. + $this->mock->register(); + } + + /** + * Confirm that User Switching is installed and active. + */ + public function test_user_switching_installed_and_activated() { + $this->assertTrue( class_exists( 'user_switching' ) ); + } + + public function test_callback_switch_to_user() { + // Create and authenticate user to be switched from. + $old_user_id = self::factory()->user->create( + array( + 'user_login' => 'oldtestuser', + 'user_role' => 'adminstrator', + 'display_name' => 'oldtestuserdisplay', + ) + ); + wp_set_current_user( $old_user_id ); + + // Create user ID for destination user. + $user_id = self::factory()->user->create( + array( + 'user_login' => 'testuser', + 'user_role' => 'adminstrator', + 'display_name' => 'testuserdisplay', + ) + ); + + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + 'Switched user to %1$s (%2$s)', + '1: User display name, 2: User login', + 'stream' + ) + ), + $this->equalTo( + array( + 'display_name' => 'testuserdisplay', + 'user_login' => 'testuser', + ) + ), + $this->equalTo( $old_user_id ), + $this->equalTo( 'sessions' ), + $this->equalTo( 'switched-to' ), + $this->equalTo( $old_user_id ) + ); + + // Switch to user to trigger callback. + \switch_to_user( $user_id ); + + // Check callback test action. + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_to_user' ) ); + } + + public function test_callback_switch_back_user() { + // Create and authenticate users for later use. + $old_user_id = self::factory()->user->create( + array( + 'user_login' => 'oldtestuser', + 'user_role' => 'adminstrator', + 'display_name' => 'oldtestuserdisplay', + ) + ); + $user_id = self::factory()->user->create( + array( + 'user_login' => 'testuser', + 'user_role' => 'adminstrator', + 'display_name' => 'testuserdisplay', + ) + ); + + wp_set_current_user( $old_user_id ); + \switch_to_user( $user_id ); + + // Expected log calls. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + 'Switched back to %1$s (%2$s)', + '1: User display name, 2: User login', + 'stream' + ) + ), + $this->equalTo( + array( + 'display_name' => 'oldtestuserdisplay', + 'user_login' => 'oldtestuser', + ) + ), + $this->equalTo( $user_id ), + $this->equalTo( 'sessions' ), + $this->equalTo( 'switched-back' ), + $this->equalTo( $user_id ) + ); + + // Switch to user to trigger callback. + \switch_to_user( $old_user_id, false, false ); + + // Check callback test action. + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_back_user' ) ); + } + + public function test_callback_switch_off_user() { + // Create/authenticate user for later use. + $user_id = self::factory()->user->create( + array( + 'user_login' => 'testuser', + 'user_role' => 'adminstrator', + 'display_name' => 'testuserdisplay', + ) + ); + wp_set_current_user( $user_id ); + + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( __( 'Switched off', 'stream' ) ), + $this->equalTo( array() ), + $this->equalTo( $user_id ), + $this->equalTo( 'sessions' ), + $this->equalTo( 'switched-off' ), + $this->equalTo( $user_id ) + ); + + // Switch to user to trigger callback. + \switch_off_user(); + + // Check callback test action. + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_switch_off_user' ) ); + } +}