mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
> PHPUnit 8.0.0 introduced a `void` return type declaration to the "fixture" methods – `setUpBeforeClass()`, `setUp()`, `tearDown()` and `tearDownAfterClass()`. As the `void` return type was not introduced until PHP 7.1, this makes it more difficult to create cross-version compatible tests when using fixtures, due to signature mismatches. > > The `Yoast\PHPUnitPolyfills\TestCases\TestCase` overcomes the signature mismatch by having two versions. The correct one will be loaded depending on the PHPUnit version being used. > > When using this TestCase, if an individual test, or another TestCase which extends this TestCase, needs to overload any of the "fixture" methods, it should do so by using a snake_case variant of the original fixture method name, i.e. `set_up_before_class()`, `set_up()`, `assert_pre_conditions()`, `assert_post_conditions()`, `tear_down()`, and `tear_down_after_class()`. > > The snake_case methods will automatically be called by PHPUnit. > > > IMPORTANT: The snake_case methods should not call the PHPUnit parent, i.e. do not use `parent::setUp()` from within an overloaded `set_up()` method. If necessary, DO call `parent::set_up()`. Reference: https://github.com/Yoast/PHPUnit-Polyfills#testcases This commit renames all declared fixture methods, and calls to parent versions of those fixture methods, from camelCase to snake_case. Follow-up to [51559-51567]. Props jrf, hellofromTonya, johnbillion, netweb, dd32, pputzer, SergeyBiryukov. See #46149. git-svn-id: https://develop.svn.wordpress.org/trunk@51568 602fd350-edb4-49c9-b593-d223f7449a82
110 lines
3.6 KiB
PHP
110 lines
3.6 KiB
PHP
<?php
|
|
/**
|
|
* @group upload
|
|
* @group media
|
|
*/
|
|
class Tests_Upload extends WP_UnitTestCase {
|
|
|
|
public $siteurl;
|
|
|
|
function set_up() {
|
|
parent::set_up();
|
|
$this->_reset_options();
|
|
}
|
|
|
|
function _reset_options() {
|
|
// System defaults.
|
|
update_option( 'upload_path', 'wp-content/uploads' );
|
|
update_option( 'upload_url_path', '' );
|
|
update_option( 'uploads_use_yearmonth_folders', 1 );
|
|
}
|
|
|
|
function test_upload_dir_default() {
|
|
// wp_upload_dir() with default parameters.
|
|
$info = wp_upload_dir();
|
|
$subdir = gmstrftime( '/%Y/%m' );
|
|
|
|
$this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
|
|
$this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
|
|
$this->assertSame( $subdir, $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
function test_upload_dir_relative() {
|
|
// wp_upload_dir() with a relative upload path that is not 'wp-content/uploads'.
|
|
update_option( 'upload_path', 'foo/bar' );
|
|
$info = _wp_upload_dir();
|
|
$subdir = gmstrftime( '/%Y/%m' );
|
|
|
|
$this->assertSame( get_option( 'siteurl' ) . '/foo/bar' . $subdir, $info['url'] );
|
|
$this->assertSame( ABSPATH . 'foo/bar' . $subdir, $info['path'] );
|
|
$this->assertSame( $subdir, $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
/**
|
|
* @ticket 5953
|
|
*/
|
|
function test_upload_dir_absolute() {
|
|
$path = get_temp_dir() . 'wp-unit-test';
|
|
|
|
// wp_upload_dir() with an absolute upload path.
|
|
update_option( 'upload_path', $path );
|
|
|
|
// Doesn't make sense to use an absolute file path without setting the url path.
|
|
update_option( 'upload_url_path', '/baz' );
|
|
|
|
// Use `_wp_upload_dir()` directly to bypass caching and work with the changed options.
|
|
// It doesn't create the /year/month directories.
|
|
$info = _wp_upload_dir();
|
|
$subdir = gmstrftime( '/%Y/%m' );
|
|
|
|
$this->assertSame( '/baz' . $subdir, $info['url'] );
|
|
$this->assertSame( $path . $subdir, $info['path'] );
|
|
$this->assertSame( $subdir, $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
function test_upload_dir_no_yearnum() {
|
|
update_option( 'uploads_use_yearmonth_folders', 0 );
|
|
|
|
// Use `_wp_upload_dir()` directly to bypass caching and work with the changed options.
|
|
$info = _wp_upload_dir();
|
|
|
|
$this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads', $info['url'] );
|
|
$this->assertSame( ABSPATH . 'wp-content/uploads', $info['path'] );
|
|
$this->assertSame( '', $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
function test_upload_path_absolute() {
|
|
update_option( 'upload_url_path', 'http://' . WP_TESTS_DOMAIN . '/asdf' );
|
|
|
|
// Use `_wp_upload_dir()` directly to bypass caching and work with the changed options.
|
|
// It doesn't create the /year/month directories.
|
|
$info = _wp_upload_dir();
|
|
$subdir = gmstrftime( '/%Y/%m' );
|
|
|
|
$this->assertSame( 'http://' . WP_TESTS_DOMAIN . '/asdf' . $subdir, $info['url'] );
|
|
$this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
|
|
$this->assertSame( $subdir, $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
function test_upload_dir_empty() {
|
|
// Upload path setting is empty - it should default to 'wp-content/uploads'.
|
|
update_option( 'upload_path', '' );
|
|
|
|
// Use `_wp_upload_dir()` directly to bypass caching and work with the changed options.
|
|
// It doesn't create the /year/month directories.
|
|
$info = _wp_upload_dir();
|
|
$subdir = gmstrftime( '/%Y/%m' );
|
|
|
|
$this->assertSame( get_option( 'siteurl' ) . '/wp-content/uploads' . $subdir, $info['url'] );
|
|
$this->assertSame( ABSPATH . 'wp-content/uploads' . $subdir, $info['path'] );
|
|
$this->assertSame( $subdir, $info['subdir'] );
|
|
$this->assertFalse( $info['error'] );
|
|
}
|
|
|
|
}
|