From ed42eaf4c99df0763b247cc2d051fbe42c85527d Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 18 Nov 2022 16:29:45 -0500 Subject: [PATCH 01/17] added tests for wp_check_filetype --- .../phpunit/tests/functions/wpuploadbits.php | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 tests/phpunit/tests/functions/wpuploadbits.php diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php new file mode 100644 index 0000000000000..842db8cf011a9 --- /dev/null +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -0,0 +1,74 @@ +expectExceptionMessage( 'Function wp_upload_bits was called with an argument that is deprecated since version 2.0.0 with no alternative available.' ); + $this->expectDeprecation(); + $this->expectException( 'PHPUnit\Framework\Error\Deprecated' ); + wp_upload_bits( 'filename.txt', 'not_null', 'bits' ); + } + /** + * return error if no filename pass in + * @expectedDeprecated + **/ + public function test_no_name_present() { + $this->expectDeprecation(); + $this->assertSameSets( array( 'error' => __( 'Empty filename' ) ), wp_upload_bits( '', '', 'bits' ) ); + } + + /** + * return an array with error message in bad/no extension in the file name + * @expectedDeprecated + **/ + public function test_no_ext_present() { + $this->assertSameSets( array( 'error' => __( 'Sorry, you are not allowed to upload this file type.' ) ), wp_upload_bits( 'filename', '', 'bits' ) ); + } + + public function test_bad_time_present() { + $this->assertSameSets( + array( + 'path' => '/var/www/src/wp-content/uploads/../1/', + 'url' => 'http://example.org/wp-content/uploads/../1/', + 'subdir' => '/../1/', + 'basedir' => '/var/www/src/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' ) + ); + } + + public function test_file_content() { + $filename = '/var/www/src/wp-content/uploads/99/1//filename.txt'; + $content = 'file content'; + + $this->unlink( $filename ); + $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' ) + ); + $file = fopen( $filename, 'r' ); + $this->assertEquals( $content, fread( $file, filesize( $filename ) ) ); + fclose( $file ); + $this->unlink( $filename ); + } +} From 970d71f2780970261a6444887cc9b9d739fd3b3b Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 12:37:19 -0500 Subject: [PATCH 02/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 842db8cf011a9..f109646b90dd5 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -10,7 +10,7 @@ class tests_wp_upload_bits extends WP_UnitTestCase { /** - * @expectedDeprecated + * @expectedDeprecated wp_upload_bits * @return void * */ From 99c4375e83b6990bb6bb837c0062c226e7f477ba Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 12:38:04 -0500 Subject: [PATCH 03/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index f109646b90dd5..34f93af069988 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -15,9 +15,6 @@ class tests_wp_upload_bits extends WP_UnitTestCase { * */ public function test_second_parm_present() { - $this->expectExceptionMessage( 'Function wp_upload_bits was called with an argument that is deprecated since version 2.0.0 with no alternative available.' ); - $this->expectDeprecation(); - $this->expectException( 'PHPUnit\Framework\Error\Deprecated' ); wp_upload_bits( 'filename.txt', 'not_null', 'bits' ); } /** From dab1998491985611109c69365f4bc95af927c7f2 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 12:38:12 -0500 Subject: [PATCH 04/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 34f93af069988..2b53f0dfc67b7 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -19,10 +19,8 @@ public function test_second_parm_present() { } /** * return error if no filename pass in - * @expectedDeprecated **/ public function test_no_name_present() { - $this->expectDeprecation(); $this->assertSameSets( array( 'error' => __( 'Empty filename' ) ), wp_upload_bits( '', '', 'bits' ) ); } From 50e8122d5e08cee35adce6e088a9058898daf390 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 12:38:19 -0500 Subject: [PATCH 05/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 2b53f0dfc67b7..0dcb43a50a325 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -26,7 +26,6 @@ public function test_no_name_present() { /** * return an array with error message in bad/no extension in the file name - * @expectedDeprecated **/ public function test_no_ext_present() { $this->assertSameSets( array( 'error' => __( 'Sorry, you are not allowed to upload this file type.' ) ), wp_upload_bits( 'filename', '', 'bits' ) ); From 7cdf32b14a2523eab779faf11f3c5239ef05089a Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 12:38:25 -0500 Subject: [PATCH 06/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 0dcb43a50a325..a74aefd3dab09 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -61,7 +61,7 @@ public function test_file_content() { wp_upload_bits( 'filename.txt', null, $content, '99/12' ) ); $file = fopen( $filename, 'r' ); - $this->assertEquals( $content, fread( $file, filesize( $filename ) ) ); + $this->assertSame( $content, fread( $file, filesize( $filename ) ) ); fclose( $file ); $this->unlink( $filename ); } From 775c30d5367bb07c5dd5c4176cad4882ac359eeb Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Tue, 22 Nov 2022 13:53:46 -0500 Subject: [PATCH 07/17] feedback from code review --- .../phpunit/tests/functions/wpuploadbits.php | 40 +++++++++++++------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index a74aefd3dab09..b3f72eb15b00b 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -10,34 +10,44 @@ class tests_wp_upload_bits extends WP_UnitTestCase { /** - * @expectedDeprecated wp_upload_bits - * @return void + * @ticket 57130 * + * @expectedDeprecated wp_upload_bits */ - public function test_second_parm_present() { + 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 **/ - public function test_no_name_present() { + 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 **/ - public function test_no_ext_present() { + 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() { $this->assertSameSets( array( - 'path' => '/var/www/src/wp-content/uploads/../1/', + 'path' => ABSPATH . 'wp-content/uploads/../1/', 'url' => 'http://example.org/wp-content/uploads/../1/', 'subdir' => '/../1/', - 'basedir' => '/var/www/src/wp-content/uploads', + '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?', ), @@ -45,11 +55,15 @@ public function test_bad_time_present() { ); } + /** + * @ticket 57130 + * + * @return void + */ public function test_file_content() { - $filename = '/var/www/src/wp-content/uploads/99/1//filename.txt'; - $content = 'file content'; + $filename = ABSPATH . 'wp-content/uploads/99/1//filename.txt'; + $content = 'file content'; - $this->unlink( $filename ); $this->assertSameSets( array( 'error' => false, @@ -60,9 +74,11 @@ public function test_file_content() { ), wp_upload_bits( 'filename.txt', null, $content, '99/12' ) ); - $file = fopen( $filename, 'r' ); - $this->assertSame( $content, fread( $file, filesize( $filename ) ) ); + $file = fopen( $filename, 'rb' ); + $file_contents = fread( $file, filesize( $filename ) ); fclose( $file ); $this->unlink( $filename ); + + $this->assertSame( $content, $file_contents ); } } From 315daf68dcee8141be0d68ebacbb8b5261f6ca99 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:31:47 -0500 Subject: [PATCH 08/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index b3f72eb15b00b..93d4bd6dd63ca 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -1,9 +1,10 @@ Date: Wed, 23 Nov 2022 17:31:59 -0500 Subject: [PATCH 09/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 93d4bd6dd63ca..52f785caa2ba9 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -8,7 +8,7 @@ * @covers ::wp_upload_bits */ -class tests_wp_upload_bits extends WP_UnitTestCase { +class Tests_Functions_WpUploadBits extends WP_UnitTestCase { /** * @ticket 57130 From 9b9d10df3677ceac3e4df4a3de92b0c6000bf161 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:32:20 -0500 Subject: [PATCH 10/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 52f785caa2ba9..17016dd578684 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -20,9 +20,9 @@ public function test_wp_upload_bits_should_throw_Deprecated_error_if_second_parm } /** - * @ticket 57130 + * Tests that wp_upload_bits() returns an array with an error message if the filename is empty. * - * return error if no filename pass in + * @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' ) ); From c69fc6dd5c61cf69439afec64773db1541125cd2 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:32:31 -0500 Subject: [PATCH 11/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 17016dd578684..bbea29c06ccbd 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -29,9 +29,9 @@ public function test_wp_upload_bits_should_return_an_array_with_error_message_if } /** - * @ticket 57130 + * Tests that wp_upload_bits() returns an array with an error message if the file type is not allowed. * - * return an array with error message in bad/no extension in the file name + * @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' ) ); From f0d5737e74f0c4d0b4ab7c9874a596a0f8a81f3b Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:32:41 -0500 Subject: [PATCH 12/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index bbea29c06ccbd..0e68b042e991e 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -57,9 +57,9 @@ public function test_bad_time_present() { } /** - * @ticket 57130 + * Tests that wp_upload_bits() creates a file in the upload folder with the given content. * - * @return void + * @ticket 57130 */ public function test_file_content() { $filename = ABSPATH . 'wp-content/uploads/99/1//filename.txt'; From 143244bf584e1bae2eb00468c3c05dcab82a9de5 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:32:53 -0500 Subject: [PATCH 13/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 0e68b042e991e..e7e82d36dc367 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -61,7 +61,7 @@ public function test_bad_time_present() { * * @ticket 57130 */ - public function test_file_content() { + public function test_wp_upload_bits_should_create_file_in_upload_folder_with_given_content() { $filename = ABSPATH . 'wp-content/uploads/99/1//filename.txt'; $content = 'file content'; From 43cb297e5987cf90486f9bfbf7938f1d016b6f98 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:33:07 -0500 Subject: [PATCH 14/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index e7e82d36dc367..cd7006befa2d3 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -73,7 +73,8 @@ public function test_wp_upload_bits_should_create_file_in_upload_folder_with_giv 'type' => 'text/plain', ), - wp_upload_bits( 'filename.txt', null, $content, '99/12' ) + wp_upload_bits( 'filename.txt', null, $content, '99/12' ), + 'wp_upload_bits() did not return the expected result.' ); $file = fopen( $filename, 'rb' ); $file_contents = fread( $file, filesize( $filename ) ); From ebca73e41a0c6301537db47a46292467b4363567 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 17:33:16 -0500 Subject: [PATCH 15/17] Update tests/phpunit/tests/functions/wpuploadbits.php Co-authored-by: Colin Stewart <79332690+costdev@users.noreply.github.com> --- tests/phpunit/tests/functions/wpuploadbits.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index cd7006befa2d3..0ced5b28c4761 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -81,6 +81,6 @@ public function test_wp_upload_bits_should_create_file_in_upload_folder_with_giv fclose( $file ); $this->unlink( $filename ); - $this->assertSame( $content, $file_contents ); + $this->assertSame( $content, $file_contents, 'The content of the file does not match the expected value.' ); } } From 2fb1c469967f516131e1acf63c57b2a38636f7e1 Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Wed, 23 Nov 2022 18:21:10 -0500 Subject: [PATCH 16/17] updates from code review --- tests/phpunit/tests/functions/wpuploadbits.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index 0ced5b28c4761..c85e075f58780 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -42,17 +42,17 @@ public function test_wp_upload_bits_should_return_an_array_with_error_message_if * * **/ - public function test_bad_time_present() { + public function test_should_return_error_if_bad_time_path_is_passed() { $this->assertSameSets( array( - 'path' => ABSPATH . 'wp-content/uploads/../1/', - 'url' => 'http://example.org/wp-content/uploads/../1/', - 'subdir' => '/../1/', + '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?', + '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' ) + wp_upload_bits( 'filename.jpg', null, 'bits', '../../12' ) ); } @@ -62,18 +62,18 @@ public function test_bad_time_present() { * @ticket 57130 */ public function test_wp_upload_bits_should_create_file_in_upload_folder_with_given_content() { - $filename = ABSPATH . 'wp-content/uploads/99/1//filename.txt'; + $filename = ABSPATH . 'wp-content/uploads/9999/12/filename.txt'; $content = 'file content'; $this->assertSameSets( array( 'error' => false, 'path' => $filename, - 'url' => 'http://example.org/wp-content/uploads/99/1//filename.txt', + 'url' => 'http://example.org/wp-content/uploads/9999/12/filename.txt', 'type' => 'text/plain', ), - wp_upload_bits( 'filename.txt', null, $content, '99/12' ), + wp_upload_bits( 'filename.txt', null, $content, '9999/12' ), 'wp_upload_bits() did not return the expected result.' ); $file = fopen( $filename, 'rb' ); From dd16a7129cda0a2e5aec4a418757ba16e089477e Mon Sep 17 00:00:00 2001 From: Paul Bearne Date: Fri, 26 Jun 2026 13:59:35 -0400 Subject: [PATCH 17/17] Update tests to use dynamic `wp_upload_dir()` in assertions --- tests/phpunit/tests/functions/wpuploadbits.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/tests/phpunit/tests/functions/wpuploadbits.php b/tests/phpunit/tests/functions/wpuploadbits.php index c85e075f58780..dbcb944d624ae 100644 --- a/tests/phpunit/tests/functions/wpuploadbits.php +++ b/tests/phpunit/tests/functions/wpuploadbits.php @@ -43,13 +43,14 @@ public function test_wp_upload_bits_should_return_an_array_with_error_message_if * **/ 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' => 'http://example.org/wp-content/uploads/.././/1', + 'url' => $upload_dir['baseurl'] . '/.././/1', 'subdir' => '/.././/1', 'basedir' => ABSPATH . 'wp-content/uploads', - 'baseurl' => 'http://example.org/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' ) @@ -62,14 +63,15 @@ public function test_should_return_error_if_bad_time_path_is_passed() { * @ticket 57130 */ public function test_wp_upload_bits_should_create_file_in_upload_folder_with_given_content() { - $filename = ABSPATH . 'wp-content/uploads/9999/12/filename.txt'; - $content = 'file 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' => 'http://example.org/wp-content/uploads/9999/12/filename.txt', + 'url' => $upload_dir['baseurl'] . '/9999/12/filename.txt', 'type' => 'text/plain', ),