root/trunk/etc/sglBridge.php

Revision 4374, 2.9 kB (checked in by demian, 2 years ago)

bloody ampersands, die now -3

Line 
1 <?php
2 //  setup seagull environment
3 require_once dirname(__FILE__)  . '/../lib/SGL/FrontController.php';
4 require_once dirname(__FILE__)  . '/../lib/SGL/Sql.php';
5 require_once dirname(__FILE__)  . '/../tests/classes/DB.php';
6
7 define('SGL_INSTALLED', true);
8
9 class TestRunnerInit extends SGL_FrontController
10 {
11     function run()
12     {
13         define('SGL_TEST_MODE', true);
14
15         if (!defined('SGL_INITIALISED')) {
16             SGL_FrontController::init();
17         }
18         //  assign request to registry
19         $input = SGL_Registry::singleton();
20         $req = SGL_Request::singleton();
21
22         if (PEAR::isError($req)) {
23             //  stop with error page
24             SGL::displayStaticPage($req->getMessage());
25         }
26         $input->setRequest($req);
27         $output = new SGL_Output();
28
29         $process =  new SGL_Task_Init(
30                     new SGL_Task_DiscoverClientOs(
31                     new SGL_Task_SetupTestDb(
32                     new SGL_Task_SetupTestDbResource(
33                     new SGL_Task_MinimalSession(
34                     new SGL_Task_SetupLangSupport(
35                     new SGL_Void()
36                    ))))));
37
38         $process->process($input, $output);
39     }
40 }
41
42 class SGL_Task_SetupTestDb extends SGL_DecorateProcess
43 {
44     function process($input, $output)
45     {
46         $conf = $GLOBALS['_STR']['CONF'];
47         if ($conf['db']['type'] == 'pgsql'){
48             $excludeDbName = false;
49         } else {
50             $excludeDbName = true;
51         }
52         $dsn = SGL_DB::_getDsnAsString($conf,$excludeDbName);
53         $dbh = SGL_DB::singleton($dsn);
54         if (PEAR::isError($dbh)) {
55             die($dbh->getMessage());
56         }
57
58         $query1 = SGL_Sql::buildDbDropStatement($conf['db']['type'], $conf['db']['name']);
59         $query2 = SGL_Sql::buildDbCreateStatement($conf['db']['type'], $conf['db']['name']);
60         $result = $dbh->query($query1);
61         $result = $dbh->query($query2);
62         $this->processRequest->process($input, $output);
63     }
64 }
65
66 class SGL_Task_SetupTestDbResource extends SGL_DecorateProcess
67 {
68     function process($input, $output)
69     {
70         $locator = SGL_ServiceLocator::singleton();
71         //  in case
72         $locator->remove('DB');
73         $dbh = STR_DB::singleton();
74         $locator->register('DB', $dbh);
75
76         $this->processRequest->process($input, $output);
77     }
78 }
79
80 class SGL_Task_MinimalSession extends SGL_DecorateProcess
81 {
82     function process($input, $output)
83     {
84         session_start();
85         $_SESSION['uid'] = 1;
86         $_SESSION['rid'] = 1;
87         $_SESSION['aPrefs'] = array();
88
89         $this->processRequest->process($input, $output);
90     }
91 }
92
93 //  value from php.ini, before sgl modifies it
94 $oldIncludePath = ini_get('include_path');
95
96 TestRunnerInit::run();
97
98 //  add global path, so SimpleTest lib can be included
99 $includeSeparator = (substr(PHP_OS, 0, 3) == 'WIN') ? ';' : ':';
100 ini_set('include_path', ini_get('include_path') . $includeSeparator . $oldIncludePath);
101 ?>
Note: See TracBrowser for help on using the browser.