Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/moodle/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
pcharsle committed Apr 17, 2012
2 parents 5c631d8 + 668a499 commit 6f5a2ef
Show file tree
Hide file tree
Showing 192 changed files with 35,392 additions and 621 deletions.
22 changes: 22 additions & 0 deletions admin/tool/phpunit/cli/init.bat
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,22 @@
@ECHO OFF
ECHO Initialising Moodle PHPUnit test environment...

CALL php %~dp0\util.php --diag > NUL 2>&1

IF ERRORLEVEL 133 GOTO drop
IF ERRORLEVEL 132 GOTO install
IF ERRORLEVEL 1 GOTO unknown
GOTO done

:drop
CALL php %~dp0\util.php --drop
IF ERRORLEVEL 1 GOTO done

:install
CALL php %~dp0\util.php --install
GOTO done

:unknown
CALL php %~dp0\util.php --diag

:done
66 changes: 66 additions & 0 deletions admin/tool/phpunit/cli/init.php
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* All in one init script - PHP version.
*
* @package tool_phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

if (isset($_SERVER['REMOTE_ADDR'])) {
die; // no access from web!
}

require_once(__DIR__.'/../../../../lib/clilib.php');
require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');

echo "Initialising Moodle PHPUnit test environment...\n";

$output = null;
exec('php --version', $output, $code);
if ($code != 0) {
phpunit_bootstrap_error(1, 'Can not execute \'php\' binary.');
}

chdir(__DIR__);
$output = null;
exec("php util.php --diag", $output, $code);
if ($code == 0) {
// everything is ready

} else if ($code == 132) {
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
}

} else if ($code == 133) {
passthru("php util.php --drop", $code);
passthru("php util.php --install", $code);
if ($code != 0) {
exit($code);
}

} else {
echo implode("\n", $output)."\n";
exit($code);
}

passthru("php util.php --buildconfig", $code);

exit(0);
31 changes: 31 additions & 0 deletions admin/tool/phpunit/cli/init.sh
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

SOURCE="${BASH_SOURCE[0]}"
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
CLIDIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

UTIL="$CLIDIR/util.php"

echo "Initialising Moodle PHPUnit test environment..."

DIGERROR=`php $UTIL --diag`
DIAG=$?
if [ $DIAG -eq 132 ] ; then
php $UTIL --install
else
if [ $DIAG -eq 133 ] ; then
php $UTIL --drop
RESULT=$?
if [ $RESULT -gt 0 ] ; then
exit $RESULT
fi
php $UTIL --install
else
if [ $DIAG -gt 0 ] ; then
echo $DIGERROR
exit $DIAG
fi
fi
fi

