~ubuntu-branches/ubuntu/utopic/moodle/utopic

« back to all changes in this revision

Viewing changes to lib/tests/componentlib_test.php

  • Committer: Package Import Robot
  • Author(s): Thijs Kinkhorst
  • Date: 2014-05-12 16:10:38 UTC
  • mfrom: (36.1.3 sid)
  • Revision ID: package-import@ubuntu.com-20140512161038-puyqf65k4e0s8ytz
Tags: 2.6.3-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
global $CFG;
29
29
require_once($CFG->libdir.'/componentlib.class.php');
30
30
 
31
 
class componentlib_testcase extends advanced_testcase {
 
31
class core_componentlib_testcase extends advanced_testcase {
32
32
 
33
33
    public function test_component_installer() {
34
34
        global $CFG;
35
35
 
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());
38
39
 
39
40
        $destpath = $CFG->dataroot.'/downloadtests';
40
41
 
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');
45
46
        @rmdir($destpath);
46
47
 
47
 
        $this->assertEquals(COMPONENT_NEEDUPDATE, $ci->need_upgrade());
48
 
 
49
 
        $status = $ci->install();
50
 
        $this->assertEquals(COMPONENT_INSTALLED, $status);
51
 
        $this->assertEquals('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5());
52
 
 
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);
57
 
 
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());
 
49
 
 
50
        $status = $ci->install();
 
51
        $this->assertSame(COMPONENT_INSTALLED, $status);
 
52
        $this->assertSame('9e94f74b3efb1ff6cf075dc6b2abf15c', $ci->get_component_md5());
 
53
 
 
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);
 
58
 
 
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'));
61
62
    }
62
63
 
63
64
    /**
64
 
     * Test the public API of the {@link lang_installer} class
 
65
     * Test the public API of the {@link lang_installer} class.
65
66
     */
66
67
    public function test_lang_installer() {
67
68
 
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());
91
92
        unset($installer);
92
93
 
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);
102
 
 
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);
 
100
 
 
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);
 
104
 
 
105
        // Exception throwing.
104
106
        $installer = new testable_lang_installer(array('yy'));
105
107
        try {
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);
110
112
        }
111
113
    }
112
114
}
113
115
 
 
116
 
114
117
/**
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
135
138
    }
136
139
 
137
140
    /**
138
 
     * Simulate lang pack installation via component_installer
 
141
     * Simulate lang pack installation via component_installer.
139
142
     *
140
143
     * Language packages 'de_du' and 'de_kids' reported as installed
141
144
     * Language packages 'cs' and 'de' reported as up-to-date
164
167
    }
165
168
 
166
169
    /**
167
 
     * Simulate detection of parent languge
 
170
     * Simulate detection of parent language.
168
171
     *
169
172
     * @see parent::get_parent_language()
170
173
     */