Ejemplo n.º 1
0
/**
 * This function will return the xmlized data belonging to one Moodle version
 *
 * @param string $version top version from which we start to look backwards
 * @param int|string $env_select one of ENV_SELECT_NEWER | ENV_SELECT_DATAROOT | ENV_SELECT_RELEASE decide xml to use. String means plugin name.
 * @return mixed the xmlized structure or false on error
 */
function get_environment_for_version($version, $env_select)
{
    /// Normalize the version requested
    $version = normalize_version($version);
    /// Load xml file
    if (!($contents = load_environment_xml($env_select))) {
        return false;
    }
    /// Detect available versions
    if (!($versions = get_list_of_environment_versions($contents))) {
        return false;
    }
    // If $env_select is not numeric then this is being called on a plugin, and not the core environment.xml
    // If a version of 'all' is in the arry is also means that the new <PLUGIN> tag was found, this should
    // be matched against any version of Moodle.
    if (!is_numeric($env_select) && in_array('all', $versions) && environment_verify_plugin($env_select, $contents['COMPATIBILITY_MATRIX']['#']['PLUGIN'][0])) {
        return $contents['COMPATIBILITY_MATRIX']['#']['PLUGIN'][0];
    }
    /// If the version requested is available
    if (!in_array($version, $versions)) {
        return false;
    }
    /// We now we have it. Extract from full contents.
    $fl_arr = array_flip($versions);
    return $contents['COMPATIBILITY_MATRIX']['#']['MOODLE'][$fl_arr[$version]];
}
Ejemplo n.º 2
0
    /**
     * Test the environment_verify_plugin() function.
     */
    public function test_verify_plugin()
    {
        global $CFG;
        require_once $CFG->libdir . '/environmentlib.php';
        // Build sample xmlised environment file fragments.
        $plugin1xml = <<<END
<PLUGIN name="block_testcase">
    <PHP_EXTENSIONS>
        <PHP_EXTENSION name="xsl" level="required" />
    </PHP_EXTENSIONS>
</PLUGIN>
END;
        $plugin1 = xmlize($plugin1xml);
        $plugin2xml = <<<END
<PLUGIN>
    <PHP_EXTENSIONS>
        <PHP_EXTENSION name="xsl" level="required" />
    </PHP_EXTENSIONS>
</PLUGIN>
END;
        $plugin2 = xmlize($plugin2xml);
        $this->assertTrue(environment_verify_plugin('block_testcase', $plugin1['PLUGIN']));
        $this->assertFalse(environment_verify_plugin('block_testcase', $plugin2['PLUGIN']));
        $this->assertFalse(environment_verify_plugin('mod_someother', $plugin1['PLUGIN']));
        $this->assertFalse(environment_verify_plugin('mod_someother', $plugin2['PLUGIN']));
    }