mirrored from git://develop.git.wordpress.org/
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reorganize hooks tests to coding standards and consistency #5849
Draft
hellofromtonya
wants to merge
2
commits into
WordPress:trunk
Choose a base branch
from
hellofromtonya:try/split-hooks-tests
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
/** | ||
* Test add_action(). | ||
* | ||
* @group hooks | ||
* @covers ::add_action | ||
*/ | ||
class Tests_Hooks_AddAction extends WP_UnitTestCase { | ||
/** | ||
* @ticket 23265 | ||
*/ | ||
public function test_action_callback_representations() { | ||
$hook_name = __FUNCTION__; | ||
|
||
$this->assertFalse( has_action( $hook_name ) ); | ||
|
||
add_action( $hook_name, array( 'Class', 'method' ) ); | ||
|
||
$this->assertSame( 10, has_action( $hook_name, array( 'Class', 'method' ) ) ); | ||
|
||
$this->assertSame( 10, has_action( $hook_name, 'Class::method' ) ); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
/** | ||
* Test apply_filters_deprecated(). | ||
* | ||
* @group hooks | ||
* @covers ::apply_filters_deprecated | ||
*/ | ||
class Tests_Hooks_ApplyFiltersDeprecated extends WP_UnitTestCase { | ||
|
||
/** | ||
* @ticket 10441 | ||
* @expectedDeprecated tests_apply_filters_deprecated | ||
*/ | ||
public function test_apply_filters_deprecated() { | ||
$p = 'Foo'; | ||
|
||
add_filter( 'tests_apply_filters_deprecated', array( __CLASS__, 'deprecated_filter_callback' ) ); | ||
$p = apply_filters_deprecated( 'tests_apply_filters_deprecated', array( $p ), '4.6.0' ); | ||
remove_filter( 'tests_apply_filters_deprecated', array( __CLASS__, 'deprecated_filter_callback' ) ); | ||
|
||
$this->assertSame( 'Bar', $p ); | ||
} | ||
|
||
public static function deprecated_filter_callback( $p ) { | ||
$p = 'Bar'; | ||
return $p; | ||
} | ||
|
||
/** | ||
* @ticket 10441 | ||
* @expectedDeprecated tests_apply_filters_deprecated | ||
*/ | ||
public function test_apply_filters_deprecated_with_multiple_params() { | ||
$p1 = 'Foo1'; | ||
$p2 = 'Foo2'; | ||
|
||
add_filter( 'tests_apply_filters_deprecated', array( __CLASS__, 'deprecated_filter_callback_multiple_params' ), 10, 2 ); | ||
$p1 = apply_filters_deprecated( 'tests_apply_filters_deprecated', array( $p1, $p2 ), '4.6.0' ); | ||
remove_filter( 'tests_apply_filters_deprecated', array( __CLASS__, 'deprecated_filter_callback_multiple_params' ), 10, 2 ); | ||
|
||
$this->assertSame( 'Bar1', $p1 ); | ||
|
||
// Not passed by reference, so not modified. | ||
$this->assertSame( 'Foo2', $p2 ); | ||
} | ||
|
||
public static function deprecated_filter_callback_multiple_params( $p1, $p2 ) { | ||
$p1 = 'Bar1'; | ||
$p2 = 'Bar2'; | ||
|
||
return $p1; | ||
} | ||
|
||
/** | ||
* @ticket 10441 | ||
*/ | ||
public function test_apply_filters_deprecated_without_filter() { | ||
$val = 'Foobar'; | ||
|
||
$this->assertSame( $val, apply_filters_deprecated( 'tests_apply_filters_deprecated', array( $val ), '4.6.0' ) ); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
/** | ||
* Test apply_filters_ref_array(). | ||
* | ||
* @group hooks | ||
* @covers ::apply_filters_ref_array | ||
*/ | ||
class Tests_Hooks_ApplyFiltersRefArray extends WP_UnitTestCase { | ||
|
||
/** | ||
* @ticket 9886 | ||
*/ | ||
public function test_filter_ref_array() { | ||
$obj = new stdClass(); | ||
$a = new MockAction(); | ||
$hook_name = __FUNCTION__; | ||
|
||
add_action( $hook_name, array( $a, 'filter' ) ); | ||
|
||
apply_filters_ref_array( $hook_name, array( &$obj ) ); | ||
|
||
$args = $a->get_args(); | ||
$this->assertSame( $args[0][0], $obj ); | ||
// Just in case we don't trust assertSame(). | ||
$obj->foo = true; | ||
$this->assertNotEmpty( $args[0][0]->foo ); | ||
} | ||
|
||
/** | ||
* @ticket 12723 | ||
*/ | ||
public function test_filter_ref_array_result() { | ||
$obj = new stdClass(); | ||
$a = new MockAction(); | ||
$b = new MockAction(); | ||
$hook_name = __FUNCTION__; | ||
|
||
add_action( $hook_name, array( $a, 'filter_append' ), 10, 2 ); | ||
add_action( $hook_name, array( $b, 'filter_append' ), 10, 2 ); | ||
|
||
$result = apply_filters_ref_array( $hook_name, array( 'string', &$obj ) ); | ||
|
||
$this->assertSame( $result, 'string_append_append' ); | ||
|
||
$args = $a->get_args(); | ||
$this->assertSame( $args[0][1], $obj ); | ||
// Just in case we don't trust assertSame(). | ||
$obj->foo = true; | ||
$this->assertNotEmpty( $args[0][1]->foo ); | ||
|
||
$args = $b->get_args(); | ||
$this->assertSame( $args[0][1], $obj ); | ||
// Just in case we don't trust assertSame(). | ||
$obj->foo = true; | ||
$this->assertNotEmpty( $args[0][1]->foo ); | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This
@covers
annotation is already on the test class.