From 74ccb68c56708c11ae2818e35a0a0e650105e688 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Sun, 25 Feb 2018 16:27:57 +0000 Subject: [PATCH] Taxonomy: restore TagSearch unit tests and correct deprecated version string. Reverts unit test removal, instead changing them to expect the function to be deprecated. Correct the version the ajax callback was deprecated. Amends [42614]. Props dlh, ocean90. Fixes #38922. git-svn-id: https://develop.svn.wordpress.org/trunk@42737 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/deprecated.php | 4 +- tests/phpunit/tests/ajax/TagSearch.php | 167 +++++++++++++++++++++++++ 2 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 tests/phpunit/tests/ajax/TagSearch.php diff --git a/src/wp-admin/includes/deprecated.php b/src/wp-admin/includes/deprecated.php index f6e249ca5e..61989cb5b9 100644 --- a/src/wp-admin/includes/deprecated.php +++ b/src/wp-admin/includes/deprecated.php @@ -1519,10 +1519,10 @@ function options_permalink_add_js() { * Ajax handler for tag search. * * @since 3.1.0 - * @deprecated 4.9.0 Use the REST API tags endpoint instead. + * @deprecated 5.0.0 Use the REST API tags endpoint instead. */ function wp_ajax_ajax_tag_search() { - _deprecated_function( __FUNCTION__, '4.8', '/wp-json/wp/v2/tags' ); + _deprecated_function( __FUNCTION__, '5.0.0', '/wp-json/wp/v2/tags' ); if ( ! isset( $_GET['tax'] ) ) { wp_die( 0 ); diff --git a/tests/phpunit/tests/ajax/TagSearch.php b/tests/phpunit/tests/ajax/TagSearch.php new file mode 100644 index 0000000000..c0f7091e33 --- /dev/null +++ b/tests/phpunit/tests/ajax/TagSearch.php @@ -0,0 +1,167 @@ +_setRole( 'administrator' ); + + // Set up a default request + $_GET['tax'] = 'post_tag'; + $_GET['q'] = 'chat'; + + // Make the request + try { + $this->_handleAjax( 'ajax-tag-search' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + // Ensure we found the right match + $this->assertEquals( $this->_last_response, 'chattels' ); + } + + /** + * Test with no results + * + * @expectedDeprecated wp_ajax_ajax_tag_search + */ + public function test_no_results() { + + // Become an administrator + $this->_setRole( 'administrator' ); + + // Set up a default request + $_GET['tax'] = 'post_tag'; + $_GET['q'] = md5( uniqid() ); + + // Make the request + // No output, so we get a stop exception + $this->setExpectedException( 'WPAjaxDieStopException', '' ); + $this->_handleAjax( 'ajax-tag-search' ); + } + + /** + * Test with commas + * + * @expectedDeprecated wp_ajax_ajax_tag_search + */ + public function test_with_comma() { + + // Become an administrator + $this->_setRole( 'administrator' ); + + // Set up a default request + $_GET['tax'] = 'post_tag'; + $_GET['q'] = 'some,nonsense, terms,chat'; // Only the last term in the list is searched + + // Make the request + try { + $this->_handleAjax( 'ajax-tag-search' ); + } catch ( WPAjaxDieContinueException $e ) { + unset( $e ); + } + + // Ensure we found the right match + $this->assertEquals( $this->_last_response, 'chattels' ); + } + + /** + * Test as a logged out user + * + * @expectedDeprecated wp_ajax_ajax_tag_search + */ + public function test_logged_out() { + + // Log out + wp_logout(); + + // Set up a default request + $_GET['tax'] = 'post_tag'; + $_GET['q'] = 'chat'; + + // Make the request + $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); + $this->_handleAjax( 'ajax-tag-search' ); + } + + /** + * Test with an invalid taxonomy type + * + * @expectedDeprecated wp_ajax_ajax_tag_search + */ + public function test_invalid_tax() { + + // Become an administrator + $this->_setRole( 'administrator' ); + + // Set up a default request + $_GET['tax'] = 'invalid-taxonomy'; + $_GET['q'] = 'chat'; + + // Make the request + $this->setExpectedException( 'WPAjaxDieStopException', '0' ); + $this->_handleAjax( 'ajax-tag-search' ); + } + + /** + * Test as an unprivileged user + * + * @expectedDeprecated wp_ajax_ajax_tag_search + */ + public function test_unprivileged_user() { + + // Become an administrator + $this->_setRole( 'subscriber' ); + + // Set up a default request + $_GET['tax'] = 'post_tag'; + $_GET['q'] = 'chat'; + + // Make the request + $this->setExpectedException( 'WPAjaxDieStopException', '-1' ); + $this->_handleAjax( 'ajax-tag-search' ); + } + +}