From f44a26432cba824e116c287d802bc2aec542f046 Mon Sep 17 00:00:00 2001 From: nathangray Date: Wed, 24 Apr 2019 14:14:35 -0600 Subject: [PATCH] Some changes to tests, maybe they pass Mostly about getting a session for Sharing, even though we're on the command line --- admin/tests/PreferencesCommandTest.php | 2 +- api/src/Sharing.php | 27 ++++++++++++------- api/tests/Vfs/SharingBase.php | 25 ++++++++++++++--- .../inc/class.calendar_import_csv.inc.php | 6 ++--- infolog/tests/SetProjectManagerTest.php | 17 +++++++++++- 5 files changed, 59 insertions(+), 18 deletions(-) diff --git a/admin/tests/PreferencesCommandTest.php b/admin/tests/PreferencesCommandTest.php index abcab63dec..bc7bb8ad9d 100644 --- a/admin/tests/PreferencesCommandTest.php +++ b/admin/tests/PreferencesCommandTest.php @@ -253,7 +253,7 @@ class PreferencesCommandTest extends CommandBase $set = array($this->config_name => null); $old = array($this->config_name => 'It will log whatever'); - $prefs = new Api\Preferences(in_array($type, 'default', 'forced') ? $type : $account); + $prefs = new Api\Preferences(in_array($type, array('default', 'forced')) ? $type : $account); $prefs->add(static::APP, $this->config_name, $old[$this->config_name], in_array($type, array('default', 'forced')) ? $type : 'user'); $prefs->save_repository(false, $type); diff --git a/api/src/Sharing.php b/api/src/Sharing.php index 380357a1a5..28e9094981 100644 --- a/api/src/Sharing.php +++ b/api/src/Sharing.php @@ -240,16 +240,8 @@ class Sharing // --> create a new anon session if ($keep_session === false && $GLOBALS['egw']->sharing->need_session() || is_null($keep_session)) { - // create session without checking auth: create(..., false, false) - if (!($sessionid = $GLOBALS['egw']->session->create('anonymous@'.$GLOBALS['egw_info']['user']['domain'], - '', 'text', false, false))) - { - sleep(1); - return static::share_fail( - '500 Internal Server Error', - "Failed to create session: ".$GLOBALS['egw']->session->reason."\n" - ); - } + $sessionid = static::create_new_session(); + $GLOBALS['egw']->sharing->after_login(); } // we have a session we want to keep, but share owner is different from current user and we dont need filemanager UI @@ -274,6 +266,21 @@ class Sharing return $sessionid; } + public static function create_new_session() + { + // create session without checking auth: create(..., false, false) + if (!($sessionid = $GLOBALS['egw']->session->create('anonymous@'.$GLOBALS['egw_info']['user']['domain'], + '', 'text', false, false))) + { + sleep(1); + return static::share_fail( + '500 Internal Server Error', + "Failed to create session: ".$GLOBALS['egw']->session->reason."\n" + ); + } + return $sessionid; + } + /** * Factory method to instanciate a share * diff --git a/api/tests/Vfs/SharingBase.php b/api/tests/Vfs/SharingBase.php index 006def8944..b477e310d5 100644 --- a/api/tests/Vfs/SharingBase.php +++ b/api/tests/Vfs/SharingBase.php @@ -346,7 +346,7 @@ class SharingBase extends LoggedInTest $files[] = $file = $path.'test_file.txt'; $this->assertTrue( file_put_contents(Vfs::PREFIX.$file, $content) !== FALSE, - 'Unable to write test file - check file permissions for CLI user' + 'Unable to write test file "' . Vfs::PREFIX . $file .'" - check file permissions for CLI user' ); // Subdirectory @@ -364,7 +364,7 @@ class SharingBase extends LoggedInTest $files[] = $file = $dir.'subdir_test_file.txt'; $this->assertTrue( file_put_contents(Vfs::PREFIX.$file, $content) !== FALSE, - 'Unable to write test file - check file permissions for CLI user' + 'Unable to write test file "' . Vfs::PREFIX . $file .'" - check file permissions for CLI user' ); // Symlinked file @@ -547,7 +547,7 @@ class SharingBase extends LoggedInTest 'noheader' => true, 'nonavbar' => 'always', // true would cause eTemplate to reset it to false for non-popups! 'currentapp' => 'filemanager', - 'autocreate_session_callback' => 'EGroupware\\Api\\Vfs\\Sharing::create_session', + 'autocreate_session_callback' => 'EGroupware\\Api\\Vfs\\TestSharing::create_session', 'no_exception_handler' => 'basic_auth', // we use a basic auth exception handler (sends exception message as basic auth realm) ) ); @@ -564,3 +564,22 @@ class SharingBase extends LoggedInTest } } } + +/** + * Use this class for sharing so we can make sure we get a session ID, even + * though we're on the command line + */ +class TestSharing extends Api\Sharing { + + public static function create_new_session() + { + if (!($sessionid = $GLOBALS['egw']->session->create('anonymous@'.$GLOBALS['egw_info']['user']['domain'], + '', 'text', false, false))) + { + // Allow for testing + $sessionid = 'CLI_TEST'; + $GLOBALS['egw']->session->session_id = $sessionid; + } + return $sessionid; + } +} \ No newline at end of file diff --git a/calendar/inc/class.calendar_import_csv.inc.php b/calendar/inc/class.calendar_import_csv.inc.php index 9cc672e910..395760c48e 100644 --- a/calendar/inc/class.calendar_import_csv.inc.php +++ b/calendar/inc/class.calendar_import_csv.inc.php @@ -42,9 +42,9 @@ class calendar_import_csv extends importexport_basic_import_csv { protected $warnings = array(); /** - * Set up tracker + * Set up import */ - protected function init(importexport_definition &$definition) + protected function init(importexport_definition &$definition, importexport_import_csv &$import_csv=NULL) { // fetch the addressbook bo $this->bo= new calendar_boupdate(); @@ -224,7 +224,7 @@ class calendar_import_csv extends importexport_basic_import_csv { $this->resource_so = new resources_so(); } $result = $this->resource_so->search($search,'res_id'); - if(count($result) >= 1) { + if($result && count($result) >= 1) { $id = $resource['type'].$result[0]['res_id']; break; } diff --git a/infolog/tests/SetProjectManagerTest.php b/infolog/tests/SetProjectManagerTest.php index d225a82498..bc876daed6 100644 --- a/infolog/tests/SetProjectManagerTest.php +++ b/infolog/tests/SetProjectManagerTest.php @@ -45,6 +45,21 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest $this->mockTracking($this->bo, 'infolog_tracking'); + // Make sure projects are not there first + $pm_numbers = array( + 'TEST', + 'SUB-TEST' + ); + foreach($pm_numbers as $number) + { + $project = $this->pm_bo->read(Array('pm_number' => $number)); + if($project && $project['pm_id']) + { + $this->pm_bo->delete($project); + } + } + + $this->makeProject(); } @@ -691,7 +706,7 @@ class SetProjectManagerTest extends \EGroupware\Api\AppTest $element_bo = new \projectmanager_elements_bo(); $element_count = 0; - foreach($element_bo->search(array('pm_id' => $this->pm_id), false) as $element) + foreach((array)$element_bo->search(array('pm_id' => $this->pm_id), false) as $element) { $element_count++; $this->assertEquals($this->info_id, $element['pe_app_id']);