-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed bug that prevented plugins from chaining actions
- Loading branch information
Showing
8 changed files
with
107 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,9 @@ | |
#, fuzzy | ||
msgid "" | ||
msgstr "" | ||
"Project-Id-Version: WpMailCatcher 2.1.8\n" | ||
"Project-Id-Version: WpMailCatcher 2.1.9\n" | ||
"Report-Msgid-Bugs-To: [email protected]\n" | ||
"POT-Creation-Date: 2024-05-29 19:52+0000\n" | ||
"POT-Creation-Date: 2024-06-08 14:39+0000\n" | ||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" | ||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" | ||
"Language-Team: LANGUAGE <[email protected]>\n" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -600,4 +600,99 @@ public function testCanStopErroredLogFromSavingViaFilter() | |
|
||
remove_filter($filterName, $func); | ||
} | ||
|
||
private function getFilterChainFunction(&$wasChainedCalled, $to, $subject, $message) | ||
{ | ||
return function ($args) use (&$wasChainedCalled, $to, $subject, $message) { | ||
$wasChainedCalled = true; | ||
$this->assertEquals($to, $args['to']); | ||
$this->assertEquals($subject, $args['subject']); | ||
$this->assertEquals($message, $args['message']); | ||
return $args; | ||
}; | ||
} | ||
|
||
/** | ||
* Other plugins hook into the `wp_mail` filter AFTER mail catcher, as such | ||
* they will rely on the values we return from our function hooked into `wp_mail`. | ||
* This test ensures that we correctly return the value so other plugins can make | ||
* use of it | ||
*/ | ||
public function testCanChainWpMailFiltersWhenLog() | ||
{ | ||
$to = '[email protected]'; | ||
$subject = 'Subject'; | ||
$message = '<strong>Hello</strong>'; | ||
$wasChainedCalled = false; | ||
$successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save'; | ||
|
||
$func = function ($log) { | ||
return $log; | ||
}; | ||
|
||
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); | ||
|
||
add_filter($successFilterName, $func); | ||
// Ensure our filter runs AFTER mail catcher | ||
add_filter('wp_mail', $chainedFunc, 9999999); | ||
|
||
wp_mail($to, $subject, $message); | ||
|
||
$this->assertTrue($wasChainedCalled); | ||
|
||
remove_filter($successFilterName, $func); | ||
remove_filter('wp_mail', $chainedFunc); | ||
} | ||
|
||
public function testCanChainWpMailFiltersWhenLogIsStopped() | ||
{ | ||
$to = '[email protected]'; | ||
$subject = 'Subject'; | ||
$message = '<strong>Hello</strong>'; | ||
$wasChainedCalled = false; | ||
$successFilterName = GeneralHelper::$actionNameSpace . '_before_success_log_save'; | ||
|
||
$func = function ($log) { | ||
return false; | ||
}; | ||
|
||
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); | ||
|
||
add_filter($successFilterName, $func); | ||
// Ensure our filter runs AFTER mail catcher | ||
add_filter('wp_mail', $chainedFunc, 9999999); | ||
|
||
wp_mail($to, $subject, $message); | ||
|
||
$this->assertTrue($wasChainedCalled); | ||
|
||
remove_filter($successFilterName, $func); | ||
remove_filter('wp_mail', $chainedFunc); | ||
} | ||
|
||
public function testCanChainWpMailFiltersWhenLogIsErrored() | ||
{ | ||
$to = 'testtest.com'; | ||
$subject = 'Subject'; | ||
$message = '<strong>Hello</strong>'; | ||
$wasChainedCalled = false; | ||
$erroredFilterName = GeneralHelper::$actionNameSpace . '_before_error_log_save'; | ||
|
||
$func = function ($log) { | ||
return false; | ||
}; | ||
|
||
$chainedFunc = $this->getFilterChainFunction($wasChainedCalled, $to, $subject, $message); | ||
|
||
add_filter($erroredFilterName, $func); | ||
// Ensure our filter runs AFTER mail catcher | ||
add_filter('wp_mail', $chainedFunc, 9999999); | ||
|
||
wp_mail($to, $subject, $message); | ||
|
||
$this->assertTrue($wasChainedCalled); | ||
|
||
remove_filter($erroredFilterName, $func); | ||
remove_filter('wp_mail', $chainedFunc); | ||
} | ||
} |