Files
moodle/lib/tests/ajaxlib_test.php
T
Daniel Ziegenberg c23d5edb0f MDL-83334 core: Remove deprecated constant E_STRICT
One of the error levels PHP previously emitted was E_STRICT, on code
that was not strictly correct to ensure interoperability and forward
compatibility. PHP 7.0 converted the majority of existing E_STRICT
warnings to E_NOTICE, and since PHP 8.0, all E_STRICT notices have
changed to E_NOTICE.

Because all of the E_STRICT notices are upgraded to E_NOTICE since PHP
8.0, PHP 8.4 deprecates the E_STRICT constant.

The E_STRICT constant is deprecated in PHP 8.4. Using the constant
anywhere in PHP code now emits a deprecation notice in PHP 8.4 and
later.

The E_STRICT constant will be removed in PHP 9.0.

PHP core and core extensions since PHP 8.0 and later do not emit
E_STRICT notices at all. It is safe to assume that any PHP applications
that run on PHP 8.0 and later will never encounter E_STRICT notices, and
error reporting and handling can be safely updated to ignore E_STRICT
notices.

See: https://php.watch/versions/8.4/E_STRICT-deprecated

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
2025-03-04 20:38:04 +01:00

131 lines
4.4 KiB
PHP

<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace core;
/**
* Code quality unit tests that are fast enough to run each time.
*
* @package core
* @category test
* @copyright 2013 Andrew Nicols
* @license http://www.gnu.org/copyleft/gpl.html GNU Public License
* @covers ::ajax_capture_output
* @covers ::ajax_check_captured_output
*/
final class ajaxlib_test extends \advanced_testcase {
/** @var string Original error log */
protected $oldlog;
protected function setUp(): void {
global $CFG;
parent::setUp();
// Discard error logs.
$this->oldlog = ini_get('error_log');
ini_set('error_log', "$CFG->dataroot/testlog.log");
}
protected function tearDown(): void {
ini_set('error_log', $this->oldlog);
parent::tearDown();
}
protected function helper_test_clean_output() {
$this->resetAfterTest();
$result = ajax_capture_output();
// ob_start should normally return without issue.
$this->assertTrue($result);
$result = ajax_check_captured_output();
$this->assertEmpty($result);
}
protected function helper_test_dirty_output($expectexception = false) {
$this->resetAfterTest();
// Keep track of the content we will output.
$content = "Some example content";
$result = ajax_capture_output();
// ob_start should normally return without issue.
$this->assertTrue($result);
// Fill the output buffer.
echo $content;
if ($expectexception) {
$this->expectException('coding_exception');
ajax_check_captured_output();
} else {
$result = ajax_check_captured_output();
$this->assertEquals($result, $content);
}
}
public function test_output_capture_normal_debug_none(): void {
// In normal conditions, and with DEBUG_NONE set, we should not receive any output or throw any exceptions.
set_debugging(DEBUG_NONE);
$this->helper_test_clean_output();
}
public function test_output_capture_normal_debug_normal(): void {
// In normal conditions, and with DEBUG_NORMAL set, we should not receive any output or throw any exceptions.
set_debugging(DEBUG_NORMAL);
$this->helper_test_clean_output();
}
public function test_output_capture_normal_debug_all(): void {
// In normal conditions, and with DEBUG_ALL set, we should not receive any output or throw any exceptions.
set_debugging(DEBUG_ALL);
$this->helper_test_clean_output();
}
public function test_output_capture_normal_debugdeveloper(): void {
// In normal conditions, and with DEBUG_DEVELOPER set, we should not receive any output or throw any exceptions.
set_debugging(DEBUG_DEVELOPER);
$this->helper_test_clean_output();
}
public function test_output_capture_error_debug_none(): void {
// With DEBUG_NONE set, we should not throw any exception, but the output will be returned.
set_debugging(DEBUG_NONE);
$this->helper_test_dirty_output();
}
public function test_output_capture_error_debug_normal(): void {
// With DEBUG_NORMAL set, we should not throw any exception, but the output will be returned.
set_debugging(DEBUG_NORMAL);
$this->helper_test_dirty_output();
}
public function test_output_capture_error_debug_all(): void {
// In error conditions, and with DEBUG_ALL set, we should throw an exceptions.
set_debugging(DEBUG_ALL);
$this->helper_test_dirty_output(true);
}
public function test_output_capture_error_debugdeveloper(): void {
// With DEBUG_DEVELOPER set, we should throw an exception.
set_debugging(DEBUG_DEVELOPER);
$this->helper_test_dirty_output(true);
}
}