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