diff --git a/tests/Units/GroupEscalationTest.php b/tests/Units/GroupEscalationTest.php index f6176241..7b97d32e 100644 --- a/tests/Units/GroupEscalationTest.php +++ b/tests/Units/GroupEscalationTest.php @@ -1041,10 +1041,11 @@ private function createGroupWithUsers($name, $num_users = 2) // Create users and add them to the group for ($i = 0; $i < $num_users; $i++) { + $rand = rand(); $user_id = $this->createItem( \User::class, [ - 'name' => "{$name}_user_{$i}", + 'name' => "{$name}_user_{$i}_{$rand}", ], )->getID(); @@ -1052,7 +1053,7 @@ private function createGroupWithUsers($name, $num_users = 2) \UserEmail::class, [ 'users_id' => $user_id, - 'email' => "{$name}_user_{$i}@example.com", + 'email' => "{$name}_user_{$i}_{$rand}@example.com", ], ); @@ -1067,8 +1068,8 @@ private function createGroupWithUsers($name, $num_users = 2) $users[] = [ 'id' => $user_id, - 'name' => "{$name}_user_{$i}", - 'email' => "{$name}_user_{$i}@example.com", + 'name' => "{$name}_user_{$i}_{$rand}", + 'email' => "{$name}_user_{$i}_{$rand}@example.com", ]; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index b02401d3..6e73a641 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -28,54 +28,24 @@ * ------------------------------------------------------------------------- */ -use Glpi\Cache\CacheManager; -use Glpi\Cache\SimpleCache; -use Symfony\Component\Cache\Adapter\ArrayAdapter; - global $CFG_GLPI, $PLUGIN_HOOKS; -ini_set('display_errors', 'On'); -error_reporting(E_ALL); - -define('GLPI_ROOT', dirname(__DIR__, 3)); -define('GLPI_LOG_DIR', GLPI_ROOT . '/files/_logs'); +define('GLPI_ROOT', __DIR__ . '/../../../'); +define('GLPI_LOG_DIR', __DIR__ . '/files/_logs'); define('TU_USER', 'glpi'); define('TU_PASS', 'glpi'); define('GLPI_LOG_LVL', 'DEBUG'); -include(GLPI_ROOT . "/inc/based_config.php"); - -if (!file_exists(GLPI_CONFIG_DIR . '/config_db.php')) { - die("\nConfiguration file for tests not found\n\nrun: bin/console glpi:database:install --config-dir=tests/config ...\n\n"); -} - -// Create subdirectories of GLPI_VAR_DIR based on defined constants -foreach (get_defined_constants() as $constant_name => $constant_value) { - if ( - preg_match('/^GLPI_[\w]+_DIR$/', $constant_name) - && preg_match('/^' . preg_quote(GLPI_VAR_DIR, '/') . '\//', $constant_value) - ) { - is_dir($constant_value) or mkdir($constant_value, 0755, true); - } -} - -//init cache -if (file_exists(GLPI_CONFIG_DIR . DIRECTORY_SEPARATOR . CacheManager::CONFIG_FILENAME)) { - // Use configured cache for cache tests - $cache_manager = new CacheManager(); - $GLPI_CACHE = $cache_manager->getCoreCacheInstance(); -} else { - // Use "in-memory" cache for other tests - $GLPI_CACHE = new SimpleCache(new ArrayAdapter()); -} - require GLPI_ROOT . '/inc/includes.php'; include_once GLPI_ROOT . '/phpunit/GLPITestCase.php'; include_once GLPI_ROOT . '/phpunit/DbTestCase.php'; require_once __DIR__ . '/../vendor/autoload.php'; require_once __DIR__ . '/../setup.php'; -plugin_init_escalade(); + +if (!Plugin::isPluginActive("escalade")) { + throw new RuntimeException("Plugin escalade is not active in the test database"); +} if (!file_exists(GLPI_LOG_DIR . '/php-errors.log')) { file_put_contents(GLPI_LOG_DIR . '/php-errors.log', ''); @@ -84,3 +54,5 @@ if (!file_exists(GLPI_LOG_DIR . '/sql-errors.log')) { file_put_contents(GLPI_LOG_DIR . '/sql-errors.log', ''); } + +plugin_init_escalade();