Skip to content
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

[pull] trunk from WordPress:trunk #1966

Merged
merged 157 commits into from
Feb 8, 2024
Merged
Changes from 1 commit
Commits
Show all changes
157 commits
Select commit Hold shift + click to select a range
c399654
I18N: Prevent PHP warning in `WP_Textdomain_Registry`.
swissspidy Jan 17, 2024
a64c96f
Twenty Twenty-Four: Remove extra tab character inside the text domain.
SergeyBiryukov Jan 17, 2024
0b7165e
I18N: Fix duplicate `determine_locale()` tests added in [57286].
swissspidy Jan 17, 2024
e707e37
Embeds: Ensure the deprecated function `print_emoji_styles` isn't used
aaronjorbin Jan 17, 2024
d4a77a3
Build/Test Tools: Fix unstable query tests.
felixarntz Jan 18, 2024
0c7b78e
Docs: Fix several typos in inline comments.
SergeyBiryukov Jan 18, 2024
c5fff20
Media: Redirect inactive attachement pages for logged-out users.
peterwilsoncc Jan 19, 2024
3287684
Twenty Twenty: Move the Inter font declaration to a separate file and…
SergeyBiryukov Jan 19, 2024
d17afcc
Bootstrap/Load: Introduce functions to check whether WordPress is ser…
felixarntz Jan 19, 2024
27ac620
Twenty Twenty: Add missing comma in `twentytwenty_classic_editor_styl…
SergeyBiryukov Jan 19, 2024
ecbd137
HTML API: Add support for HR element.
dmsnell Jan 19, 2024
5815624
Editor: Support deferred block variation initialization on the server.
joemcgill Jan 19, 2024
91e51f9
HTML API: Add support for BR, EMBED, & other tags.
dmsnell Jan 19, 2024
85de4aa
HTML API: Add support for PRE and LISTING elements.
dmsnell Jan 19, 2024
3d154d7
Media: Revert [57310].
peterwilsoncc Jan 19, 2024
edcc85c
HTML API: Cleanup tests and list of void elements.
dmsnell Jan 20, 2024
74abf14
Docs: Correct the placement of `@global` tags in `wp-settings.php`.
SergeyBiryukov Jan 20, 2024
4a2eb5c
Plugins: Correct table layout on smaller screens.
SergeyBiryukov Jan 21, 2024
5cd843e
Build/Test Tools: Expand "imagemin" Grunt task to cover default themes.
swissspidy Jan 22, 2024
d8785e3
Bundled Theme: Fix a couple of incorrect theme name references.
swissspidy Jan 22, 2024
b4eeefe
Twenty Twenty-Four: Update license information in readme.
swissspidy Jan 22, 2024
a1cf525
Docs: Correct the `WP_User Query` location reference in query cache t…
SergeyBiryukov Jan 22, 2024
6653002
HTML API: Support PARAM, SOURCE, and TRACK tags.
dmsnell Jan 23, 2024
3c4fbc3
Script Modules API: Rename `wp_module` to `wp_script_module`
dmsnell Jan 23, 2024
c9f04d4
Editor: fix classname output on blocks without layout.
tellthemachines Jan 23, 2024
ba42713
Editor: fix fluid font division by zero error when min and max viewpo…
tellthemachines Jan 23, 2024
d3ac623
Build Tools: Configure prettier properly.
youknowriad Jan 23, 2024
2e3b292
Editor: Set show_tagcloud to false for Pattern Categories.
youknowriad Jan 23, 2024
d0262ec
Editor: Ensure PHPUnit10 compatibility for ThemeJson unit test.
youknowriad Jan 23, 2024
e42e65d
Editor: Update the ThemeJson unit test to cover custom CSS feature.
youknowriad Jan 23, 2024
1381ad9
Editor: Define the labels of the pattern category taxonomy.
youknowriad Jan 23, 2024
3bf2b25
Editor: Fix back to items label capitalization for the pattern catego…
youknowriad Jan 23, 2024
de0c402
General: Add $schema property to block and theme JSON files.
ockham Jan 23, 2024
e83f5a1
I18N: Introduce a more performant localization library.
swissspidy Jan 23, 2024
5a8e44c
I18N: Add missing variable in string replacement.
swissspidy Jan 23, 2024
2f91b1f
I18N: Improve edge case handling in `WP_Translation_Controller`.
swissspidy Jan 23, 2024
a21e447
Editor: Unset reference used in foreach statement.
youknowriad Jan 23, 2024
5139923
Script Loader: Only emit CDATA wrapper comments in `wp_get_inline_scr…
westonruter Jan 23, 2024
86d4ac2
Docs: Add missing full stop in `WP_Comment_Query::parse_query()` DocB…
SergeyBiryukov Jan 23, 2024
78ef4f7
HTML API: Support INPUT tags.
dmsnell Jan 24, 2024
28fd787
I18N: Improve docblocks after [57337].
swissspidy Jan 24, 2024
6daf853
Script Loader: Load the modules to the footer in classic themes
youknowriad Jan 24, 2024
616e673
HTML API: Scan all syntax tokens in a document, read modifiable text.
dmsnell Jan 24, 2024
fa441af
Docs: Fix typo in `_get_block_template_file()` DocBlock.
SergeyBiryukov Jan 24, 2024
a615250
I18N: Rename `WP_Translation_Controller::instance()` method to `get_i…
swissspidy Jan 25, 2024
b617b5c
Twenty Twenty-Four: Change font family slug to lowercase.
swissspidy Jan 25, 2024
5bd13e7
Editor: Fix Theme.json application of custom root selector for styles.
youknowriad Jan 25, 2024
1fdafca
Editor: Add video and audio pattern categories.
youknowriad Jan 25, 2024
a92aa29
Block Hooks: Introduce a new `hooked_block_{$block_type}` filter.
ockham Jan 25, 2024
2526eab
Block Hooks: Amend PHPDoc for `hooked_block_{$hooked_block_type}` fil…
ockham Jan 25, 2024
bb14399
Docs: Fix a few typos in `wp-includes/pomo/po.php`.
SergeyBiryukov Jan 25, 2024
fe1df40
Media: Redirect inactive attachment pages for logged-out users.
aaronjorbin Jan 25, 2024
3cb6f03
Build/Tests: Ensure set_error_handler is cleaned up.
aaronjorbin Jan 26, 2024
d7d91b8
Build/Test Tools: Update third-party GitHub Actions.
desrosj Jan 26, 2024
311f45e
Build/Test Tools: Update the `caniuse` data.
desrosj Jan 26, 2024
5fbcb55
Coding Standards: Add missing escaping in `Custom_Image_Header::step_…
SergeyBiryukov Jan 26, 2024
338fb7e
Coding Standards: Fix some spaces on block-supports background.
jorgefilipecosta Jan 26, 2024
400a7ac
Editor: Add original_source and author_text to the templates REST API.
jorgefilipecosta Jan 27, 2024
5c4b488
Script Loader: Clarify in docs that `wp_get_inline_script_tag()` and …
westonruter Jan 27, 2024
0c4cc89
Tests: Expand `sanitize_text_field()` tests.
SergeyBiryukov Jan 27, 2024
a9e4769
Coding Standards: Add missing escaping functions to `WP_Customize_Con…
audrasjb Jan 28, 2024
c8e4c33
Docs: Improve various globals documentation, as per docblock standards.
audrasjb Jan 28, 2024
c786aa8
Docs: Typo correction in `wp_internal_hosts` docblock.
audrasjb Jan 28, 2024
e108d27
Coding Standards: Use strict type check for `in_array()` in `get_hook…
SergeyBiryukov Jan 28, 2024
adbd348
Editor: Add registry for block binding sources
gziolo Jan 29, 2024
9b0d0af
Coding Standards: Remove unnecessary access and internal annotations …
jorgefilipecosta Jan 29, 2024
2ce87aa
Editor: Add Block Bindings API helpers
gziolo Jan 29, 2024
393f673
Build/Test Tools: Update third-party Slack action.
desrosj Jan 29, 2024
cf8b74d
Editor: Update the WordPress packages to the Gutenberg 16.7 RC2 version.
youknowriad Jan 29, 2024
90ad304
Coding Standards: Update PHPCS to version 3.8.1.
SergeyBiryukov Jan 29, 2024
94e6fe9
Build/Test Tools: Test against MySQL 8.3
desrosj Jan 30, 2024
0e0b100
REST API: Support assigning terms when creating attachments.
swissspidy Jan 30, 2024
179b680
I18N: Ensure `.l10n.php` files are deleted when upgrading language pa…
swissspidy Jan 30, 2024
b57c822
I18N: Delete `.l10n.php` files when deleting a theme.
swissspidy Jan 30, 2024
5466d3a
Editor: Fix PHP warning in Layout block support.
youknowriad Jan 30, 2024
a9c985c
Editor: Update the minimum compatible version of Gutenberg.
youknowriad Jan 30, 2024
cabfa6f
Tests: Remove redundant unregister call in block bindings tear down
gziolo Jan 30, 2024
71b8dcb
I18N: Improve singular lookup of pluralized strings.
swissspidy Jan 30, 2024
3e92635
I18N: Add missing space after `foreach` keyword.
swissspidy Jan 30, 2024
9573b33
Uploads: Check for and verify ZIP archives.
aaronjorbin Jan 30, 2024
a172e31
Install: When populating options, maybe_serialize instead of always s…
aaronjorbin Jan 30, 2024
0b800d7
HTML API: Fix splitting single text node.
dmsnell Jan 30, 2024
5a59dbe
Editor: reduce specificity of block style variation selector.
tellthemachines Jan 30, 2024
5d3f66a
Editor: introduce `dimensions.aspectRatio` block support.
tellthemachines Jan 31, 2024
dc15d66
Script Modules API: Add import map polyfill for older browsers
gziolo Jan 31, 2024
1a5ff3f
Editor: Add `viewStyle` property to `block.json` for frontend-only bl…
gziolo Jan 31, 2024
c45f527
REST API: Add route for single styles revisions.
youknowriad Jan 31, 2024
4472385
Twenty Eleven: Fix typo in `twentyeleven_widgets_init()` description.
SergeyBiryukov Jan 31, 2024
b999860
Editor: Sanitize nested array in theme.json properly.
youknowriad Jan 31, 2024
621ac04
Editor: Fix Theme.json font settings in unit test.
youknowriad Jan 31, 2024
38ff970
Editor: Fix Theme.json font settings unit test.
youknowriad Jan 31, 2024
9453f3a
Editor: Update WordPress packages to Gutenberg 16.7 RC3.
youknowriad Jan 31, 2024
1338984
Editor: fix small typos in block bindings API docblocks.
swissspidy Jan 31, 2024
7076ebb
HTTP API: Ensure cookie names are cast to strings.
swissspidy Jan 31, 2024
6dd00b1
Twenty Twenty-Three: Rename Comments template part.
swissspidy Jan 31, 2024
03cb3e3
Script Loader: Use a global variable in `wp_script_modules()`.
swissspidy Jan 31, 2024
e26bbdb
I18N: Load new translation library in `wp_load_translations_early()`.
swissspidy Jan 31, 2024
5e33f4b
I18N: Revert [57386] pending further investigation.
swissspidy Jan 31, 2024
4a2aa99
HTML API: Fix CDATA lookalike matching invalid CDATA
dmsnell Feb 1, 2024
cdb218b
HTML API: Fix void tag nesting with next_token
dmsnell Feb 1, 2024
f16c792
HTML API: Test cleanup
dmsnell Feb 1, 2024
65be4cd
Docs: Fix typo in `do_robots()` docblock.
swissspidy Feb 1, 2024
ef37e6b
Editor: Remove shadow support via direct attribute.
youknowriad Feb 1, 2024
3600105
Editor: Add deprecated functions from interactivity core blocks.
youknowriad Feb 1, 2024
d27872e
Twenty Fifteen: Fix typo in `css/blocks.css`.
SergeyBiryukov Feb 1, 2024
5b46851
I18N: Improve singular lookup of pluralized strings.
swissspidy Feb 1, 2024
1e564ad
Editor: Add the Block Bindings API.
youknowriad Feb 1, 2024
67e9ffb
Media: Prevent local edits during media upload.
joedolson Feb 1, 2024
8d3e4a1
I18N: Support loading `.l10n.php` translation files on their own.
swissspidy Feb 1, 2024
9486dc1
Build/Test Tools: Introduce Props Bot workflow.
desrosj Feb 1, 2024
5e178ff
I18N: Fix plural forms parsing in `WP_Translation_File`.
swissspidy Feb 1, 2024
88bcfb7
I18N: Add type declaration to new method missed in [57518].
swissspidy Feb 2, 2024
50215df
Administration: Accessibility: Use the default cursor style for label…
afercia Feb 2, 2024
2a494ac
Editor: Add `allowed_blocks` field to block registration and REST API
gziolo Feb 2, 2024
b645284
Coding Standards: Use strict comparison for functions lookup in plugi…
SergeyBiryukov Feb 2, 2024
e9e2281
Build/Test Tools: Some improvements to the Props Bot workflow.
desrosj Feb 2, 2024
575ce15
Media: enable AVIF support.
adamsilverstein Feb 2, 2024
7e34c4b
Media: fix AVIF tests.
adamsilverstein Feb 2, 2024
235cb39
Editor: Refactor the way block bindings sources are handled
gziolo Feb 2, 2024
f80516d
HTML API: Reset parser state after seeking to bookmark.
dmsnell Feb 2, 2024
324f2d7
HTML API: Fix typo setting the wrong self-closing flag.
dmsnell Feb 2, 2024
7d9eb8f
Coding Standards: Use strict comparison in `wp-admin/update-core.php`.
SergeyBiryukov Feb 3, 2024
629d4c5
Coding Standards: Rename the `$ID` parameter to `$post_id` in `trackb…
SergeyBiryukov Feb 4, 2024
ac240f0
Build/Test Tools: Mock plugin API response in `WP_REST_Plugins_Contro…
peterwilsoncc Feb 4, 2024
8d47e64
Coding Standards: Rename the `$expires_offset` variable in `cache_jav…
SergeyBiryukov Feb 5, 2024
2ae28c5
Script Loader: Remove unused `WP_Scripts::get_unaliased_deps()` method.
swissspidy Feb 5, 2024
4e633b5
Build/Test Tools: Update the `codecov/codecov-action` action.
desrosj Feb 5, 2024
77aad3a
General: Add tests for `array_is_list` polyfill added in r57337.
swissspidy Feb 5, 2024
1950da3
Build/Test Tools: Pass a token to the Codecov action.
desrosj Feb 5, 2024
2ac96bc
Upload: Fallback to `PclZip` to validate ZIP file uploads.
peterwilsoncc Feb 5, 2024
5810f22
Coding Standards: Rename the `$oSelf` variable in `WP_MatchesMapRegex…
SergeyBiryukov Feb 6, 2024
0cab832
Editor: Introduce the Font Library post types and low level APIs.
youknowriad Feb 6, 2024
d928e5f
Editor: Fix Font Library PHP unit tests.
youknowriad Feb 6, 2024
a0fedc9
Coding Standards: Fix array key alignment after [57539].
swissspidy Feb 6, 2024
b7027a8
HTML API: Join text nodes on invalid-tag-name boundaries.
dmsnell Feb 6, 2024
7a71339
Editor: Show the patterns page for classic themes.
youknowriad Feb 6, 2024
3eb7bd1
Build/Test Tools: Make the props bot message shorter.
aaronjorbin Feb 6, 2024
2b08a77
Upgrade/Install: Introduce Plugin Dependencies.
costdev Feb 6, 2024
27087b7
Script Loader: always output core block global styles after base glob…
tellthemachines Feb 7, 2024
952004a
Editor: Fix block style variation selector generation.
youknowriad Feb 7, 2024
a770c6d
REST API: Introduce the necessary endpoints for the font library.
youknowriad Feb 7, 2024
f4861ba
Editor: Fix typo in FontUtils doc block.
youknowriad Feb 7, 2024
5e345d4
Editor: Update PHPDoc for block bindings's context arg.
youknowriad Feb 7, 2024
e285ac8
Build/Test Tools: Pin a specific commit for Hosting Test Reporter.
desrosj Feb 7, 2024
86f8a3c
Build/Test Tools: Revert [57551].
desrosj Feb 7, 2024
bd534cc
Administration: Improve contrast and consistency of focus styles.
joedolson Feb 7, 2024
b88ad1b
Bundled Theme: Improve focus outline in Twenty Twenty-Four.
joedolson Feb 7, 2024
50af5db
Twenty Twenty-Four: Prefix the block pattern category name.
SergeyBiryukov Feb 7, 2024
9da53b8
Script Loader: Add a timezone offset display value to wp.date.setSett…
Feb 8, 2024
435155f
Script Loader: Improve translators comments for wp.date.setSettings i…
youknowriad Feb 8, 2024
b3d834c
Editor: Register the Google Font collection.
youknowriad Feb 8, 2024
0ff0842
Editor: Make asset file optional for block scripts
gziolo Feb 8, 2024
ae3ec69
Editor: Improve code documentation for block bindings
gziolo Feb 8, 2024
fd8c730
Editor: Avoid double escaping on value passed for attribute in HTML t…
gziolo Feb 8, 2024
f03a263
Editor: Introduce WP_Block_Bindings_Source class
gziolo Feb 8, 2024
6917cac
Interactivity API: Integrate Server Directive Processing
gziolo Feb 8, 2024
1d8d810
Interactivity API: Remove empty file
gziolo Feb 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Upload: Fallback to PclZip to validate ZIP file uploads.
`ZipArchive` can fail to validate ZIP files correctly and report valid files as invalid. This introduces a fallback to `PclZip` to check validity of files if `ZipArchive` fails them.

