Ticket #37096: 37096.2.patch
File 37096.2.patch, 9.9 KB (added by , 4 years ago) |
---|
-
src/wp-includes/functions.php
742 742 function xmlrpc_getposttitle( $content ) { 743 743 global $post_default_title; 744 744 if ( preg_match( '/<title>(.+?)<\/title>/is', $content, $matchtitle ) ) { 745 $post_title = $matchtitle[1]; 745 $post_title = trim( $matchtitle[1] ); 746 if( empty( $post_title ) ) { 747 $post_title = $post_default_title; 748 } 746 749 } else { 747 750 $post_title = $post_default_title; 748 751 } … … 767 770 global $post_default_category; 768 771 if ( preg_match( '/<category>(.+?)<\/category>/is', $content, $matchcat ) ) { 769 772 $post_category = trim( $matchcat[1], ',' ); 770 $post_category = explode( ',', $post_category ); 773 $post_category = array_unique( array_map('trim', explode( ',', $post_category ) ) ); 774 if ( count($post_category) === 1 ){ 775 $post_category = $post_category[0]; 776 } 777 if( empty( $post_category ) ) { 778 $post_category = $post_default_category; 779 } 771 780 } else { 772 781 $post_category = $post_default_category; 773 782 } … … 5391 5400 5392 5401 if ( ! is_null( $force ) ) { 5393 5402 $old_forced = $forced; 5394 $forced = $force;5403 $forced = ( $force === true || trim( $force ) === 'true' ) ? true : false; 5395 5404 return $old_forced; 5396 5405 } 5397 5406 -
tests/phpunit/tests/functions/xmlrpc-getpostcatergory.php
1 <?php 2 3 /** 4 * @group functions.php 5 * @group xmlrpc 6 * 7 * Class Tests_Xmlrpc_Getpostcategory 8 * test the xmlrpc_getpostcategory function 9 */ 10 class Tests_Xmlrpc_GetPostCategory extends WP_UnitTestCase 11 { 12 13 /** 14 * setup 15 * declare the default category needed in function 16 */ 17 function setup(){ 18 global $post_default_category; 19 $post_default_category = 'post_default_category'; 20 } 21 22 /** 23 * remove global 24 */ 25 function tearDown(){ 26 global $post_default_category; 27 $post_default_category = null; 28 } 29 30 /** 31 * @dataProvider xmlrpc_getpostcategory_data 32 * 33 * @covers ::xmlrpc_getpostcategory 34 */ 35 function test_xmlrpc_getpostcategory( $expected, $value, $text){ 36 37 $this->assertEquals($expected, xmlrpc_getpostcategory($value), $text); 38 } 39 40 41 function xmlrpc_getpostcategory_data(){ 42 $post_default_category = 'post_default_category'; 43 return array( 44 array('good_category', '<category>good_category</category>', 'single category'), 45 array(array('good_category1', 'good_category2', 'good_category3'), '<category>good_category1, good_category2, good_category3</category>', 'multiple categories'), 46 array(array(0 => 'good_category1', 2 => 'good_category3'), '<category>good_category1, good_category1, good_category3,</category>', 'duplicate categories'), 47 array('good_category', '<post><category>good_category</category><cat>fsdfsfsf</cat></post>', 'category in post tag'), 48 array('<category>category', '<category> <category>category</category> </category>', 'nested categories terms'), 49 array('<span>category</span>', '<category> <span>category</span> </category>', 'category nested span tags'), 50 array('category1', '<category>category1</category><category>category2</category>', 'find just the first category'), 51 array('<![CDATA["category"]]>', '<category><![CDATA["category"]]></category>', 'CDATA'), 52 array('<![CDATA["<category>category', '<category><![CDATA["<category>category</category>"]]></category>', 'cdata with tag category'), 53 54 array($post_default_category, null, 'null'), 55 array($post_default_category, '<category>good_category<category>ssssss', 'missing close tag'), 56 array($post_default_category, '<category></category>', 'no category in tag'), 57 array($post_default_category, '<category> </category>', 'space in tag'), 58 array($post_default_category, '<category <span>category</span> </category>', 'bad opening tag'), 59 array($post_default_category, '<category>category</category dddddd>', 'bad closing tag'), 60 array($post_default_category, '<category id="id">category</category>', 'dosen\'t find category if attribute set'), 61 62 63 array( 'good_category', $this->_xml_rpc_request_fixture('<title>good_title</title>', '<category>good_category</category>' ), 'single title in XML'), 64 ); 65 } 66 private function _xml_rpc_request_fixture( $title = '', $category = '' ) 67 { 68 $XML_RPC = " 69 <?xml version=\"1.0\"?> 70 <methodResponse> 71 <params> 72 <param> 73 $title 74 $category 75 </param> 76 </params> 77 </methodResponse> 78 "; 79 80 return $XML_RPC; 81 } 82 } -
tests/phpunit/tests/functions/xmlrpc-getposttitle.php
1 <?php 2 3 /** 4 * @group functions.php 5 * @group xmlrpc 6 * 7 * Class Tests_Xmlrpc_Getposttitle 8 * test the xmlrpc_getposttitle function 9 */ 10 class Tests_Xmlrpc_Getposttitle extends WP_UnitTestCase 11 { 12 13 /** 14 * setup 15 * declare the default title needed in function 16 */ 17 function setup() 18 { 19 global $post_default_title; 20 $post_default_title = 'post_default_title'; 21 } 22 23 /** 24 * remove global 25 */ 26 function tearDown() 27 { 28 global $post_default_title; 29 $post_default_title = null; 30 } 31 32 /** 33 * @dataProvider xmlrpc_getposttitle_data 34 * 35 * @covers ::xmlrpc_getposttitle 36 */ 37 function test_xmlrpc_getposttitle( $expected, $value, $text) 38 { 39 $this->assertEquals($expected, xmlrpc_getposttitle( $value), $text); 40 } 41 42 43 function xmlrpc_getposttitle_data(){ 44 $post_default_title = 'post_default_title'; 45 return array( 46 array( 'good_title', '<title>good_title</title>', 'single title'), 47 array( 'good_title', '<post><title>good_title</title><cat>fsdfsfsf</cat></post>', 'good title in lot of content'), 48 array( '<title>title', '<title> <title>title</title> </title>', 'nested title'), 49 array( '<span>title</span>', '<title> <span>title</span> </title>', 'title with spans'), 50 array( '<![CDATA["title"]]>', '<title><![CDATA["title"]]></title>', 'pass cdata'), 51 array( '<![CDATA["<title>title', '<title><![CDATA["<title>title</title>"]]></title>', 'cdata with tag title'), 52 53 array($post_default_title, null, 'null'), 54 array($post_default_title, '<title>good_title<title>ssssss', 'missing close'), 55 array($post_default_title, '<title></title>', 'title has no content'), 56 array($post_default_title, '<title> </title>', 'title is just space'), 57 array($post_default_title, '<title <span>title</span> </title>', 'bad opening tag'), 58 array($post_default_title, '<title>title</title dddddd>', ' bad closing tag'), 59 60 array( 'good_title', $this->_xml_rpc_request_fixture('<title>good_title</title>', '<category>good_category</category>' ), 'single title in XML'), 61 ); 62 } 63 64 private function _xml_rpc_request_fixture( $title = '', $category = '' ) 65 { 66 $XML_RPC = " 67 <?xml version=\"1.0\"?> 68 <methodResponse> 69 <params> 70 <param> 71 $title 72 $category 73 </param> 74 </params> 75 </methodResponse> 76 "; 77 78 return $XML_RPC; 79 } 80 } -
tests/phpunit/tests/functions/xmlrpc-removepostdata.php
1 <?php 2 /** 3 * @group functions.php 4 * @group xmlrpc 5 * 6 * Class Tests_Xmlrpc_Removepostdata 7 * test the xmlrpc_removepostdata function 8 */ 9 10 11 class Tests_Xmlrpc_Removepostdata extends WP_UnitTestCase{ 12 13 /** 14 * @dataProvider xmlrpc_getposttitle_data 15 * 16 * @covers ::xmlrpc_getposttitle 17 */ 18 function test_xmlrpc_getposttitle($expected, $value, $text) 19 { 20 foreach ($expected as $regx ){ 21 22 $this->assertEquals(0, preg_match( $regx, xmlrpc_removepostdata($value), $matchcat), $text .'shouldn\'t exists after the xmlrpc_removepostdata call'); 23 } 24 25 } 26 27 28 function xmlrpc_getposttitle_data() 29 { 30 $post_default_title = 'post_default_title'; 31 return array( 32 array( array('/<title>(.+?)<\/title>/is'), $this->_xml_rpc_request_fixture('<title>good_title</title>' ), 'single title'), 33 // array('good_title', '<post><title>good_title</title><cat>fsdfsfsf</cat></post>', 'good title in lot of content'), 34 // array('<title>title', '<title> <title>title</title> </title>', 'nested title'), 35 // array('<span>title</span>', '<title> <span>title</span> </title>', 'title with spans'), 36 // array('<![CDATA["title"]]>', '<title><![CDATA["title"]]></title>', 'pass cdata'), 37 // array('<![CDATA["<title>title', '<title><![CDATA["<title>title</title>"]]></title>', 'cdata with tag title'), 38 39 array( array('/<category>(.+?)<\/category>/is'), $this->_xml_rpc_request_fixture('', '<category>good_category</category>'), 'single category' ), 40 array( array('/<category>(.+?)<\/category>/is'), $this->_xml_rpc_request_fixture('', '<category>good_category1, good_category2, good_category3</category>' ), 'multiple categories'), 41 42 array( array('/<category>(.+?)<\/category>/is','/<title>(.+?)<\/title>/is'), $this->_xml_rpc_request_fixture('<title>good_title</title>','<category>good_category</category>'), 'single category' ), 43 array( array('/<category>(.+?)<\/category>/is', '/<title>(.+?)<\/title>/is'), $this->_xml_rpc_request_fixture('<title>good_title</title>','<category>good_category1, good_category2, good_category3</category>' ), 'multiple categories'), 44 45 ); 46 } 47 48 private function _xml_rpc_request_fixture( $title = '', $category = '' ) 49 { 50 $XML_RPC = " 51 <?xml version=\"1.0\"?> 52 <methodResponse> 53 <params> 54 <param> 55 $title 56 $category 57 </param> 58 </params> 59 </methodResponse> 60 "; 61 62 return $XML_RPC; 63 } 64 }