php $UTIL --buildconfig
98 changes: 84 additions & 14 deletions admin/tool/phpunit/cli/util.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,69 +20,139 @@
* Exit codes: * Exit codes:
* 0 - success * 0 - success
* 1 - general error * 1 - general error
* 130 - coding error * 130 - missing PHPUnit library error
* 131 - configuration problem * 131 - configuration problem
* 132 - install new test database
* 133 - drop existing data before installing * 133 - drop existing data before installing
* 134 - can not create main phpunit.xml
* *
* @package tool_phpunit * @package tool_phpunit
* @copyright 2012 Petr Skoda {@link http://skodak.org} * @copyright 2012 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */


define('PHPUNIT_UTIL', true); if (isset($_SERVER['REMOTE_ADDR'])) {
die; // no access from web!
}


require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php'); require_once(__DIR__.'/../../../../lib/clilib.php');
require_once($CFG->libdir.'/phpunit/lib.php'); require_once(__DIR__.'/../../../../lib/phpunit/bootstraplib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/upgradelib.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->libdir.'/pluginlib.php');
require_once($CFG->libdir.'/installlib.php');


// now get cli options // now get cli options
list($options, $unrecognized) = cli_get_params( list($options, $unrecognized) = cli_get_params(
array( array(
'drop' => false, 'drop' => false,
'install' => false, 'install' => false,
'buildconfig' => false, 'buildconfig' => false,
'diag' => false,
'phpunitdir' => false,
'run' => false,
'help' => false, 'help' => false,
), ),
array( array(
'h' => 'help' 'h' => 'help'
) )
); );


if ($options['phpunitdir']) {
// nasty skodak's hack for testing of future PHPUnit versions - intentionally not documented
if (!file_exists($options['phpunitdir'])) {
cli_error('Invalid custom PHPUnit lib location');
}
$files = scandir($options['phpunitdir']);
foreach ($files as $file) {
$path = $options['phpunitdir'].'/'.$file;
if (!is_dir($path) or strpos($file, '.') === 0) {
continue;
}
ini_set('include_path', $path . PATH_SEPARATOR . ini_get('include_path'));
}
unset($files);
unset($file);
}

// verify PHPUnit libs are loaded
if (!@include_once('PHPUnit/Autoload.php')) {
phpunit_bootstrap_error(130);
}

if (!@include_once('PHPUnit/Extensions/Database/Autoload.php')) {
phpunit_bootstrap_error(130);
}

if ($options['run']) {
unset($options);
unset($unrecognized);

foreach ($_SERVER['argv'] as $k=>$v) {
if (strpos($v, '--run') === 0 or strpos($v, '--phpunitdir') === 0) {
unset($_SERVER['argv'][$k]);
$_SERVER['argc'] = $_SERVER['argc'] - 1;
}
}
$_SERVER['argv'] = array_values($_SERVER['argv']);
PHPUnit_TextUI_Command::main();
exit(0);
}

define('PHPUNIT_UTIL', true);

require(__DIR__ . '/../../../../lib/phpunit/bootstrap.php');

// from now on this is a regular moodle CLI_SCRIPT

require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/upgradelib.php');
require_once($CFG->libdir.'/clilib.php');
require_once($CFG->libdir.'/pluginlib.php');
require_once($CFG->libdir.'/installlib.php');

if ($unrecognized) { if ($unrecognized) {
$unrecognized = implode("\n ", $unrecognized); $unrecognized = implode("\n ", $unrecognized);
cli_error(get_string('cliunknowoption', 'admin', $unrecognized)); cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
} }


$diag = $options['diag'];
$drop = $options['drop']; $drop = $options['drop'];
$install = $options['install']; $install = $options['install'];
$buildconfig = $options['buildconfig']; $buildconfig = $options['buildconfig'];


if ($options['help'] or (!$drop and !$install and !$buildconfig)) { if ($options['help'] or (!$drop and !$install and !$buildconfig and !$diag)) {
$help = "Various PHPUnit utility functions $help = "Various PHPUnit utility functions
Options: Options:
--drop Drop database and dataroot --drop Drop database and dataroot
--install Install database --install Install database
--buildconfig Build /phpunit.xml from /phpunit.xml.dist that includes suites for all plugins and core --buildconfig Build /phpunit.xml from /phpunit.xml.dist that includes suites for all plugins and core
--diag Diagnose installation and return error code only
--run Execute PHPUnit tests (alternative for standard phpunit binary)
-h, --help Print out this help -h, --help Print out this help
Example: Example:
\$/usr/bin/php lib/phpunit/tool.php \$/usr/bin/php lib/phpunit/tool.php --install
"; ";
echo $help; echo $help;
die; exit(0);
} }


if ($buildconfig) { if ($diag) {
phpunit_util::build_config_file(); list($errorcode, $message) = phpunit_util::testing_ready_problem();
if ($errorcode) {
phpunit_bootstrap_error($errorcode, $message);
}
exit(0); exit(0);


} else if ($buildconfig) {
if (phpunit_util::build_config_file()) {
exit(0);
} else {
phpunit_bootstrap_error(134);
}

} else if ($drop) { } else if ($drop) {
// make sure tests do not run in parallel
phpunit_util::acquire_test_lock();
phpunit_util::drop_site(); phpunit_util::drop_site();
// note: we must stop here because $CFG is messed up and we can not reinstall, sorry // note: we must stop here because $CFG is messed up and we can not reinstall, sorry
exit(0); exit(0);
Expand Down
4 changes: 1 addition & 3 deletions admin/tool/phpunit/index.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/ */


define('NO_OUTPUT_BUFFERING', true);

require(dirname(__FILE__) . '/../../../config.php'); require(dirname(__FILE__) . '/../../../config.php');
require_once($CFG->libdir.'/adminlib.php'); require_once($CFG->libdir.'/adminlib.php');


Expand All @@ -37,4 +35,4 @@
echo markdown_to_html($info); echo markdown_to_html($info);


echo $OUTPUT->box_end(); echo $OUTPUT->box_end();
echo $OUTPUT->footer(); echo $OUTPUT->footer();
6 changes: 5 additions & 1 deletion admin/tool/phpunit/settings.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@


defined('MOODLE_INTERNAL') || die; defined('MOODLE_INTERNAL') || die;


$ADMIN->add('development', new admin_externalpage('toolphpunit', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/index.php")); if ($hassiteconfig) {
$ADMIN->add('development', new admin_externalpage('toolphpunit', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/index.php"));
$ADMIN->add('development', new admin_externalpage('toolphpunitwebrunner', get_string('pluginname', 'tool_phpunit'), "$CFG->wwwroot/$CFG->admin/tool/phpunit/webrunner.php",
'moodle/site:config', true));
}
4 changes: 2 additions & 2 deletions admin/tool/phpunit/version.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


defined('MOODLE_INTERNAL') || die(); defined('MOODLE_INTERNAL') || die();


$plugin->version = 2012030800; // The current plugin version (Date: YYYYMMDDXX) $plugin->version = 2012040500; // The current plugin version (Date: YYYYMMDDXX)
$plugin->requires = 2012030100; // Requires this Moodle version $plugin->requires = 2012040500; // Requires this Moodle version
$plugin->component = 'tool_phpunit'; // Full name of the plugin (used for diagnostics) $plugin->component = 'tool_phpunit'; // Full name of the plugin (used for diagnostics)


Loading

0 comments on commit 6f5a2ef

Please sign in to comment.