From 4a1b74597d25abc8fb44904d70161e66711c3a05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Sauvat?= Date: Fri, 28 Aug 2015 17:09:57 +0200 Subject: [PATCH] Add new tests for better coverage. --- phpunit.xml.dist | 9 + src/Application.php | 1 - tests/ApplicationTest.php | 12 + tests/EntryPointTest.php | 20 +- tests/invalid_sugar/config.php | 434 ++++++++++++++++++++++++ tests/invalid_sugar/config_override.php | 3 + tests/invalid_sugar/sugar_version.php | 14 + 7 files changed, 491 insertions(+), 2 deletions(-) create mode 100644 tests/invalid_sugar/config.php create mode 100644 tests/invalid_sugar/config_override.php create mode 100644 tests/invalid_sugar/sugar_version.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 50fca6e..b00ffa6 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -9,8 +9,17 @@ + + + tests/EntryPointTest.php + tests + + + src + + diff --git a/src/Application.php b/src/Application.php index 093c456..b5690a3 100644 --- a/src/Application.php +++ b/src/Application.php @@ -68,7 +68,6 @@ public function isInstalled() return $sugarConfig['installer_locked']; } } catch (SugarException $e) { - return false; } return false; } diff --git a/tests/ApplicationTest.php b/tests/ApplicationTest.php index 57de949..ca4db7b 100644 --- a/tests/ApplicationTest.php +++ b/tests/ApplicationTest.php @@ -13,6 +13,9 @@ public function testSugarPath() $this->assertEquals(realpath($sugarDir), $app->getPath()); $this->assertTrue($app->isValid()); $this->assertTrue($app->isInstalled()); + + $app = new Application(__DIR__ . '/invalid_sugar'); + $this->assertFalse($app->isInstalled()); } /** @@ -98,4 +101,13 @@ public function testGetVersion() ); $this->assertEquals($expected, $sugar->getVersion()); } + + /** + * @expectedException \Inet\SugarCrm\SugarException + */ + public function testInvalidVersion() + { + $sugar = new Application(__DIR__); + $sugar->getVersion(); + } } diff --git a/tests/EntryPointTest.php b/tests/EntryPointTest.php index f81845c..a44d9f4 100644 --- a/tests/EntryPointTest.php +++ b/tests/EntryPointTest.php @@ -13,7 +13,6 @@ class EntryPointTest extends SugarTestCase /** Define a wrong folder: exception thrown * @expectedException \Inet\SugarCRM\SugarException * @expectedExceptionMessageRegExp #Unable to find an installed instance of SugarCRM in :/foo# - * @runInSeparateProcess */ public function testWrongInstanciationBadFolder() { @@ -21,6 +20,25 @@ public function testWrongInstanciationBadFolder() EntryPoint::createInstance($logger, new Application('/foo'), '1'); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessageRegExp #You must first create the singleton instance with createInstance().# + */ + public function testGetInstanceFailure() + { + EntryPoint::getInstance(); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessageRegExp #Unable to create a SugarCRM\\EntryPoint more than once.# + */ + public function testCreateInstanceFailure() + { + $this->getEntryPointInstance(); + EntryPoint::createInstance(new NullLogger, new Application('/foo'), '1'); + } + public function testGettersSetters() { $entryPoint = $this->getEntryPointInstance(); diff --git a/tests/invalid_sugar/config.php b/tests/invalid_sugar/config.php new file mode 100644 index 0000000..024a197 --- /dev/null +++ b/tests/invalid_sugar/config.php @@ -0,0 +1,434 @@ + + array ( + ), + 'admin_access_control' => false, + 'admin_export_only' => false, + 'cache_dir' => 'cache/', + 'calculate_response_time' => true, + 'calendar' => + array ( + 'default_view' => 'week', + 'show_calls_by_default' => true, + 'show_tasks_by_default' => true, + 'show_completed_by_default' => true, + 'editview_width' => 990, + 'editview_height' => 485, + 'day_timestep' => 15, + 'week_timestep' => 30, + 'items_draggable' => true, + 'items_resizable' => true, + 'enable_repeat' => true, + 'max_repeat_count' => 1000, + ), + 'chartEngine' => 'nvd3', + 'common_ml_dir' => '', + 'create_default_user' => false, + 'cron' => + array ( + 'max_cron_jobs' => 10, + 'max_cron_runtime' => 1800, + 'min_cron_interval' => 30, + ), + 'currency' => '', + 'dashlet_display_row_options' => + array ( + 0 => '1', + 1 => '3', + 2 => '5', + 3 => '10', + ), + 'date_formats' => + array ( + 'Y-m-d' => '2010-12-23', + 'm-d-Y' => '12-23-2010', + 'd-m-Y' => '23-12-2010', + 'Y/m/d' => '2010/12/23', + 'm/d/Y' => '12/23/2010', + 'd/m/Y' => '23/12/2010', + 'Y.m.d' => '2010.12.23', + 'd.m.Y' => '23.12.2010', + 'm.d.Y' => '12.23.2010', + ), + 'datef' => 'm/d/Y', + 'dbconfig' => + array ( + 'db_host_name' => 'localhost', + 'db_host_instance' => '', + 'db_user_name' => 'XXXXXXXX', + 'db_password' => 'XXXXXXXX', + 'db_name' => 'XXXXXXXX', + 'db_type' => 'mysql', + 'db_port' => '', + 'db_manager' => 'MysqliManager', + ), + 'dbconfigoption' => + array ( + 'persistent' => true, + 'autofree' => false, + 'debug' => 0, + 'ssl' => false, + ), + 'default_action' => 'index', + 'default_charset' => 'UTF-8', + 'default_currencies' => + array ( + 'AUD' => + array ( + 'name' => 'Australian Dollars', + 'iso4217' => 'AUD', + 'symbol' => '$', + ), + 'BRL' => + array ( + 'name' => 'Brazilian Reais', + 'iso4217' => 'BRL', + 'symbol' => 'R$', + ), + 'GBP' => + array ( + 'name' => 'British Pounds', + 'iso4217' => 'GBP', + 'symbol' => '£', + ), + 'CAD' => + array ( + 'name' => 'Canadian Dollars', + 'iso4217' => 'CAD', + 'symbol' => '$', + ), + 'CNY' => + array ( + 'name' => 'Chinese Yuan', + 'iso4217' => 'CNY', + 'symbol' => '¥', + ), + 'EUR' => + array ( + 'name' => 'Euro', + 'iso4217' => 'EUR', + 'symbol' => '€', + ), + 'HKD' => + array ( + 'name' => 'Hong Kong Dollars', + 'iso4217' => 'HKD', + 'symbol' => '$', + ), + 'INR' => + array ( + 'name' => 'Indian Rupees', + 'iso4217' => 'INR', + 'symbol' => '₨', + ), + 'KRW' => + array ( + 'name' => 'Korean Won', + 'iso4217' => 'KRW', + 'symbol' => '₩', + ), + 'YEN' => + array ( + 'name' => 'Japanese Yen', + 'iso4217' => 'JPY', + 'symbol' => '¥', + ), + 'MXM' => + array ( + 'name' => 'Mexican Pesos', + 'iso4217' => 'MXM', + 'symbol' => '$', + ), + 'SGD' => + array ( + 'name' => 'Singaporean Dollars', + 'iso4217' => 'SGD', + 'symbol' => '$', + ), + 'CHF' => + array ( + 'name' => 'Swiss Franc', + 'iso4217' => 'CHF', + 'symbol' => 'SFr.', + ), + 'THB' => + array ( + 'name' => 'Thai Baht', + 'iso4217' => 'THB', + 'symbol' => '฿', + ), + 'USD' => + array ( + 'name' => 'US Dollars', + 'iso4217' => 'USD', + 'symbol' => '$', + ), + ), + 'default_currency_iso4217' => 'USD', + 'default_currency_name' => 'US Dollars', + 'default_currency_show_preferred' => false, + 'default_currency_significant_digits' => '2', + 'default_currency_symbol' => '$', + 'default_date_format' => 'm/d/Y', + 'default_decimal_seperator' => '.', + 'default_email_charset' => 'UTF-8', + 'default_email_client' => 'sugar', + 'default_email_editor' => 'html', + 'default_export_charset' => 'UTF-8', + 'default_language' => 'en_us', + 'default_locale_name_format' => 's f l', + 'default_max_tabs' => '7', + 'default_module' => 'Home', + 'default_navigation_paradigm' => 'gm', + 'default_number_grouping_seperator' => ',', + 'default_password' => '', + 'default_permissions' => + array ( + 'dir_mode' => 1528, + 'file_mode' => 432, + 'user' => '', + 'group' => '', + ), + 'default_subpanel_links' => false, + 'default_subpanel_tabs' => true, + 'default_swap_last_viewed' => false, + 'default_swap_shortcuts' => false, + 'default_theme' => 'RacerX', + 'default_time_format' => 'h:ia', + 'default_user_is_admin' => false, + 'default_user_name' => '', + 'demoData' => 'no', + 'disable_convert_lead' => false, + 'disable_export' => false, + 'disable_persistent_connections' => 'false', + 'display_email_template_variable_chooser' => false, + 'display_inbound_email_buttons' => false, + 'dump_slow_queries' => false, + 'email_address_separator' => ',', + 'email_default_client' => 'sugar', + 'email_default_delete_attachments' => true, + 'email_default_editor' => 'html', + 'enable_legacy_dashboards' => true, + 'enable_mobile_redirect' => true, + 'export_delimiter' => ',', + 'export_excel_compatible' => false, + 'full_text_engine' => + array ( + 'Elastic' => + array ( + 'host' => 'localhost', + 'port' => '9200', + ), + ), + 'hide_history_contacts_emails' => + array ( + 'Cases' => false, + 'Accounts' => false, + 'Opportunities' => true, + ), + 'history_max_viewed' => 50, + 'host_name' => 'localhost', + 'import_max_execution_time' => 3600, + 'import_max_records_per_file' => 100, + 'import_max_records_total_limit' => '', + 'installer_locked' => true, + 'jobs' => + array ( + 'min_retry_interval' => 30, + 'max_retries' => 5, + 'timeout' => 3600, + ), + 'js_custom_version' => 1, + 'js_lang_version' => 3, + 'languages' => + array ( + 'en_us' => 'English (US)', + 'bg_BG' => 'Български', + 'cs_CZ' => 'Česky', + 'da_DK' => 'Dansk', + 'de_DE' => 'Deutsch', + 'es_ES' => 'Español', + 'fr_FR' => 'Français', + 'he_IL' => 'עברית', + 'hu_HU' => 'Magyar', + 'it_it' => 'Italiano', + 'lt_LT' => 'Lietuvių', + 'ja_JP' => '日本語', + 'lv_LV' => 'Latviešu', + 'nb_NO' => 'Bokmål', + 'nl_NL' => 'Nederlands', + 'pl_PL' => 'Polski', + 'pt_PT' => 'Português', + 'ro_RO' => 'Română', + 'ru_RU' => 'Русский', + 'sv_SE' => 'Svenska', + 'tr_TR' => 'Türkçe', + 'zh_CN' => '简体中文', + 'pt_BR' => 'Português Brasileiro', + 'ca_ES' => 'Català', + 'en_UK' => 'English (UK)', + 'sr_RS' => 'Српски', + 'el_EL' => 'Ελληνικά', + 'ko_KR' => '한국어', + 'sk_SK' => 'Slovenčina', + 'sq_AL' => 'Shqip', + 'et_EE' => 'Eesti', + 'es_LA' => 'Español (Latinoamérica)', + 'fi_FI' => 'Suomi', + ), + 'large_scale_test' => false, + 'lead_conv_activity_opt' => 'donothing', + 'list_max_entries_per_page' => 20, + 'list_max_entries_per_subpanel' => 10, + 'lock_default_user_name' => false, + 'lock_homepage' => true, + 'lock_subpanels' => false, + 'log_dir' => '.', + 'log_file' => 'sugarcrm.log', + 'log_memory_usage' => false, + 'logger' => + array ( + 'level' => 'fatal', + 'file' => + array ( + 'ext' => '.log', + 'name' => 'sugarcrm', + 'dateFormat' => '%c', + 'maxSize' => '10MB', + 'maxLogs' => 10, + 'suffix' => '', + ), + ), + 'mass_actions' => + array ( + 'mass_update_chunk_size' => 20, + 'mass_delete_chunk_size' => 20, + 'mass_link_chunk_size' => 20, + ), + 'max_dashlets_homepage' => '15', + 'max_record_fetch_size' => 1000, + 'max_record_link_fetch_size' => 5000, + 'merge_duplicates' => + array ( + 'merge_relate_fetch_concurrency' => 2, + 'merge_relate_fetch_timeout' => 90000, + 'merge_relate_fetch_limit' => 20, + 'merge_relate_update_concurrency' => 4, + 'merge_relate_update_timeout' => 90000, + 'merge_relate_max_attempt' => 3, + ), + 'name_formats' => + array ( + 's f l' => 's f l', + 'f l' => 'f l', + 's l' => 's l', + 'l, s f' => 'l, s f', + 'l, f' => 'l, f', + 's l, f' => 's l, f', + 'l s f' => 'l s f', + 'l f s' => 'l f s', + ), + 'oauth_token_expiry' => 0, + 'oauth_token_life' => 86400, + 'passwordsetting' => + array ( + 'minpwdlength' => 6, + 'maxpwdlength' => '', + 'oneupper' => true, + 'onelower' => true, + 'onenumber' => true, + 'onespecial' => '', + 'SystemGeneratedPasswordON' => true, + 'generatepasswordtmpl' => 'f0480521-79db-81e8-d942-54b7f919e54c', + 'lostpasswordtmpl' => '15ea8f38-6f72-6e3a-4f21-54b7f900353d', + 'customregex' => '', + 'regexcomment' => '', + 'forgotpasswordON' => true, + 'linkexpiration' => true, + 'linkexpirationtime' => 24, + 'linkexpirationtype' => 60, + 'userexpiration' => '0', + 'userexpirationtime' => '', + 'userexpirationtype' => '1', + 'userexpirationlogin' => '', + 'systexpiration' => 1, + 'systexpirationtime' => 7, + 'systexpirationtype' => '0', + 'systexpirationlogin' => '', + 'lockoutexpiration' => '0', + 'lockoutexpirationtime' => '', + 'lockoutexpirationtype' => '1', + 'lockoutexpirationlogin' => '', + ), + 'portal_view' => 'single_user', + 'require_accounts' => true, + 'resource_management' => + array ( + 'special_query_limit' => 50000, + 'special_query_modules' => + array ( + 0 => 'Reports', + 1 => 'Export', + 2 => 'Import', + 3 => 'Administration', + 4 => 'Sync', + ), + 'default_limit' => 1000, + ), + 'rss_cache_time' => '10800', + 'save_query' => 'all', + 'search_wildcard_char' => '%', + 'search_wildcard_infront' => false, + 'session_dir' => '', + 'showDetailData' => true, + 'showThemePicker' => true, + 'site_url' => 'XXXXXXXXXXXXXXX', + 'slow_query_time_msec' => '100', + 'snip_url' => 'http://ease.sugarcrm.com:20010/', + 'sugar_version' => '7.5.0.1', + 'time_formats' => + array ( + 'H:i' => '23:00', + 'h:ia' => '11:00pm', + 'h:iA' => '11:00PM', + 'h:i a' => '11:00 pm', + 'h:i A' => '11:00 PM', + 'H.i' => '23.00', + 'h.ia' => '11.00pm', + 'h.iA' => '11.00PM', + 'h.i a' => '11.00 pm', + 'h.i A' => '11.00 PM', + ), + 'timef' => 'H:i', + 'tmp_dir' => 'cache/xml/', + 'tracker_max_display_length' => 30, + 'translation_string_prefix' => false, + 'unique_key' => '9b4af07fd8b49289db29eacb326d8766', + 'upload_badext' => + array ( + 0 => 'php', + 1 => 'php3', + 2 => 'php4', + 3 => 'php5', + 4 => 'pl', + 5 => 'cgi', + 6 => 'py', + 7 => 'asp', + 8 => 'cfm', + 9 => 'js', + 10 => 'vbs', + 11 => 'html', + 12 => 'htm', + ), + 'upload_dir' => 'upload/', + 'upload_maxsize' => 30000000, + 'use_common_ml_dir' => false, + 'use_real_names' => true, + 'use_sprites' => true, + 'vcal_time' => '2', + 'verify_client_ip' => true, + 'wl_list_max_entries_per_page' => 10, + 'wl_list_max_entries_per_subpanel' => 3, +); diff --git a/tests/invalid_sugar/config_override.php b/tests/invalid_sugar/config_override.php new file mode 100644 index 0000000..8f5348b --- /dev/null +++ b/tests/invalid_sugar/config_override.php @@ -0,0 +1,3 @@ +