MDL-75111 phpunit: Move tests to use correct names and ns (take#4)

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.
This commit is contained in:
Eloy Lafuente (stronk7)
2022-08-26 16:34:28 +02:00
parent 376e57d267
commit 61cedbd56e
125 changed files with 2441 additions and 2725 deletions
+92 -79
View File
@@ -17,19 +17,33 @@
/**
* Unit tests for /lib/filelib.php.
*
* @package core_files
* @category phpunit
* @package core
* @category test
* @copyright 2009 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core;
use core_filetypes;
use curl;
use repository;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->libdir . '/filelib.php');
require_once($CFG->dirroot . '/repository/lib.php');
class core_filelib_testcase extends advanced_testcase {
/**
* Unit tests for /lib/filelib.php.
*
* @package core
* @category test
* @copyright 2009 Jerome Mouneyrac
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class filelib_test extends \advanced_testcase {
public function test_format_postdata_for_curlcall() {
// POST params with just simple types.
@@ -196,12 +210,12 @@ class core_filelib_testcase extends advanced_testcase {
// Test HTTP success.
$testhtml = $this->getExternalTestFileUrl('/test.html');
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($testhtml);
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
$this->assertSame(0, $curl->get_errno());
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$fp = fopen($tofile, 'w');
@@ -212,7 +226,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame($contents, file_get_contents($tofile));
@unlink($tofile);
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$result = $curl->download_one($testhtml, array(), array('filepath'=>$tofile));
@@ -222,7 +236,7 @@ class core_filelib_testcase extends advanced_testcase {
@unlink($tofile);
// Test 404 request.
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($this->getExternalTestFileUrl('/i.do.not.exist'));
$response = $curl->getResponse();
$this->assertSame('404 Not Found', reset($response));
@@ -237,12 +251,12 @@ class core_filelib_testcase extends advanced_testcase {
// Test a request with a basic hostname filter applied.
$testhtml = $this->getExternalTestFileUrl('/test.html');
$url = new moodle_url($testhtml);
$url = new \moodle_url($testhtml);
$host = $url->get_host();
set_config('curlsecurityblockedhosts', $host); // Blocks $host.
// Create curl with the default security enabled. We expect this to be blocked.
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($testhtml);
$expected = $curl->get_security()->get_blocked_url_string();
$this->assertSame($expected, $contents);
@@ -250,7 +264,7 @@ class core_filelib_testcase extends advanced_testcase {
// Now, create a curl using the 'ignoresecurity' override.
// We expect this request to pass, despite the admin setting having been set earlier.
$curl = new curl(['ignoresecurity' => true]);
$curl = new \curl(['ignoresecurity' => true]);
$contents = $curl->get($testhtml);
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
$this->assertSame(0, $curl->get_errno());
@@ -264,7 +278,7 @@ class core_filelib_testcase extends advanced_testcase {
// And make the mock security helper block all URLs. This helper instance doesn't care about config.
$mockhelper->expects($this->any())->method('url_is_blocked')->will($this->returnValue(true));
$curl = new curl(['securityhelper' => $mockhelper]);
$curl = new \curl(['securityhelper' => $mockhelper]);
$contents = $curl->get($testhtml);
$this->assertSame('You shall not pass', $curl->get_security()->get_blocked_url_string());
$this->assertSame($curl->get_security()->get_blocked_url_string(), $contents);
@@ -275,7 +289,7 @@ class core_filelib_testcase extends advanced_testcase {
$testurl = $this->getExternalTestFileUrl('/test_redir.php');
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?redir=2", array(), array('CURLOPT_MAXREDIRS'=>2));
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -284,7 +298,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('done', $contents);
// All redirects are emulated now. Enabling "emulateredirects" explicitly does not have effect.
$curl = new curl();
$curl = new \curl();
$curl->emulateredirects = true;
$contents = $curl->get("$testurl?redir=2", array(), array('CURLOPT_MAXREDIRS'=>2));
$response = $curl->getResponse();
@@ -294,7 +308,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('done', $contents);
// All redirects are emulated now. Attempting to disable "emulateredirects" explicitly causes warning.
$curl = new curl();
$curl = new \curl();
$curl->emulateredirects = false;
$contents = $curl->get("$testurl?redir=2", array(), array('CURLOPT_MAXREDIRS' => 2));
$response = $curl->getResponse();
@@ -314,7 +328,7 @@ class core_filelib_testcase extends advanced_testcase {
$responsecode302 = '302 Found';
}
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?redir=3", array(), array('CURLOPT_FOLLOWLOCATION'=>0));
$response = $curl->getResponse();
$this->assertSame($responsecode302, reset($response));
@@ -322,12 +336,12 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(302, $curl->info['http_code']);
$this->assertSame('', $contents);
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?redir=2", array(), array('CURLOPT_MAXREDIRS'=>1));
$this->assertSame(CURLE_TOO_MANY_REDIRECTS, $curl->get_errno());
$this->assertNotEmpty($contents);
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$fp = fopen($tofile, 'w');
@@ -338,7 +352,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('done', file_get_contents($tofile));
@unlink($tofile);
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$fp = fopen($tofile, 'w');
@@ -349,7 +363,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('done', file_get_contents($tofile));
@unlink($tofile);
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$result = $curl->download_one("$testurl?redir=1", array(), array('filepath'=>$tofile));
@@ -358,7 +372,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('done', file_get_contents($tofile));
@unlink($tofile);
$curl = new curl();
$curl = new \curl();
$tofile = "$CFG->tempdir/test.html";
@unlink($tofile);
$result = $curl->download_one("$testurl?redir=1&verbose=1", array(), array('filepath' => $tofile));
@@ -381,21 +395,21 @@ class core_filelib_testcase extends advanced_testcase {
set_config('curlsecurityblockedhosts', 'moodle.com');
// Redirecting to a non-blocked host should resolve.
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("{$testurl}?redir=2");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
$this->assertSame(0, $curl->get_errno());
// Redirecting to the blocked host should fail.
$curl = new curl();
$curl = new \curl();
$blockedstring = $curl->get_security()->get_blocked_url_string();
$contents = $curl->get("{$testurl}?redir=1&extdest=1");
$this->assertSame($blockedstring, $contents);
$this->assertSame(0, $curl->get_errno());
// Redirecting to the blocked host after multiple successful redirects should also fail.
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("{$testurl}?redir=3&extdest=1");
$this->assertSame($blockedstring, $contents);
$this->assertSame(0, $curl->get_errno());
@@ -405,7 +419,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test relative location redirects.
$testurl = $this->getExternalTestFileUrl('/test_relative_redir.php');
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($testurl);
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -416,7 +430,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test different redirect types.
$testurl = $this->getExternalTestFileUrl('/test_relative_redir.php');
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?type=301");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -424,7 +438,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(1, $curl->info['redirect_count']);
$this->assertSame('done', $contents);
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?type=302");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -432,7 +446,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(1, $curl->info['redirect_count']);
$this->assertSame('done', $contents);
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?type=303");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -440,7 +454,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(1, $curl->info['redirect_count']);
$this->assertSame('done', $contents);
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?type=307");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -448,7 +462,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame(1, $curl->info['redirect_count']);
$this->assertSame('done', $contents);
$curl = new curl();
$curl = new \curl();
$contents = $curl->get("$testurl?type=308");
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -467,7 +481,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test without proxy bypass and inaccessible proxy.
$CFG->proxyhost = 'i.do.not.exist';
$CFG->proxybypass = '';
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($testurl);
$this->assertNotEquals(0, $curl->get_errno());
$this->assertNotEquals('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
@@ -475,7 +489,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test with proxy bypass.
$testurlhost = parse_url($testurl, PHP_URL_HOST);
$CFG->proxybypass = $testurlhost;
$curl = new curl();
$curl = new \curl();
$contents = $curl->get($testurl);
$this->assertSame(0, $curl->get_errno());
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
@@ -490,7 +504,7 @@ class core_filelib_testcase extends advanced_testcase {
public function test_duplicate_curl_header() {
$testurl = $this->getExternalTestFileUrl('/test_post.php');
$curl = new curl();
$curl = new \curl();
$headerdata = 'Accept: application/json';
$header = [$headerdata, $headerdata];
$this->assertCount(2, $header);
@@ -503,7 +517,7 @@ class core_filelib_testcase extends advanced_testcase {
$testurl = $this->getExternalTestFileUrl('/test_post.php');
// Test post request.
$curl = new curl();
$curl = new \curl();
$contents = $curl->post($testurl, 'data=moodletest');
$response = $curl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -511,7 +525,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertSame('OK', $contents);
// Test 100 requests.
$curl = new curl();
$curl = new \curl();
$curl->setHeader('Expect: 100-continue');
$contents = $curl->post($testurl, 'data=moodletest');
$response = $curl->getResponse();
@@ -526,7 +540,7 @@ class core_filelib_testcase extends advanced_testcase {
$fs = get_file_storage();
$filerecord = array(
'contextid' => context_system::instance()->id,
'contextid' => \context_system::instance()->id,
'component' => 'test',
'filearea' => 'curl_post',
'itemid' => 0,
@@ -538,7 +552,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test post with file.
$data = array('testfile' => $testfile);
$curl = new curl();
$curl = new \curl();
$contents = $curl->post($testurl, $data);
$this->assertSame('OK', $contents);
}
@@ -549,7 +563,7 @@ class core_filelib_testcase extends advanced_testcase {
$fs = get_file_storage();
$filerecord = array(
'contextid' => context_system::instance()->id,
'contextid' => \context_system::instance()->id,
'component' => 'test',
'filearea' => 'curl_post',
'itemid' => 0,
@@ -561,7 +575,7 @@ class core_filelib_testcase extends advanced_testcase {
// Test post with file.
$data = array('testfile' => $testfile);
$curl = new curl();
$curl = new \curl();
$contents = $curl->post($testurl, $data);
$this->assertSame('OK', $contents);
}
@@ -570,7 +584,7 @@ class core_filelib_testcase extends advanced_testcase {
// HTTP and HTTPS requests were verified in previous requests. Now check
// that we can selectively disable some protocols.
$curl = new curl();
$curl = new \curl();
// Other protocols than HTTP(S) are disabled by default.
$testurl = 'file:///';
@@ -618,7 +632,7 @@ class core_filelib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$USER = $DB->get_record('user', array('id'=>$user->id));
$repositorypluginname = 'user';
@@ -631,7 +645,7 @@ class core_filelib_testcase extends advanced_testcase {
$fs = get_file_storage();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$component = 'core';
$filearea = 'unittest';
$itemid = 0;
@@ -654,7 +668,7 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertInstanceOf('stored_file', $originalfile);
// Create a user private file.
$userfilerecord = new stdClass;
$userfilerecord = new \stdClass;
$userfilerecord->contextid = $usercontext->id;
$userfilerecord->component = 'user';
$userfilerecord->filearea = 'private';
@@ -729,7 +743,7 @@ class core_filelib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$USER = $DB->get_record('user', array('id'=>$user->id));
$repositorypluginname = 'user';
@@ -741,12 +755,12 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertInstanceOf('repository', $userrepository);
$fs = get_file_storage();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$filecontent = 'User file content';
// Create a user private file.
$userfilerecord = new stdClass;
$userfilerecord = new \stdClass;
$userfilerecord->contextid = $usercontext->id;
$userfilerecord->component = 'user';
$userfilerecord->filearea = 'private';
@@ -800,7 +814,7 @@ class core_filelib_testcase extends advanced_testcase {
$generator = $this->getDataGenerator();
$user = $generator->create_user();
$usercontext = context_user::instance($user->id);
$usercontext = \context_user::instance($user->id);
$USER = $DB->get_record('user', array('id' => $user->id));
$repositorypluginname = 'user';
@@ -812,12 +826,12 @@ class core_filelib_testcase extends advanced_testcase {
$this->assertInstanceOf('repository', $userrepository);
$fs = get_file_storage();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$filecontent = 'User file content';
// Create a user private file.
$userfilerecord = new stdClass;
$userfilerecord = new \stdClass;
$userfilerecord->contextid = $usercontext->id;
$userfilerecord->component = 'user';
$userfilerecord->filearea = 'private';
@@ -913,9 +927,9 @@ EOF;
$mdl30648expected = preg_replace("~(?!<\r)\n~", "\r\n", $mdl30648expected);
// Test stripping works OK.
$this->assertSame($mdl30648expected, curl::strip_double_headers($mdl30648example));
$this->assertSame($mdl30648expected, \curl::strip_double_headers($mdl30648example));
// Test it does nothing to the 'plain' data.
$this->assertSame($mdl30648expected, curl::strip_double_headers($mdl30648expected));
$this->assertSame($mdl30648expected, \curl::strip_double_headers($mdl30648expected));
// Example from OU proxy.
$httpsexample = <<<EOF
@@ -951,9 +965,9 @@ EOF;
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.0 200 Connection established
@@ -988,9 +1002,9 @@ EOF;
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.0 200 Connection established
@@ -1025,9 +1039,9 @@ EOF;
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/1.1 200 Connection established
@@ -1062,9 +1076,9 @@ EOF;
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexpected));
$httpsexample = <<<EOF
HTTP/2 200 Connection established
@@ -1099,10 +1113,9 @@ EOF;
$httpsexpected = preg_replace("~(?!<\r)\n~", "\r\n", $httpsexpected);
// Test stripping works OK.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexample));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexample));
// Test it does nothing to the 'plain' data.
$this->assertSame($httpsexpected, curl::strip_double_headers($httpsexpected));
$this->assertSame($httpsexpected, \curl::strip_double_headers($httpsexpected));
}
/**
@@ -1131,7 +1144,7 @@ EOF;
get_mimetype_description(array('filename' => 'test.frog')));
// Test custom description using multilang filter.
filter_manager::reset_caches();
\filter_manager::reset_caches();
filter_set_global_state('multilang', TEXTFILTER_ON);
filter_set_applies_to_strings('multilang', true);
core_filetypes::update_type('frog', 'frog', 'application/x-frog', 'document',
@@ -1221,7 +1234,7 @@ EOF;
// Finally, test it via exttests, to ensure the agent is sent properly.
// Matching.
$testurl = $this->getExternalTestFileUrl('/test_agent.php');
$extcurl = new curl();
$extcurl = new \curl();
$contents = $extcurl->get($testurl, array(), array('CURLOPT_USERAGENT' => 'AnotherUserAgent/1.2'));
$response = $extcurl->getResponse();
$this->assertSame('200 OK', reset($response));
@@ -1240,7 +1253,7 @@ EOF;
*/
public function test_file_rewrite_pluginfile_urls() {
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$originaltext = 'Fake test with an image <img src="@@PLUGINFILE@@/image.png">';
// Do the rewrite.
@@ -1265,7 +1278,7 @@ EOF;
$this->resetAfterTest();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$originaltext = 'Fake test with an image <img src="@@PLUGINFILE@@/image.png">';
$options = ['includetoken' => true];
@@ -1314,7 +1327,7 @@ EOF;
$this->resetAfterTest();
$syscontext = context_system::instance();
$syscontext = \context_system::instance();
$originaltext = 'Fake test with an image <img src="@@PLUGINFILE@@/image.png">';
$options = ['includetoken' => true];
@@ -1364,7 +1377,7 @@ EOF;
if (isset($filedata['contextid'])) {
$filerecord['contextid'] = $filedata['contextid'];
} else {
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$filerecord['contextid'] = $usercontext->id;
}
$source = isset($filedata['source']) ? $filedata['source'] : serialize((object)array('source' => 'From string'));
@@ -1385,7 +1398,7 @@ EOF;
$this->resetAfterTest(true);
$this->setAdminUser();
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
// Create a draft file.
$filename = 'data.txt';
@@ -1499,7 +1512,7 @@ EOF;
// Add new file.
file_merge_files_from_draft_area_into_filearea($file->get_itemid(), $file->get_contextid(), 'user', 'private', 0, $options);
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$files = $fs->get_area_files($usercontext->id, 'user', 'private', 0);
$this->assertCount(0, $files);
}
@@ -1524,7 +1537,7 @@ EOF;
// Add new file.
file_merge_files_from_draft_area_into_filearea($file->get_itemid(), $file->get_contextid(), 'user', 'private', 0, $options);
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
// Check we only get the base directory, not a new file.
$files = $fs->get_area_files($usercontext->id, 'user', 'private', 0);
$this->assertCount(1, $files);
@@ -1550,7 +1563,7 @@ EOF;
// Add new file.
file_merge_files_from_draft_area_into_filearea($file->get_itemid(), $file->get_contextid(), 'user', 'private', 0, $options);
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
// Check we only get the base directory, not a new file.
$files = $fs->get_area_files($usercontext->id, 'user', 'private', 0);
$this->assertCount(1, $files);
@@ -1583,7 +1596,7 @@ EOF;
$size += $file->get_filesize();
// Create directory.
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$dir = $fs->create_directory($usercontext->id, 'user', 'draft', $draftitemid, '/testsubdir/');
// Add file to directory.
$filerecord = array(
@@ -1640,7 +1653,7 @@ EOF;
$size += $file->get_filesize();
// Create directory.
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$dir = $fs->create_directory($usercontext->id, 'user', 'draft', $draftitemid, '/testsubdir/');
// Add file to directory.
$filerecord = array(
@@ -1692,7 +1705,7 @@ EOF;
// Confirm the user drafts area lists 3 files.
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $draftitemid, 'itemid', 0);
$this->assertCount(3, $draftfiles);
@@ -1776,7 +1789,7 @@ EOF;
// Confirm one file in each draft area.
$fs = get_file_storage();
$usercontext = context_user::instance($USER->id);
$usercontext = \context_user::instance($USER->id);
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $file1->get_itemid(), 'itemid', 0);
$this->assertCount(1, $draftfiles);
$draftfiles = $fs->get_area_files($usercontext->id, 'user', 'draft', $file2->get_itemid(), 'itemid', 0);
@@ -1874,7 +1887,7 @@ class testable_curl extends curl {
*/
public function get_options() {
// Access to private property.
$rp = new ReflectionProperty('curl', 'options');
$rp = new \ReflectionProperty('curl', 'options');
$rp->setAccessible(true);
return $rp->getValue($this);
}
@@ -1886,7 +1899,7 @@ class testable_curl extends curl {
*/
public function set_options($options) {
// Access to private property.
$rp = new ReflectionProperty('curl', 'options');
$rp = new \ReflectionProperty('curl', 'options');
$rp->setAccessible(true);
$rp->setValue($this, $options);
}
@@ -1913,14 +1926,14 @@ class testable_curl extends curl {
}
/**
* Wrapper to access the private curl::apply_opt() method using reflection.
* Wrapper to access the private \curl::apply_opt() method using reflection.
*
* @param array $options
* @return resource The curl handle
*/
public function call_apply_opt($options = null) {
// Access to private method.
$rm = new ReflectionMethod('curl', 'apply_opt');
$rm = new \ReflectionMethod('curl', 'apply_opt');
$rm->setAccessible(true);
$ch = curl_init();
return $rm->invoke($this, $ch, $options);