This introduces the new function `wp_zip_file_is_valid()` to validate archives.

Follow up to [57388].

Props audunmb, azaozz, britner, cdevroe, colorful-tones, costdev, courane01, endymion00, feastdesignco, halounsbury, jeffpaul, johnbillion, jorbin, jsandtro, karinclimber, kevincoleman, koesper, maartenbelmans, mathewemoore, melcarthus, mujuonly, nerdpressteam, olegfuture, otto42, peterwilsoncc, room34, sayful, schutzsmith, stephencronin, svitlana41319, swissspidy, tnolte, tobiasbg, vikram6, welaunchio.
Fixes #60398.


git-svn-id: https://develop.svn.wordpress.org/trunk@57537 602fd350-edb4-49c9-b593-d223f7449a82
peterwilsoncc committed Feb 5, 2024
commit 2ac96bcd07ca615216cedbd855d641fca65853e5
19 changes: 1 addition & 18 deletions src/wp-admin/includes/class-file-upload-upgrader.php
Original file line number Diff line number Diff line change
@@ -70,24 +70,7 @@ public function __construct( $form, $urlholder ) {
}

if ( 'pluginzip' === $form || 'themezip' === $form ) {
$archive_is_valid = false;

/** This filter is documented in wp-admin/includes/file.php */
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
$archive = new ZipArchive();
$archive_is_valid = $archive->open( $file['file'], ZIPARCHIVE::CHECKCONS );

if ( true === $archive_is_valid ) {
$archive->close();
}
} else {
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

$archive = new PclZip( $file['file'] );
$archive_is_valid = is_array( $archive->properties() );
}

