Permalink
Browse files

Add API call support to Utils::getSiteRootPathFromFileSystem

  • Loading branch information...
1 parent 9d1a8d3 commit 0fce75c51c64da06bbf36b87d34e067216c14dc7 @ginatrapani ginatrapani committed Dec 29, 2013
Showing with 14 additions and 1 deletion.
  1. +7 −1 tests/TestOfUtils.php
  2. +7 −0 webapp/_lib/class.Utils.php
View
@@ -212,7 +212,13 @@ public function testGetLastSaturday() {
public function testGetSiteRootPathFromFileSystem() {
// function assumes $_SERVER['PHP_SELF'] is set
// 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();
$cfg_site_root_path = Config::getInstance()->getValue('site_root_path');
$this->assertEqual($filesystem_site_root_path, $cfg_site_root_path);
@@ -289,6 +289,13 @@ public static function getSiteRootPathFromFileSystem() {
if ( in_array( end($current_script_path), $dirs_under_root ) ) {
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) . '/';
return $current_script_path;
}

0 comments on commit 0fce75c

Please sign in to comment.