-
Notifications
You must be signed in to change notification settings - Fork 40
Performance: reduce Popup Editor memory and TTFB #1317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
tests/php/tests/Block_Editor_Assets_Controller_Test.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| <?php | ||
| /** | ||
| * Tests for block editor popup asset data. | ||
| * | ||
| * @package Popup_Maker | ||
| */ | ||
|
|
||
| /** | ||
| * Verify block editor popup choices stay lightweight and compatible. | ||
| */ | ||
| class PUM_Block_Editor_Assets_Controller_Test extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Existing block editor variable filters retain the original popup models. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_block_editor_preserves_popup_models_for_existing_filters() { | ||
| self::factory()->post->create( | ||
| [ | ||
| 'post_type' => 'popup', | ||
| 'post_status' => 'publish', | ||
| ] | ||
| ); | ||
|
|
||
| $expected = pum_get_all_popups(); | ||
| $filter = function ( $vars ) { | ||
| return $vars; | ||
| }; | ||
|
|
||
| add_filter( 'popup_maker/block-editor_localized_vars', $filter, 0 ); | ||
|
|
||
| $assets = \PopupMaker\plugin()->get_controller( 'Assets' ); | ||
| $packages = $assets->get_packages(); | ||
| $vars = call_user_func( $packages['block-editor']['vars'] ); | ||
|
|
||
| remove_filter( 'popup_maker/block-editor_localized_vars', $filter, 0 ); | ||
|
|
||
| $this->assertSame( $expected, $vars['popups'] ); | ||
| } | ||
|
|
||
| /** | ||
| * Authorized editors retain private popups in the viewer title data. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_block_editor_preserves_private_popup_choices_for_authorized_editors() { | ||
| $previous_user_id = get_current_user_id(); | ||
| $admin_user_id = self::factory()->user->create( [ 'role' => 'administrator' ] ); | ||
| $private_id = self::factory()->post->create( | ||
| [ | ||
| 'post_type' => 'popup', | ||
| 'post_status' => 'private', | ||
| 'post_title' => 'Private popup', | ||
| ] | ||
| ); | ||
|
|
||
| wp_set_current_user( $admin_user_id ); | ||
|
|
||
| try { | ||
| $assets = \PopupMaker\plugin()->get_controller( 'Assets' ); | ||
| $packages = $assets->get_packages(); | ||
| $vars = call_user_func( $packages['block-editor']['vars'] ); | ||
| } finally { | ||
| wp_set_current_user( $previous_user_id ); | ||
| } | ||
|
|
||
| $this->assertContains( | ||
| [ | ||
| 'ID' => $private_id, | ||
| 'post_title' => 'Private popup', | ||
| ], | ||
| $vars['popups'] | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Shared title-choice filters are retained in lightweight popup choices. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_block_editor_preserves_filtered_popup_titles() { | ||
| $popup_id = self::factory()->post->create( | ||
| [ | ||
| 'post_type' => 'popup', | ||
| 'post_status' => 'publish', | ||
| 'post_title' => 'Stored popup title', | ||
| ] | ||
| ); | ||
|
|
||
| $filter = function ( $titles ) use ( $popup_id ) { | ||
| $titles[ $popup_id ] = 'Filtered popup title'; | ||
|
|
||
| return $titles; | ||
| }; | ||
|
|
||
| add_filter( 'popup_maker/popup_title_choices', $filter ); | ||
|
|
||
| $assets = \PopupMaker\plugin()->get_controller( 'Assets' ); | ||
| $packages = $assets->get_packages(); | ||
| $vars = call_user_func( $packages['block-editor']['vars'] ); | ||
|
|
||
| remove_filter( 'popup_maker/popup_title_choices', $filter ); | ||
|
|
||
| $this->assertContains( | ||
| [ | ||
| 'ID' => $popup_id, | ||
| 'post_title' => 'Filtered popup title', | ||
| ], | ||
| $vars['popups'] | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <?php | ||
| /** | ||
| * Tests for Popup Maker editor stylesheet loading. | ||
| * | ||
| * @package Popup_Maker | ||
| */ | ||
|
|
||
| /** | ||
| * Verify editor styles do not require HTTP requests. | ||
| */ | ||
| class PUM_Admin_Shortcode_UI_Test extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * Prepare an editor-capable user. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function set_up() { | ||
| parent::set_up(); | ||
|
|
||
| $user_id = self::factory()->user->create( [ 'role' => 'administrator' ] ); | ||
|
|
||
| wp_set_current_user( $user_id ); | ||
| update_user_option( $user_id, 'rich_editing', 'true' ); | ||
| } | ||
|
|
||
| /** | ||
| * TinyMCE retains both Popup Maker editor stylesheets. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_mce_css_includes_popup_maker_styles() { | ||
| PUM_Admin_Shortcode_UI::init_editor(); | ||
|
|
||
| $stylesheets = apply_filters( 'mce_css', 'https://example.com/theme.css' ); | ||
|
|
||
| $this->assertStringContainsString( 'https://example.com/theme.css', $stylesheets ); | ||
| $this->assertStringContainsString( Popup_Maker::$URL . 'dist/assets/site.css', $stylesheets ); | ||
| $this->assertStringContainsString( Popup_Maker::$URL . 'dist/assets/admin-editor-styles.css', $stylesheets ); | ||
| } | ||
|
|
||
| /** | ||
| * RTL editors load only the RTL Popup Maker stylesheets. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_mce_css_selects_rtl_popup_maker_styles() { | ||
| global $wp_locale; | ||
|
|
||
| $original_direction = $wp_locale->text_direction; | ||
| $wp_locale->text_direction = 'rtl'; | ||
|
|
||
| try { | ||
| PUM_Admin_Shortcode_UI::init_editor(); | ||
|
|
||
| $stylesheets = apply_filters( 'mce_css', '' ); | ||
| } finally { | ||
| $wp_locale->text_direction = $original_direction; | ||
| } | ||
|
|
||
| $this->assertStringContainsString( Popup_Maker::$URL . 'dist/assets/site-rtl.css', $stylesheets ); | ||
| $this->assertStringContainsString( Popup_Maker::$URL . 'dist/assets/admin-editor-styles-rtl.css', $stylesheets ); | ||
| $this->assertStringNotContainsString( Popup_Maker::$URL . 'dist/assets/site.css', $stylesheets ); | ||
| $this->assertStringNotContainsString( Popup_Maker::$URL . 'dist/assets/admin-editor-styles.css', $stylesheets ); | ||
| } | ||
|
|
||
| /** | ||
| * Block editor settings receive local CSS without an HTTP request. | ||
| * | ||
| * @return void | ||
| */ | ||
| public function test_block_editor_settings_include_local_styles() { | ||
| $site_styles_path = Popup_Maker::$DIR . 'dist/assets/site.css'; | ||
| $admin_styles_path = Popup_Maker::$DIR . 'dist/assets/admin-editor-styles.css'; | ||
|
|
||
| if ( ! is_readable( $site_styles_path ) || ! is_readable( $admin_styles_path ) ) { | ||
| $this->markTestSkipped( 'Dist assets not built in test environment.' ); | ||
| } | ||
|
|
||
| $http_requests = 0; | ||
| $filter = function ( $response ) use ( &$http_requests ) { | ||
| ++$http_requests; | ||
|
|
||
| return $response; | ||
| }; | ||
|
|
||
| add_filter( 'pre_http_request', $filter ); | ||
|
|
||
| PUM_Admin_Shortcode_UI::init_editor(); | ||
|
|
||
| $settings = apply_filters( 'block_editor_settings_all', [ 'styles' => [] ], null ); | ||
|
|
||
| remove_filter( 'pre_http_request', $filter ); | ||
|
|
||
| $this->assertSame( 0, $http_requests ); | ||
|
|
||
| $styles = array_column( $settings['styles'], 'css' ); | ||
|
|
||
| $this->assertContains( file_get_contents( $site_styles_path ), $styles ); | ||
| $this->assertContains( file_get_contents( $admin_styles_path ), $styles ); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.