WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/25/2016 06:30:27 AM (5 years ago)
Author:
westonruter
Message:

Customize: Allow page stubs to be created via dropdown-pages controls in the Static Front Page section.

This ability was previously added to nav menus via the available page items panel. The "Add New Page" button only appears when the allow_addition control param is supplied as true. Code is adapted from the Customize Posts feature plugin.

Props celloexpressions, westonruter.
See #38013, #34923.
Fixes #38164.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/customize/control.php

    r38858 r38906  
    2727    function setUp() {
    2828        parent::setUp();
     29        wp_set_current_user( $this->factory()->user->create( array( 'role' => 'administrator' ) ) );
    2930        require_once( ABSPATH . WPINC . '/class-wp-customize-manager.php' );
    3031        // @codingStandardsIgnoreStart
     
    4041     */
    4142    function test_check_capabilities() {
    42         wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
    4343        do_action( 'customize_register', $this->wp_customize );
    4444        $control = new WP_Customize_Control( $this->wp_customize, 'blogname', array(
     
    7979
    8080    /**
     81     * @ticket 38164
     82     */
     83    function test_dropdown_pages() {
     84        do_action( 'customize_register', $this->wp_customize );
     85
     86        $this->assertInstanceOf( 'WP_Customize_Nav_Menus', $this->wp_customize->nav_menus );
     87        $nav_menus_created_posts_setting = $this->wp_customize->get_setting( 'nav_menus_created_posts' );
     88        $this->assertInstanceOf( 'WP_Customize_Filter_Setting', $nav_menus_created_posts_setting );
     89        $page_on_front_control = $this->wp_customize->get_control( 'page_on_front' );
     90
     91        // Ensure the add-new-toggle is absent if allow_addition param is not set.
     92        $page_on_front_control->allow_addition = false;
     93        ob_start();
     94        $page_on_front_control->maybe_render();
     95        $content = ob_get_clean();
     96        $this->assertNotContains( 'add-new-toggle', $content );
     97
     98        // Ensure the add-new-toggle is absent if allow_addition param is set.
     99        $page_on_front_control->allow_addition = true;
     100        ob_start();
     101        $page_on_front_control->maybe_render();
     102        $content = ob_get_clean();
     103        $this->assertContains( 'add-new-toggle', $content );
     104
     105        // Ensure that dropdown-pages delect is rendered even if there are no pages published (yet).
     106        foreach ( get_pages() as $page ) {
     107            wp_delete_post( $page->ID );
     108        }
     109        $page_on_front_control->allow_addition = true;
     110        ob_start();
     111        $page_on_front_control->maybe_render();
     112        $content = ob_get_clean();
     113        $this->assertContains( '<option value="0">', $content, 'Dropdown-pages renders select even without any pages published.' );
     114
     115        // Ensure that auto-draft pages are included if they are among the nav_menus_created_posts.
     116        $auto_draft_page_id = $this->factory()->post->create( array(
     117            'post_type' => 'page',
     118            'post_status' => 'auto-draft',
     119            'post_title' => 'Auto Draft Page',
     120        ) );
     121        $this->factory()->post->create( array(
     122            'post_type' => 'page',
     123            'post_status' => 'auto-draft',
     124            'post_title' => 'Orphan Auto Draft Page',
     125        ) );
     126        $auto_draft_post_id = $this->factory()->post->create( array(
     127            'post_type' => 'post',
     128            'post_status' => 'auto-draft',
     129            'post_title' => 'Auto Draft Post',
     130        ) );
     131        $this->wp_customize->set_post_value( $nav_menus_created_posts_setting->id, array( $auto_draft_page_id, $auto_draft_post_id ) );
     132        $nav_menus_created_posts_setting->preview();
     133        ob_start();
     134        $page_on_front_control->maybe_render();
     135        $content = ob_get_clean();
     136        $this->assertContains( sprintf( '<option value="%d">Auto Draft Page</option>', $auto_draft_page_id ), $content );
     137        $this->assertNotContains( 'Auto Draft Post', $content );
     138        $this->assertNotContains( 'Orphan Auto Draft Page', $content );
     139    }
     140
     141    /**
    81142     * Tear down.
    82143     */
Note: See TracChangeset for help on using the changeset viewer.