Making WordPress.org

Changeset 10765


Ignore:
Timestamp:
03/04/2021 11:49:42 PM (5 years ago)
Author:
coffee2code
Message:

Handbooks, Init: Add get_handbook() for obtaining a handbook based on post type.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/inc/init.php

    r10759 r10765  
    2020    public static function get_handbook_objects() {
    2121        return self::$handbooks;
     22    }
     23
     24    /**
     25     * Returns a handbook of the given post type.
     26     *
     27     * @param string $post_type The handbook post type.
     28     * @return WPorg_Handbook|false The handbook object, or false if no such
     29     *                              handbook.
     30     */
     31    public static function get_handbook( $post_type ) {
     32        $handbooks = self::get_handbook_objects();
     33        return $handbooks[ $post_type ] ?? false;
    2234    }
    2335
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/handbook/phpunit/tests/init.php

    r10761 r10765  
    7070
    7171    /*
     72     * get_handbook()
     73     */
     74
     75    public function test_get_handbook_for_invalid_handbook() {
     76        $this->assertFalse( WPorg_Handbook_Init::get_handbook( 'nonexistent-handbook' ) );
     77    }
     78
     79    public function test_get_handbook() {
     80        $handbook = WPorg_Handbook_Init::get_handbook( 'handbook' );
     81
     82        $this->assertTrue( is_a( $handbook, 'WPorg_Handbook' ) );
     83        $this->assertEquals( 'handbook', $handbook->post_type );
     84    }
     85
     86    public function test_get_handbook_when_multiple_handbooks_present() {
     87        reinit_handbooks( [ 'plugins-handbook', 'themes-handbook' ], 'post_types' );
     88
     89        $handbook = WPorg_Handbook_Init::get_handbook( 'plugins-handbook' );
     90
     91        $this->assertTrue( is_a( $handbook, 'WPorg_Handbook' ) );
     92        $this->assertEquals( 'plugins-handbook', $handbook->post_type );
     93    }
     94
     95    /*
    7296     * get_post_types()
    7397     */
Note: See TracChangeset for help on using the changeset viewer.