From 36f34cf58db90096b503e0b8ceedb329ba8fb95e Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 2 May 2022 00:11:35 +0000 Subject: [PATCH] Tests: Add unit tests for some XML-RPC functions: * `xmlrpc_getposttitle()` * `xmlrpc_getpostcategory()` * `xmlrpc_removepostdata()` Props pbearne, audrasjb, costdev, SergeyBiryukov. Fixes #53490. git-svn-id: https://develop.svn.wordpress.org/trunk@53326 602fd350-edb4-49c9-b593-d223f7449a82 --- tests/phpunit/tests/functions/xmlrpc.php | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/phpunit/tests/functions/xmlrpc.php diff --git a/tests/phpunit/tests/functions/xmlrpc.php b/tests/phpunit/tests/functions/xmlrpc.php new file mode 100644 index 0000000000..20164e2e4f --- /dev/null +++ b/tests/phpunit/tests/functions/xmlrpc.php @@ -0,0 +1,68 @@ +title + category,category1 + content + '; + + /** + * Tests that xmlrpc_getposttitle() returns the post title if found in the XML. + * + * @covers ::xmlrpc_getposttitle + */ + public function test_xmlrpc_getposttitle() { + $this->assertSame( 'title', xmlrpc_getposttitle( $this->test_content ) ); + } + + /** + * Tests that xmlrpc_getposttitle() defaults to the `$post_default_title` global. + * + * @covers ::xmlrpc_getposttitle + */ + public function test_xmlrpc_getposttitle_default() { + global $post_default_title; + + $post_default_title = 'post_default_title'; + + $this->assertSame( 'post_default_title', xmlrpc_getposttitle( '' ) ); + } + + + /** + * Tests that xmlrpc_getpostcategory() returns post categories if found in the XML. + * + * @covers ::xmlrpc_getpostcategory + */ + public function test_xmlrpc_getpostcategory() { + $this->assertSame( array( 'category', 'category1' ), xmlrpc_getpostcategory( $this->test_content ) ); + } + + /** + * Tests that xmlrpc_getpostcategory() defaults to the `$post_default_category` global. + * + * @covers ::xmlrpc_getpostcategory + */ + public function test_xmlrpc_getpostcategory_default() { + global $post_default_category; + + $post_default_category = 'post_default_category'; + + $this->assertSame( 'post_default_category', xmlrpc_getpostcategory( '' ) ); + } + + /** + * Tests that xmlrpc_removepostdata() returns XML content without title and category elements. + * + * @covers ::xmlrpc_removepostdata + */ + public function test_xmlrpc_removepostdata() { + $this->assertSame( 'content', xmlrpc_removepostdata( $this->test_content ) ); + } +}