diff --git a/composer.lock b/composer.lock index d45b1aa6d..c3bdcb931 100644 --- a/composer.lock +++ b/composer.lock @@ -137,20 +137,21 @@ "packages-dev": [ { "name": "automattic/vipwpcs", - "version": "2.1.0", + "version": "2.2.0", "source": { "type": "git", "url": "https://github.com/Automattic/VIP-Coding-Standards.git", - "reference": "03e75ddd0261b675dece60fb67fc2e9c6af4ad35" + "reference": "4d0612461232b313d06321f1501c3989bd6aecf9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/03e75ddd0261b675dece60fb67fc2e9c6af4ad35", - "reference": "03e75ddd0261b675dece60fb67fc2e9c6af4ad35", + "url": "https://api.github.com/repos/Automattic/VIP-Coding-Standards/zipball/4d0612461232b313d06321f1501c3989bd6aecf9", + "reference": "4d0612461232b313d06321f1501c3989bd6aecf9", "shasum": "" }, "require": { "php": ">=5.4", + "sirbrillig/phpcs-variable-analysis": "^2.8.3", "squizlabs/php_codesniffer": "^3.5.5", "wp-coding-standards/wpcs": "^2.3" }, @@ -179,20 +180,20 @@ "standards", "wordpress" ], - "time": "2020-07-07T07:48:04+00:00" + "time": "2020-09-07T10:45:45+00:00" }, { "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,20 +236,34 @@ "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", - "version": "1.10.10", + "version": "1.10.13", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "32966a3b1d48bc01472a8321fd6472b44fad033a" + "reference": "47c841ba3b2d3fc0b4b13282cf029ea18b66d78b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/32966a3b1d48bc01472a8321fd6472b44fad033a", - "reference": "32966a3b1d48bc01472a8321fd6472b44fad033a", + "url": "https://api.github.com/repos/composer/composer/zipball/47c841ba3b2d3fc0b4b13282cf029ea18b66d78b", + "reference": "47c841ba3b2d3fc0b4b13282cf029ea18b66d78b", "shasum": "" }, "require": { @@ -329,20 +344,20 @@ "type": "tidelift" } ], - "time": "2020-08-03T09:35:19+00:00" + "time": "2020-09-09T09:46:34+00:00" }, { "name": "composer/semver", - "version": "1.5.1", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/composer/semver.git", - "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de" + "reference": "114f819054a2ea7db03287f5efb757e2af6e4079" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/semver/zipball/c6bea70230ef4dd483e6bbcab6005f682ed3a8de", - "reference": "c6bea70230ef4dd483e6bbcab6005f682ed3a8de", + "url": "https://api.github.com/repos/composer/semver/zipball/114f819054a2ea7db03287f5efb757e2af6e4079", + "reference": "114f819054a2ea7db03287f5efb757e2af6e4079", "shasum": "" }, "require": { @@ -390,7 +405,21 @@ "validation", "versioning" ], - "time": "2020-01-13T12:06:48+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-09-09T09:34:06+00:00" }, { "name": "composer/spdx-licenses", @@ -468,16 +497,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 +537,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 +965,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 +1000,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 +1021,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 +1041,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 +2770,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 +2825,7 @@ "type": "tidelift" } ], - "time": "2020-08-13T09:07:59+00:00" + "time": "2020-08-25T06:56:57+00:00" }, { "name": "seld/phar-utils", @@ -2828,6 +2871,54 @@ ], "time": "2020-07-07T18:42:57+00:00" }, + { + "name": "sirbrillig/phpcs-variable-analysis", + "version": "v2.8.3", + "source": { + "type": "git", + "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", + "reference": "00b4fa3130faa26762c929989e3d958086c627f1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/00b4fa3130faa26762c929989e3d958086c627f1", + "reference": "00b4fa3130faa26762c929989e3d958086c627f1", + "shasum": "" + }, + "require": { + "php": ">=5.4.0", + "squizlabs/php_codesniffer": "^3.1" + }, + "require-dev": { + "dealerdirect/phpcodesniffer-composer-installer": "^0.4.4 || ^0.5 || ^0.6", + "limedeck/phpunit-detailed-printer": "^3.1 || ^4.0 || ^5.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^5.0 || ^6.5 || ^7.0 || ^8.0", + "sirbrillig/phpcs-import-detection": "^1.1" + }, + "type": "phpcodesniffer-standard", + "autoload": { + "psr-4": { + "VariableAnalysis\\": "VariableAnalysis/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-2-Clause" + ], + "authors": [ + { + "name": "Sam Graham", + "email": "php-codesniffer-variableanalysis@illusori.co.uk" + }, + { + "name": "Payton Swick", + "email": "payton@foolord.com" + } + ], + "description": "A PHPCS sniff to detect problems with variables.", + "time": "2020-07-11T23:32:06+00:00" + }, { "name": "squizlabs/php_codesniffer", "version": "3.5.6", @@ -2881,16 +2972,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 +3046,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 +3132,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 +3202,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 +3266,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 +3802,7 @@ }, { "name": "symfony/process", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/process.git", @@ -3774,7 +3865,7 @@ }, { "name": "symfony/stopwatch", - "version": "v3.4.43", + "version": "v3.4.44", "source": { "type": "git", "url": "https://github.com/symfony/stopwatch.git", @@ -3837,16 +3928,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 +3997,7 @@ "type": "tidelift" } ], - "time": "2020-07-23T09:37:51+00:00" + "time": "2020-08-26T06:32:27+00:00" }, { "name": "webmozart/assert", @@ -5971,16 +6062,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 +6101,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 +6123,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" diff --git a/connectors/class-connector-posts.php b/connectors/class-connector-posts.php index ce74a4226..dd6893b1d 100644 --- a/connectors/class-connector-posts.php +++ b/connectors/class-connector-posts.php @@ -170,7 +170,8 @@ public function callback_transition_post_status( $new, $old, $post ) { return; } - if ( in_array( $new, array( 'auto-draft', 'inherit' ), true ) ) { + $start_statuses = array( 'auto-draft', 'inherit', 'new' ); + if ( in_array( $new, $start_statuses, true ) ) { return; } elseif ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; @@ -196,7 +197,7 @@ public function callback_transition_post_status( $new, $old, $post ) { '1: Post title, 2: Post type singular name', 'stream' ); - } elseif ( 'publish' === $new && 'draft' === $old ) { + } elseif ( 'publish' === $new && ! in_array( $old, array( 'future', 'publish' ), true ) ) { /* translators: %1$s: a post title, %2$s: a post type singular name (e.g. "Hello World", "Post") */ $summary = _x( '"%1$s" %2$s published', @@ -255,7 +256,7 @@ public function callback_transition_post_status( $new, $old, $post ) { ); } - if ( 'auto-draft' === $old && 'auto-draft' !== $new ) { + if ( in_array( $old, $start_statuses, true ) && ! in_array( $new, $start_statuses, true ) ) { $action = 'created'; } diff --git a/tests/tests/connectors/test-class-connector-posts.php b/tests/tests/connectors/test-class-connector-posts.php index bc9fab027..149637e31 100644 --- a/tests/tests/connectors/test-class-connector-posts.php +++ b/tests/tests/connectors/test-class-connector-posts.php @@ -1,12 +1,499 @@ markTestIncomplete( - 'Not implemented yet.' + /** + * Holds GMT timestamp in "Y-m-d H:i:s" format + * + * @var string + */ + private $date_gmt; + + /** + * Runs before each test. + */ + public function setUp() { + parent::setUp(); + + $this->plugin->connectors->unload_connectors(); + + // Set static timestamps. + $this->date = '2007-07-04 12:30:00'; + $this->date_gmt = get_gmt_from_date( $this->date ); + + // Make partial of Connector_Posts class, with mocked "log" function. + $this->mock = $this->getMockBuilder( Connector_Posts::class ) + ->setMethods( [ 'log' ] ) + ->getMock(); + + // Register connector. + $this->mock->register(); + } + + /** + * Tests "transition_post_status" callback function. + */ + public function test_callback_transition_post_status() { + // Create post args for later use. + $post_args = array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_date' => $this->date, + 'post_date_gmt' => $this->date_gmt, + 'post_status' => 'draft' + ); + + // Set expected calls for the Mock. + $this->mock->expects( $this->exactly( 12 ) ) + ->method( 'log' ) + ->withConsecutive( + array( + $this->equalTo( + _x( + '"%1$s" %2$s drafted', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'draft', + 'old_status' => 'new', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'created' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s published', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'publish', + 'old_status' => 'draft', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s unpublished', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'draft', + 'old_status' => 'publish', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s draft saved', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'draft', + 'old_status' => 'draft', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s pending review', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'pending', + 'old_status' => 'draft', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s scheduled for %3$s', + '1: Post title, 2: Post type singular name, 3: Scheduled post date', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'future', + 'old_status' => 'pending', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" scheduled %2$s published', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'publish', + 'old_status' => 'future', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s privately published', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'private', + 'old_status' => 'publish', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s trashed', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'trash', + 'old_status' => 'private', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'trashed' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s restored from trash', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'publish', + 'old_status' => 'trash', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'untrashed' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s updated', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'publish', + 'old_status' => 'publish', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'updated' ), + ), + array( + $this->equalTo( + _x( + '"%1$s" %2$s published', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->callback( + function( $subject ) { + $expected = array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + 'new_status' => 'publish', + 'old_status' => 'new', + ); + return $expected === array_intersect_key( $expected, $subject ); + } + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'created' ), + ), + ); + + // Create post/update post status trigger callbacks. + $post_id = wp_insert_post( $post_args ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'publish', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'draft', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'draft', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'pending', + ) + ); + $time = strtotime( 'tomorrow' ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'future', + 'post_date' => date( 'Y-m-d H:i:s', $time ), + 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $time ), + ) + ); + $time = strtotime( 'now' ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'publish', + 'post_date' => date( 'Y-m-d H:i:s', $time ), + 'post_date_gmt' => gmdate( 'Y-m-d H:i:s', $time ), + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'private', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'trash', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'publish', + ) + ); + wp_update_post( + array( + 'ID' => $post_id, + 'post_status' => 'publish', + ) ); + + // Expected log to be made with "created" action. + wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + ) + ); + + /** + * Expected log to not be called for newly published attachment + * because it's an excluded post type. + */ + wp_insert_post( + array( + 'post_title' => 'Test attachment', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_type' => 'attachment', + ) + ); + + + // Confirm callback execution. + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_transition_post_status' ) ); + } + + /** + * Tests "deleted_post" callback function. + */ + public function test_callback_deleted_post() { + // Create post for later use. + $post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish' + ) + ); + + $auto_draft_post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'auto-draft' + ) + ); + + $attachment_post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_type' => 'attachment' + ) + ); + + // Set expected calls for the Mock. + $this->mock->expects( $this->once() ) + ->method( 'log' ) + ->with( + $this->equalTo( + _x( + '"%1$s" %2$s deleted from trash', + '1: Post title, 2: Post type singular name', + 'stream' + ) + ), + $this->equalTo( + array( + 'post_title' => 'Test post', + 'singular_name' => 'post', + ) + ), + $this->greaterThan( 0 ), + $this->equalTo( 'post' ), + $this->equalTo( 'deleted' ) + ); + + // Delete post and trigger mock. + wp_delete_post( $post_id, true ); + + // Delete auto-drafted post and attachment to confirm these actions is ignored. + wp_delete_post( $auto_draft_post_id, true ); + wp_delete_post( $attachment_post_id, true ); + + + // Confirm callback execution. + $this->assertGreaterThan( 0, did_action( $this->action_prefix . 'callback_deleted_post' ) ); } }