diff --git a/tests/phpunit/tests/link/editTermLink.php b/tests/phpunit/tests/link/editTermLink.php index 2137bdd82a..3128ddfe0e 100644 --- a/tests/phpunit/tests/link/editTermLink.php +++ b/tests/phpunit/tests/link/editTermLink.php @@ -42,8 +42,8 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { * @since 5.9.0 * * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. + * @param bool $use_id Whether to return term ID or term object. + * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. */ private function get_term( $taxonomy, $use_id ) { $term = self::$terms[ $taxonomy ]; @@ -59,11 +59,11 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - * @param string $expected Expected URL within admin of edit link. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. + * @param string $expected Expected part of admin URL for the edit link. */ - public function test_edit_term_link_for_permitted_user( $taxonomy, $use_id, $expected ) { + public function test_edit_term_link_should_return_the_link_for_permitted_user( $taxonomy, $use_id, $expected ) { $term = $this->get_term( $taxonomy, $use_id ); // Term IDs are not known by the data provider so need to be replaced. @@ -71,7 +71,6 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { $expected = '"' . admin_url( $expected ) . '"'; $this->assertStringContainsString( $expected, edit_term_link( '', '', '', $term, false ) ); - $this->assertStringContainsString( $expected, edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) ); } /** @@ -79,15 +78,14 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. */ - public function test_edit_term_link_for_denied_user( $taxonomy, $use_id ) { + public function test_edit_term_link_should_return_null_for_denied_user( $taxonomy, $use_id ) { wp_set_current_user( self::$user_ids['subscriber'] ); $term = $this->get_term( $taxonomy, $use_id ); $this->assertNull( edit_term_link( '', '', '', $term, false ) ); - $this->assertNull( edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ) ); } /** @@ -95,10 +93,10 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `edit_term_link()`. */ - public function test_edit_term_link_filter_is_int_by_term_id( $taxonomy, $use_id ) { + public function test_edit_term_link_filter_should_receive_term_id( $taxonomy, $use_id ) { $term = $this->get_term( $taxonomy, $use_id ); add_filter( @@ -113,29 +111,6 @@ class Tests_Link_EditTermLink extends WP_UnitTestCase { edit_term_link( '', '', '', $term, false ); } - /** - * @dataProvider data_edit_term_link - * - * @ticket 50225 - * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - */ - public function test_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) { - $term = $this->get_term( $taxonomy, $use_id ); - - add_filter( - 'edit_term_link', - function( $location, $term ) { - $this->assertIsInt( $term ); - }, - 10, - 2 - ); - - edit_term_link( '', '', '', get_term( $term, $taxonomy ), false ); - } - /** * Data provider. * diff --git a/tests/phpunit/tests/link/getEditTermLink.php b/tests/phpunit/tests/link/getEditTermLink.php index 68f4ad7c02..2df1aa7aac 100644 --- a/tests/phpunit/tests/link/getEditTermLink.php +++ b/tests/phpunit/tests/link/getEditTermLink.php @@ -42,8 +42,8 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { * @since 5.9.0 * * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. + * @param bool $use_id Whether to return term ID or term object. + * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. */ private function get_term( $taxonomy, $use_id ) { $term = self::$terms[ $taxonomy ]; @@ -145,11 +145,11 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - * @param string $expected Expected URL within admin of edit link. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. + * @param string $expected Expected part of admin URL for the edit link. */ - public function test_get_edit_term_link_for_permitted_user( $taxonomy, $use_id, $expected ) { + public function test_get_edit_term_link_should_return_the_link_for_permitted_user( $taxonomy, $use_id, $expected ) { $term = $this->get_term( $taxonomy, $use_id ); // Term IDs are not known by the data provider so need to be replaced. @@ -157,7 +157,6 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { $expected = admin_url( $expected ); $this->assertSame( $expected, get_edit_term_link( $term, $taxonomy ) ); - $this->assertSame( $expected, get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy ) ); } /** @@ -165,15 +164,14 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. */ - public function test_get_edit_term_link_for_denied_user( $taxonomy, $use_id ) { + public function test_get_edit_term_link_should_return_null_for_denied_user( $taxonomy, $use_id ) { wp_set_current_user( self::$user_ids['subscriber'] ); $term = $this->get_term( $taxonomy, $use_id ); $this->assertNull( get_edit_term_link( $term, $taxonomy ) ); - $this->assertNull( get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy ) ); } /** @@ -181,10 +179,10 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `get_edit_term_link()`. */ - public function test_get_edit_term_link_filter_is_int_by_term_id( $taxonomy, $use_id ) { + public function test_get_edit_term_link_filter_should_receive_term_id( $taxonomy, $use_id ) { $term = $this->get_term( $taxonomy, $use_id ); add_filter( @@ -199,29 +197,6 @@ class Tests_Link_GetEditTermLink extends WP_UnitTestCase { get_edit_term_link( $term, $taxonomy ); } - /** - * @dataProvider data_get_edit_term_link - * - * @ticket 50225 - * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - */ - public function test_get_edit_term_link_filter_is_int_by_term_object( $taxonomy, $use_id ) { - $term = $this->get_term( $taxonomy, $use_id ); - - add_filter( - 'get_edit_term_link', - function( $location, $term ) { - $this->assertIsInt( $term ); - }, - 10, - 2 - ); - - get_edit_term_link( get_term( $term, $taxonomy ), $taxonomy ); - } - /** * Data provider. * diff --git a/tests/phpunit/tests/term/getTermLink.php b/tests/phpunit/tests/term/getTermLink.php index b3301c4f5f..2a92d8afee 100644 --- a/tests/phpunit/tests/term/getTermLink.php +++ b/tests/phpunit/tests/term/getTermLink.php @@ -37,8 +37,8 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { * @since 5.9.0 * * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - * @return WP_Term|int If $use_id is true, term ID is returned; else instance of WP_Term. + * @param bool $use_id Whether to return term ID or term object. + * @return WP_Term|int Term ID if `$use_id` is true, WP_Term instance otherwise. */ private function get_term( $taxonomy, $use_id ) { $term = self::$terms[ $taxonomy ]; @@ -247,14 +247,14 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { } /** - * @dataProvider data_get_term_link + * @dataProvider data_term_link_filter_should_receive_term_object * * @ticket 50225 * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. + * @param string $taxonomy Taxonomy being tested. + * @param bool $use_id Whether to pass term ID or term object to `get_term_link()`. */ - public function test_get_term_link_filter_is_object_by_term_id( $taxonomy, $use_id ) { + public function test_term_link_filter_should_receive_term_object( $taxonomy, $use_id ) { $term = $this->get_term( $taxonomy, $use_id ); add_filter( @@ -269,57 +269,12 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { get_term_link( $term, $taxonomy ); } - /** - * @dataProvider data_get_term_link - * - * @ticket 50225 - * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, pass term object. - */ - public function test_get_term_link_filter_is_object_by_term_object( $taxonomy, $use_id ) { - $term = $this->get_term( $taxonomy, $use_id ); - - add_filter( - 'term_link', - function( $location, $term ) { - $this->assertInstanceOf( 'WP_Term', $term ); - }, - 10, - 2 - ); - - get_term_link( get_term( $term, $taxonomy ), $taxonomy ); - } - - /** - * @dataProvider data_get_term_link - * - * @ticket 50225 - * - * @param string $taxonomy Taxonomy being tested (used for index of term keys). - * @param bool $use_id When true, pass term ID. Else, skip the test. - */ - public function test_get_term_feed_link_backward_compatibility( $taxonomy, $use_id ) { - if ( $use_id ) { - $term = $this->get_term( $taxonomy, $use_id ); - - $term_feed_link = get_term_feed_link( $term, $taxonomy ); - $this->assertIsString( $term_feed_link ); - - $term_feed_link = get_term_feed_link( $term, '' ); - $this->assertIsString( $term_feed_link ); - } else { - $this->markTestSkipped( 'This test requires to pass an ID to get_term_feed_link()' ); - } - } - /** * Data provider. * * @return array */ - public function data_get_term_link() { + public function data_term_link_filter_should_receive_term_object() { return array( 'category passing term_id' => array( 'taxonomy' => 'category', @@ -347,4 +302,32 @@ class Tests_Term_GetTermLink extends WP_UnitTestCase { ), ); } + + /** + * @dataProvider data_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed + * + * @ticket 50225 + * + * @param string $taxonomy Taxonomy being tested. + */ + public function test_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed( $taxonomy ) { + $term = $this->get_term( $taxonomy, true ); + + $term_feed_link = get_term_feed_link( $term, $taxonomy ); + $this->assertIsString( $term_feed_link ); + + $term_feed_link = get_term_feed_link( $term, '' ); + $this->assertIsString( $term_feed_link ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_get_term_feed_link_should_use_term_taxonomy_when_term_id_is_passed() { + $taxonomies = array( 'category', 'post_tag', 'wptests_tax' ); + + return $this->text_array_to_dataprovider( $taxonomies ); + } }