Make WordPress Core

Ticket #35993: 35993.diff

File 35993.diff, 2.5 KB (added by borgesbruno, 9 years ago)

Patch for tests related to XML-Request

  • tests/phpunit/tests/functions.php

     
    716716                $GLOBALS['previousday'] = '17.09.15';
    717717                the_date( 'Y', 'before ', ' after', false );
    718718                $this->assertEquals( '', ob_get_clean() );
     719        }       
     720
     721        /**     
     722         * @ticket 35993
     723         */
     724        private function _xml_rpc_request_fixture($title = '', $category = '') {
     725                $str_title = !empty($title)?"<title>$title</title>":'';
     726                $str_category = !empty($title)?"<category>$category</category>":'';
     727
     728                $XML_RPC = <<<RPC
     729                        <?xml version="1.0"?>
     730                        <methodResponse>
     731                          <params>
     732                            <param>
     733                              $str_title
     734                              $str_category
     735                            </param>
     736                          </params>
     737                        </methodResponse>
     738RPC;
     739                return $XML_RPC;
    719740        }
     741
     742
     743        /**
     744         * @ticket 35993
     745         */
     746        function test_xmlrpc_getposttitle() {
     747                $title = "This is the title";
     748                $xml_rpc_with_title = $this->_xml_rpc_request_fixture($title);
     749                $this->assertEquals($title, xmlrpc_getposttitle($xml_rpc_with_title), "The title doesn't match with $title");
     750
     751                global $post_default_title;
     752                $post_default_title = "This is the default title";
     753                $xml_rpc_with_out_title = $this->_xml_rpc_request_fixture;
     754                $this->assertEquals($post_default_title, xmlrpc_getposttitle($xml_rpc_with_out_title), "The title doesn't match with $post_default_title");
     755        }
     756
     757        /**
     758         * @ticket 35993
     759         */
     760        function test_xmlrpc_getpostcategory() {
     761                $category = "Foo";
     762                $xml_rpc_with_category = $this->_xml_rpc_request_fixture('x title', $category);
     763                $this->assertEquals(array($category), xmlrpc_getpostcategory($xml_rpc_with_category), "The category doesn't match");
     764
     765                global $post_default_category;
     766                $post_default_category = array("Default category");
     767                $xml_rpc_with_out_category = $this->_xml_rpc_request_fixture;
     768                $this->assertEquals($post_default_category, xmlrpc_getpostcategory($xml_rpc_with_out_category), "The category doesn't match");
     769        }
     770
     771        /**
     772         * @ticket 35993
     773         */
     774        function test_xmlrpc_removepostdata() {
     775                $xml_rpc = $this->_xml_rpc_request_fixture('Foo', 'X Category');
     776                $xml_rpc_without_post_data = xmlrpc_removepostdata($xml_rpc);
     777
     778                $this->assertEquals(0, preg_match( '/<title>(.+?)<\/title>/is', $xml_rpc_without_post_data, $matchcat), "The title shouldn't exists after the xmlrpc_removepostdata call");
     779                $this->assertEquals(0, preg_match( '/<category>(.+?)<\/category>/is', $xml_rpc_without_post_data, $matchcat), "No category should exist after the xmlrpc_removepostdata call");         
     780        }
    720781}