diff --git a/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php b/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php index 1d736cd..d1a0f9d 100644 --- a/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php +++ b/core/tests/Drupal/Tests/Core/Bootstrap/BootstrapTest.php @@ -27,6 +27,12 @@ public static function getInfo() { /** * Tests providing a direct URL to to drupal_override_server_variables(). * + * @param string $url + * The url argument for Bootstrap::overrideServerVariables(). + * @param array $expected_server_values + * Expected values of the `$_SERVER` variable after calling + * Bootstrap::overrideServerVariables(). + * * @dataProvider providerTestOverrideServerVariables */ public function testOverrideServerVariables($url, $expected_server_values) { @@ -45,28 +51,31 @@ public function testOverrideServerVariables($url, $expected_server_values) { /** * Tests that the Bootstrap::checkMemoryLimit() method works as expected. + * + * @param string $required + * The required memory limit argument for Bootstrap::checkMemoryLimit(). + * @param string $memory_limit + * The memory limit argument for Bootstrap::checkMemoryLimit(). + * @param boolean $expected + * The expected return value from Bootstrap::checkMemoryLimit(). + * @param string $message + * The message to print on test failure. + * + * @dataProvider providerTestCheckMemoryLimit */ - function testCheckMemoryLimit() { - $memory_limit = ini_get('memory_limit'); - // Test that a very reasonable amount of memory is available. - $this->assertTrue(Bootstrap::checkMemoryLimit('30MB'), '30MB of memory tested available.'); - - // Get the available memory and multiply it by two to make it unreasonably - // high. - $twice_avail_memory = ($memory_limit * 2) . 'MB'; - // The function should always return true if the memory limit is set to -1. - $this->assertTrue(Bootstrap::checkMemoryLimit($twice_avail_memory, -1), 'Bootstrap::checkMemoryLimit() returns TRUE when a limit of -1 (none) is supplied'); - - // Test that even though we have 30MB of memory available - the function - // returns FALSE when given an upper limit for how much memory can be used. - $this->assertFalse(Bootstrap::checkMemoryLimit('30MB', '16MB'), 'Bootstrap::checkMemoryLimit() returns FALSE with a 16MB upper limit on a 30MB requirement.'); - - // Test that an equal amount of memory to the amount requested returns TRUE. - $this->assertTrue(Bootstrap::checkMemoryLimit('30MB', '30MB'), 'Bootstrap::checkMemoryLimit() returns TRUE when requesting 30MB on a 30MB requirement.'); + public function testCheckMemoryLimit($required, $memory_limit, $expected, $message) { + $return = Bootstrap::checkMemoryLimit($required, $memory_limit); + $this->assertEquals($return, $expected, $message); } /** * Provide data for self::testDrupalOverrideServerVariablesProvideURL(). + * + * @return array + * An array of arrays, each containing: + * - 'url' - The url argument for Bootstrap::overrideServerVariables(). + * - 'expected_server_values' - Expected values of the `$_SERVER` variable + * after calling Bootstrap::overrideServerVariables(). */ public function providerTestOverrideServerVariables() { return array( @@ -94,4 +103,36 @@ public function providerTestOverrideServerVariables() { ), ); } + + /** + * Data provider for self::testCheckMemoryLimit(). + * + * @return array + * An array of arrays, each containing: + * - 'required' - The required memory limit argument for Bootstrap::checkMemoryLimit(). + * - 'memory_limit` - The memory limit argument for Bootstrap::checkMemoryLimit(). + * - 'expected' - The expected return value from Bootstrap::checkMemoryLimit(). + * - 'message' - The message to print on test failure. + */ + public function providerTestCheckMemoryLimit() { + $memory_limit = ini_get('memory_limit'); + $twice_avail_memory = ($memory_limit * 2) . 'MB'; + + return array( + // Test that a very reasonable amount of memory is available. + array('30MB', NULL, TRUE, '30MB of memory tested not available.'), + + // Get the available memory and multiply it by two to make it unreasonably + // high. + array($twice_avail_memory, -1, TRUE, 'Bootstrap::checkMemoryLimit() failed to return TRUE when a limit of -1 (none) is supplied'), + + // Test that even though we have 30MB of memory available - the function + // returns FALSE when given an upper limit for how much memory can be used. + array('30MB', '16MB', FALSE, 'Bootstrap::checkMemoryLimit() failed to return FALSE with a 16MB upper limit on a 30MB requirement.'), + + // Test that an equal amount of memory to the amount requested returns TRUE. + array('30MB', '30MB', TRUE, 'Bootstrap::checkMemoryLimit() failed to return TRUE when requesting 30MB on a 30MB requirement.'), + ); + } + }