From 5fe3c9d7dee2fb31806632883b3f9bd9eba6945d Mon Sep 17 00:00:00 2001
From: llaffont <laurent.laffont@gmail.com>
Date: Tue, 25 Feb 2014 14:20:19 +0100
Subject: [PATCH] Search for bokeh's config.ini now handled by CosmoPaths

---
 cosmogramme/php/classes/classe_cosmopaths.php    | 8 +++++++-
 cosmogramme/storm_init.php                       | 5 +----
 cosmogramme/tests/php/classes/CosmoPathsTest.php | 6 ++++++
 3 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/cosmogramme/php/classes/classe_cosmopaths.php b/cosmogramme/php/classes/classe_cosmopaths.php
index 986b39992fe..330119d8bab 100644
--- a/cosmogramme/php/classes/classe_cosmopaths.php
+++ b/cosmogramme/php/classes/classe_cosmopaths.php
@@ -36,6 +36,11 @@ class CosmoPaths {
 	}
 
 
+	public function getBokehConfigPath() {
+		return $this->getBasePath() . 'config.ini';
+	}
+
+
 	public function getBaseUrl() {
 		return str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->getBasePath());
 	}
@@ -47,7 +52,8 @@ class CosmoPaths {
 
 
 	public function getSite() {
-		return array_pop(array_filter(explode('/', $this->getBasePath())));
+		$parts = array_filter(explode('/', $this->getBasePath()));
+		return array_pop($parts);
 	}
 
 
diff --git a/cosmogramme/storm_init.php b/cosmogramme/storm_init.php
index 35b4e229d29..46d2f5e70b9 100644
--- a/cosmogramme/storm_init.php
+++ b/cosmogramme/storm_init.php
@@ -46,10 +46,7 @@ require_once "Zend/Loader.php";
 require_once "startup.php";
 Zend_Loader::registerAutoload();
 
-$base_dir = $_SERVER['DOCUMENT_ROOT'].'/'.explode('/', $_SERVER['SCRIPT_NAME'])[1];
-if (!file_exists($cfg_file = $base_dir.'/config.ini')) {
-  $cfg_file = file_exists('../config.ini') ? '../config.ini' : OPAC_PATH.'/config.ini';
-}
+$cfg_file = (new CosmoPaths())->getBokehConfigPath();
 
 setupConstants();
 $cfg = loadConfig($cfg_file);
diff --git a/cosmogramme/tests/php/classes/CosmoPathsTest.php b/cosmogramme/tests/php/classes/CosmoPathsTest.php
index 1ee8995aa70..e6bda5b9492 100644
--- a/cosmogramme/tests/php/classes/CosmoPathsTest.php
+++ b/cosmogramme/tests/php/classes/CosmoPathsTest.php
@@ -50,6 +50,12 @@ class CosmoPathsTest extends PHPUnit_Framework_TestCase {
 	}
 
 
+	/** @test */
+	public function bokehConfigPathShouldEndWithBokehSlashConfigDotIni() {
+		$this->assertEquals('bokeh.fr/config.ini', substr($this->_cosmo_paths->getBokehConfigPath(), -19));
+	}
+
+
 	/** @test */
 	public function baseUrlShouldBeBokehDotFr() {
 		$this->assertEquals('/bokeh.fr/', $this->_cosmo_paths->getBaseUrl());
-- 
GitLab