-
Notifications
You must be signed in to change notification settings - Fork 3.5k
added tests for wp_upload_bits #3659
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
Open
pbearne
wants to merge
18
commits into
WordPress:trunk
Choose a base branch
from
pbearne:57130_wp_upload_bits
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
ed42eaf
added tests for wp_check_filetype
pbearne 970d71f
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 99c4375
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne dab1998
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 50e8122
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 7cdf32b
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 775c30d
feedback from code review
pbearne 315daf6
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 96c4580
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 9b9d10d
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne c69fc6d
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne f0d5737
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 143244b
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 43cb297
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne ebca73e
Update tests/phpunit/tests/functions/wpuploadbits.php
pbearne 2fb1c46
updates from code review
pbearne 51ea9b1
Merge branch 'trunk' into 57130_wp_upload_bits
pbearne dd16a71
Update tests to use dynamic `wp_upload_dir()` in assertions
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| <?php | ||
| /** | ||
| * Tests the wp_upload_bits() function. | ||
| * | ||
| * @group functions.php | ||
| * @group upload | ||
| * | ||
| * @covers ::wp_upload_bits | ||
| */ | ||
|
|
||
| class Tests_Functions_WpUploadBits extends WP_UnitTestCase { | ||
|
|
||
| /** | ||
| * @ticket 57130 | ||
| * | ||
| * @expectedDeprecated wp_upload_bits | ||
| */ | ||
| public function test_wp_upload_bits_should_throw_Deprecated_error_if_second_parm_present_and_not_null() { | ||
| wp_upload_bits( 'filename.txt', 'not_null', 'bits' ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_upload_bits() returns an array with an error message if the filename is empty. | ||
| * | ||
| * @ticket 57130 | ||
| **/ | ||
| public function test_wp_upload_bits_should_return_an_array_with_error_message_if_no_name_present() { | ||
| $this->assertSameSets( array( 'error' => __( 'Empty filename' ) ), wp_upload_bits( '', '', 'bits' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_upload_bits() returns an array with an error message if the file type is not allowed. | ||
| * | ||
| * @ticket 57130 | ||
| **/ | ||
| public function test_wp_upload_bits_should_return_an_array_with_error_message_if_filename_without_an_extension() { | ||
| $this->assertSameSets( array( 'error' => __( 'Sorry, you are not allowed to upload this file type.' ) ), wp_upload_bits( 'filename', '', 'bits' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 57130 | ||
| * | ||
| * | ||
| **/ | ||
| public function test_should_return_error_if_bad_time_path_is_passed() { | ||
| $upload_dir = wp_upload_dir(); | ||
| $this->assertSameSets( | ||
| array( | ||
| 'path' => ABSPATH . 'wp-content/uploads/.././/1', | ||
| 'url' => $upload_dir['baseurl'] . '/.././/1', | ||
| 'subdir' => '/.././/1', | ||
| 'basedir' => ABSPATH . 'wp-content/uploads', | ||
| 'baseurl' => $upload_dir['baseurl'], | ||
| 'error' => 'Unable to create directory wp-content/uploads/.././/1. Is its parent directory writable by the server?', | ||
| ), | ||
| wp_upload_bits( 'filename.jpg', null, 'bits', '../../12' ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Tests that wp_upload_bits() creates a file in the upload folder with the given content. | ||
| * | ||
| * @ticket 57130 | ||
| */ | ||
| public function test_wp_upload_bits_should_create_file_in_upload_folder_with_given_content() { | ||
| $upload_dir = wp_upload_dir(); | ||
| $filename = ABSPATH . 'wp-content/uploads/9999/12/filename.txt'; | ||
| $content = 'file content'; | ||
|
|
||
| $this->assertSameSets( | ||
| array( | ||
| 'error' => false, | ||
| 'path' => $filename, | ||
| 'url' => $upload_dir['baseurl'] . '/9999/12/filename.txt', | ||
| 'type' => 'text/plain', | ||
|
|
||
| ), | ||
| wp_upload_bits( 'filename.txt', null, $content, '9999/12' ), | ||
| 'wp_upload_bits() did not return the expected result.' | ||
| ); | ||
| $file = fopen( $filename, 'rb' ); | ||
| $file_contents = fread( $file, filesize( $filename ) ); | ||
| fclose( $file ); | ||
| $this->unlink( $filename ); | ||
|
|
||
| $this->assertSame( $content, $file_contents, 'The content of the file does not match the expected value.' ); | ||
| } | ||
| } | ||
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.