diff --git a/composer.lock b/composer.lock index 8c4cad947..48cc598bc 100644 --- a/composer.lock +++ b/composer.lock @@ -239,16 +239,16 @@ }, { "name": "composer/composer", - "version": "1.10.8", + "version": "1.10.9", "source": { "type": "git", "url": "https://github.com/composer/composer.git", - "reference": "56e0e094478f30935e9128552188355fa9712291" + "reference": "83c3250093d5491600a822e176b107a945baf95a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/composer/zipball/56e0e094478f30935e9128552188355fa9712291", - "reference": "56e0e094478f30935e9128552188355fa9712291", + "url": "https://api.github.com/repos/composer/composer/zipball/83c3250093d5491600a822e176b107a945baf95a", + "reference": "83c3250093d5491600a822e176b107a945baf95a", "shasum": "" }, "require": { @@ -315,7 +315,21 @@ "dependency", "package" ], - "time": "2020-06-24T19:23:30+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-07-16T10:57:00+00:00" }, { "name": "composer/semver", @@ -380,16 +394,16 @@ }, { "name": "composer/spdx-licenses", - "version": "1.5.3", + "version": "1.5.4", "source": { "type": "git", "url": "https://github.com/composer/spdx-licenses.git", - "reference": "0c3e51e1880ca149682332770e25977c70cf9dae" + "reference": "6946f785871e2314c60b4524851f3702ea4f2223" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/0c3e51e1880ca149682332770e25977c70cf9dae", - "reference": "0c3e51e1880ca149682332770e25977c70cf9dae", + "url": "https://api.github.com/repos/composer/spdx-licenses/zipball/6946f785871e2314c60b4524851f3702ea4f2223", + "reference": "6946f785871e2314c60b4524851f3702ea4f2223", "shasum": "" }, "require": { @@ -436,7 +450,21 @@ "spdx", "validator" ], - "time": "2020-02-14T07:44:31+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-07-15T15:35:07+00:00" }, { "name": "composer/xdebug-handler", @@ -1265,6 +1293,55 @@ ], "time": "2013-02-24T15:01:54+00:00" }, + { + "name": "paragonie/random_compat", + "version": "v2.0.18", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "0a58ef6e3146256cc3dc7cc393927bcc7d1b72db" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/0a58ef6e3146256cc3dc7cc393927bcc7d1b72db", + "reference": "0a58ef6e3146256cc3dc7cc393927bcc7d1b72db", + "shasum": "" + }, + "require": { + "php": ">=5.2.0" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "autoload": { + "files": [ + "lib/random.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "time": "2019-01-03T20:59:08+00:00" + }, { "name": "php-coveralls/php-coveralls", "version": "v2.2.0", @@ -3084,16 +3161,16 @@ }, { "name": "symfony/polyfill-ctype", - "version": "v1.17.1", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-ctype.git", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d" + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", - "reference": "2edd75b8b35d62fd3eeabba73b26b8f1f60ce13d", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/1c302646f6efc070cd46856e600e5e0684d6b454", + "reference": "1c302646f6efc070cd46856e600e5e0684d6b454", "shasum": "" }, "require": { @@ -3105,7 +3182,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3142,25 +3219,40 @@ "polyfill", "portable" ], - "time": "2020-06-06T08:46:27+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.17.1", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "a57f8161502549a742a63c09f0a604997bf47027" + "reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/a57f8161502549a742a63c09f0a604997bf47027", - "reference": "a57f8161502549a742a63c09f0a604997bf47027", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", + "reference": "bc6549d068d0160e0f10f7a5a23c7d1406b95ebe", "shasum": "" }, "require": { "php": ">=5.3.3", - "symfony/polyfill-mbstring": "^1.3", + "symfony/polyfill-intl-normalizer": "^1.10", + "symfony/polyfill-php70": "^1.10", "symfony/polyfill-php72": "^1.10" }, "suggest": { @@ -3169,7 +3261,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3193,6 +3285,10 @@ "name": "Laurent Bassin", "email": "laurent@bassin.info" }, + { + "name": "Trevor Rowbotham", + "email": "trevor.rowbotham@pm.me" + }, { "name": "Symfony Community", "homepage": "https://symfony.com/contributors" @@ -3208,20 +3304,115 @@ "portable", "shim" ], - "time": "2020-06-06T08:46:27+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.18.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", + "reference": "37078a8dd4a2a1e9ab0231af7c6cb671b2ed5a7e", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.17.1", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7" + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/7110338d81ce1cbc3e273136e4574663627037a7", - "reference": "7110338d81ce1cbc3e273136e4574663627037a7", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/a6977d63bf9a0ad4c65cd352709e230876f9904a", + "reference": "a6977d63bf9a0ad4c65cd352709e230876f9904a", "shasum": "" }, "require": { @@ -3233,7 +3424,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" }, "thanks": { "name": "symfony/polyfill", @@ -3271,20 +3462,111 @@ "portable", "shim" ], - "time": "2020-06-06T08:46:27+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" + }, + { + "name": "symfony/polyfill-php70", + "version": "v1.18.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "0dd93f2c578bdc9c72697eaa5f1dd25644e618d3" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/0dd93f2c578bdc9c72697eaa5f1dd25644e618d3", + "reference": "0dd93f2c578bdc9c72697eaa5f1dd25644e618d3", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0|~9.99", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/polyfill-php72", - "version": "v1.17.0", + "version": "v1.18.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php72.git", - "reference": "f048e612a3905f34931127360bdd2def19a5e582" + "reference": "639447d008615574653fb3bc60d1986d7172eaae" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/f048e612a3905f34931127360bdd2def19a5e582", - "reference": "f048e612a3905f34931127360bdd2def19a5e582", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/639447d008615574653fb3bc60d1986d7172eaae", + "reference": "639447d008615574653fb3bc60d1986d7172eaae", "shasum": "" }, "require": { @@ -3293,7 +3575,11 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "1.17-dev" + "dev-master": "1.18-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" } }, "autoload": { @@ -3326,7 +3612,21 @@ "portable", "shim" ], - "time": "2020-05-12T16:47:27+00:00" + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2020-07-14T12:35:20+00:00" }, { "name": "symfony/process", diff --git a/connectors/class-connector-comments.php b/connectors/class-connector-comments.php index 81c4dd0af..edffcec3f 100644 --- a/connectors/class-connector-comments.php +++ b/connectors/class-connector-comments.php @@ -615,6 +615,10 @@ public function callback_comment_duplicate_trigger( $comment_data ) { global $wpdb; unset( $comment_data ); + if ( empty( $wpdb->last_result ) ) { + return; + } + $comment_id = $wpdb->last_result[0]->comment_ID; $comment = get_comment( $comment_id ); diff --git a/docker-compose.yml b/docker-compose.yml index db46074e1..00a25c593 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -20,7 +20,7 @@ services: - mysql - db_phpunit ports: - - "80:80" + - "8080:80" - "443:443" - "9000:9000" # Xdebug volumes: diff --git a/tests/tests/connectors/test-class-connector-comments.php b/tests/tests/connectors/test-class-connector-comments.php index 50b0dfcf7..3892896ab 100644 --- a/tests/tests/connectors/test-class-connector-comments.php +++ b/tests/tests/connectors/test-class-connector-comments.php @@ -1,33 +1,45 @@ mock = $this->getMockBuilder( Connector_Comments::class ) - ->setMethods( [ 'log' ] ) + ->setMethods( array( 'log' ) ) ->getMock(); // Register connector. $this->mock->register(); } + /** + * Tests "wp_insert_comment" callback function. + */ public function test_callback_wp_insert_comment() { + // Create post for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->withConsecutive( - [ + array( $this->equalTo( _x( 'New %4$s by %1$s on %2$s %3$s', @@ -36,21 +48,21 @@ public function test_callback_wp_insert_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_status' => 'pending approval', 'comment_type' => 'comment', 'post_id' => $post_id, 'is_spam' => false, - ] + ) ), $this->greaterThan( 0 ), $this->equalTo( 'post' ), $this->equalTo( 'created' ), $this->equalTo( 0 ) - ], - [ + ), + array( $this->equalTo( _x( 'Reply to %1$s\'s %5$s by %2$s on %3$s %4$s', @@ -59,64 +71,70 @@ public function test_callback_wp_insert_comment() { ) ), $this->equalTo( - [ + array( 'parent_user_name' => 'Jim Bean', 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_status' => 'pending approval', 'comment_type' => 'comment', 'post_id' => "$post_id", - ] + ) ), $this->greaterThan( 0 ), $this->equalTo( 'post' ), $this->equalTo( 'replied' ), $this->equalTo( 0 ) - ] + ) ); - // Do stuff. + // Create comments and trigger mocks. $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, 'comment_parent' => $comment_id, - ] + ) ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_wp_insert_comment' ) ); } + /** + * Tests "edit_comment" callback function. + */ public function test_callback_edit_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -128,48 +146,54 @@ public function test_callback_edit_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'edited' ) ); - // Do stuff. + // Update comment and trigger mock. wp_update_comment( - [ + array( 'comment_ID' => $comment_id, 'comment_content' => 'Lorem ipsum dolor... 2', - ] + ) ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_edit_comment' ) ); } + /** + * Tests "delete_comment" callback function. + */ public function test_callback_delete_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -181,43 +205,49 @@ public function test_callback_delete_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'deleted' ) ); - // Do stuff. + // Delete comment and trigger mock. wp_delete_comment( $comment_id, true ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_delete_comment' ) ); } + /** + * Tests "trash_comment" callback function. + */ public function test_callback_trash_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -229,44 +259,50 @@ public function test_callback_trash_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'trashed' ) ); - // Do stuff. + // Trash comment and trigger mock. wp_trash_comment( $comment_id ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_trash_comment' ) ); } + /** + * Tests "untrash_comment" callback function. + */ public function test_callback_untrash_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); wp_trash_comment( $comment_id ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -278,43 +314,49 @@ public function test_callback_untrash_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'untrashed' ) ); - // Do stuff. + // Untrash comment and trigger mock. wp_untrash_comment( $comment_id ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_untrash_comment' ) ); } + /** + * Tests "spam_comment" callback function. + */ public function test_callback_spam_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -326,44 +368,50 @@ public function test_callback_spam_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'spammed' ) ); - // Do stuff. + // Set comment to spam and trigger mock. wp_spam_comment( $comment_id ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_spam_comment' ) ); } + /** + * Tests "unspam_comment" callback function. + */ public function test_callback_unspam_comment() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); wp_spam_comment( $comment_id ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -375,43 +423,49 @@ public function test_callback_unspam_comment() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'unspammed' ) ); - // Do stuff. + // Unspam comment and trigger mock. wp_unspam_comment( $comment_id ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_unspam_comment' ) ); } + /** + * Tests "transition_comment_status" callback function. + */ public function test_callback_transition_comment_status() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); $comment_id = wp_insert_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -423,7 +477,7 @@ public function test_callback_transition_comment_status() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'new_status' => 'unapproved', 'comment_type' => 'comment', @@ -431,37 +485,45 @@ public function test_callback_transition_comment_status() { 'post_title' => '"Test post"', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'unapproved' ) ); - // Do stuff. + // Update comment status and trigger mock. wp_transition_comment_status( 'hold', 'pending approval', get_comment( $comment_id ) ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_transition_comment_status' ) ); } + /** + * Tests "comment_duplicate_trigger" callback function. + */ public function test_callback_comment_duplicate_trigger() { + // Create post and comment for later use. $post_id = wp_insert_post( - [ + array( 'post_title' => 'Test post', 'post_content' => 'Lorem ipsum dolor...', 'post_status' => 'publish', - ] + ) ); - $comment_id = wp_insert_comment( - [ + $comment_id = wp_new_comment( + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', + 'comment_author_url' => '', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ] + 'comment_type' => 'post', + ) ); + // Set expected calls for the Mock. $this->mock->expects( $this->atLeastOnce() ) ->method( 'log' ) ->with( @@ -473,32 +535,34 @@ public function test_callback_comment_duplicate_trigger() { ) ), $this->equalTo( - [ + array( 'user_name' => 'Jim Bean', 'post_title' => '"Test post"', 'comment_type' => 'comment', 'post_id' => "$post_id", 'user_id' => 0, - ] + ) ), $this->equalTo( $comment_id ), $this->equalTo( 'post' ), $this->equalTo( 'duplicate' ) ); - // Do stuff. + // Create duplicate comment and trigger mock. wp_new_comment( - [ + array( 'comment_content' => 'Lorem ipsum dolor...', 'comment_author' => 'Jim Bean', 'comment_author_email' => 'jim_bean@example.com', 'comment_author_url' => '', 'comment_author_IP' => '::1', 'comment_post_ID' => $post_id, - ], + 'comment_type' => 'post', + ), true ); + // Confirm callback execution. $this->assertFalse( 0 === did_action( 'wp_stream_test_callback_comment_duplicate_trigger' ) ); } }