Ignore:
Timestamp:
May 2, 2016, 12:09:23 PM (3 years ago)
Author:
jrpelegrina
Message:

Updated to moodle 3.0.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • moodle/trunk/fuentes/admin/tool/installaddon/tests/installer_test.php

    r136 r1331  
    2727defined('MOODLE_INTERNAL') || die();
    2828
     29global $CFG;
     30require_once(__DIR__.'/fixtures/testable_installer.php');
    2931
    3032/**
     
    4850        $this->assertSame('file:///etc/passwd', $site['url']);
    4951        $this->assertSame("2.5'; DROP TABLE mdl_user; --", $site['majorversion']);
    50     }
    51 
    52     public function test_extract_installfromzip_file() {
    53         $jobid = md5(rand().uniqid('test_', true));
    54         $sourcedir = make_temp_directory('tool_installaddon/'.$jobid.'/source');
    55         $contentsdir = make_temp_directory('tool_installaddon/'.$jobid.'/contents');
    56         copy(dirname(__FILE__).'/fixtures/zips/invalidroot.zip', $sourcedir.'/testinvalidroot.zip');
    57 
    58         $installer = tool_installaddon_installer::instance();
    59         $files = $installer->extract_installfromzip_file($sourcedir.'/testinvalidroot.zip', $contentsdir, 'fixed_root');
    60         $this->assertInternalType('array', $files);
    61         $this->assertCount(4, $files);
    62         $this->assertSame(true, $files['fixed_root/']);
    63         $this->assertSame(true, $files['fixed_root/lang/']);
    64         $this->assertSame(true, $files['fixed_root/lang/en/']);
    65         $this->assertSame(true, $files['fixed_root/lang/en/fixed_root.php']);
    66         foreach ($files as $file => $status) {
    67             if (substr($file, -1) === '/') {
    68                 $this->assertTrue(is_dir($contentsdir.'/'.$file));
    69             } else {
    70                 $this->assertTrue(is_file($contentsdir.'/'.$file));
    71             }
    72         }
    7352    }
    7453
     
    131110    }
    132111
    133     public function test_move_directory() {
    134         $jobid = md5(rand().uniqid('test_', true));
    135         $jobroot = make_temp_directory('tool_installaddon/'.$jobid);
    136         $contentsdir = make_temp_directory('tool_installaddon/'.$jobid.'/contents/sub/folder');
    137         file_put_contents($contentsdir.'/readme.txt', 'Hello world!');
     112    public function test_detect_plugin_component() {
     113        global $CFG;
    138114
    139115        $installer = tool_installaddon_installer::instance();
    140         $installer->move_directory($jobroot.'/contents', $jobroot.'/moved', 0777, 0666);
    141116
    142         $this->assertFalse(is_dir($jobroot.'/contents'));
    143         $this->assertTrue(is_file($jobroot.'/moved/sub/folder/readme.txt'));
    144         $this->assertSame('Hello world!', file_get_contents($jobroot.'/moved/sub/folder/readme.txt'));
     117        $zipfile = $CFG->libdir.'/tests/fixtures/update_validator/zips/bar.zip';
     118        $this->assertEquals('foo_bar', $installer->detect_plugin_component($zipfile));
     119
     120        $zipfile = $CFG->libdir.'/tests/fixtures/update_validator/zips/invalidroot.zip';
     121        $this->assertFalse($installer->detect_plugin_component($zipfile));
     122    }
     123
     124    public function test_detect_plugin_component_from_versionphp() {
     125        global $CFG;
     126
     127        $installer = testable_tool_installaddon_installer::instance();
     128        $fixtures = $CFG->libdir.'/tests/fixtures/update_validator/';
     129
     130        $this->assertEquals('bar_bar_conan', $installer->testable_detect_plugin_component_from_versionphp('
     131$plugin->version  = 2014121300;
     132  $plugin->component=   "bar_bar_conan"  ; // Go Arnie go!'));
     133
     134        $versionphp = file_get_contents($fixtures.'/github/moodle-repository_mahara-master/version.php');
     135        $this->assertEquals('repository_mahara', $installer->testable_detect_plugin_component_from_versionphp($versionphp));
     136
     137        $versionphp = file_get_contents($fixtures.'/nocomponent/baz/version.php');
     138        $this->assertFalse($installer->testable_detect_plugin_component_from_versionphp($versionphp));
     139    }
     140
     141    public function test_make_installfromzip_storage() {
     142        $installer = testable_tool_installaddon_installer::instance();
     143
     144        // Check we get writable directory.
     145        $storage1 = $installer->make_installfromzip_storage();
     146        $this->assertTrue(is_dir($storage1));
     147        $this->assertTrue(is_writable($storage1));
     148        file_put_contents($storage1.'/hello.txt', 'Find me if you can!');
     149
     150        // Check we get unique directory on each call.
     151        $storage2 = $installer->make_installfromzip_storage();
     152        $this->assertTrue(is_dir($storage2));
     153        $this->assertTrue(is_writable($storage2));
     154        $this->assertFalse(file_exists($storage2.'/hello.txt'));
     155
     156        // Check both are in the same parent directory.
     157        $this->assertEquals(dirname($storage1), dirname($storage2));
    145158    }
    146159}
    147 
    148 
    149 /**
    150  * Testable subclass of the tested class
    151  *
    152  * @copyright 2013 David Mudrak <david@moodle.com>
    153  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
    154  */
    155 class testable_tool_installaddon_installer extends tool_installaddon_installer {
    156 
    157     public function get_site_fullname() {
    158         return strip_tags('<h1 onmouseover="alert(\'Hello Moodle.org!\');">Nasty site</h1>');
    159     }
    160 
    161     public function get_site_url() {
    162         return 'file:///etc/passwd';
    163     }
    164 
    165     public function get_site_major_version() {
    166         return "2.5'; DROP TABLE mdl_user; --";
    167     }
    168 
    169     public function testable_decode_remote_request($request) {
    170         return parent::decode_remote_request($request);
    171     }
    172 
    173     protected function should_send_site_info() {
    174         return true;
    175     }
    176 }
Note: See TracChangeset for help on using the changeset viewer.