Skip to content

Commit

Permalink
Add API call support to Utils::getSiteRootPathFromFileSystem
Browse files Browse the repository at this point in the history
  • Loading branch information
ginatrapani committed Dec 29, 2013
1 parent 9d1a8d3 commit 0fce75c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 7 additions & 1 deletion tests/TestOfUtils.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -212,7 +212,13 @@ public function testGetLastSaturday() {
public function testGetSiteRootPathFromFileSystem() { public function testGetSiteRootPathFromFileSystem() {
// function assumes $_SERVER['PHP_SELF'] is set // function assumes $_SERVER['PHP_SELF'] is set
// it only is in the web server context so we set it here to test // it only is in the web server context so we set it here to test
$_SERVER['PHP_SELF'] = Config::getInstance()->getValue('site_root_path'); $_SERVER['PHP_SELF'] = Config::getInstance()->getValue('site_root_path').'index.php';
$filesystem_site_root_path = Utils::getSiteRootPathFromFileSystem();
$cfg_site_root_path = Config::getInstance()->getValue('site_root_path');
$this->assertEqual($filesystem_site_root_path, $cfg_site_root_path);

//API calls
$_SERVER['PHP_SELF'] = Config::getInstance()->getValue('site_root_path').'api/v1/session/login.php';
$filesystem_site_root_path = Utils::getSiteRootPathFromFileSystem(); $filesystem_site_root_path = Utils::getSiteRootPathFromFileSystem();
$cfg_site_root_path = Config::getInstance()->getValue('site_root_path'); $cfg_site_root_path = Config::getInstance()->getValue('site_root_path');
$this->assertEqual($filesystem_site_root_path, $cfg_site_root_path); $this->assertEqual($filesystem_site_root_path, $cfg_site_root_path);
Expand Down
7 changes: 7 additions & 0 deletions webapp/_lib/class.Utils.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -289,6 +289,13 @@ public static function getSiteRootPathFromFileSystem() {
if ( in_array( end($current_script_path), $dirs_under_root ) ) { if ( in_array( end($current_script_path), $dirs_under_root ) ) {
array_pop($current_script_path); array_pop($current_script_path);
} }
// Account for API calls
if ( end($current_script_path) == 'v1' ) {
array_pop($current_script_path);
if ( end($current_script_path) == 'api' ) {
array_pop($current_script_path);
}
}
$current_script_path = implode('/', $current_script_path) . '/'; $current_script_path = implode('/', $current_script_path) . '/';
return $current_script_path; return $current_script_path;
} }
Expand Down

0 comments on commit 0fce75c

Please sign in to comment.