29
29
require_once($CFG->libdir.'/componentlib.class.php');
31
class componentlib_testcase extends advanced_testcase {
31
class core_componentlib_testcase extends advanced_testcase {
33
33
public function test_component_installer() {
36
$ci = new component_installer('http://download.moodle.org', 'unittest', 'downloadtests.zip');
36
$url = $this->getExternalTestFileUrl('');
37
$ci = new component_installer($url, '', 'downloadtests.zip');
37
38
$this->assertTrue($ci->check_requisites());
39
40
$destpath = $CFG->dataroot.'/downloadtests';
41
//carefully remove component files to enforce fresh installation
42
// Carefully remove component files to enforce fresh installation.
42
43
@unlink($destpath.'/'.'downloadtests.md5');
43
44
@unlink($destpath.'/'.'test.html');
44
45
@unlink($destpath.'/'.'test.jpg');
47
$this->assertEquals(COMPONENT_NEEDUPDATE, $ci->need_upgrade());
49
$status = $ci->install();
50
$this->assertEquals(COMPONENT_INSTALLED, $status);
51
$this->assertEquals('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5());
53
//it's already installed, so Moodle should detect it's up to date
54
$this->assertEquals(COMPONENT_UPTODATE, $ci->need_upgrade());
55
$status = $ci->install();
56
$this->assertEquals(COMPONENT_UPTODATE, $status);
58
//check if correct files were downloaded
59
$this->assertEquals('2af180e813dc3f446a9bb7b6af87ce24', md5_file($destpath.'/'.'test.jpg'));
60
$this->assertEquals('47250a973d1b88d9445f94db4ef2c97a', md5_file($destpath.'/'.'test.html'));
48
$this->assertSame(COMPONENT_NEEDUPDATE, $ci->need_upgrade());
50
$status = $ci->install();
51
$this->assertSame(COMPONENT_INSTALLED, $status);
52
$this->assertSame('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5());
54
// It's already installed, so Moodle should detect it's up to date.
55
$this->assertSame(COMPONENT_UPTODATE, $ci->need_upgrade());
56
$status = $ci->install();
57
$this->assertSame(COMPONENT_UPTODATE, $status);
59
// Check if correct files were downloaded.
60
$this->assertSame('2af180e813dc3f446a9bb7b6af87ce24', md5_file($destpath.'/'.'test.jpg'));
61
$this->assertSame('47250a973d1b88d9445f94db4ef2c97a', md5_file($destpath.'/'.'test.html'));
64
* Test the public API of the {@link lang_installer} class
65
* Test the public API of the {@link lang_installer} class.
66
67
public function test_lang_installer() {
68
// test the manipulation with the download queue
69
// Test the manipulation with the download queue.
69
70
$installer = new testable_lang_installer();
70
71
$this->assertFalse($installer->protected_is_queued());
71
72
$installer->protected_add_to_queue('cs');
90
91
$this->assertFalse($installer->protected_is_queued());
93
// install a set of lang packs
94
// Install a set of lang packs.
94
95
$installer = new testable_lang_installer(array('cs', 'de_kids', 'xx'));
95
96
$result = $installer->run();
96
$this->assertEquals($result['cs'], lang_installer::RESULT_UPTODATE);
97
$this->assertEquals($result['de_kids'], lang_installer::RESULT_INSTALLED);
98
$this->assertEquals($result['xx'], lang_installer::RESULT_DOWNLOADERROR);
99
// the following two were automatically added to the queue
100
$this->assertEquals($result['de_du'], lang_installer::RESULT_INSTALLED);
101
$this->assertEquals($result['de'], lang_installer::RESULT_UPTODATE);
103
// exception throwing
97
$this->assertSame($result['cs'], lang_installer::RESULT_UPTODATE);
98
$this->assertSame($result['de_kids'], lang_installer::RESULT_INSTALLED);
99
$this->assertSame($result['xx'], lang_installer::RESULT_DOWNLOADERROR);
101
// The following two were automatically added to the queue.
102
$this->assertSame($result['de_du'], lang_installer::RESULT_INSTALLED);
103
$this->assertSame($result['de'], lang_installer::RESULT_UPTODATE);
105
// Exception throwing.
104
106
$installer = new testable_lang_installer(array('yy'));
106
108
$installer->run();
107
109
$this->fail('lang_installer_exception exception expected');
108
} catch (Exception $e) {
109
$this->assertEquals('lang_installer_exception', get_class($e));
110
} catch (moodle_exception $e) {
111
$this->assertInstanceOf('lang_installer_exception', $e);
115
118
* Testable lang_installer subclass that does not actually install anything
116
119
* and provides access to the protected methods of the parent class