Skip to content

Commit

Permalink
MDL-42842 testing: Generalization of the site info
Browse files Browse the repository at this point in the history
  • Loading branch information
David Monllao committed Nov 26, 2013
1 parent d949882 commit 7514c2f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 57 deletions.
58 changes: 1 addition & 57 deletions lib/phpunit/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,63 +272,7 @@ public static function bootstrap_init() {
* @return void
*/
public static function bootstrap_moodle_info() {
global $CFG;

// All developers have to understand English, do not localise!

$release = null;
require("$CFG->dirroot/version.php");

echo "Moodle $release, $CFG->dbtype";
if ($hash = self::get_git_hash()) {
echo ", $hash";
}
echo "\n";
}

/**
* Try to get current git hash of the Moodle in $CFG->dirroot.
* @return string null if unknown, sha1 hash if known
*/
public static function get_git_hash() {
global $CFG;

// This is a bit naive, but it should mostly work for all platforms.

if (!file_exists("$CFG->dirroot/.git/HEAD")) {
return null;
}

$ref = file_get_contents("$CFG->dirroot/.git/HEAD");
if ($ref === false) {
return null;
}

$ref = trim($ref);

if (strpos($ref, 'ref: ') !== 0) {
return null;
}

$ref = substr($ref, 5);

if (!file_exists("$CFG->dirroot/.git/$ref")) {
return null;
}

$hash = file_get_contents("$CFG->dirroot/.git/$ref");

if ($hash === false) {
return null;
}

$hash = trim($hash);

if (strlen($hash) != 40) {
return null;
}

return $hash;
echo self::get_site_info();
}

/**
Expand Down
69 changes: 69 additions & 0 deletions lib/testing/classes/util.php
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,75 @@ public static function reset_dataroot() {
cache_helper::purge_all();
}

/**
* Gets a text-based site version description.
*
* @return string The site info
*/
public static function get_site_info() {
global $CFG;

$output = '';

// All developers have to understand English, do not localise!

$release = null;
require("$CFG->dirroot/version.php");

$output .= "Moodle $release, $CFG->dbtype";
if ($hash = self::get_git_hash()) {
$output .= ", $hash";
}
$output .= "\n";

return $output;
}

/**
* Try to get current git hash of the Moodle in $CFG->dirroot.
* @return string null if unknown, sha1 hash if known
*/
public static function get_git_hash() {
global $CFG;

// This is a bit naive, but it should mostly work for all platforms.

if (!file_exists("$CFG->dirroot/.git/HEAD")) {
return null;
}

$ref = file_get_contents("$CFG->dirroot/.git/HEAD");
if ($ref === false) {
return null;
}

$ref = trim($ref);

if (strpos($ref, 'ref: ') !== 0) {
return null;
}

$ref = substr($ref, 5);

if (!file_exists("$CFG->dirroot/.git/$ref")) {
return null;
}

$hash = file_get_contents("$CFG->dirroot/.git/$ref");

if ($hash === false) {
return null;
}

$hash = trim($hash);

if (strlen($hash) != 40) {
return null;
}

return $hash;
}

/**
* Drop the whole test database
* @static
Expand Down

0 comments on commit 7514c2f

Please sign in to comment.