From 52fd0d43d6366307a8d0bde84dc03b6a91893e5f Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Fri, 28 Aug 2020 16:07:28 -0400 Subject: [PATCH 1/4] Settings connector test implemented. --- composer.lock | 166 +++++++++--------- connectors/class-connector-settings.php | 4 +- .../connectors/test-class-connector-acf.php | 4 +- .../connectors/test-class-connector-blogs.php | 9 +- .../connectors/test-class-connector-edd.php | 2 + .../test-class-connector-mercator.php | 7 +- .../connectors/test-class-connector-posts.php | 4 + .../test-class-connector-settings.php | 141 ++++++++++++--- 8 files changed, 224 insertions(+), 113 deletions(-) diff --git a/composer.lock b/composer.lock index c8feb947f..6924f352d 100644 --- a/composer.lock +++ b/composer.lock @@ -348,16 +348,16 @@ }, { "name": "composer/semver", - "version": "1.7.0", + "version": "1.7.1", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "114f819054a2ea7db03287f5efb757e2af6e4079" + "reference": "38276325bd896f90dfcfe30029aa5db40df387a7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/114f819054a2ea7db03287f5efb757e2af6e4079", - "reference": "114f819054a2ea7db03287f5efb757e2af6e4079", + "url": "https://api.github.com/repos/composer/semver/zipball/38276325bd896f90dfcfe30029aa5db40df387a7", + "reference": "38276325bd896f90dfcfe30029aa5db40df387a7", "shasum": "" }, "require": { @@ -419,7 +419,7 @@ "type": "tidelift" } ], - "time": "2020-09-09T09:34:06+00:00" + "time": "2020-09-27T13:13:07+00:00" }, { "name": "composer/spdx-licenses", @@ -843,23 +843,23 @@ }, { "name": "guzzlehttp/promises", - "version": "v1.3.1", + "version": "1.4.0", "source": { "type": "git", "url": "https://github.com/guzzle/promises.git", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646" + "reference": "60d379c243457e073cff02bc323a2a86cb355631" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/promises/zipball/a59da6cf61d80060647ff4d3eb2c03a2bc694646", - "reference": "a59da6cf61d80060647ff4d3eb2c03a2bc694646", + "url": "https://api.github.com/repos/guzzle/promises/zipball/60d379c243457e073cff02bc323a2a86cb355631", + "reference": "60d379c243457e073cff02bc323a2a86cb355631", "shasum": "" }, "require": { - "php": ">=5.5.0" + "php": ">=5.5" }, "require-dev": { - "phpunit/phpunit": "^4.0" + "symfony/phpunit-bridge": "^4.4 || ^5.1" }, "type": "library", "extra": { @@ -890,20 +890,20 @@ "keywords": [ "promise" ], - "time": "2016-12-20T10:07:11+00:00" + "time": "2020-09-30T07:37:28+00:00" }, { "name": "guzzlehttp/psr7", - "version": "1.6.1", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/guzzle/psr7.git", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a" + "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/guzzle/psr7/zipball/239400de7a173fe9901b9ac7c06497751f00727a", - "reference": "239400de7a173fe9901b9ac7c06497751f00727a", + "url": "https://api.github.com/repos/guzzle/psr7/zipball/53330f47520498c0ae1f61f7e2c90f55690c06a3", + "reference": "53330f47520498c0ae1f61f7e2c90f55690c06a3", "shasum": "" }, "require": { @@ -916,15 +916,15 @@ }, "require-dev": { "ext-zlib": "*", - "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.8" + "phpunit/phpunit": "~4.8.36 || ^5.7.27 || ^6.5.14 || ^7.5.20 || ^8.5.8 || ^9.3.10" }, "suggest": { - "zendframework/zend-httphandlerrunner": "Emit PSR-7 responses" + "laminas/laminas-httphandlerrunner": "Emit PSR-7 responses" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "1.6-dev" + "dev-master": "1.7-dev" } }, "autoload": { @@ -961,7 +961,7 @@ "uri", "url" ], - "time": "2019-07-01T23:21:34+00:00" + "time": "2020-09-30T07:37:11+00:00" }, { "name": "johnpbloch/wordpress", @@ -1387,23 +1387,23 @@ }, { "name": "php-coveralls/php-coveralls", - "version": "v2.2.0", + "version": "v2.4.0", "source": { "type": "git", "url": "https://github.com/php-coveralls/php-coveralls.git", - "reference": "3e6420fa666ef7bae5e750ddeac903153e193bae" + "reference": "9e39f1142e0f07708291030290f81cf0b2b4cc7e" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-coveralls/php-coveralls/zipball/3e6420fa666ef7bae5e750ddeac903153e193bae", - "reference": "3e6420fa666ef7bae5e750ddeac903153e193bae", + "url": "https://api.github.com/repos/php-coveralls/php-coveralls/zipball/9e39f1142e0f07708291030290f81cf0b2b4cc7e", + "reference": "9e39f1142e0f07708291030290f81cf0b2b4cc7e", "shasum": "" }, "require": { "ext-json": "*", "ext-simplexml": "*", - "guzzlehttp/guzzle": "^6.0", - "php": "^5.5 || ^7.0", + "guzzlehttp/guzzle": "^6.0 || ^7.0", + "php": "^5.5 || ^7.0 || ^8.0", "psr/log": "^1.0", "symfony/config": "^2.1 || ^3.0 || ^4.0 || ^5.0", "symfony/console": "^2.1 || ^3.0 || ^4.0 || ^5.0", @@ -1411,7 +1411,8 @@ "symfony/yaml": "^2.0.5 || ^3.0 || ^4.0 || ^5.0" }, "require-dev": { - "phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0" + "phpunit/phpunit": "^4.8.35 || ^5.4.3 || ^6.0 || ^7.0 || ^8.0 || ^9.0", + "sanmai/phpunit-legacy-adapter": "^6.1 || ^8.0" }, "suggest": { "symfony/http-kernel": "Allows Symfony integration" @@ -1420,11 +1421,6 @@ "bin/php-coveralls" ], "type": "library", - "extra": { - "branch-alias": { - "dev-master": "2.2-dev" - } - }, "autoload": { "psr-4": { "PhpCoveralls\\": "src/" @@ -1466,7 +1462,7 @@ "github", "test" ], - "time": "2019-11-20T16:29:20+00:00" + "time": "2020-10-05T21:31:54+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2972,16 +2968,16 @@ }, { "name": "symfony/config", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/config.git", - "reference": "801a3bbc17fb1ba44b0d7d41a6db7a0b74953595" + "reference": "d061a451ff6bc170c5454f4ac9b41ad2179e3960" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/config/zipball/801a3bbc17fb1ba44b0d7d41a6db7a0b74953595", - "reference": "801a3bbc17fb1ba44b0d7d41a6db7a0b74953595", + "url": "https://api.github.com/repos/symfony/config/zipball/d061a451ff6bc170c5454f4ac9b41ad2179e3960", + "reference": "d061a451ff6bc170c5454f4ac9b41ad2179e3960", "shasum": "" }, "require": { @@ -3046,20 +3042,20 @@ "type": "tidelift" } ], - "time": "2020-08-10T07:13:15+00:00" + "time": "2020-09-02T16:06:40+00:00" }, { "name": "symfony/console", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/console.git", - "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c" + "reference": "b28996bc0a3b08914b2a8609163ec35b36b30685" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/console/zipball/71da881ad579f0cd66aef8677e4cf6217d8ecd0c", - "reference": "71da881ad579f0cd66aef8677e4cf6217d8ecd0c", + "url": "https://api.github.com/repos/symfony/console/zipball/b28996bc0a3b08914b2a8609163ec35b36b30685", + "reference": "b28996bc0a3b08914b2a8609163ec35b36b30685", "shasum": "" }, "require": { @@ -3132,20 +3128,20 @@ "type": "tidelift" } ], - "time": "2020-08-09T08:16:57+00:00" + "time": "2020-09-09T05:09:37+00:00" }, { "name": "symfony/debug", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/debug.git", - "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164" + "reference": "9109e4414e684d0b75276ae203883467476d25d0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/debug/zipball/0893a0b07c499a1530614d65869ea6a7b1b8a164", - "reference": "0893a0b07c499a1530614d65869ea6a7b1b8a164", + "url": "https://api.github.com/repos/symfony/debug/zipball/9109e4414e684d0b75276ae203883467476d25d0", + "reference": "9109e4414e684d0b75276ae203883467476d25d0", "shasum": "" }, "require": { @@ -3202,20 +3198,20 @@ "type": "tidelift" } ], - "time": "2020-08-09T08:13:48+00:00" + "time": "2020-09-08T22:19:14+00:00" }, { "name": "symfony/filesystem", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/filesystem.git", - "reference": "8e6eff546d0fe879996fa701ee2f312767e95e50" + "reference": "495646f13d051cc5a8f77a68b68313dc854080aa" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/filesystem/zipball/8e6eff546d0fe879996fa701ee2f312767e95e50", - "reference": "8e6eff546d0fe879996fa701ee2f312767e95e50", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/495646f13d051cc5a8f77a68b68313dc854080aa", + "reference": "495646f13d051cc5a8f77a68b68313dc854080aa", "shasum": "" }, "require": { @@ -3266,20 +3262,20 @@ "type": "tidelift" } ], - "time": "2020-08-21T12:53:49+00:00" + "time": "2020-09-02T16:06:40+00:00" }, { "name": "symfony/finder", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/finder.git", - "reference": "5ec813ccafa8164ef21757e8c725d3a57da59200" + "reference": "52140652ed31cee3dabd0c481b5577201fa769b4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/finder/zipball/5ec813ccafa8164ef21757e8c725d3a57da59200", - "reference": "5ec813ccafa8164ef21757e8c725d3a57da59200", + "url": "https://api.github.com/repos/symfony/finder/zipball/52140652ed31cee3dabd0c481b5577201fa769b4", + "reference": "52140652ed31cee3dabd0c481b5577201fa769b4", "shasum": "" }, "require": { @@ -3329,7 +3325,7 @@ "type": "tidelift" } ], - "time": "2020-02-14T07:34:21+00:00" + "time": "2020-09-02T16:06:40+00:00" }, { "name": "symfony/polyfill-ctype", @@ -3802,16 +3798,16 @@ }, { "name": "symfony/process", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/process.git", - "reference": "af8d812d75fcdf2eae30928b42396fe17df137e4" + "reference": "46a862d0f334e51c1ed831b49cbe12863ffd5475" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/process/zipball/af8d812d75fcdf2eae30928b42396fe17df137e4", - "reference": "af8d812d75fcdf2eae30928b42396fe17df137e4", + "url": "https://api.github.com/repos/symfony/process/zipball/46a862d0f334e51c1ed831b49cbe12863ffd5475", + "reference": "46a862d0f334e51c1ed831b49cbe12863ffd5475", "shasum": "" }, "require": { @@ -3861,11 +3857,11 @@ "type": "tidelift" } ], - "time": "2020-07-16T09:41:49+00:00" + "time": "2020-09-02T16:06:40+00:00" }, { "name": "symfony/stopwatch", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -3928,16 +3924,16 @@ }, { "name": "symfony/yaml", - "version": "v3.4.44", + "version": "v3.4.45", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06" + "reference": "ec3c2ac4d881a4684c1f0317d2107f1a4152bad9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/4152e36b0f305c2a57aa0233dee56ec27bca4f06", - "reference": "4152e36b0f305c2a57aa0233dee56ec27bca4f06", + "url": "https://api.github.com/repos/symfony/yaml/zipball/ec3c2ac4d881a4684c1f0317d2107f1a4152bad9", + "reference": "ec3c2ac4d881a4684c1f0317d2107f1a4152bad9", "shasum": "" }, "require": { @@ -3997,7 +3993,7 @@ "type": "tidelift" } ], - "time": "2020-08-26T06:32:27+00:00" + "time": "2020-09-18T15:58:55+00:00" }, { "name": "webmozart/assert", @@ -4243,16 +4239,16 @@ }, { "name": "wp-cli/core-command", - "version": "v2.0.10", + "version": "v2.0.11", "source": { "type": "git", "url": "https://github.com/wp-cli/core-command.git", - "reference": "a2eb072919b252b3c8859f4c9b68fdbb9601099d" + "reference": "db88c14881bb927452c4ae13d7129132ab267e4a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/core-command/zipball/a2eb072919b252b3c8859f4c9b68fdbb9601099d", - "reference": "a2eb072919b252b3c8859f4c9b68fdbb9601099d", + "url": "https://api.github.com/repos/wp-cli/core-command/zipball/db88c14881bb927452c4ae13d7129132ab267e4a", + "reference": "db88c14881bb927452c4ae13d7129132ab267e4a", "shasum": "" }, "require": { @@ -4306,7 +4302,7 @@ ], "description": "Downloads, installs, updates, and manages a WordPress installation.", "homepage": "https://github.com/wp-cli/core-command", - "time": "2020-07-05T13:48:05+00:00" + "time": "2020-08-26T14:01:29+00:00" }, { "name": "wp-cli/cron-command", @@ -5029,16 +5025,16 @@ }, { "name": "wp-cli/language-command", - "version": "v2.0.6", + "version": "v2.0.7", "source": { "type": "git", "url": "https://github.com/wp-cli/language-command.git", - "reference": "569be810e057cf9df7d7924e62ebe569e440f6b1" + "reference": "aea62e70125d040d1fbe5c24e0fd49d977de3e9d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/wp-cli/language-command/zipball/569be810e057cf9df7d7924e62ebe569e440f6b1", - "reference": "569be810e057cf9df7d7924e62ebe569e440f6b1", + "url": "https://api.github.com/repos/wp-cli/language-command/zipball/aea62e70125d040d1fbe5c24e0fd49d977de3e9d", + "reference": "aea62e70125d040d1fbe5c24e0fd49d977de3e9d", "shasum": "" }, "require": { @@ -5100,7 +5096,7 @@ ], "description": "Installs, activates, and manages language packs.", "homepage": "https://github.com/wp-cli/language-command", - "time": "2020-06-12T00:17:09+00:00" + "time": "2020-08-26T14:58:05+00:00" }, { "name": "wp-cli/maintenance-mode-command", @@ -6123,15 +6119,15 @@ }, { "name": "wpackagist-plugin/easy-digital-downloads", - "version": "2.9.25", + "version": "2.9.26", "source": { "type": "svn", "url": "https://plugins.svn.wordpress.org/easy-digital-downloads/", - "reference": "tags/2.9.25" + "reference": "tags/2.9.26" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/easy-digital-downloads.2.9.25.zip" + "url": "https://downloads.wordpress.org/plugin/easy-digital-downloads.2.9.26.zip" }, "require": { "composer/installers": "~1.0" @@ -6141,15 +6137,15 @@ }, { "name": "wpackagist-plugin/user-switching", - "version": "1.5.5", + "version": "1.5.6", "source": { "type": "svn", "url": "https://plugins.svn.wordpress.org/user-switching/", - "reference": "tags/1.5.5" + "reference": "tags/1.5.6" }, "dist": { "type": "zip", - "url": "https://downloads.wordpress.org/plugin/user-switching.1.5.5.zip" + "url": "https://downloads.wordpress.org/plugin/user-switching.1.5.6.zip" }, "require": { "composer/installers": "~1.0" diff --git a/connectors/class-connector-settings.php b/connectors/class-connector-settings.php index b1a54c278..97acbe386 100644 --- a/connectors/class-connector-settings.php +++ b/connectors/class-connector-settings.php @@ -31,7 +31,7 @@ class Connector_Settings extends Connector { * @var array */ public $actions = array( - 'whitelist_options', + 'allowed_options', 'update_option', 'update_site_option', 'update_option_permalink_structure', @@ -636,7 +636,7 @@ public function callback_update_option( $option, $value, $old_value ) { * * @return array */ - public function callback_whitelist_options( $options ) { + public function callback_allowed_options( $options ) { add_action( 'updated_option', array( $this, 'callback' ), 10, 3 ); return $options; diff --git a/tests/tests/connectors/test-class-connector-acf.php b/tests/tests/connectors/test-class-connector-acf.php index 8259544ef..b54505269 100644 --- a/tests/tests/connectors/test-class-connector-acf.php +++ b/tests/tests/connectors/test-class-connector-acf.php @@ -2,7 +2,9 @@ /** * WP Integration Test w/ Advanced Custom Fields * - * Tests for ACF Connector class callbacks. + * Tests for ACF connector class callbacks. + * + * @package WP_Stream */ namespace WP_Stream; diff --git a/tests/tests/connectors/test-class-connector-blogs.php b/tests/tests/connectors/test-class-connector-blogs.php index 21feec94e..aeac6eda6 100644 --- a/tests/tests/connectors/test-class-connector-blogs.php +++ b/tests/tests/connectors/test-class-connector-blogs.php @@ -1,4 +1,9 @@ connector_blogs = new Connector_Blogs; $this->assertNotEmpty( $this->connector_blogs ); } - + /** * Test for get_context_labels(). * - * @group ms-required + * @group ms-required */ public function test_get_context_labels() { if ( ! is_multisite() ) { diff --git a/tests/tests/connectors/test-class-connector-edd.php b/tests/tests/connectors/test-class-connector-edd.php index bb457995f..1b1e55f12 100644 --- a/tests/tests/connectors/test-class-connector-edd.php +++ b/tests/tests/connectors/test-class-connector-edd.php @@ -3,6 +3,8 @@ * WP Integration Test w/ Easy Digital Downloads * * Tests for EDD Connector class callbacks. + * + * @package WP_Stream */ namespace WP_Stream; diff --git a/tests/tests/connectors/test-class-connector-mercator.php b/tests/tests/connectors/test-class-connector-mercator.php index d12ac6bfe..b708c6bcf 100644 --- a/tests/tests/connectors/test-class-connector-mercator.php +++ b/tests/tests/connectors/test-class-connector-mercator.php @@ -1,4 +1,9 @@ >>>>>> Settings connector test implemented. * * @package WP_Stream */ diff --git a/tests/tests/connectors/test-class-connector-settings.php b/tests/tests/connectors/test-class-connector-settings.php index 5b0c6bff7..70bcb7483 100644 --- a/tests/tests/connectors/test-class-connector-settings.php +++ b/tests/tests/connectors/test-class-connector-settings.php @@ -1,47 +1,144 @@ connector = new Connector_Settings(); - $this->assertNotEmpty( $this->connector ); + $this->plugin->connectors->unload_connectors(); + + // Make partial of Connector_Settings class, with mocked "log" function. + $this->mock = $this->getMockBuilder( Connector_Settings::class ) + ->setMethods( array( 'log' ) ) + ->getMock(); + + // Register connector. + $this->mock->register(); } public function test_is_option_ignored() { - $this->assertTrue( $this->connector->is_option_ignored( '_transient_option_name' ) ); - $this->assertTrue( $this->connector->is_option_ignored( '_site_transient_option_name' ) ); - $this->assertTrue( $this->connector->is_option_ignored( 'option_name$' ) ); - $this->assertTrue( $this->connector->is_option_ignored( 'image_default_link_type' ) ); - $this->assertTrue( $this->connector->is_option_ignored( 'medium_large_size_w' ) ); - $this->assertTrue( $this->connector->is_option_ignored( 'medium_large_size_h' ) ); - - $this->assertFalse( $this->connector->is_option_ignored( 'option_site_transient_name' ) ); - $this->assertFalse( $this->connector->is_option_ignored( 'option_transient_name' ) ); - $this->assertFalse( $this->connector->is_option_ignored( 'option_$_name' ) ); - $this->assertFalse( $this->connector->is_option_ignored( 'not_ignored' ) ); + $this->assertTrue( $this->mock->is_option_ignored( '_transient_option_name' ) ); + $this->assertTrue( $this->mock->is_option_ignored( '_site_transient_option_name' ) ); + $this->assertTrue( $this->mock->is_option_ignored( 'option_name$' ) ); + $this->assertTrue( $this->mock->is_option_ignored( 'image_default_link_type' ) ); + $this->assertTrue( $this->mock->is_option_ignored( 'medium_large_size_w' ) ); + $this->assertTrue( $this->mock->is_option_ignored( 'medium_large_size_h' ) ); + + $this->assertFalse( $this->mock->is_option_ignored( 'option_site_transient_name' ) ); + $this->assertFalse( $this->mock->is_option_ignored( 'option_transient_name' ) ); + $this->assertFalse( $this->mock->is_option_ignored( 'option_$_name' ) ); + $this->assertFalse( $this->mock->is_option_ignored( 'not_ignored' ) ); // Test custom ignores. - $this->assertFalse( $this->connector->is_option_ignored( 'ignore_me' ) ); + $this->assertFalse( $this->mock->is_option_ignored( 'ignore_me' ) ); add_filter( 'wp_stream_is_option_ignored', function( $is_ignored, $option_name, $default_ignored ) { return in_array( $option_name, array_merge( [ 'ignore_me' ], $default_ignored ), true ); }, 10, 3 ); - $this->assertTrue( $this->connector->is_option_ignored( 'ignore_me' ) ); + $this->assertTrue( $this->mock->is_option_ignored( 'ignore_me' ) ); } + public function test_callback_updated_option() { + // Create options in database for later use. + add_option( 'users_can_register', false ); + add_option( 'permalink_structure', '' ); + add_option( 'category_base', '' ); + add_option( 'tag_base', '' ); + + $this->mock->expects( $this->exactly( 4 ) ) + ->method( 'log' ) + ->withConsecutive( + array( + $this->equalTo( __( '"%s" setting was updated', 'stream' ) ), + $this->equalTo( + array( + 'label' => 'Membership', + 'option' => 'users_can_register', + 'context' => 'settings', + 'old_value' => '0', + 'value' => '1', + ) + ), + $this->equalTo( null ), + $this->equalTo( 'settings' ), + $this->equalTo( 'updated' ) + ), + array( + $this->equalTo( __( '"%s" setting was updated', 'stream' ) ), + $this->equalTo( + array( + 'label' => 'Permalink Settings', + 'option' => 'permalink_structure', + 'context' => 'permalink', + 'old_value' => '', + 'value' => '/%year%/%postname%/', + ) + ), + $this->equalTo( null ), + $this->equalTo( 'permalink' ), + $this->equalTo( 'updated' ) + ), + array( + $this->equalTo( __( '"%s" setting was updated', 'stream' ) ), + $this->equalTo( + array( + 'label' => 'Category base', + 'option' => 'category_base', + 'context' => 'permalink', + 'old_value' => '', + 'value' => 'cat/', + ) + ), + $this->equalTo( null ), + $this->equalTo( 'permalink' ), + $this->equalTo( 'updated' ) + ), + array( + $this->equalTo( __( '"%s" setting was updated', 'stream' ) ), + $this->equalTo( + array( + 'label' => 'Tag base', + 'option' => 'tag_base', + 'context' => 'permalink', + 'old_value' => '', + 'value' => 'tag/', + ) + ), + $this->equalTo( null ), + $this->equalTo( 'permalink' ), + $this->equalTo( 'updated' ) + ) + ); + + // Simulate being on the WP Customizr page. + require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; + do_action( 'customize_save', new \WP_Customize_Manager( array() ) ); + + // Update options to trigger callback. + update_option( 'users_can_register', true ); + + // Use this to prevent repeated log calls. + global $wp_actions; + unset( $wp_actions['customize_save'] ); + + update_option( 'permalink_structure', '/%year%/%postname%/' ); + update_option( 'category_base', 'cat/' ); + update_option( 'tag_base', 'tag/' ); + + + // Check callback test action. + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_updated_option' ) ); + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_tag_base' ) ); + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_category_base' ) ); + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_permalink_structure' ) ); + $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option' ) ); + } } From 207a7e9b766bdc71c4447053cc608b051cd78a4d Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Tue, 29 Sep 2020 11:57:42 -0400 Subject: [PATCH 2/4] Bug fixed in the "update_site_option" callback in the Settings connector class. --- composer.json | 4 +- connectors/class-connector-settings.php | 2 +- .../test-class-connector-settings.php | 41 +++++++++++-------- 3 files changed, 28 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 9989fa6f3..c2a3d5396 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,8 @@ "license": "GPL-2.0-or-later", "repositories": [ { - "type":"composer", - "url":"https://wpackagist.org" + "type": "composer", + "url": "https://wpackagist.org" } ], "require": { diff --git a/connectors/class-connector-settings.php b/connectors/class-connector-settings.php index 97acbe386..a4a65385d 100644 --- a/connectors/class-connector-settings.php +++ b/connectors/class-connector-settings.php @@ -664,7 +664,7 @@ public function callback_update_option_permalink_structure( $old_value, $value ) * @param mixed $old_value Option old value. */ public function callback_update_site_option( $option, $value, $old_value ) { - $this->callback_updated_option( $option, $value, $old_value ); + $this->callback_updated_option( $option, $old_value, $value ); } /** diff --git a/tests/tests/connectors/test-class-connector-settings.php b/tests/tests/connectors/test-class-connector-settings.php index 70bcb7483..f708594c8 100644 --- a/tests/tests/connectors/test-class-connector-settings.php +++ b/tests/tests/connectors/test-class-connector-settings.php @@ -47,11 +47,16 @@ public function test_is_option_ignored() { } public function test_callback_updated_option() { + // If multisite use site_option methods and test "update_site_option" callback + // instead of the update_option callback. + $add_method = is_multisite() ? 'add_site_option' : 'add_option'; + $update_method = is_multisite() ? 'update_site_option' : 'update_option'; + // Create options in database for later use. - add_option( 'users_can_register', false ); - add_option( 'permalink_structure', '' ); - add_option( 'category_base', '' ); - add_option( 'tag_base', '' ); + call_user_func( $add_method, 'users_can_register', 0 ); + call_user_func( $add_method, 'permalink_structure', '' ); + call_user_func( $add_method, 'category_base', '' ); + call_user_func( $add_method, 'tag_base', '' ); $this->mock->expects( $this->exactly( 4 ) ) ->method( 'log' ) @@ -123,22 +128,26 @@ public function test_callback_updated_option() { do_action( 'customize_save', new \WP_Customize_Manager( array() ) ); // Update options to trigger callback. - update_option( 'users_can_register', true ); + call_user_func( $update_method, 'users_can_register', 1 ); // Use this to prevent repeated log calls. global $wp_actions; unset( $wp_actions['customize_save'] ); - update_option( 'permalink_structure', '/%year%/%postname%/' ); - update_option( 'category_base', 'cat/' ); - update_option( 'tag_base', 'tag/' ); - - - // Check callback test action. - $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_updated_option' ) ); - $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_tag_base' ) ); - $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_category_base' ) ); - $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option_permalink_structure' ) ); - $this->assertGreaterThan( 0, did_action( 'wp_stream_test_callback_update_option' ) ); + call_user_func( $update_method, 'permalink_structure', '/%year%/%postname%/' ); + call_user_func( $update_method, 'category_base', 'cat/' ); + call_user_func( $update_method, 'tag_base', 'tag/' ); + + // If multisite only check update_site_option test callback. + if ( is_multisite() ) { + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_site_option' ) ); + } else { + // Check callback test action. + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_tag_base' ) ); + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_category_base' ) ); + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option_permalink_structure' ) ); + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_updated_option' ) ); + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_update_option' ) ); + } } } From e428ac45a9bef90a8fc97e3748a422ecf7d5df7e Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 5 Oct 2020 17:41:02 -0400 Subject: [PATCH 3/4] "Connector_Settings::callback_update_option()" signature parameter order fixed. --- connectors/class-connector-settings.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/connectors/class-connector-settings.php b/connectors/class-connector-settings.php index a4a65385d..714df1713 100644 --- a/connectors/class-connector-settings.php +++ b/connectors/class-connector-settings.php @@ -618,12 +618,12 @@ function( $rule ) use ( $submenu, $record ) { * @action update_option * * @param string $option Option name. - * @param mixed $value Option new value. * @param mixed $old_value Option old value. + * @param mixed $value Option new value. */ - public function callback_update_option( $option, $value, $old_value ) { + public function callback_update_option( $option, $old_value, $value ) { if ( ( defined( '\WP_CLI' ) && \WP_CLI || did_action( 'customize_save' ) ) && array_key_exists( $option, $this->labels ) ) { - $this->callback_updated_option( $option, $value, $old_value ); + $this->callback_updated_option( $option, $old_value, $value ); } } From ec330c8cca8e5ded4e45871964c7b593302c2967 Mon Sep 17 00:00:00 2001 From: Geoff Taylor Date: Mon, 5 Oct 2020 17:50:02 -0400 Subject: [PATCH 4/4] Posts connector test DocBlock cleaned. --- tests/tests/connectors/test-class-connector-posts.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/tests/connectors/test-class-connector-posts.php b/tests/tests/connectors/test-class-connector-posts.php index dc88b0ba5..86d592c9c 100644 --- a/tests/tests/connectors/test-class-connector-posts.php +++ b/tests/tests/connectors/test-class-connector-posts.php @@ -1,10 +1,6 @@ >>>>>> Settings connector test implemented. * * @package WP_Stream */