mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
83b490a594
Applied the following changes to various testcase classes: - Namespaced with component[\level2-API] - Moved to level2-API subdirectory when required. - Fixed incorrect use statements with leading backslash. - Remove file phpdoc block - Remove MOODLE_INTERNAL if not needed. - Changed code to point to global scope when needed. - Fix some relative paths and comments here and there. - All them passing individually. - Complete runs passing too. Special mention to: - The following task tests have been moved within the level2 directory: - \core\adhoc_task_test => \core\task\adhoc_task_test - \core\scheduled_task_test => \core\task\scheduled_task_test - \core\calendar_cron_task_test => \core\task\calendar_cron_task_test - \core\h5p_get_content_types_task_test => \core\task\h5p_get_content_types_task_test - \core\task_database_logger_test => \core\task\database_logger_test - \core\task_logging_test => \core\task\logging_test - The following event tests have been moved within level2 directory: - \core\event_context_locked_test => \core\event\context_locked_test - \core\event_deprecated_test => \core\event\deprecated_test - \core\event_grade_deleted_test => \core\event\grade_deleted_test - \core\event_profile_field_test => \core\event\profile_field_test - \core\event_unknown_logged_test => \core\event\unknown_logged_test - \core\event_user_graded_test => \core\event\user_graded_test - \core\event_user_password_updated_test => \core\event\user_password_updated_test - The following output tests have been moved within level2 directory: - \core\mustache_template_finder_test => \core\output\mustache_template_finder_test - \core\mustache_template_source_loader_test => \core\output\mustache_template_source_loader_test - \core\output_mustache_helper_collection_test => \core\output\mustache_helper_collection_test - The following tests have been moved to their correct tests directories: - lib/tests/time_splittings_test.php => analytics/tests/time_splittings_test.php - All the classes and tests under lib/filebrowser and lib/filestorage belong to core, not to core_files. Some day we should move them to their correct subsystem. - All the classes and tests under lib/grade belong to core, not to core_grades. Some day we should move them to their correct subsystem. - The core_grades_external class and its \core\grades_external_test unit test should belong to the grades subsystem or, alternatively, to \core\external, they both should be moved together. - The core_grading_external class and its \core\grading_external_test unit test should belong to the grading subsystem or, alternatively, to \core\external, they both should be moved together. - The \core\message\message and \core\message\inbound (may be others) classes, and their associated tests should go to the core_message subsystem. - The core_user class, and its associated tests should go to the core_user subsystem. - The \core\update namespace is plain wrong (update is not valid API) and needs action 1) create it or 2) move elsewhere.
148 lines
5.9 KiB
PHP
148 lines
5.9 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;
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
// Global $CFG not used here intentionally to make sure it is not required inside the lib.
|
|
require_once(__DIR__ . '/../configonlylib.php');
|
|
|
|
|
|
/**
|
|
* Unit tests for config only library functions.
|
|
*
|
|
* @package core
|
|
* @category test
|
|
* @copyright 2012 Petr Skoda {@link http://skodak.org}
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
*/
|
|
class configonlylib_test extends \advanced_testcase {
|
|
|
|
/**
|
|
* Test cleaning of invalid utf-8 entities.
|
|
*/
|
|
public function test_min_fix_utf8() {
|
|
$this->assertSame('abc', min_fix_utf8('abc'));
|
|
$this->assertSame("žlutý koníček přeskočil potůček \n\t\r", min_fix_utf8("žlutý koníček přeskočil potůček \n\t\r\0"));
|
|
$this->assertSame('aš', min_fix_utf8('a'.chr(130).'š'), 'This fails with buggy iconv() when mbstring extenstion is not available as fallback.');
|
|
}
|
|
|
|
/**
|
|
* Test minimalistic parameter cleaning.
|
|
*/
|
|
public function test_min_clean_param() {
|
|
$this->assertSame('foo', min_clean_param('foo', 'RAW'));
|
|
$this->assertSame('aš', min_clean_param('a'.chr(130).'š', 'RAW'));
|
|
|
|
$this->assertSame(1, min_clean_param('1', 'INT'));
|
|
$this->assertSame(1, min_clean_param('1aa', 'INT'));
|
|
|
|
$this->assertSame('1abc-d_f', min_clean_param('/.1ačž"b?;c-d{}\\_f.', 'SAFEDIR'));
|
|
$this->assertSame(1, min_clean_param('1aa', 'INT'));
|
|
|
|
$this->assertSame('/a/b/./c5', min_clean_param('/a*?$//b/.../c5', 'SAFEPATH'));
|
|
$this->assertSame(1, min_clean_param('1aa', 'INT'));
|
|
}
|
|
|
|
/**
|
|
* Test minimalistic getting of page parameters.
|
|
*/
|
|
public function test_min_optional_param() {
|
|
$this->resetAfterTest();
|
|
|
|
$_GET['foo'] = 'bar';
|
|
$_GET['num'] = '1';
|
|
$_GET['xnum'] = '1aa';
|
|
|
|
$_POST['foo'] = 'rebar';
|
|
$_POST['oof'] = 'rab';
|
|
|
|
$this->assertSame('bar', min_optional_param('foo', null, 'RAW'));
|
|
$this->assertSame(null, min_optional_param('foo2', null, 'RAW'));
|
|
$this->assertSame('rab', min_optional_param('oof', null, 'RAW'));
|
|
|
|
$this->assertSame(1, min_optional_param('num', null, 'INT'));
|
|
$this->assertSame(1, min_optional_param('xnum', null, 'INT'));
|
|
}
|
|
|
|
/**
|
|
* Test fail-safe minimalistic slashargument processing.
|
|
*/
|
|
public function test_min_get_slash_argument() {
|
|
global $CFG;
|
|
|
|
$this->resetAfterTest();
|
|
$this->assertEquals('https://www.example.com/moodle', $CFG->wwwroot);
|
|
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22 (Unix)';
|
|
$_SERVER['QUERY_STRING'] = 'theme=standard&component=core&rev=5&image=u/f1';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php?theme=standard&component=core&rev=5&image=u/f1';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$this->assertSame('', min_get_slash_argument());
|
|
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Apache/2.2.22 (Unix)';
|
|
$_SERVER['QUERY_STRING'] = '';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['PATH_INFO'] = '/standard/core/5/u/f1';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$_GET = array();
|
|
$this->assertSame('/standard/core/5/u/f1', min_get_slash_argument());
|
|
|
|
// IIS no url rewriting.
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Microsoft-IIS/7.0';
|
|
$_SERVER['QUERY_STRING'] = '';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['PATH_INFO'] = '/standard/core/5/u/f1';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$_GET = array();
|
|
$this->assertSame('/standard/core/5/u/f1', min_get_slash_argument());
|
|
|
|
// IIS with url rewriting.
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Microsoft-IIS/7.0';
|
|
$_SERVER['QUERY_STRING'] = 'file=/standard/core/5/u/f1';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['PATH_INFO'] = '/';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$_GET = array();
|
|
$_GET['file'] = '/standard/core/5/u/f1';
|
|
$this->assertSame('/standard/core/5/u/f1', min_get_slash_argument());
|
|
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Weird server';
|
|
$_SERVER['QUERY_STRING'] = '';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['PATH_INFO'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$_GET = array();
|
|
$this->assertSame('/standard/core/5/u/f1', min_get_slash_argument());
|
|
|
|
$_SERVER = array();
|
|
$_SERVER['SERVER_SOFTWARE'] = 'Hacker server';
|
|
$_SERVER['QUERY_STRING'] = '';
|
|
$_SERVER['REQUEST_URI'] = '/moodle/theme/image.php/standard/core/5/u/f1';
|
|
$_SERVER['PATH_INFO'] = '/moodle/theme/image.php/standard\\core/..\\../5/u/f1';
|
|
$_SERVER['SCRIPT_NAME'] = '/moodle/theme/image.php';
|
|
$_GET = array();
|
|
// Windows dir separators are removed, multiple ... gets collapsed to one .
|
|
$this->assertSame('/standardcore/./5/u/f1', min_get_slash_argument());
|
|
}
|
|
}
|