]> git.agnieray.net Git - galette.git/blob - tests/TestsBootstrap.php
Fix groups selection widget on member form
[galette.git] / tests / TestsBootstrap.php
1 <?php
2
3 /**
4 * Test bootstrap
5 *
6 * PHP version 5
7 *
8 * @category Tests
9 * @package Galette
10 *
11 * @author Johan Cwiklinski <johan@x-tnd.be>
12 * @copyright 2012-2014 The Galette Team
13 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
14 * @link http://galette.tuxfamily.org
15 * @since Available since 0.7.3dev 2012-12-12
16 */
17
18 $basepath = null;
19 if (file_exists('../galette/index.php')) {
20 $basepath = '../galette/';
21 } elseif (file_exists('galette/index.php')) {
22 $basepath = 'galette/';
23 } else {
24 die('Unable to define GALETTE_BASE_PATH :\'(');
25 }
26
27 $db = 'mysql';
28 $dbenv = getenv('DB');
29 if (
30 $dbenv === 'pgsql'
31 || substr($dbenv, 0, strlen('postgres')) === 'postgres'
32 ) {
33 $db = 'pgsql';
34 }
35
36 $fail_env = getenv('FAIL');
37 if ($fail_env !== false) {
38 $db .= '_fail';
39 }
40
41 define('GALETTE_CONFIG_PATH', __DIR__ . '/config/' . $db . '/');
42 define('GALETTE_BASE_PATH', $basepath);
43 define('GALETTE_TESTS', true);
44 define('GALETTE_TESTS_PATH', __DIR__);
45 define('GALETTE_MODE', 'PROD');
46 define('GALETTE_PLUGINS_PATH', GALETTE_TESTS_PATH . '/plugins/');
47 define('GALETTE_TPL_SUBDIR', 'templates/default/');
48 define('GALETTE_THEME', 'themes/default/');
49 define('GALETTE_DATA_PATH', GALETTE_TESTS_PATH . '/tests-data/');
50 define('GALETTE_CACHE_DIR', GALETTE_DATA_PATH . 'cache/');
51 if (is_dir(GALETTE_DATA_PATH)) {
52 $files = new RecursiveIteratorIterator(
53 new RecursiveDirectoryIterator(
54 GALETTE_DATA_PATH,
55 RecursiveDirectoryIterator::SKIP_DOTS
56 ),
57 RecursiveIteratorIterator::CHILD_FIRST
58 );
59
60 foreach ($files as $fileinfo) {
61 $todo = ($fileinfo->isDir() ? 'rmdir' : 'unlink');
62 $todo($fileinfo->getRealPath());
63 }
64 rmdir(GALETTE_DATA_PATH);
65 }
66
67 mkdir(GALETTE_DATA_PATH);
68 $directories = [
69 'logs',
70 'templates_c',
71 'cache',
72 'exports',
73 'imports',
74 'photos',
75 'attachments',
76 'files',
77 'tempimages'
78 ];
79 foreach ($directories as $directory) {
80 mkdir(GALETTE_DATA_PATH . $directory);
81 }
82
83 $logfile = 'galette_tests';
84 require_once GALETTE_BASE_PATH . 'includes/galette.inc.php';
85
86 $session_name = 'galette_tests';
87 $session = new \RKA\SessionMiddleware([
88 'name' => $session_name,
89 'lifetime' => 0
90 ]);
91 $session->start();
92
93 $gapp = new \Galette\Core\SlimApp();
94 $app = $gapp->getApp();
95 $app->add($session);
96
97 require_once GALETTE_BASE_PATH . '/includes/dependencies.php';
98 //Globals... :(
99 global $preferences, $emitter, $zdb;
100 $zdb = $container->get('zdb');
101 $preferences = $container->get('preferences');
102 $emitter = $container->get('event_manager');
103 $i18n->changeLanguage('en_US');
104
105 if (!defined('_CURRENT_THEME_PATH')) {
106 define(
107 '_CURRENT_THEME_PATH',
108 GALETTE_THEMES_PATH . $preferences->pref_theme . '/'
109 );
110 }
111
112 $updateenv = getenv('UPDATE');
113 if (
114 $updateenv !== 'UPDATE'
115 ) {
116 //do not initialize Ttiles on update tests
117 $titles = new \Galette\Repository\Titles($zdb);
118 $res = $titles->installInit($zdb);
119 }
120
121 require_once __DIR__ . '/GaletteTestCase.php';