Ticket #37096: 37096.patch
File 37096.patch, 6.3 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 TestsXmlrpcGetPostCategory 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 64 } -
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 } 61 }