Make WordPress Core

Ticket #19733: 19733.tests-subclass.diff

File 19733.tests-subclass.diff, 2.5 KB (added by ericmann, 13 years ago)

Same unit tests as proposed before, but using a subclass rather than reflection to access the protected methods.

  • tests/phpunit/tests/xmlrpc/basic.php

     
    44require_once ABSPATH . WPINC . '/class-IXR.php';
    55require_once ABSPATH . WPINC . '/class-wp-xmlrpc-server.php';
    66
     7class XMLRPC_Date_Conversion_Access extends wp_xmlrpc_server {
     8        public function convert_date( $date ) {
     9                return $this->_convert_date( $date );
     10        }
     11
     12        public function convert_date_gmt( $date_gmt, $date ) {
     13                return $this->_convert_date_gmt( $date_gmt, $date );
     14        }
     15}
     16
    717/**
    818 * @group xmlrpc
    919 */
     
    2535                $this->assertTrue( $this->myxmlrpcserver->login_pass_ok( 'subscriber', 'subscriber' ) );
    2636                $this->assertInstanceOf( 'WP_User', $this->myxmlrpcserver->login( 'subscriber', 'subscriber' ) );
    2737        }
     38
     39        /**
     40         * @ticket 19733
     41         */
     42        function test__convert_date() {
     43                $server = new XMLRPC_Date_Conversion_Access();
     44
     45                /** Standard Date *********************************************************************************************/
     46
     47                // Set up
     48                $good_date = '1983-11-09 05:00:00';
     49                $expected = new IXR_Date( '19831109T05:00:00' );
     50
     51                // Result
     52                $result = $server->convert_date( $good_date );
     53
     54                // Verify
     55                $this->assertEquals( $expected, $result );
     56
     57                /** Null Date *************************************************************************************************/
     58
     59                // Set up
     60                $null_date = '0000-00-00 00:00:00';
     61                $expected = new IXR_Date( '00000000T00:00:00Z' );
     62
     63                // Result
     64                $result = $server->convert_date( $null_date );
     65
     66                // Verify
     67                $this->assertEquals( $expected, $result );
     68        }
     69
     70        /**
     71         * @ticket 19733
     72         */
     73        function test__convert_date_gmt() {
     74                $server = new XMLRPC_Date_Conversion_Access();
     75
     76                /** Standard Date *********************************************************************************************/
     77
     78                // Set up
     79                $good_date = '1983-11-09 05:00:00';
     80                $expected = new IXR_Date( '19831109T05:00:00' );
     81
     82                // Result
     83                $result = $server->convert_date_gmt( $good_date, $good_date );
     84
     85                // Verify
     86                $this->assertEquals( $expected, $result );
     87
     88                /** Null Date *************************************************************************************************/
     89
     90                // Set up
     91                $null_date = '0000-00-00 00:00:00';
     92                $expected = new IXR_Date( '00000000T00:00:00Z' );
     93
     94                // Result
     95                $result = $server->convert_date_gmt( $null_date, $null_date );
     96
     97                // Verify
     98                $this->assertEquals( $expected, $result );
     99        }
    28100}
     101 No newline at end of file