2008-11-01 22:43:28 +00:00
|
|
|
<?php defined("SYSPATH") or die("No direct script access.");
|
|
|
|
|
/**
|
2008-11-01 07:55:48 +00:00
|
|
|
* Gallery - a web based photo album viewer and editor
|
|
|
|
|
* Copyright (C) 2000-2008 Bharat Mediratta
|
|
|
|
|
*
|
|
|
|
|
* This program 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 2 of the License, or (at
|
|
|
|
|
* your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program 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 this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
*/
|
|
|
|
|
class Test_Controller extends Controller {
|
|
|
|
|
function Index() {
|
|
|
|
|
if (!defined('TEST_MODE')) {
|
|
|
|
|
print Kohana::show_404();
|
|
|
|
|
}
|
2008-11-01 09:02:24 +00:00
|
|
|
|
2008-11-02 23:55:09 +00:00
|
|
|
$original_config = DOCROOT . "var/database.php";
|
|
|
|
|
$test_config = VARPATH . "database.php";
|
|
|
|
|
if (!file_exists($original_config)) {
|
2008-11-05 21:52:22 +00:00
|
|
|
print "Please copy kohana/config/database.php to $original_config.\n";
|
|
|
|
|
print "Then, add a \$config['unit_test'] database configuration in $original_config.\n";
|
|
|
|
|
return;
|
2008-11-02 23:55:09 +00:00
|
|
|
} else {
|
|
|
|
|
copy($original_config, $test_config);
|
|
|
|
|
$db_config = Kohana::config('database');
|
|
|
|
|
if (empty($db_config['unit_test'])) {
|
2008-11-05 21:52:22 +00:00
|
|
|
print "Please create a \$config['unit_test'] database configuration in $test_config.\n";
|
2008-11-04 02:19:46 +00:00
|
|
|
return;
|
2008-11-02 23:55:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2008-11-04 02:19:46 +00:00
|
|
|
$db = Database::instance('unit_test');
|
|
|
|
|
$db->connect();
|
2008-11-03 00:07:38 +00:00
|
|
|
|
2008-11-04 02:19:46 +00:00
|
|
|
// Make this the default database for the rest of this run
|
|
|
|
|
Database::$instances = array('default' => $db);
|
2008-11-02 23:55:09 +00:00
|
|
|
} catch (Exception $e) {
|
2008-11-04 05:22:06 +00:00
|
|
|
print "{$e->getMessage()}\n";
|
|
|
|
|
return;
|
2008-11-02 23:55:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-11-01 09:02:24 +00:00
|
|
|
// Find all tests, excluding sample tests that come with the unit_test module.
|
|
|
|
|
$paths = array(APPPATH . "tests");
|
|
|
|
|
foreach (glob(MODPATH . "*/tests") as $path) {
|
|
|
|
|
if ($path != MODPATH . "unit_test/tests") {
|
2008-11-02 21:39:10 +00:00
|
|
|
$paths[] = $path;
|
2008-11-01 09:02:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Kohana::config_set('unit_test.paths', $paths);
|
|
|
|
|
|
2008-11-03 02:05:59 +00:00
|
|
|
// We probably don't want to uninstall and reinstall the core every time, but let's start off
|
2008-11-06 03:51:30 +00:00
|
|
|
// this way. Uninstall modules first and core last. Ignore errors during uninstall.
|
|
|
|
|
try {
|
2008-11-25 18:00:33 +00:00
|
|
|
$this->_uninstall_modules();
|
2008-11-06 03:51:30 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
}
|
2008-11-02 23:55:09 +00:00
|
|
|
|
2008-11-25 15:01:17 +00:00
|
|
|
$this->_install_modules();
|
2008-11-05 22:10:35 +00:00
|
|
|
|
2008-11-01 10:45:51 +00:00
|
|
|
print new Unit_Test();
|
2008-11-01 07:55:48 +00:00
|
|
|
}
|
2008-11-25 15:01:17 +00:00
|
|
|
|
|
|
|
|
private function _uninstall_modules() {
|
|
|
|
|
foreach (module::get_list() as $module) {
|
|
|
|
|
if ($module->name == "core") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$installer_class = "{$module->name}_installer";
|
|
|
|
|
if (method_exists($installer_class, "uninstall")) {
|
2008-11-25 18:00:33 +00:00
|
|
|
Kohana::log("debug", "method uninstall exists");
|
2008-11-25 15:01:17 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Always uninstall core last.
|
|
|
|
|
core_installer::uninstall();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function _install_modules() {
|
|
|
|
|
core_installer::install();
|
|
|
|
|
|
|
|
|
|
foreach (glob(MODPATH . "*/helpers/*_installer.php") as $file) {
|
|
|
|
|
$module_name = basename(dirname(dirname($file)));
|
|
|
|
|
if ($module_name == "core") {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$installer_class = "{$module_name}_installer";
|
|
|
|
|
if (method_exists($installer_class, "install")) {
|
|
|
|
|
call_user_func_array( array($installer_class, "install"), array());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2008-11-01 07:55:48 +00:00
|
|
|
}
|