diff --git a/alerts/class-alert-type-die.php b/alerts/class-alert-type-die.php index 8ffb6cce3..48536631e 100644 --- a/alerts/class-alert-type-die.php +++ b/alerts/class-alert-type-die.php @@ -12,7 +12,7 @@ * * @package WP_Stream */ -class Alert_Type_Die extends Alert_Type { +class Alert_Type_Die extends Alert_Type { // @codingStandardsIgnoreLine /** * Alert type name @@ -40,6 +40,6 @@ public function alert( $record_id, $recordarr, $options ) { echo '
';
 		print_r( $recordarr ); // @codingStandardsIgnoreLine debug not loaded in production
 		echo '
'; - die( 'You have been notified!' ); + throw new Die_Exception( 'You have been notified!' ); } } diff --git a/alerts/class-alert-type-ifttt.php b/alerts/class-alert-type-ifttt.php index d15036504..a22780766 100644 --- a/alerts/class-alert-type-ifttt.php +++ b/alerts/class-alert-type-ifttt.php @@ -99,6 +99,7 @@ public function __construct( $plugin ) { */ public function alert( $record_id, $recordarr, $alert ) { $recordarr['ID'] = $record_id; + error_log( 'here' ); $this->notify_ifttt( $alert, $recordarr ); } diff --git a/classes/class-alert.php b/classes/class-alert.php index 13f30bf36..8cb28a349 100644 --- a/classes/class-alert.php +++ b/classes/class-alert.php @@ -282,6 +282,7 @@ public static function update_record_triggered_alerts( $record, $alert_slug, $al } elseif ( ! array_key_exists( $alert_slug, $alerts_triggered ) || ! is_array( $alerts_triggered[ $alert_slug ] ) ) { $alerts_triggered[ $alert_slug ] = $alert_meta; } + return $record->update_meta( Alerts::ALERTS_TRIGGERED_META_KEY, $alerts_triggered ); } diff --git a/classes/class-db.php b/classes/class-db.php index 65bdeeba3..6cd79df34 100755 --- a/classes/class-db.php +++ b/classes/class-db.php @@ -172,6 +172,7 @@ public function get_records( $args ) { // Additional property fields. $properties = array( + 'ID' => null, 'user_id' => null, 'user_role' => null, 'ip' => null, diff --git a/classes/class-die-exception.php b/classes/class-die-exception.php new file mode 100644 index 000000000..cb1109819 --- /dev/null +++ b/classes/class-die-exception.php @@ -0,0 +1,14 @@ +prepare( " AND $wpdb->stream.ID = %d", $args['ID'] ); + } if ( is_numeric( $args['site_id'] ) ) { $where .= $wpdb->prepare( " AND $wpdb->stream.site_id = %d", $args['site_id'] ); } diff --git a/composer.lock b/composer.lock index c8feb947f..ede2fd218 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", @@ -555,24 +555,24 @@ }, { "name": "cweagans/composer-patches", - "version": "1.6.7", + "version": "1.7.0", "source": { "type": "git", "url": "https://github.com/cweagans/composer-patches.git", - "reference": "2e6f72a2ad8d59cd7e2b729f218bf42adb14f590" + "reference": "ae02121445ad75f4eaff800cc532b5e6233e2ddf" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/cweagans/composer-patches/zipball/2e6f72a2ad8d59cd7e2b729f218bf42adb14f590", - "reference": "2e6f72a2ad8d59cd7e2b729f218bf42adb14f590", + "url": "https://api.github.com/repos/cweagans/composer-patches/zipball/ae02121445ad75f4eaff800cc532b5e6233e2ddf", + "reference": "ae02121445ad75f4eaff800cc532b5e6233e2ddf", "shasum": "" }, "require": { - "composer-plugin-api": "^1.0", + "composer-plugin-api": "^1.0 || ^2.0", "php": ">=5.3.0" }, "require-dev": { - "composer/composer": "~1.0", + "composer/composer": "~1.0 || ~2.0", "phpunit/phpunit": "~4.6" }, "type": "composer-plugin", @@ -595,7 +595,7 @@ } ], "description": "Provides a way to patch Composer packages.", - "time": "2019-08-29T20:11:49+00:00" + "time": "2020-09-30T17:56:20+00:00" }, { "name": "doctrine/instantiator", @@ -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.1", "source": { "type": "git", "url": "https://github.com/php-coveralls/php-coveralls.git", - "reference": "3e6420fa666ef7bae5e750ddeac903153e193bae" + "reference": "c3f682e7cd50191ce0a9c396bc4dee8cbcf05383" }, "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/c3f682e7cd50191ce0a9c396bc4dee8cbcf05383", + "reference": "c3f682e7cd50191ce0a9c396bc4dee8cbcf05383", "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-05T23:08:28+00:00" }, { "name": "phpdocumentor/reflection-common", @@ -2873,16 +2869,16 @@ }, { "name": "sirbrillig/phpcs-variable-analysis", - "version": "v2.8.3", + "version": "v2.9.0", "source": { "type": "git", "url": "https://github.com/sirbrillig/phpcs-variable-analysis.git", - "reference": "00b4fa3130faa26762c929989e3d958086c627f1" + "reference": "ff54d4ec7f2bd152d526fdabfeff639aa9b8be01" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/00b4fa3130faa26762c929989e3d958086c627f1", - "reference": "00b4fa3130faa26762c929989e3d958086c627f1", + "url": "https://api.github.com/repos/sirbrillig/phpcs-variable-analysis/zipball/ff54d4ec7f2bd152d526fdabfeff639aa9b8be01", + "reference": "ff54d4ec7f2bd152d526fdabfeff639aa9b8be01", "shasum": "" }, "require": { @@ -2917,7 +2913,7 @@ } ], "description": "A PHPCS sniff to detect problems with variables.", - "time": "2020-07-11T23:32:06+00:00" + "time": "2020-10-07T23:32:29+00:00" }, { "name": "squizlabs/php_codesniffer", @@ -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/tests/tests/alerts/test-class-alert-type-email.php b/tests/tests/alerts/test-class-alert-type-email.php new file mode 100644 index 000000000..416424391 --- /dev/null +++ b/tests/tests/alerts/test-class-alert-type-email.php @@ -0,0 +1,70 @@ +register(); + + $this->alerts = new Alerts( $this->plugin ); + } + + public function test_alert() { + + // Set alert fields + try { + $_POST['wp_stream_alerts_nonce'] = wp_create_nonce( 'save_alert' ); + $_POST['wp_stream_trigger_author'] = 1; + $_POST['wp_stream_trigger_context'] = 'posts-post'; + $_POST['wp_stream_trigger_action'] = 'created'; + $_POST['wp_stream_alert_type'] = 'email'; + $_POST['wp_stream_alert_status'] = 'wp_stream_enabled'; + + // Email alert meta. + $_POST['wp_stream_email_recipient'] = 'admin@example.com'; + $_POST['wp_stream_email_subject'] = 'Test email'; + + // Simulate saving an alert. + $this->_handleAjax( 'save_new_alert' ); + } catch ( \WPAjaxDieContinueException $e ) { + $exception = $e; + } + + // Use filter callback to the 'wp_mail' as a place to run assertions. + $asserted = false; + add_action( + 'wp_mail', + function( $mail_props ) use ( &$asserted ) { + $this->assertEquals( 'admin@example.com', $mail_props['to'] ); + $this->assertEquals( 'Test email', $mail_props['subject'] ); + $this->assertContains( 'A Stream Alert was triggered on Test Blog', $mail_props['message'] ); + $asserted = true; + } + ); + + // Trigger alert. + wp_set_current_user( 1 ); + wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_author' => 1 + ) + ); + + // Confirm assertion were run. + $this->assertTrue( $asserted ); + } +} diff --git a/tests/tests/alerts/test-class-alert-type-highlight.php b/tests/tests/alerts/test-class-alert-type-highlight.php new file mode 100644 index 000000000..48c2a52e0 --- /dev/null +++ b/tests/tests/alerts/test-class-alert-type-highlight.php @@ -0,0 +1,75 @@ +register(); + + $this->alert_type = new Alert_Type_Highlight( $this->plugin ); + } + + public function test_alert() { + + // Set alert fields + try { + $_POST['wp_stream_alerts_nonce'] = wp_create_nonce( 'save_alert' ); + $_POST['wp_stream_trigger_author'] = 1; + $_POST['wp_stream_trigger_context'] = 'posts-post'; + $_POST['wp_stream_trigger_action'] = 'created'; + $_POST['wp_stream_alert_type'] = 'highlight'; + $_POST['wp_stream_alert_status'] = 'wp_stream_enabled'; + + // Highlight alert meta. + $_POST['wp_stream_highlight_color'] = 'yellow'; + + // Simulate saving an alert. + $this->_handleAjax( 'save_new_alert' ); + } catch ( \WPAjaxDieContinueException $e ) { + $exception = $e; + } + + $response = json_decode( $this->_last_response ); + $this->assertInternalType( 'object', $response ); + $this->assertObjectHasAttribute( 'success', $response ); + $this->assertTrue( $response->success ); + + // Trigger alert. + wp_set_current_user( 1 ); + $post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_author' => 1 + ) + ); + + // Retrieve record. + $record = ( $this->plugin->db->query( array( 'object_id' => $post_id ) ) )[0]; + $record = new Record( $record ); + + // Retrieve alert trigger meta. + $record->meta[ Alerts::ALERTS_TRIGGERED_META_KEY ] = $record->get_meta( Alerts::ALERTS_TRIGGERED_META_KEY, true ); + + $this->assertTrue( + in_array( + 'alert-highlight highlight-yellow record-id-' . $record->ID, + $this->alert_type->post_class( array(), $record ), + true + ) + ); + } +} diff --git a/tests/tests/alerts/test-class-alert-type-ifttt.php b/tests/tests/alerts/test-class-alert-type-ifttt.php new file mode 100644 index 000000000..dc710c4fd --- /dev/null +++ b/tests/tests/alerts/test-class-alert-type-ifttt.php @@ -0,0 +1,76 @@ +register(); + + $this->alerts = new Alerts( $this->plugin ); + } + + public function test_alert() { + // Set alert fields + try { + $_POST['wp_stream_alerts_nonce'] = wp_create_nonce( 'save_alert' ); + $_POST['wp_stream_trigger_author'] = 1; + $_POST['wp_stream_trigger_context'] = 'posts-post'; + $_POST['wp_stream_trigger_action'] = 'created'; + $_POST['wp_stream_alert_type'] = 'ifttt'; + $_POST['wp_stream_alert_status'] = 'wp_stream_enabled'; + + // IFTTT alert meta. + $_POST['wp_stream_ifttt_maker_key'] = 'http://example.com'; + $_POST['wp_stream_ifttt_event_name'] = 'Post created'; + + // Simulate saving an alert. + $this->_handleAjax( 'save_new_alert' ); + } catch ( \WPAjaxDieContinueException $e ) { + $exception = $e; + } + + $response = json_decode( $this->_last_response ); + $this->assertInternalType( 'object', $response ); + $this->assertObjectHasAttribute( 'success', $response ); + $this->assertTrue( $response->success ); + + // Use filter callback to the 'wp_mail' as a place to run assertions. + $asserted = false; + add_filter( + 'http_request_args', + function( $parsed_args ) use ( &$asserted ) { + $this->assertNotEmpty( $parsed_args['body'] ); + $body = wp_json_decode( $parsed_args['body'] ); + + error_log( print_r( $body, true ) ); + $this->assertNotEmpty( $body ); + $asserted = true; + } + ); + + // Trigger alert. + wp_set_current_user( 1 ); + $post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_author' => 1 + ) + ); + + // Confirm assertion were run. + $this->assertTrue( $asserted ); + } +} diff --git a/tests/tests/alerts/test-class-alert-type-none.php b/tests/tests/alerts/test-class-alert-type-none.php new file mode 100644 index 000000000..0b95fd270 --- /dev/null +++ b/tests/tests/alerts/test-class-alert-type-none.php @@ -0,0 +1,57 @@ +register(); + + $this->alerts = new Alerts( $this->plugin ); + } + + public function test_alert() { + // Set alert fields + try { + $_POST['wp_stream_alerts_nonce'] = wp_create_nonce( 'save_alert' ); + $_POST['wp_stream_trigger_author'] = 1; + $_POST['wp_stream_trigger_context'] = 'posts-post'; + $_POST['wp_stream_trigger_action'] = 'created'; + $_POST['wp_stream_alert_type'] = 'none'; + $_POST['wp_stream_alert_status'] = 'wp_stream_enabled'; + + // None alert meta. + + // Simulate saving an alert. + $this->_handleAjax( 'save_new_alert' ); + } catch ( \WPAjaxDieContinueException $e ) { + $exception = $e; + } + + $response = json_decode( $this->_last_response ); + $this->assertInternalType( 'object', $response ); + $this->assertObjectHasAttribute( 'success', $response ); + $this->assertTrue( $response->success ); + + // Trigger alert. + wp_set_current_user( 1 ); + $post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_author' => 1 + ) + ); + } +} diff --git a/tests/tests/alerts/test-class-alert-type-slack.php b/tests/tests/alerts/test-class-alert-type-slack.php new file mode 100644 index 000000000..01d935255 --- /dev/null +++ b/tests/tests/alerts/test-class-alert-type-slack.php @@ -0,0 +1,78 @@ +register(); + + $this->alerts = new Alerts( $this->plugin ); + } + + public function test_alert() { + // Set alert fields + try { + $_POST['wp_stream_alerts_nonce'] = wp_create_nonce( 'save_alert' ); + $_POST['wp_stream_trigger_author'] = 1; + $_POST['wp_stream_trigger_context'] = 'posts-post'; + $_POST['wp_stream_trigger_action'] = 'created'; + $_POST['wp_stream_alert_type'] = 'none'; + $_POST['wp_stream_alert_status'] = 'wp_stream_enabled'; + + // Slack alert meta. + $_POST['wp_stream_slack_webhook'] = ''; + $_POST['wp_stream_slack_channel'] = ''; + $_POST['wp_stream_slack_username'] = ''; + $_POST['wp_stream_slack_icon'] = ''; + + // Simulate saving an alert. + $this->_handleAjax( 'save_new_alert' ); + } catch ( \WPAjaxDieContinueException $e ) { + $exception = $e; + } + + $response = json_decode( $this->_last_response ); + $this->assertInternalType( 'object', $response ); + $this->assertObjectHasAttribute( 'success', $response ); + $this->assertTrue( $response->success ); + + // Use filter callback to the 'wp_mail' as a place to run assertions. + $asserted = false; + add_filter( + 'http_request_args', + function( $parsed_args ) use ( &$asserted ) { + $this->assertNotEmpty( $parsed_args['body'] ); + $body = wp_json_decode( $parsed_args['body'] ); + + error_log( print_r( $body, true ) ); + $this->assertNotEmpty( $body ); + $asserted = true; + } + ); + + // Trigger alert. + wp_set_current_user( 1 ); + $post_id = wp_insert_post( + array( + 'post_title' => 'Test post', + 'post_content' => 'Lorem ipsum dolor...', + 'post_status' => 'publish', + 'post_author' => 1 + ) + ); + + // Confirm assertion were run. + $this->assertTrue( $asserted ); + } +} diff --git a/tests/tests/connectors/test-class-connector-acf.php b/tests/tests/connectors/test-class-connector-acf.php index f2de880f0..db6bc7030 100644 --- a/tests/tests/connectors/test-class-connector-acf.php +++ b/tests/tests/connectors/test-class-connector-acf.php @@ -20,6 +20,9 @@ class Test_WP_Stream_Connector_ACF extends WP_StreamTestCase { public function setUp() { parent::setUp(); + global $unit_test; + $unit_test = $this; + $this->plugin->connectors->unload_connectors(); // Make partial of Connector_ACF class, with mocked "log" function.