WordPress.org

Make WordPress Core


Ignore:
Timestamp:
10/19/2020 03:38:11 PM (6 weeks ago)
Author:
SergeyBiryukov
Message:

Widgets: Introduce before_sidebar and after_sidebar arguments for register_sidebar().

Props deepaklalwani, flixos90, christophherr, dgwyer, markoheijnen, morganestes, audrasjb.
Fixes #19709.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/widgets.php

    r48939 r49203  
    245245        unregister_sidebar( $sidebar_id );
    246246        $this->assertArrayNotHasKey( $sidebar_id, $wp_registered_sidebars );
     247    }
     248
     249    /**
     250     * @group sidebar
     251     * @ticket 19709
     252     */
     253    public function test_register_sidebar_with_after_and_before_sidebar() {
     254        global $wp_registered_sidebars;
     255
     256        $sidebar_id = 'test-sidebar';
     257        register_sidebar(
     258            array(
     259                'id'             => $sidebar_id,
     260                'before_sidebar' => '<div id="%1$s" class="before-sidebar %2$s">',
     261                'after_sidebar'  => '</div> <!-- .before-sidebar -->',
     262                'class'          => 'test-sidebar',
     263            )
     264        );
     265
     266        $this->assertArrayHasKey( $sidebar_id, $wp_registered_sidebars );
     267        $this->assertContains( '<div id="%1$s" class="before-sidebar %2$s">', $wp_registered_sidebars[ $sidebar_id ]['before_sidebar'] );
     268        $this->assertContains( '</div> <!-- .before-sidebar -->', $wp_registered_sidebars[ $sidebar_id ]['after_sidebar'] );
     269
     270    }
     271
     272    /**
     273     * @group sidebar
     274     * @ticket 19709
     275     */
     276    public function test_register_sidebar_without_after_and_before_sidebar() {
     277        global $wp_registered_sidebars;
     278
     279        $sidebar_id = 'test-sidebar-2';
     280        register_sidebar(
     281            array(
     282                'id' => $sidebar_id,
     283            )
     284        );
     285
     286        $this->assertArrayHasKey( $sidebar_id, $wp_registered_sidebars );
     287        $this->assertEmpty( $wp_registered_sidebars[ $sidebar_id ]['before_sidebar'] );
     288        $this->assertEmpty( $wp_registered_sidebars[ $sidebar_id ]['after_sidebar'] );
     289
    247290    }
    248291
Note: See TracChangeset for help on using the changeset viewer.