From bbd49627ba6325d636538b8b02f313c0a8b1a9cb Mon Sep 17 00:00:00 2001 From: Josaphat Imani Date: Sat, 2 Sep 2023 13:33:13 +0200 Subject: [PATCH] Fixed phpunit failing tests (cherry picked from commit fbf121974b5f19b6db8ab108089ef8ce53bb365c) --- tests/phpunit/config.php | 6 +++--- tests/phpunit/mocks.php | 2 +- tests/phpunit/modules.php | 8 ++++---- tests/phpunit/modules/core/functions.php | 6 +++--- tests/phpunit/modules/core/message_functions.php | 2 +- .../modules/core/message_list_functions.php | 2 +- tests/phpunit/modules/core/modules.php | 14 +++++++------- tests/phpunit/modules/imap/hm-imap.php | 2 +- 8 files changed, 21 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/config.php b/tests/phpunit/config.php index 559c8af071..101a39695a 100644 --- a/tests/phpunit/config.php +++ b/tests/phpunit/config.php @@ -129,7 +129,7 @@ public function test_decode_failed() { * @runInSeparateProcess */ public function test_get_path() { - $this->assertEquals('./data/testuser.txt', $this->config->get_path('testuser')); + $this->assertEquals(APP_PATH.'tests/phpunit/data/testuser.txt', $this->config->get_path('testuser')); } /** * @preserveGlobalState disabled @@ -181,7 +181,7 @@ public function test_get_modules() { * @runInSeparateProcess */ public function test_site_load() { - $config = new Hm_Site_Config_File('./data/siteconfig.rc'); + $config = new Hm_Site_Config_File(APP_PATH.'tests/phpunit/data/siteconfig.rc'); $this->assertEquals(array('version' => VERSION, 'foo' => 'bar', 'default_setting_foo' => 'bar'), $config->dump()); } /** @@ -189,7 +189,7 @@ public function test_site_load() { * @runInSeparateProcess */ public function test_get_user_defaults() { - $config = new Hm_Site_Config_File('./data/siteconfig.rc'); + $config = new Hm_Site_Config_File(APP_PATH.'tests/phpunit/data/siteconfig.rc'); $this->assertEquals(array('version' => VERSION, 'foo' => 'bar', 'default_setting_foo' => 'bar'), $config->dump()); } public function tearDown(): void { diff --git a/tests/phpunit/mocks.php b/tests/phpunit/mocks.php index d5267222f7..d96c383bdb 100644 --- a/tests/phpunit/mocks.php +++ b/tests/phpunit/mocks.php @@ -144,7 +144,7 @@ class Hm_Mock_Config { public $mods = array(); public $user_defaults = array(); public $data = array( - 'user_settings_dir' => './data', + 'user_settings_dir' => APP_PATH.'tests/phpunit/data', 'default_language' => 'es', 'default_setting_inline_message' => true ); diff --git a/tests/phpunit/modules.php b/tests/phpunit/modules.php index ed8403f8e7..bcff8f1c6d 100644 --- a/tests/phpunit/modules.php +++ b/tests/phpunit/modules.php @@ -188,8 +188,8 @@ public function test_run_output_modules() { * @runInSeparateProcess */ public function test_run_output_module() { - require '../../modules/core/setup.php'; - require '../../modules/core/modules.php'; + require APP_PATH.'/modules/core/setup.php'; + require APP_PATH.'/modules/core/modules.php'; $request = new Hm_Mock_Request('HTTP'); $session = new Hm_Mock_Session(); Hm_Output_Modules::add('test', 'date', false, false, false, true, 'core'); @@ -205,8 +205,8 @@ public function test_run_output_module() { * @runInSeparateProcess */ public function test_run_handler_modules() { - require '../../modules/core/setup.php'; - require '../../modules/core/modules.php'; + require APP_PATH.'/modules/core/setup.php'; + require APP_PATH.'/modules/core/modules.php'; $request = new Hm_Mock_Request('HTTP'); $session = new Hm_Mock_Session(); Hm_Handler_Modules::add('test', 'date', false, false, false, true, 'core'); diff --git a/tests/phpunit/modules/core/functions.php b/tests/phpunit/modules/core/functions.php index 46ec03a1df..1fd77cfb8a 100644 --- a/tests/phpunit/modules/core/functions.php +++ b/tests/phpunit/modules/core/functions.php @@ -5,7 +5,7 @@ class Hm_Test_Core_Functions extends TestCase { public function setUp(): void { - require 'bootstrap.php'; + require __DIR__.'/../../bootstrap.php'; require APP_PATH.'modules/core/modules.php'; } /** @@ -228,7 +228,7 @@ class Hm_Test_Core_Functions_Debug extends TestCase { public function setUp(): void { define('DEBUG_MODE', true); - require 'bootstrap.php'; + require __DIR__.'/../../bootstrap.php'; require APP_PATH.'modules/core/modules.php'; } /** @@ -237,7 +237,7 @@ public function setUp(): void { */ public function test_get_ini_debug() { $mock_config = new Hm_Mock_Config(); - $mock_config->data['app_data_dir'] = './data'; + $mock_config->data['app_data_dir'] = APP_PATH.'tests/phpunit/data'; $mock_config->data['foo.ini'] = 'bar'; $this->assertEquals(array('foo' => 'bar'), get_ini($mock_config, 'foo.ini')); $this->assertEquals(array(), get_ini($mock_config, 'no.ini')); diff --git a/tests/phpunit/modules/core/message_functions.php b/tests/phpunit/modules/core/message_functions.php index 5e1d15e7b7..24b1e104ff 100644 --- a/tests/phpunit/modules/core/message_functions.php +++ b/tests/phpunit/modules/core/message_functions.php @@ -5,7 +5,7 @@ class Hm_Test_Core_Message_Functions extends TestCase { public function setUp(): void { - require 'bootstrap.php'; + require __DIR__.'/../../bootstrap.php'; require APP_PATH.'modules/core/modules.php'; } /** diff --git a/tests/phpunit/modules/core/message_list_functions.php b/tests/phpunit/modules/core/message_list_functions.php index 6d0b1e0e55..622666e8ab 100644 --- a/tests/phpunit/modules/core/message_list_functions.php +++ b/tests/phpunit/modules/core/message_list_functions.php @@ -6,7 +6,7 @@ class Hm_Test_Core_Message_List_Functions extends TestCase { public function setUp(): void { date_default_timezone_set('UTC'); - require 'bootstrap.php'; + require __DIR__.'/../../bootstrap.php'; require APP_PATH.'modules/core/modules.php'; } /** diff --git a/tests/phpunit/modules/core/modules.php b/tests/phpunit/modules/core/modules.php index 3447ffb359..e3005bba85 100644 --- a/tests/phpunit/modules/core/modules.php +++ b/tests/phpunit/modules/core/modules.php @@ -5,8 +5,8 @@ class Hm_Test_Core_Handler_Modules extends TestCase { public function setUp(): void { - require 'bootstrap.php'; - require 'helpers.php'; + require __DIR__.'/../../bootstrap.php'; + require __DIR__.'/../../helpers.php'; require APP_PATH.'modules/core/modules.php'; } /** @@ -466,7 +466,7 @@ public function test_load_user_data() { public function test_save_user_data() { $test = new Handler_Test('save_user_data', 'core'); $res = $test->run(); - $this->assertEquals(array('user_settings_dir' => './data', 'default_language' => 'es', 'default_setting_inline_message' => true), $res->session->get('user_data')); + $this->assertEquals(array('user_settings_dir' => APP_PATH.'tests/phpunit/data', 'default_language' => 'es', 'default_setting_inline_message' => true), $res->session->get('user_data')); } /** * @preserveGlobalState disabled @@ -567,8 +567,8 @@ public function test_process_search_terms() { class Hm_Test_Core_Output_Modules extends TestCase { public function setUp(): void { - require 'bootstrap.php'; - require 'helpers.php'; + require __DIR__.'/../../bootstrap.php'; + require __DIR__.'/../../helpers.php'; require APP_PATH.'modules/core/modules.php'; } /** @@ -1479,8 +1479,8 @@ public function test_message_list_end() { class Hm_Test_Core_Output_Modules_Debug extends TestCase { public function setUp(): void { define('DEBUG_MODE', true); - require 'bootstrap.php'; - require 'helpers.php'; + require __DIR__.'/../../bootstrap.php'; + require __DIR__.'/../../helpers.php'; require APP_PATH.'modules/core/modules.php'; } /** diff --git a/tests/phpunit/modules/imap/hm-imap.php b/tests/phpunit/modules/imap/hm-imap.php index 7f72bb044c..9b3593d5d0 100644 --- a/tests/phpunit/modules/imap/hm-imap.php +++ b/tests/phpunit/modules/imap/hm-imap.php @@ -6,7 +6,7 @@ class Hm_Test_Hm_IMAP extends TestCase { public function setUp(): void { define('IMAP_TEST', true); - require 'bootstrap.php'; + require __DIR__.'/../../bootstrap.php'; require APP_PATH.'modules/imap/hm-imap.php'; require APP_PATH.'modules/core/message_functions.php'; $this->create();