Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 29... Línea 29...
29
 * @copyright 2015 David Mudrak <david@moodle.com>
29
 * @copyright 2015 David Mudrak <david@moodle.com>
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
31
 */
32
class update_code_manager_test extends \advanced_testcase {
32
class update_code_manager_test extends \advanced_testcase {
Línea 33... Línea 33...
33
 
33
 
34
    public function test_get_remote_plugin_zip() {
34
    public function test_get_remote_plugin_zip(): void {
Línea 35... Línea 35...
35
        $codeman = new \core\update\testable_code_manager();
35
        $codeman = new \core\update\testable_code_manager();
36
 
36
 
Línea 47... Línea 47...
47
        $this->assertEquals(3, $codeman->downloadscounter);
47
        $this->assertEquals(3, $codeman->downloadscounter);
48
        $this->assertNotFalse($codeman->get_remote_plugin_zip('http://first/', md5('http://first/')));
48
        $this->assertNotFalse($codeman->get_remote_plugin_zip('http://first/', md5('http://first/')));
49
        $this->assertEquals(3, $codeman->downloadscounter);
49
        $this->assertEquals(3, $codeman->downloadscounter);
50
    }
50
    }
Línea 51... Línea 51...
51
 
51
 
Línea 52... Línea 52...
52
    public function test_get_remote_plugin_zip_corrupted_cache() {
52
    public function test_get_remote_plugin_zip_corrupted_cache(): void {
53
 
53
 
Línea 54... Línea 54...
54
        $temproot = make_request_directory();
54
        $temproot = make_request_directory();
Línea 62... Línea 62...
62
 
62
 
63
        $this->assertEquals(basename($returned), md5('http://valid/').'.zip');
63
        $this->assertEquals(basename($returned), md5('http://valid/').'.zip');
64
        $this->assertEquals(file_get_contents($returned), 'http://valid/');
64
        $this->assertEquals(file_get_contents($returned), 'http://valid/');
Línea 65... Línea 65...
65
    }
65
    }
66
 
66
 
67
    public function test_unzip_plugin_file() {
67
    public function test_unzip_plugin_file(): void {
68
        $codeman = new \core\update\testable_code_manager();
68
        $codeman = new \core\update\testable_code_manager();
69
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/invalidroot.zip';
69
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/invalidroot.zip';
Línea 104... Línea 104...
104
 
104
 
105
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip';
105
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip';
106
        $files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'bar');
106
        $files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'bar');
Línea 107... Línea 107...
107
    }
107
    }
108
 
108
 
109
    public function test_unzip_plugin_file_multidir() {
109
    public function test_unzip_plugin_file_multidir(): void {
110
        $codeman = new \core\update\testable_code_manager();
110
        $codeman = new \core\update\testable_code_manager();
111
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
111
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
112
        $targetdir = make_request_directory();
112
        $targetdir = make_request_directory();
113
        // Attempting to rename the root folder if there are multiple ones should lead to exception.
113
        // Attempting to rename the root folder if there are multiple ones should lead to exception.
114
        $this->expectException(\moodle_exception::class);
114
        $this->expectException(\moodle_exception::class);
Línea 115... Línea 115...
115
        $files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'foo');
115
        $files = $codeman->unzip_plugin_file($zipfilepath, $targetdir, 'foo');
116
    }
116
    }
Línea 117... Línea 117...
117
 
117
 
118
    public function test_get_plugin_zip_root_dir() {
118
    public function test_get_plugin_zip_root_dir(): void {
Línea 126... Línea 126...
126
 
126
 
127
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
127
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
128
        $this->assertSame(false, $codeman->get_plugin_zip_root_dir($zipfilepath));
128
        $this->assertSame(false, $codeman->get_plugin_zip_root_dir($zipfilepath));
Línea 129... Línea 129...
129
    }
129
    }
130
 
130
 
131
    public function test_list_plugin_folder_files() {
131
    public function test_list_plugin_folder_files(): void {
132
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
132
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
133
        $codeman = new \core\update\testable_code_manager();
133
        $codeman = new \core\update\testable_code_manager();
134
        $files = $codeman->list_plugin_folder_files($fixtures.'/foobar');
134
        $files = $codeman->list_plugin_folder_files($fixtures.'/foobar');
135
        $this->assertIsArray($files);
135
        $this->assertIsArray($files);
136
        $this->assertEquals(6, count($files));
136
        $this->assertEquals(6, count($files));
137
        $fixtures = str_replace(DIRECTORY_SEPARATOR, '/', $fixtures);
137
        $fixtures = str_replace(DIRECTORY_SEPARATOR, '/', $fixtures);
138
        $this->assertEquals($files['foobar/'], $fixtures.'/foobar');
138
        $this->assertEquals($files['foobar/'], $fixtures.'/foobar');
Línea 139... Línea 139...
139
        $this->assertEquals($files['foobar/lang/en/local_foobar.php'], $fixtures.'/foobar/lang/en/local_foobar.php');
139
        $this->assertEquals($files['foobar/lang/en/local_foobar.php'], $fixtures.'/foobar/lang/en/local_foobar.php');
140
    }
140
    }
141
 
141
 
142
    public function test_zip_plugin_folder() {
142
    public function test_zip_plugin_folder(): void {
143
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
143
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
144
        $storage = make_request_directory();
144
        $storage = make_request_directory();
Línea 156... Línea 156...
156
                $this->assertTrue(file_exists($fixtures.'/'.$zipfile->pathname));
156
                $this->assertTrue(file_exists($fixtures.'/'.$zipfile->pathname));
157
            }
157
            }
158
        }
158
        }
159
    }
159
    }
Línea 160... Línea 160...
160
 
160
 
161
    public function test_archiving_plugin_version() {
161
    public function test_archiving_plugin_version(): void {
162
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
162
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
Línea 163... Línea 163...
163
        $codeman = new \core\update\testable_code_manager();
163
        $codeman = new \core\update\testable_code_manager();
164
 
164