-
Notifications
You must be signed in to change notification settings - Fork 210
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes regex and optimizes rocket_clean_minify() (PR #2574)
- Loading branch information
Tonya Mork
committed
Apr 23, 2020
1 parent
c42f139
commit 14f6669
Showing
8 changed files
with
346 additions
and
187 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,67 +1,166 @@ | ||
<?php | ||
|
||
return [ | ||
'vfs_dir' => 'wp-content/cache/min/', | ||
|
||
// Virtual filesystem structure. | ||
'structure' => [ | ||
'wp-content' => [ | ||
'cache' => [ | ||
'min' => [ | ||
'1' => [ | ||
'5c795b0e3a1884eec34a989485f863ff.js' => '', | ||
'5c795b0e3a1884eec34a989485f863ff.js.gz' => '', | ||
'fa2965d41f1515951de523cecb81f85e.css' => '', | ||
'fa2965d41f1515951de523cecb81f85e.css.gz' => '', | ||
], | ||
'3rd-party' => [ | ||
'2n7x3vd41f1515951de523cecb81f85e.css' => '', | ||
'2n7x3vd41f1515951de523cecb81f85e.css.gz' => '', | ||
'bt937b0e3a1884eec34a989485f863ff.js' => '', | ||
'bt937b0e3a1884eec34a989485f863ff.js.gz' => '', | ||
], | ||
'vfs_dir' => 'wp-content/cache/min/', | ||
|
||
'structure' => require WP_ROCKET_TESTS_FIXTURES_DIR . '/vfs-structure/default.php', | ||
|
||
// Test data. | ||
'test_data' => [ | ||
'shouldNotCleanWhenNoExtensionsGiven' => [ | ||
'extensions' => '', | ||
'expected' => [ | ||
'cleaned' => [], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => true, | ||
'vfs://public/wp-content/cache/min/2/' => true, | ||
'vfs://public/wp-content/cache/min/3rd-party/' => true, | ||
], | ||
], | ||
], | ||
], | ||
'shouldNotCleanWhenExtensionDoesNotExist' => [ | ||
'extensions' => [ 'php', 'html' ], | ||
'expected' => [ | ||
'cleaned' => [], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => true, | ||
'vfs://public/wp-content/cache/min/2/' => true, | ||
'vfs://public/wp-content/cache/min/3rd-party/' => true, | ||
], | ||
], | ||
], | ||
'shouldClean_css' => [ | ||
'extensions' => 'css', | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => null, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => null, | ||
|
||
// Test data. | ||
// The virtual filesystem does not work with glob. Therefore, we have to specify all of the file extensions. | ||
'test_data' => [ | ||
[ | ||
[ 'css', 'css.gz' ], | ||
[ | ||
'wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css', | ||
'wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz', | ||
] | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => false, | ||
|
||
'vfs://public/wp-content/cache/min/2/' => true, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => false, | ||
], | ||
], | ||
], | ||
[ | ||
[ 'js', 'js.gz' ], | ||
[ | ||
'wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js', | ||
'wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz', | ||
] | ||
'shouldClean_css.gz' => [ | ||
'extensions' => 'css.gz', | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => false, | ||
|
||
'vfs://public/wp-content/cache/min/2/' => true, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => false, | ||
], | ||
], | ||
], | ||
[ | ||
[ 'css', 'css.gz', 'js', 'js.gz' ], | ||
[ | ||
'wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css', | ||
'wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz', | ||
'wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js', | ||
'wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css', | ||
'wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js', | ||
'wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz', | ||
] | ||
'shouldClean_js' => [ | ||
'extensions' => 'js', | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => null, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => false, | ||
|
||
'vfs://public/wp-content/cache/min/2/' => true, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => false, | ||
], | ||
], | ||
], | ||
'shouldClean_js.gz' => [ | ||
'extensions' => 'js.gz', | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => false, | ||
|
||
'vfs://public/wp-content/cache/min/2/' => true, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => false, | ||
], | ||
], | ||
], | ||
'shouldCleanCssAndJs' => [ | ||
'extensions' => [ 'css', 'js' ], | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => null, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => null, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => null, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/2/' => true, | ||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
], | ||
], | ||
], | ||
'shouldClean_.gz' => [ | ||
'extensions' => 'gz', | ||
'expected' => [ | ||
'cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css.gz' => null, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css.gz' => null, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js.gz' => null, | ||
], | ||
'non_cleaned' => [ | ||
'vfs://public/wp-content/cache/min/1/' => false, | ||
'vfs://public/wp-content/cache/min/1/5c795b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/1/fa2965d41f1515951de523cecb81f85e.css' => false, | ||
|
||
'vfs://public/wp-content/cache/min/2/' => true, | ||
|
||
'vfs://public/wp-content/cache/min/3rd-party/' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/bt937b0e3a1884eec34a989485f863ff.js' => false, | ||
'vfs://public/wp-content/cache/min/3rd-party/2n7x3vd41f1515951de523cecb81f85e.css' => false, | ||
], | ||
], | ||
], | ||
], | ||
]; |
This file contains 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 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
Oops, something went wrong.