-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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 7 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,84 @@ | ||
| <?php | ||
| /** | ||
| * Test the wp_upload_bits function | ||
| * | ||
| * @group Functions | ||
| * @group Upload | ||
| * @covers ::wp_upload_bits | ||
| */ | ||
|
|
||
| class tests_wp_upload_bits extends WP_UnitTestCase { | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
|
|
||
| /** | ||
| * @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' ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 57130 | ||
| * | ||
| * return error if no filename pass in | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| **/ | ||
| 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' ) ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 57130 | ||
| * | ||
| * return an array with error message in bad/no extension in the file name | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| **/ | ||
| 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_bad_time_present() { | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| $this->assertSameSets( | ||
| array( | ||
| 'path' => ABSPATH . 'wp-content/uploads/../1/', | ||
| 'url' => 'http://example.org/wp-content/uploads/../1/', | ||
| 'subdir' => '/../1/', | ||
| 'basedir' => ABSPATH . 'wp-content/uploads', | ||
| 'baseurl' => 'http://example.org/wp-content/uploads', | ||
| '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' ) | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * @ticket 57130 | ||
| * | ||
| * @return void | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| */ | ||
| public function test_file_content() { | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| $filename = ABSPATH . 'wp-content/uploads/99/1//filename.txt'; | ||
| $content = 'file content'; | ||
|
|
||
| $this->assertSameSets( | ||
| array( | ||
| 'error' => false, | ||
| 'path' => $filename, | ||
| 'url' => 'http://example.org/wp-content/uploads/99/1//filename.txt', | ||
| 'type' => 'text/plain', | ||
|
|
||
| ), | ||
| wp_upload_bits( 'filename.txt', null, $content, '99/12' ) | ||
| ); | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| $file = fopen( $filename, 'rb' ); | ||
| $file_contents = fread( $file, filesize( $filename ) ); | ||
| fclose( $file ); | ||
| $this->unlink( $filename ); | ||
|
pbearne marked this conversation as resolved.
|
||
|
|
||
| $this->assertSame( $content, $file_contents ); | ||
|
pbearne marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
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.