Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 27... Línea 27...
27
 * @package   core_plugin
27
 * @package   core_plugin
28
 * @category  test
28
 * @category  test
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
final class update_code_manager_test extends \advanced_testcase {
Línea 33... Línea 33...
33
 
33
 
34
    public function test_get_remote_plugin_zip(): void {
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();
Línea 64... Línea 64...
64
        $this->assertEquals(file_get_contents($returned), 'http://valid/');
64
        $this->assertEquals(file_get_contents($returned), 'http://valid/');
65
    }
65
    }
Línea 66... Línea 66...
66
 
66
 
67
    public function test_unzip_plugin_file(): void {
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 = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/invalidroot.zip');
70
        $targetdir = make_request_directory();
70
        $targetdir = make_request_directory();
Línea 71... Línea 71...
71
        mkdir($targetdir.'/aaa_another');
71
        mkdir($targetdir.'/aaa_another');
Línea 100... Línea 100...
100
            } else {
100
            } else {
101
                $this->assertTrue(is_file($targetdir.'/'.$file));
101
                $this->assertTrue(is_file($targetdir.'/'.$file));
102
            }
102
            }
103
        }
103
        }
Línea 104... Línea 104...
104
 
104
 
105
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip';
105
        $zipfilepath = self::get_fixture_path(__NAMESPACE__, '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(): void {
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 = self::get_fixture_path(__NAMESPACE__, '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(): void {
118
    public function test_get_plugin_zip_root_dir(): void {
Línea 119... Línea 119...
119
        $codeman = new \core\update\testable_code_manager();
119
        $codeman = new \core\update\testable_code_manager();
120
 
120
 
Línea 121... Línea 121...
121
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/invalidroot.zip';
121
        $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/invalidroot.zip');
122
        $this->assertEquals('invalid-root', $codeman->get_plugin_zip_root_dir($zipfilepath));
122
        $this->assertEquals('invalid-root', $codeman->get_plugin_zip_root_dir($zipfilepath));
123
 
123
 
Línea 124... Línea 124...
124
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/bar.zip';
124
        $zipfilepath = self::get_fixture_path(__NAMESPACE__, 'update_validator/zips/bar.zip');
125
        $this->assertEquals('bar', $codeman->get_plugin_zip_root_dir($zipfilepath));
125
        $this->assertEquals('bar', $codeman->get_plugin_zip_root_dir($zipfilepath));
126
 
126
 
127
        $zipfilepath = __DIR__.'/fixtures/update_validator/zips/multidir.zip';
127
        $zipfilepath = self::get_fixture_path(__NAMESPACE__, '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));
129
    }
129
    }
130
 
130
 
131
    public function test_list_plugin_folder_files(): void {
131
    public function test_list_plugin_folder_files(): void {
132
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
132
        $fixtures = self::get_fixture_path(__NAMESPACE__, 'update_validator/plugindir');
133
        $codeman = new \core\update\testable_code_manager();
133
        $codeman = new \core\update\testable_code_manager();
Línea 134... Línea 134...
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');
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');
Línea 157... Línea 157...
157
            }
157
            }
158
        }
158
        }
159
    }
159
    }
Línea 160... Línea 160...
160
 
160
 
161
    public function test_archiving_plugin_version(): void {
161
    public function test_archiving_plugin_version(): void {
162
        $fixtures = __DIR__.'/fixtures/update_validator/plugindir';
162
        $fixtures = self::get_fixture_path(__NAMESPACE__, '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
 
165
        $this->assertFalse($codeman->archive_plugin_version($fixtures.'/foobar', 'local_foobar', 0));
165
        $this->assertFalse($codeman->archive_plugin_version($fixtures.'/foobar', 'local_foobar', 0));