mirror of
https://github.com/moodle/moodle.git
synced 2025-08-08 10:26:40 +02:00
MDL-41707 allow custom location of external test files used from unit tests
This commit is contained in:
parent
d45e65ccad
commit
a9d2f1b414
8 changed files with 78 additions and 37 deletions
|
@ -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';
|
||||
|
|
|
@ -84,7 +84,7 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
$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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
$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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
$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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
$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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
*/
|
||||
|
||||
// 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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
@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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
@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 @@ class core_filelib_testcase extends advanced_testcase {
|
|||
$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");
|
||||
|
|
|
@ -35,14 +35,8 @@ global $CFG;
|
|||
require_once($CFG->libdir.'/simplepie/moodle_simplepie.php');
|
||||
|
||||
|
||||
class core_rsslib_testcase extends basic_testcase {
|
||||
class core_rsslib_testcase extends advanced_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';
|
||||
// The number of seconds tests should wait for the server to respond (high to prevent false positives).
|
||||
const TIMEOUT = 10;
|
||||
|
||||
|
@ -51,7 +45,7 @@ class core_rsslib_testcase extends basic_testcase {
|
|||
}
|
||||
|
||||
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 @@ EOD;
|
|||
* 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 @@ EOD;
|
|||
$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 @@ EOD;
|
|||
* 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());
|
||||
|
|
|
@ -15,13 +15,7 @@
|
|||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue