0
0
Fork 0
mirror of https://github.com/salesagility/SuiteCRM.git synced 2025-01-13 04:48:07 +00:00
salesagility_SuiteCRM/tests/unit/phpunit/includes/MVC/SugarApplicationTest.php

411 lines
13 KiB
PHP
Raw Normal View History

2016-02-17 14:09:41 +00:00
<?php
/**
*
* SugarCRM Community Edition is a customer relationship management program developed by
* SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
*
* SuiteCRM is an extension to SugarCRM Community Edition developed by SalesAgility Ltd.
* Copyright (C) 2011 - 2021 SalesAgility Ltd.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License version 3 as published by the
* Free Software Foundation with the addition of the following permission added
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along with
* this program; if not, see http://www.gnu.org/licenses or write to the Free
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "Powered by
* SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
* reasonably feasible for technical reasons, the Appropriate Legal Notices must
* display the words "Powered by SugarCRM" and "Supercharged by SuiteCRM".
*/
namespace SuiteCRM\Tests\Unit\includes\MVC;
use BeanFactory;
use Exception;
use SugarApplication;
use SugarController;
use SuiteCRM\Test\SuitePHPUnitFrameworkTestCase;
/**
* Class SugarApplicationTest
* @package SuiteCRM\Tests\Unit\MVC
*/
class SugarApplicationTest extends SuitePHPUnitFrameworkTestCase
2016-02-17 14:09:41 +00:00
{
protected $sessionStartedOk = false;
public function testACLFilter(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_SESSION)) {
2018-03-29 12:50:10 +00:00
$session = $_SESSION;
}
2016-03-18 16:33:43 +00:00
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->ACLFilter();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2018-12-20 13:04:52 +00:00
if (isset($session)) {
2018-03-29 12:50:10 +00:00
$_SESSION = $session;
} else {
unset($_SESSION);
}
2016-03-18 16:33:43 +00:00
}
public function testsetupResourceManagement(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
//execute the method with invalid input and test if it works and does not throws an exception.
try {
$SugarApplication->setupResourceManagement('');
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
//execute the method with valid input and test if it works and does not throws an exception.
try {
$SugarApplication->setupResourceManagement('Users');
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testsetupPrint(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->setupPrint();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testpreProcess(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_SESSION)) {
2018-03-29 12:50:10 +00:00
$session = $_SESSION;
}
2016-03-18 16:33:43 +00:00
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->preProcess();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2018-12-20 13:04:52 +00:00
if (isset($session)) {
2018-03-29 12:50:10 +00:00
$_SESSION = $session;
} else {
unset($_SESSION);
}
2016-03-18 16:33:43 +00:00
}
public function testhandleOfflineClient(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->handleOfflineClient();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testhandleAccessControl(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
$result = $SugarApplication->handleAccessControl();
//check that it returns Null
self::assertEquals(null, $result);
2016-03-18 16:33:43 +00:00
//check that controller->hasAccess is true i-e default setting.
self::assertEquals(true, $SugarApplication->controller->hasAccess);
2016-03-18 16:33:43 +00:00
}
public function testpreLoadLanguages(): void
2016-03-18 16:33:43 +00:00
{
try {
SugarApplication::preLoadLanguages();
//check that method call got the current_language global variable set.
self::assertTrue(isset($GLOBALS['current_language']));
2016-03-18 16:33:43 +00:00
//check that method call got the app_strings global variable set.
self::assertTrue(is_array($GLOBALS['app_strings']) && count($GLOBALS['app_strings']) > 0);
2016-03-18 16:33:43 +00:00
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
}
public function testloadLanguages(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
try {
$SugarApplication->loadLanguages();
//check that method call got the current_language global variable set.
self::assertTrue(isset($GLOBALS['current_language']));
2016-03-18 16:33:43 +00:00
//check that method call got the app_strings global variable set.
self::assertTrue(is_array($GLOBALS['app_strings']) && count($GLOBALS['app_strings']) > 0);
2016-03-18 16:33:43 +00:00
//check that method call got the app_list_strings global variable set.
self::assertTrue(is_array($GLOBALS['app_list_strings']) && count($GLOBALS['app_list_strings']) > 0);
2016-03-18 16:33:43 +00:00
//check that method call got the mod_strings global variable set.
self::assertTrue(is_array($GLOBALS['mod_strings']) && count($GLOBALS['mod_strings']) > 0);
2016-03-18 16:33:43 +00:00
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
}
public function testcheckDatabaseVersion(): void
2016-03-18 16:33:43 +00:00
{
2018-04-10 15:45:33 +00:00
self::markTestIncomplete('environment dependency');
2019-09-03 17:05:25 +00:00
2016-03-18 16:33:43 +00:00
$SugarApplication = new SugarApplication();
//execute the method with false parameter and check for false returned as it cannot connect to DB.
//testing with true will allow it to use die() which stops phpunit execution as well.
2018-04-03 13:41:52 +00:00
include __DIR__ . '/../../../../sugar_version.php';
self::assertTrue(isset($sugar_db_version) && $sugar_db_version);
Merge remote-tracking branch 'upstream/hotfix-7.10.x' into fix/merge_statechecker # Conflicts: # README.md # composer.json # composer.lock # files.md5 # include/StateChecker.php # include/utils.php # modules/ACLRoles/DetailView.php # modules/AOS_Products_Quotes/Line_Items.php # modules/Administration/ElasticSearchSettings.php # modules/Currencies/Currency.php # service/core/webservice.php # suitecrm_version.php # tests/SuiteCRM/Test/SuitePHPUnitFrameworkTestCase.php # tests/unit/phpunit/SuitePHPUnit_Framework_TestCase.php # tests/unit/phpunit/data/SugarBeanTest.php # tests/unit/phpunit/include/APIErrorObjectTest.php # tests/unit/phpunit/include/ErrorMessageTest.php # tests/unit/phpunit/include/Imap/ImapHandlerFactoryTest.php # tests/unit/phpunit/include/MVC/Controller/SugarControllerTest.php # tests/unit/phpunit/include/MVC/SugarApplicationTest.php # tests/unit/phpunit/include/MVC/View/SugarViewTest.php # tests/unit/phpunit/include/MVC/View/views/view.classicTest.php # tests/unit/phpunit/include/MVC/View/views/view.detailTest.php # tests/unit/phpunit/include/MVC/View/views/view.editTest.php # tests/unit/phpunit/include/MVC/View/views/view.importvcardsaveTest.php # tests/unit/phpunit/include/MVC/View/views/view.jsonTest.php # tests/unit/phpunit/include/SugarEmailAddress/SugarEmailAddressTest.php # tests/unit/phpunit/include/SugarFolders/SugarFolderTest.php # tests/unit/phpunit/include/utils/LogicHookTest.php # tests/unit/phpunit/include/utils/phpZipUtilsTest.php # tests/unit/phpunit/include/utils/securityUtilsTest.php # tests/unit/phpunit/lib/SuiteCRM/Utility/SuiteLoggerTest.php # tests/unit/phpunit/modules/ACLActions/ACLActionTest.php # tests/unit/phpunit/modules/AOW_WorkFlow/AOW_WorkFlowTest.php # tests/unit/phpunit/modules/Emails/EmailTest.php # tests/unit/phpunit/modules/FP_events/FP_eventsTest.php # tests/unit/phpunit/modules/ProspectLists/ProspectListTest.php # tests/unit/phpunit/modules/SchedulersJobs/SchedulersJobTest.php # tests/unit/phpunit/modules/Tasks/TaskTest.php # tests/unit/phpunit/modules/UserPreferences/UserPreferenceTest.php # themes/SuiteP/css/Dawn/style.css # themes/SuiteP/css/Day/style.css # themes/SuiteP/css/Dusk/style.css # themes/SuiteP/css/Night/style.css
2019-11-19 14:32:37 +00:00
2018-04-03 13:41:52 +00:00
$GLOBALS['sugar_db_version'] = $sugar_db_version;
2016-03-18 16:33:43 +00:00
$result = $SugarApplication->checkDatabaseVersion(false);
self::assertTrue($result);
2016-03-18 16:33:43 +00:00
}
public function testloadDisplaySettings(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->loadDisplaySettings();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testloadLicense(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->loadLicense();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testloadGlobals(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_REQUEST)) {
2018-03-29 12:50:10 +00:00
$request = $_REQUEST;
}
2016-03-18 16:33:43 +00:00
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$SugarApplication->loadGlobals();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2018-12-20 13:04:52 +00:00
if (isset($request)) {
2018-03-29 12:50:10 +00:00
$_REQUEST = $request;
} else {
unset($_REQUEST);
}
2016-03-18 16:33:43 +00:00
}
public function teststartSession(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_SESSION)) {
2018-03-29 12:50:10 +00:00
$session = $_SESSION;
}
2016-03-18 16:33:43 +00:00
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
2018-12-20 13:04:52 +00:00
if (!headers_sent()) {
2018-03-30 11:22:02 +00:00
$SugarApplication->startSession();
$this->sessionStartedOk = true;
}
2016-03-18 16:33:43 +00:00
} catch (Exception $e) {
$err = $e->getMessage() . ' ' . $e->getCode() . ' ' . $e->getFile() . ' ' . $e->getLine() . ' ' . $e->getTraceAsString();
var_dump($err);
self::fail($err);
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2018-03-29 12:50:10 +00:00
// cleanup
2018-12-20 13:04:52 +00:00
if (isset($session)) {
2018-03-29 12:50:10 +00:00
$_SESSION = $session;
} else {
unset($_SESSION);
}
2016-03-18 16:33:43 +00:00
}
public function testendSession(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
$SugarApplication->controller = new SugarController();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
2018-12-20 13:04:52 +00:00
if ($this->sessionStartedOk) {
2018-03-30 11:22:02 +00:00
$SugarApplication->endSession();
}
2016-03-18 16:33:43 +00:00
} catch (Exception $e) {
2018-03-30 11:22:02 +00:00
$err = $e->getMessage() . ' ' . $e->getCode() . ' ' . $e->getFile() . ' ' . $e->getLine() . ' ' . $e->getTraceAsString();
var_dump($err);
self::fail($err);
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testappendErrorMessage(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_SESSION)) {
2018-03-29 12:50:10 +00:00
$session = $_SESSION;
}
2016-03-18 16:33:43 +00:00
//execute the method and check that the method adds the message to user_error_message array.
//there should be one more array element after method execution.
$_SESSION['user_error_message'] = [];
2016-03-18 16:33:43 +00:00
$user_error_message_count = count($_SESSION['user_error_message']);
SugarApplication::appendErrorMessage('some error');
self::assertGreaterThan($user_error_message_count, count($_SESSION['user_error_message']));
2018-03-29 12:50:10 +00:00
// cleanup
2018-12-20 13:04:52 +00:00
if (isset($session)) {
2018-03-29 12:50:10 +00:00
$_SESSION = $session;
} else {
unset($_SESSION);
}
2016-03-18 16:33:43 +00:00
}
2016-02-17 14:09:41 +00:00
public function testgetErrorMessages(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
//execute the method and check if it returns a array.
2016-03-18 16:33:43 +00:00
$errorMessages = SugarApplication::getErrorMessages();
self::assertIsArray($errorMessages);
2016-03-18 16:33:43 +00:00
}
public function testsetCookie(): void
2016-03-18 16:33:43 +00:00
{
2018-12-20 13:04:52 +00:00
if (isset($_COOKIE)) {
2018-03-29 12:50:10 +00:00
$cookie = $_COOKIE;
}
2016-03-18 16:33:43 +00:00
//execute the method and check that the method adds the key value pair to cookies array.
SugarApplication::setCookie('key', 'value');
self::assertEquals('value', $_COOKIE['key']);
2018-03-29 12:50:10 +00:00
// cleanup
2018-12-20 13:04:52 +00:00
if (isset($cookie)) {
2018-03-29 12:50:10 +00:00
$_COOKIE = $cookie;
} else {
unset($_COOKIE);
}
2016-03-18 16:33:43 +00:00
}
public function testcreateLoginVars(): void
2016-03-18 16:33:43 +00:00
{
$SugarApplication = new SugarApplication();
// Execute the method and test that it works and doesn't throw an exception.
2016-03-18 16:33:43 +00:00
try {
$vars = $SugarApplication->createLoginVars();
} catch (Exception $e) {
self::fail($e->getMessage() . "\nTrace:\n" . $e->getTraceAsString());
2016-03-18 16:33:43 +00:00
}
self::assertTrue(true);
2016-03-18 16:33:43 +00:00
}
public function testgetLoginVars(): void
2016-03-18 16:33:43 +00:00
{
//execute the method and test that it returns a array.
$vars = (new SugarApplication())->getLoginVars();
self::assertIsArray($vars);
2016-03-18 16:33:43 +00:00
}
public function testgetLoginRedirect(): void
2016-03-18 16:33:43 +00:00
{
//execute the method and test that it returns a plus length string
$redirect = (new SugarApplication())->getLoginRedirect();
2023-06-01 15:27:04 +00:00
self::assertGreaterThan(0, strlen((string) $redirect));
2016-03-18 16:33:43 +00:00
}
protected function setUp(): void
{
parent::setUp();
global $current_user;
get_sugar_config_defaults();
$current_user = BeanFactory::newBean('Users');
}
2016-02-17 14:09:41 +00:00
}