Make WordPress Core


Ignore:
Timestamp:
01/09/2024 11:30:10 PM (3 years ago)
Author:
isabel_brison
Message:

Editor: output palette presets when appearance tools or border are enabled.

Adds color palette presets to global styles output if current theme supports either appearance tools or border.

Props andrewserong, noisysocks.
Fixes #60134.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpGetGlobalStylesheet.php

    r56978 r57259  
    2020
    2121        /**
     22         * Flag to indicate whether to remove 'border' theme support at tear_down().
     23         *
     24         * @var bool
     25         */
     26        private $remove_border_support_at_teardown = false;
     27
     28        /**
    2229         * Flag to indicate whether to switch back to the default theme at tear down.
    2330         *
     
    4148                }
    4249
     50                if ( $this->remove_border_support_at_teardown ) {
     51                        $this->remove_border_support_at_teardown = false;
     52                        remove_theme_support( 'border' );
     53                        remove_theme_support( 'editor-color-palette' );
     54                }
     55
    4356                parent::tear_down();
    4457        }
     
    248261
    249262        /**
     263         * Tests that theme color palette presets are output when appearance tools are enabled via theme support.
     264         *
     265         * @ticket 60134
     266         */
     267        public function test_theme_color_palette_presets_output_when_border_support_enabled() {
     268
     269                $args = array(
     270                        array(
     271                                'name'  => 'Black',
     272                                'slug'  => 'nice-black',
     273                                'color' => '#000000',
     274                        ),
     275                        array(
     276                                'name'  => 'Dark Gray',
     277                                'slug'  => 'dark-gray',
     278                                'color' => '#28303D',
     279                        ),
     280                        array(
     281                                'name'  => 'Green',
     282                                'slug'  => 'haunted-green',
     283                                'color' => '#D1E4DD',
     284                        ),
     285                        array(
     286                                'name'  => 'Blue',
     287                                'slug'  => 'soft-blue',
     288                                'color' => '#D1DFE4',
     289                        ),
     290                        array(
     291                                'name'  => 'Purple',
     292                                'slug'  => 'cool-purple',
     293                                'color' => '#D1D1E4',
     294                        ),
     295                );
     296
     297                // Add theme support for appearance tools.
     298                add_theme_support( 'border' );
     299                add_theme_support( 'editor-color-palette', $args );
     300                $this->remove_border_support_at_teardown = true;
     301
     302                // Check for both the variable declaration and its use as a value.
     303                $variables = wp_get_global_stylesheet( array( 'variables' ) );
     304
     305                $this->assertStringContainsString( '--wp--preset--color--nice-black: #000000', $variables );
     306                $this->assertStringContainsString( '--wp--preset--color--dark-gray: #28303D', $variables );
     307                $this->assertStringContainsString( '--wp--preset--color--haunted-green: #D1E4DD', $variables );
     308                $this->assertStringContainsString( '--wp--preset--color--soft-blue: #D1DFE4', $variables );
     309                $this->assertStringContainsString( '--wp--preset--color--cool-purple: #D1D1E4', $variables );
     310
     311                $presets = wp_get_global_stylesheet( array( 'presets' ) );
     312
     313                $this->assertStringContainsString( 'var(--wp--preset--color--nice-black)', $presets );
     314                $this->assertStringContainsString( 'var(--wp--preset--color--dark-gray)', $presets );
     315                $this->assertStringContainsString( 'var(--wp--preset--color--haunted-green)', $presets );
     316                $this->assertStringContainsString( 'var(--wp--preset--color--soft-blue)', $presets );
     317                $this->assertStringContainsString( 'var(--wp--preset--color--cool-purple)', $presets );
     318        }
     319
     320        /**
    250321         * Adds the 'editor-font-sizes' theme support with custom font sizes.
    251322         *
Note: See TracChangeset for help on using the changeset viewer.