if ( true !== $archive_is_valid ) {
if ( ! wp_zip_file_is_valid( $file['file'] ) ) {
wp_delete_file( $file['file'] );
wp_die( __( 'Incompatible Archive.' ) );
}
31 changes: 31 additions & 0 deletions src/wp-admin/includes/file.php
Original file line number Diff line number Diff line change
@@ -1563,6 +1563,37 @@ function wp_trusted_keys() {
return apply_filters( 'wp_trusted_keys', $trusted_keys );
}

/**
* Determines whether the given file is a valid ZIP file.
*
* This function does not test to ensure that a file exists. Non-existent files
* are not valid ZIPs, so those will also return false.
*
* @since 6.4.4
*
* @param string $file Full path to the ZIP file.
* @return bool Whether the file is a valid ZIP file.
*/
function wp_zip_file_is_valid( $file ) {
/** This filter is documented in wp-admin/includes/file.php */
if ( class_exists( 'ZipArchive', false ) && apply_filters( 'unzip_file_use_ziparchive', true ) ) {
$archive = new ZipArchive();
$archive_is_valid = $archive->open( $file, ZipArchive::CHECKCONS );
if ( true === $archive_is_valid ) {
$archive->close();
return true;
}
}

// Fall through to PclZip if ZipArchive is not available, or encountered an error opening the file.
require_once ABSPATH . 'wp-admin/includes/class-pclzip.php';

$archive = new PclZip( $file );
$archive_is_valid = is_array( $archive->properties() );

return $archive_is_valid;
}

/**
* Unzips a specified ZIP file to a location on the filesystem via the WordPress
* Filesystem Abstraction.
33 changes: 33 additions & 0 deletions tests/phpunit/data/filesystem/_source-license
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
The following files were sourced from https://github.com/ZJONSSON/node-unzipper a fork of https://github.com/EvanOxfeld/node-unzip

* archive-comment.zip
* archive-cp866.zip
* archive-directory-entry.zip
* archive-encrypted.zip
* archive-flags-set.zip
* archive-invalid.zip
* archive-large.zip
* archive-uncompressed.zip
* archive.crx

Copyright (c) 2012 - 2013 Near Infinity Corporation
Copyright (c) 2016 - 2024 Ziggy Jonsson ([email protected])

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Binary file added tests/phpunit/data/filesystem/archive-comment.zip
Binary file not shown.
Binary file added tests/phpunit/data/filesystem/archive-cp866.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/phpunit/data/filesystem/archive-gnome.zip
Binary file not shown.
7 changes: 7 additions & 0 deletions tests/phpunit/data/filesystem/archive-invalid-ext.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Shucked

Shucked is a 2022 musical with music and lyrics by Brandy Clark and Shane McAnally, and a book by Robert Horn. The Broadway production began previews at the Nederlander Theatre on March 8, 2023, before opening on April 4. The show received positive reviews and went on to receive nine nominations at the 76th Tony Awards, including Best Musical. Cast member Alex Newell became one of the first two openly non-binary performers to be nominated for and win a Tony Award, with their win for Best Featured Actor in a Musical.

A U.S. tour, West End production, and feature film adaptation are currently planned.

From Wikipedia (https://en.wikipedia.org/wiki/Shucked) under Creative Commons Attribution CC-BY-SA 3.0 (https://creativecommons.org/licenses/by-sa/3.0/legalcode)
Binary file added tests/phpunit/data/filesystem/archive-invalid.zip
Binary file not shown.
Binary file added tests/phpunit/data/filesystem/archive-large.zip
Binary file not shown.
Binary file added tests/phpunit/data/filesystem/archive-macos.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added tests/phpunit/data/filesystem/archive.crx
Binary file not shown.
75 changes: 75 additions & 0 deletions tests/phpunit/tests/filesystem/wpZipFileIsValid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

/**
* Tests wp_zip_file_is_valid().
*
* @group file
* @group filesystem
*
* @covers ::wp_zip_file_is_valid
*/
class Tests_Filesystem_WpZipFileIsValid extends WP_UnitTestCase {

/**
* The test data directory.
*
* @var string $test_data_dir
*/
private static $test_data_dir;

/**
* Sets up the filesystem and test data directory property
* before any tests run.
*/
public static function set_up_before_class() {
parent::set_up_before_class();

require_once ABSPATH . 'wp-admin/includes/file.php';
WP_Filesystem();

self::$test_data_dir = DIR_TESTDATA . '/filesystem/';
}

/**
* Tests ZIP file validity is correctly determined.
*
* @ticket 60398
*
* @dataProvider data_zip_file_validity
*
* @param string $file The ZIP file to test.
* @param bool $expected Whether the ZIP file is expected to be valid.
*/
public function test_zip_file_validity( $file, $expected ) {
$zip_file = self::$test_data_dir . $file;

$expected_message = $expected ? 'valid' : 'invalid';
$this->assertSame( $expected, wp_zip_file_is_valid( $zip_file ), "Expected archive to be {$expected_message}." );
}

/**
* Data provider.
*
* @return array[]
*/
public function data_zip_file_validity() {
return array(
'standard zip' => array( 'archive.zip', true ),
'large zip' => array( 'archive-large.zip', true ),
'commented zip' => array( 'archive-comment.zip', true ),
'cp866 zip' => array( 'archive-cp866.zip', true ),
'directory entry zip' => array( 'archive-directory-entry.zip', true ),
'encrypted zip' => array( 'archive-encrypted.zip', true ),
'flags-set zip' => array( 'archive-flags-set.zip', true ),
'uncompressed zip' => array( 'archive-uncompressed.zip', true ),
'crx zip' => array( 'archive.crx', true ),
'macos generated zip' => array( 'archive-macos.zip', true ),
'gnome generated zip' => array( 'archive-gnome.zip', true ),
'ubuntu nautilus zip' => array( 'archive-ubuntu-nautilus.zip', true ),

'invalid zip file' => array( 'archive-invalid.zip', false ),
'invalid file extension' => array( 'archive-invalid-ext.md', false ),
'non-existent file' => array( 'archive-non-existent.zip', false ),
);
}
}