Skip to content

Commit

Permalink
Add new modules to unit tests
Browse files Browse the repository at this point in the history
- Fix failing Email test
  • Loading branch information
jack7anderson7 committed Feb 23, 2023
1 parent 58433f2 commit a83a845
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 26 deletions.
4 changes: 2 additions & 2 deletions include/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1889,8 +1889,8 @@ function get_select_options_with_id_separate_key($label_list, $key_list, $select
// the system is evaluating $selected_key == 0 || '' to true. Be very careful when changing this. Test all cases.
// The bug was only happening with one of the users in the drop down. It was being replaced by none.
if (
($option_key != '' && $selected_key == $option_key) || (
$option_key == '' && (($selected_key == '' && !$massupdate) || $selected_key == '__SugarMassUpdateClearField__')
($option_key !== '' && $selected_key === $option_key) || (
$option_key === '' && (($selected_key === '' && !$massupdate) || $selected_key === '__SugarMassUpdateClearField__')
) || (is_array($selected_key) && in_array($option_key, $selected_key))
) {
$selected_string = 'selected ';
Expand Down
7 changes: 5 additions & 2 deletions modules/InboundEmail/InboundEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6189,7 +6189,10 @@ public function getConnectString($service = '', $mbox = '', $includeMbox = true)
$service = empty($service) ? $this->getServiceString() : $service;
$mbox = empty($mbox) ? $this->mailbox : $mbox;

$connectString = '{' . $this->server_url . ':' . $this->port . '/service=' . $this->protocol . $service . '}';
$protocol = $this->protocol ?? 'imap';
$port = $this->port ?? '143';

$connectString = '{' . $this->server_url . ':' . $port . '/service=' . $protocol . $service . '}';
$connectString .= ($includeMbox) ? $mbox : "";

return $connectString;
Expand Down Expand Up @@ -6245,7 +6248,7 @@ public function connectMailserver($test = false, $force = false)
$this->getImap()->setTimeout(3, 15);

$opts = $this->findOptimumSettings($useSsl);
if (!empty($opts) && isset($opts['good']) && empty($opts['good'])) {
if (!empty($opts) && isset($opts['good']) && empty($opts['bad'])) {
$ret = array_pop($opts['err']); // TODO: lost error info?
return $ret;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,12 @@ public function testfindFieldsWithAttributes(): void
self::assertIsArray($fields1);

//check with a very common attribute
$attributes = array('id');
$attributes = ['id' => 'true'];
$fields2 = VardefBrowser::findFieldsWithAttributes($attributes);
self::assertIsArray($fields2);

//check with a very specific attribute
$attributes = array('category');
$attributes = ['category' => 'true'];
$fields3 = VardefBrowser::findFieldsWithAttributes($attributes);
self::assertIsArray($fields3);

Expand Down
1 change: 1 addition & 0 deletions tests/unit/phpunit/modules/ACLRoles/ACLRoleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ public function testgetRoleActions(): void
'EmailMarketing',
'Emails',
'FP_events',
'InboundEmail',
'AOD_Index',
'AOD_IndexEvent',
'AOS_Invoices',
Expand Down
38 changes: 19 additions & 19 deletions tests/unit/phpunit/modules/InboundEmail/InboundEmailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public function testConnectMailserverNoGood(): void
$fake->add('setTimeout', [1, 15], [true]);
$fake->add('setTimeout', [2, 15], [true]);
$fake->add('setTimeout', [3, 15], [true]);
$fake->add('open', ["{:/service=/ssl/tls/validate-cert/secure}", null, null, 0, 0, []], [function () {
$fake->add('open', ["{:143/service=imap/ssl/tls/validate-cert/secure}", null, null, 0, 0, []], [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getLastError', null, ['Too many login failures']);
Expand Down Expand Up @@ -194,7 +194,7 @@ public function testFindOptimumSettingsFalsePositive(): void
$fake->add('setTimeout', [2, 60], [true]);
$fake->add('setTimeout', [3, 60], [true]);
$fake->add('getErrors', null, [false]);
$fake->add('open', ["{:/service=/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
$fake->add('open', ["{:143/service=imap/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getLastError', null, ["SECURITY PROBLEM: insecure server advertised AUTH=PLAIN"]);
Expand Down Expand Up @@ -230,20 +230,20 @@ public function testFindOptimumSettingsFail(): void
$fake->add('setTimeout', [2, 60], [true]);
$fake->add('setTimeout', [3, 60], [true]);
$fake->add('getErrors', null, [false]);
$fake->add('open', ["{:/service=/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
$fake->add('open', ["{:143/service=imap/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getLastError', null, ['Too many login failures']);
$fake->add('getAlerts', null, [false]);
$fake->add('getConnection', null, [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getMailboxes', ['{:/service=/notls/novalidate-cert/secure}', '*'], [[]]);
$fake->add('getMailboxes', ['{:143/service=imap/notls/novalidate-cert/secure}', '*'], [[]]);
$fake->add('close', null, [null]);

$exp = [
'good' => [],
'bad' => ['both-secure' => '{:/service=/notls/novalidate-cert/secure}'],
'bad' => ['both-secure' => '{:143/service=imap/notls/novalidate-cert/secure}'],
'err' => ['both-secure' => 'Login or Password Incorrect'],
];

Expand Down Expand Up @@ -275,7 +275,7 @@ public function testFindOptimumSettingsOk(): void
$fake->add('setTimeout', [2, 60], [true]);
$fake->add('setTimeout', [3, 60], [true]);
$fake->add('getErrors', null, [false]);
$fake->add('open', ["{:/service=/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
$fake->add('open', ["{:143/service=imap/notls/novalidate-cert/secure}", null, null, 0, 0, []], [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getLastError', null, [false]);
Expand Down Expand Up @@ -316,7 +316,7 @@ public function testFindOptimumSettingsUseSsl(): void
$fake->add('setTimeout', [2, 60], [true]);
$fake->add('setTimeout', [3, 60], [true]);
$fake->add('getErrors', null, [false]);
$fake->add('open', ["{:/service=/ssl/tls/validate-cert/secure}", null, null, 0, 0, []], [function () {
$fake->add('open', ["{:143/service=imap/ssl/tls/validate-cert/secure}", null, null, 0, 0, []], [function () {
return tempFileWithMode('wb+');
}]);
$fake->add('getLastError', null, [false]);
Expand Down Expand Up @@ -2185,9 +2185,9 @@ public function testgetConnectString(): void
{
$inboundEmail = BeanFactory::newBean('InboundEmail');

self::assertEquals('{:/service=}', $inboundEmail->getConnectString()); //test with default options
self::assertEquals('{:/service=mail.google.com}INBOX', $inboundEmail->getConnectString('mail.google.com', 'INBOX'));//test with includeMbox true
self::assertEquals('{:/service=mail.google.com}', $inboundEmail->getConnectString('mail.google.com', 'INBOX', false));//test with includeMbox false
self::assertEquals('{:143/service=imap}', $inboundEmail->getConnectString()); //test with default options
self::assertEquals('{:143/service=imapmail.google.com}INBOX', $inboundEmail->getConnectString('mail.google.com', 'INBOX'));//test with includeMbox true
self::assertEquals('{:143/service=imapmail.google.com}', $inboundEmail->getConnectString('mail.google.com', 'INBOX', false));//test with includeMbox false
}

public function testdisconnectMailserver(): void
Expand All @@ -2213,7 +2213,7 @@ public function testconnectMailserver(): void

//test with test and force true
$result = $inboundEmail->connectMailserver(true, true);
self::assertEquals("Can't open mailbox {:/service=}: invalid remote specification<p><p><p>Please check your settings and try again.", $result);
self::assertEquals("Can't open mailbox {:143/service=imap}: invalid remote specification<p><p><p>Please check your settings and try again.", $result);
}

public function testcheckImap(): void
Expand Down Expand Up @@ -2266,14 +2266,14 @@ public function testget_list_view_data(): void
$result = $inboundEmail->get_list_view_data();

$expected = array(
'DELETED' => '0',
'STATUS' => 'Active',
'DELETE_SEEN' => '0',
'MAILBOX_TYPE' => 'INBOX',
'IS_PERSONAL' => '0',
'MAILBOX_TYPE_NAME' => null,
'GLOBAL_PERSONAL_STRING' => 'group',
);
'DELETED' => '0',
'STATUS' => 'Active',
'DELETE_SEEN' => '0',
'MAILBOX_TYPE' => 'INBOX',
'IS_PERSONAL' => '0',
'MAILBOX_TYPE_NAME' => null,
'GLOBAL_PERSONAL_STRING' => 'group',
);

self::assertIsArray($result);
self::assertEquals($expected, $result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public function testgetSecurityModules(): void
'Contacts',
'AOS_Contracts',
'AOS_Quotes',
'InboundEmail',
'Bugs',
'Users',
'Documents',
Expand All @@ -307,6 +308,7 @@ public function testgetSecurityModules(): void
'jjwg_Maps',
'AOS_Product_Categories',
'Spots' => 'Spots',
'OutboundEmailAccounts' => 'OutboundEmailAccounts',
'SurveyQuestionOptions' => 'SurveyQuestionOptions',
'SurveyQuestionResponses' => 'SurveyQuestionResponses',
'SurveyQuestions' => 'SurveyQuestions',
Expand Down
2 changes: 1 addition & 1 deletion themes/SuiteP/tpls/header.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<script type='text/javascript'>
if (SUGAR.ajaxUI && !SUGAR.ajaxUI.hist_loaded) {
YAHOO.util.History.register('ajaxUILoc', "", SUGAR.ajaxUI.go);
{/literal}{if $smarty.request.module != "ModuleBuilder"}{* Module builder will init YUI history on its own *}
{/literal}{if isset($smarty.request.module) && $smarty.request.module != "ModuleBuilder"}{* Module builder will init YUI history on its own *}
YAHOO.util.History.initialize("ajaxUI-history-field", "ajaxUI-history-iframe");
{/if}{literal}
}
Expand Down

0 comments on commit a83a845

Please sign in to comment.