diff options
Diffstat (limited to 'tests/phpunit/tests/customize/nav-menus.php')
-rw-r--r-- | tests/phpunit/tests/customize/nav-menus.php | 54 |
1 files changed, 36 insertions, 18 deletions
diff --git a/tests/phpunit/tests/customize/nav-menus.php b/tests/phpunit/tests/customize/nav-menus.php index e731774693..e25418242a 100644 --- a/tests/phpunit/tests/customize/nav-menus.php +++ b/tests/phpunit/tests/customize/nav-menus.php @@ -15,6 +15,22 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { public $wp_customize; /** + * ID of the administrator user. + * + * @var int + */ + public static $administrator_id; + + /** + * Set up the shared fixture. + * + * @param WP_UnitTest_Factory $factory Factory instance. + */ + public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) { + self::$administrator_id = $factory->user->create( array( 'role' => 'administrator' ) ); + } + + /** * Set up a test case. * * @see WP_UnitTestCase_Base::set_up() @@ -22,7 +38,7 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { public function set_up() { parent::set_up(); require_once ABSPATH . WPINC . '/class-wp-customize-manager.php'; - wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) ); + wp_set_current_user( self::$administrator_id ); global $wp_customize; $this->wp_customize = new WP_Customize_Manager(); $wp_customize = $this->wp_customize; @@ -766,25 +782,27 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $this->assertStringContainsString( $expected, $template ); $post_types = get_post_types( array( 'show_in_nav_menus' => true ), 'object' ); - if ( $post_types ) { - foreach ( $post_types as $type ) { - $this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template ); - $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $type->labels->name ) . '#', $template ); - $this->assertStringContainsString( 'data-type="post_type"', $template ); - $this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template ); - $this->assertStringContainsString( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template ); - } + + $this->assertNotEmpty( $post_types ); + + foreach ( $post_types as $type ) { + $this->assertStringContainsString( 'available-menu-items-post_type-' . esc_attr( $type->name ), $template ); + $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $type->labels->name ) . '#', $template ); + $this->assertStringContainsString( 'data-type="post_type"', $template ); + $this->assertStringContainsString( 'data-object="' . esc_attr( $type->name ) . '"', $template ); + $this->assertStringContainsString( 'data-type_label="' . esc_attr( $type->labels->singular_name ) . '"', $template ); } $taxonomies = get_taxonomies( array( 'show_in_nav_menus' => true ), 'object' ); - if ( $taxonomies ) { - foreach ( $taxonomies as $tax ) { - $this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template ); - $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $tax->labels->name ) . '#', $template ); - $this->assertStringContainsString( 'data-type="taxonomy"', $template ); - $this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template ); - $this->assertStringContainsString( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template ); - } + + $this->assertNotEmpty( $taxonomies ); + + foreach ( $taxonomies as $tax ) { + $this->assertStringContainsString( 'available-menu-items-taxonomy-' . esc_attr( $tax->name ), $template ); + $this->assertMatchesRegularExpression( '#<h4 class="accordion-section-title".*>\s*<button type="button" class="accordion-trigger" aria-expanded="false" aria-controls=".*">\s*' . esc_html( $tax->labels->name ) . '#', $template ); + $this->assertStringContainsString( 'data-type="taxonomy"', $template ); + $this->assertStringContainsString( 'data-object="' . esc_attr( $tax->name ) . '"', $template ); + $this->assertStringContainsString( 'data-type_label="' . esc_attr( $tax->labels->singular_name ) . '"', $template ); } $this->assertStringContainsString( 'available-menu-items-custom_type', $template ); @@ -852,7 +870,7 @@ class Test_WP_Customize_Nav_Menus extends WP_UnitTestCase { $menus = new WP_Customize_Nav_Menus( $this->wp_customize ); $contributor_user_id = self::factory()->user->create( array( 'role' => 'contributor' ) ); $author_user_id = self::factory()->user->create( array( 'role' => 'author' ) ); - $administrator_user_id = self::factory()->user->create( array( 'role' => 'administrator' ) ); + $administrator_user_id = self::$administrator_id; $contributor_post_id = self::factory()->post->create( array( |