wordpress-develop/tests/phpunit/tests/load/isIniValueChangeable.php
Dominik Schilling c68f1ec772 Bootstrap: Enhance core's memory limit handling.
* Don't lower memory limit if the current limit is greater than `WP_MAX_MEMORY_LIMIT`.
* Set `WP_MEMORY_LIMIT` and `WP_MAX_MEMORY_LIMIT` to current limit if the `memory_limit` setting can't be changed at runtime.
* Use `wp_convert_hr_to_bytes()` when parsing the value of the `memory_limit` setting because it can be a shorthand or an integer value.
* Introduce `wp_raise_memory_limit( $context )` to raise the PHP memory limit for memory intensive processes. This DRYs up some logic and includes the existing `admin_memory_limit` and `image_memory_limit` filters. The function can also be used for custom contexts, the `{$context}_memory_limit` filter allows to customize the limit.
* Introduce `wp_is_ini_value_changeable( $setting )` to determine whether a PHP ini value is changeable at runtime.
* Remove a `function_exists( 'memory_get_usage' )` check. Since PHP 5.2.1 support for memory limit is always enabled.

Related commits: [38011-38013]

Props jrf, A5hleyRich, swissspidy, ocean90.
Fixes #32075.

git-svn-id: https://develop.svn.wordpress.org/trunk@38015 602fd350-edb4-49c9-b593-d223f7449a82
2016-07-08 14:36:37 +00:00

49 lines
1.3 KiB
PHP

<?php
/**
* Tests for wp_is_ini_value_changeable().
*
* @group load.php
*/
class Tests_Functions_Is_Ini_Value_Changeable extends WP_UnitTestCase {
/**
* Tests the determining of the changeability of a PHP ini value.
*
* @ticket 32075
*
* @dataProvider data_wp_is_ini_value_changeable
*
* @param string $setting The setting passed to wp_is_ini_value_changeable().
* @param bool $expected The expected output of wp_convert_hr_to_bytes().
*/
function test_wp_is_ini_value_changeable( $setting, $expected ) {
$this->assertSame( $expected, wp_is_ini_value_changeable( $setting ) );
}
/**
* Data provider for test_wp_is_ini_value_changeable().
*
* @return array {
* @type array {
* @type string $setting The setting passed to wp_is_ini_value_changeable().
* @type bool $expected The expected output of wp_convert_hr_to_bytes().
* }
* }
*/
function data_wp_is_ini_value_changeable() {
$array = array(
array( 'memory_limit', true ), // PHP_INI_ALL.
array( 'log_errors', true ), // PHP_INI_ALL.
array( 'upload_max_filesize', false ), // PHP_INI_PERDIR.
array( 'upload_tmp_dir', false ), // PHP_INI_SYSTEM.
);
if ( extension_loaded( 'Tidy' ) && version_compare( PHP_VERSION, '7.0.0', '>' ) ) {
$array[] = array( 'tidy.clean_output', true ); // PHP_INI_USER.
}
return $array;
}
}