diff --git a/lib/componentlib.class.php b/lib/componentlib.class.php
index c10389e564451..55fc6439e3490 100644
--- a/lib/componentlib.class.php
+++ b/lib/componentlib.class.php
@@ -220,12 +220,12 @@ function check_requisites() {
$this->requisitesok = false;
/// Check that everything we need is present
- if (empty($this->sourcebase) || empty($this->zippath) || empty($this->zipfilename)) {
+ if (empty($this->sourcebase) || empty($this->zipfilename)) {
$this->errorstring='missingrequiredfield';
return false;
}
/// Check for correct sourcebase (this will be out in the future)
- if ($this->sourcebase != 'http://download.moodle.org') {
+ if (!PHPUNIT_TEST and $this->sourcebase != 'http://download.moodle.org') {
$this->errorstring='wrongsourcebase';
return false;
}
@@ -286,7 +286,12 @@ function install() {
return COMPONENT_ERROR;
}
/// Download zip file and save it to temp
- $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->zipfilename;
+ if ($this->zippath) {
+ $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->zipfilename;
+ } else {
+ $source = $this->sourcebase.'/'.$this->zipfilename;
+ }
+
$zipfile= $CFG->tempdir.'/'.$this->zipfilename;
if($contents = download_file_content($source)) {
@@ -474,7 +479,11 @@ function get_all_components_md5() {
$comp_arr = array();
/// Define and retrieve the full md5 file
- $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->md5filename;
+ if ($this->zippath) {
+ $source = $this->sourcebase.'/'.$this->zippath.'/'.$this->md5filename;
+ } else {
+ $source = $this->sourcebase.'/'.$this->md5filename;
+ }
/// Check if we have downloaded the md5 file before (per request cache)
if (!empty($this->cachedmd5components[$source])) {
diff --git a/lib/filestorage/tests/file_storage_test.php b/lib/filestorage/tests/file_storage_test.php
index 15f8d335f0941..76a4b631b0608 100644
--- a/lib/filestorage/tests/file_storage_test.php
+++ b/lib/filestorage/tests/file_storage_test.php
@@ -865,7 +865,7 @@ public function test_create_file_from_url() {
'itemid' => 0,
'filepath' => '/downloadtest/',
);
- $url = 'http://download.moodle.org/unittest/test.html';
+ $url = $this->getExternalTestFileUrl('/test.html');
$fs = get_file_storage();
diff --git a/lib/phpunit/classes/advanced_testcase.php b/lib/phpunit/classes/advanced_testcase.php
index 42d4dd3f5777c..9c275e3cce615 100644
--- a/lib/phpunit/classes/advanced_testcase.php
+++ b/lib/phpunit/classes/advanced_testcase.php
@@ -452,6 +452,46 @@ public static function getDataGenerator() {
return phpunit_util::get_data_generator();
}
+ /**
+ * Returns UTL of the external test file.
+ *
+ * The result depends on the value of following constants:
+ * - TEST_EXTERNAL_FILES_HTTP_URL
+ * - TEST_EXTERNAL_FILES_HTTPS_URL
+ *
+ * They should point to standard external test files repository,
+ * it defaults to 'http://download.moodle.org/unittest'.
+ *
+ * False value means skip tests that require external files.
+ *
+ * @param string $path
+ * @param bool $https true if https required
+ * @return string url
+ */
+ public function getExternalTestFileUrl($path, $https = false) {
+ $path = ltrim($path, '/');
+ if ($path) {
+ $path = '/'.$path;
+ }
+ if ($https) {
+ if (defined('TEST_EXTERNAL_FILES_HTTPS_URL')) {
+ if (!TEST_EXTERNAL_FILES_HTTPS_URL) {
+ $this->markTestSkipped('Tests using external https test files are disabled');
+ }
+ return TEST_EXTERNAL_FILES_HTTPS_URL.$path;
+ }
+ return 'https://download.moodle.org/unittest'.$path;
+ }
+
+ if (defined('TEST_EXTERNAL_FILES_HTTP_URL')) {
+ if (!TEST_EXTERNAL_FILES_HTTP_URL) {
+ $this->markTestSkipped('Tests using external http test files are disabled');
+ }
+ return TEST_EXTERNAL_FILES_HTTP_URL.$path;
+ }
+ return 'http://download.moodle.org/unittest'.$path;
+ }
+
/**
* Recursively visit all the files in the source tree. Calls the callback
* function with the pathname of each file found.
diff --git a/lib/tests/componentlib_test.php b/lib/tests/componentlib_test.php
index 1096e30c4b790..53a401c4b5ba0 100644
--- a/lib/tests/componentlib_test.php
+++ b/lib/tests/componentlib_test.php
@@ -33,7 +33,8 @@ class core_componentlib_testcase extends advanced_testcase {
public function test_component_installer() {
global $CFG;
- $ci = new component_installer('http://download.moodle.org', 'unittest', 'downloadtests.zip');
+ $url = $this->getExternalTestFileUrl('');
+ $ci = new component_installer($url, '', 'downloadtests.zip');
$this->assertTrue($ci->check_requisites());
$destpath = $CFG->dataroot.'/downloadtests';
diff --git a/lib/tests/filelib_test.php b/lib/tests/filelib_test.php
index 57e41971db8ac..0dc7a6491ff19 100644
--- a/lib/tests/filelib_test.php
+++ b/lib/tests/filelib_test.php
@@ -84,7 +84,7 @@ public function test_download_file_content() {
global $CFG;
// Test http success first.
- $testhtml = "http://download.moodle.org/unittest/test.html";
+ $testhtml = $this->getExternalTestFileUrl('/test.html');
$contents = download_file_content($testhtml);
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
@@ -109,7 +109,7 @@ public function test_download_file_content() {
$this->assertSame('', $response->error);
// Test https success.
- $testhtml = "https://download.moodle.org/unittest/test.html";
+ $testhtml = $this->getExternalTestFileUrl('/test.html', true);
$contents = download_file_content($testhtml, null, null, false, 300, 20, true);
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
@@ -118,7 +118,7 @@ public function test_download_file_content() {
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5($contents));
// Now 404.
- $testhtml = "http://download.moodle.org/unittest/test.html_nonexistent";
+ $testhtml = $this->getExternalTestFileUrl('/test.html_nonexistent');
$contents = download_file_content($testhtml);
$this->assertFalse($contents);
@@ -133,13 +133,14 @@ public function test_download_file_content() {
$this->assertSame('', $response->error);
// Invalid url.
- $testhtml = "ftp://download.moodle.org/unittest/test.html";
+ $testhtml = $this->getExternalTestFileUrl('/test.html');
+ $testhtml = str_replace('http://', 'ftp://', $testhtml);
$contents = download_file_content($testhtml);
$this->assertFalse($contents);
// Test standard redirects.
- $testurl = 'http://download.moodle.org/unittest/test_redir.php';
+ $testurl = $this->getExternalTestFileUrl('/test_redir.php');
$contents = download_file_content("$testurl?redir=2");
$this->assertSame('done', $contents);
@@ -152,13 +153,11 @@ public function test_download_file_content() {
$this->assertSame('done', $response->results);
$this->assertSame('', $response->error);
+ // Commented out this block if there are performance problems.
/*
- // Commented out for performance reasons.
-
$contents = download_file_content("$testurl?redir=6");
$this->assertFalse(false, $contents);
$this->assertDebuggingCalled();
-
$response = download_file_content("$testurl?redir=6", null, null, true);
$this->assertInstanceOf('stdClass', $response);
$this->assertSame('0', $response->status);
@@ -168,7 +167,7 @@ public function test_download_file_content() {
*/
// Test relative redirects.
- $testurl = 'http://download.moodle.org/unittest/test_relative_redir.php';
+ $testurl = $this->getExternalTestFileUrl('/test_relative_redir.php');
$contents = download_file_content("$testurl");
$this->assertSame('done', $contents);
@@ -184,7 +183,7 @@ public function test_curl_class() {
global $CFG;
// Test https success.
- $testhtml = "https://download.moodle.org/unittest/test.html";
+ $testhtml = $this->getExternalTestFileUrl('/test.html');
$curl = new curl();
$contents = $curl->get($testhtml);
@@ -212,7 +211,7 @@ public function test_curl_class() {
@unlink($tofile);
// Test full URL redirects.
- $testurl = 'http://download.moodle.org/unittest/test_redir.php';
+ $testurl = $this->getExternalTestFileUrl('/test_redir.php');
$curl = new curl();
$contents = $curl->get("$testurl?redir=2", array(), array('CURLOPT_MAXREDIRS'=>2));
@@ -294,7 +293,7 @@ public function test_curl_class() {
@unlink($tofile);
// Test relative location redirects.
- $testurl = 'http://download.moodle.org/unittest/test_relative_redir.php';
+ $testurl = $this->getExternalTestFileUrl('/test_relative_redir.php');
$curl = new curl();
$contents = $curl->get($testurl);
@@ -310,7 +309,7 @@ public function test_curl_class() {
$this->assertSame('done', $contents);
// Test different redirect types.
- $testurl = 'http://download.moodle.org/unittest/test_relative_redir.php';
+ $testurl = $this->getExternalTestFileUrl('/test_relative_redir.php');
$curl = new curl();
$contents = $curl->get("$testurl?type=301");
diff --git a/lib/tests/rsslib_test.php b/lib/tests/rsslib_test.php
index 34fe337dfa99b..a10d05ab832da 100644
--- a/lib/tests/rsslib_test.php
+++ b/lib/tests/rsslib_test.php
@@ -35,14 +35,8 @@
require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');
-class core_rsslib_testcase extends basic_testcase {
-
- // A url we know exists and is valid.
- const VALIDURL = 'http://download.moodle.org/unittest/rsstest.xml';
- // A url which we know doesn't exist.
- const INVALIDURL = 'http://download.moodle.org/unittest/rsstest-which-doesnt-exist.xml';
- // This tinyurl redirects to th rsstest.xml file.
- const REDIRECTURL = 'http://tinyurl.com/lvyslv';
+class core_rsslib_testcase extends advanced_testcase {
+
// The number of seconds tests should wait for the server to respond (high to prevent false positives).
const TIMEOUT = 10;
@@ -51,7 +45,7 @@ protected function setUp() {
}
public function test_getfeed() {
- $feed = new moodle_simplepie(self::VALIDURL, self::TIMEOUT);
+ $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml'), self::TIMEOUT);
$this->assertInstanceOf('moodle_simplepie', $feed);
@@ -105,7 +99,7 @@ public function test_getfeed() {
* Test retrieving a url which doesn't exist.
*/
public function test_failurl() {
- $feed = @new moodle_simplepie(self::INVALIDURL, self::TIMEOUT); // We do not want this in php error log.
+ $feed = @new moodle_simplepie($this->getExternalTestFileUrl('/rsstest-which-doesnt-exist.xml'), self::TIMEOUT); // We do not want this in php error log.
$this->assertNotEmpty($feed->error());
}
@@ -119,7 +113,7 @@ public function test_failproxy() {
$oldproxy = $CFG->proxyhost;
$CFG->proxyhost = 'xxxxxxxxxxxxxxx.moodle.org';
- $feed = new moodle_simplepie(self::VALIDURL);
+ $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rsstest.xml'));
$this->assertNotEmpty($feed->error());
$this->assertEmpty($feed->get_title());
@@ -130,7 +124,7 @@ public function test_failproxy() {
* Test retrieving a url which sends a redirect to another valid feed.
*/
public function test_redirect() {
- $feed = new moodle_simplepie(self::REDIRECTURL, self::TIMEOUT);
+ $feed = new moodle_simplepie($this->getExternalTestFileUrl('/rss_redir.php'), self::TIMEOUT);
$this->assertNull($feed->error());
$this->assertSame('Moodle News', $feed->get_title());
diff --git a/lib/tests/weblib_test.php b/lib/tests/weblib_test.php
index 8705dccca931d..87185348148fa 100644
--- a/lib/tests/weblib_test.php
+++ b/lib/tests/weblib_test.php
@@ -15,13 +15,7 @@
// along with Moodle. If not, see .
/**
- * These tests rely on the rsstest.xml file on download.moodle.org,
- * from eloys listing:
- * rsstest.xml: One valid rss feed.
- * md5: 8fd047914863bf9b3a4b1514ec51c32c
- * size: 32188
- *
- * If networking/proxy configuration is wrong these tests will fail..
+ * Weblib tests.
*
* @package core
* @category phpunit
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index 13dd92cd0db41..509ed1a574e07 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -20,6 +20,10 @@
+
+
+
+