Merged in feature/PMC-1332 (pull request #7136)
PMC-1332 PMCORE-1018 Approved-by: Julio Cesar Laura Avendaño <contact@julio-laura.com> Approved-by: Paula Quispe <paula.quispe@processmaker.com>
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -10,6 +10,7 @@ use ProcessMaker\Model\EmailServerModel;
|
||||
use ProcessMaker\Model\Process;
|
||||
use ProcessMaker\Model\Task;
|
||||
use ProcessMaker\Model\User;
|
||||
use ProcessMaker\Util\WsMessageResponse;
|
||||
use Tests\TestCase;
|
||||
|
||||
class WsBaseTest extends TestCase
|
||||
@@ -484,48 +485,48 @@ class WsBaseTest extends TestCase
|
||||
|
||||
//Create the application factory
|
||||
$application1 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
);
|
||||
$application2 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
);
|
||||
|
||||
//Create the delegation factory
|
||||
$delegation1 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
);
|
||||
$delegation2 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
[
|
||||
'USR_UID' => $user->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
);
|
||||
|
||||
//Create app thread factory
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
);
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
);
|
||||
|
||||
//Instance the object
|
||||
@@ -559,48 +560,48 @@ class WsBaseTest extends TestCase
|
||||
|
||||
//Create the application factory
|
||||
$application1 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
[
|
||||
'APP_STATUS' => 'TO_DO',
|
||||
'APP_TITLE' => 'Title1'
|
||||
]
|
||||
);
|
||||
$application2 = factory(Application::class)->create(
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
[
|
||||
'APP_STATUS' => 'DRAFT',
|
||||
'APP_TITLE' => 'Title2'
|
||||
]
|
||||
);
|
||||
|
||||
//Create the delegation factory
|
||||
$delegation1 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application1->APP_NUMBER
|
||||
]
|
||||
);
|
||||
$delegation2 = factory(Delegation::class)->create(
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
[
|
||||
'USR_UID' => $user1->USR_UID,
|
||||
'DEL_THREAD_STATUS' => 'OPEN',
|
||||
'DEL_FINISH_DATE' => null,
|
||||
'APP_NUMBER' => $application2->APP_NUMBER
|
||||
]
|
||||
);
|
||||
|
||||
//Create app thread factory
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation1->APP_UID
|
||||
]
|
||||
);
|
||||
factory(AppThread::class)->create(
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
[
|
||||
'APP_THREAD_STATUS' => 'OPEN',
|
||||
'APP_UID' => $delegation2->APP_UID
|
||||
]
|
||||
);
|
||||
|
||||
//Instance the object
|
||||
@@ -612,4 +613,36 @@ class WsBaseTest extends TestCase
|
||||
//Assert the result his empty
|
||||
$this->assertEmpty($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures obtaining the email configuration with all fields.
|
||||
* @test
|
||||
* @covers \WsBase::sendMessage()
|
||||
*/
|
||||
public function it_should_get_email_configuration()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
//data
|
||||
$case = $this->createNewCase();
|
||||
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
|
||||
|
||||
//parameters
|
||||
$appUid = $case->applicationUid;
|
||||
$from = $faker->email;
|
||||
$to = "";
|
||||
$cc = "";
|
||||
$bcc = "";
|
||||
$subject = $faker->title;
|
||||
$templateName = basename($template->PRF_PATH);
|
||||
$appFields = [
|
||||
'var1' => $faker->numberBetween(1, 100)
|
||||
];
|
||||
|
||||
$wsBase = new WsBase();
|
||||
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields);
|
||||
|
||||
//assertions
|
||||
$this->assertInstanceOf(WsMessageResponse::class, $result);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,208 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\methods\emailServer;
|
||||
|
||||
use Faker\Factory;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailServerAjaxTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This set initial parameters for each test.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->settingUserLogged();
|
||||
}
|
||||
|
||||
/**
|
||||
* This starts a valid user in session with the appropriate permissions.
|
||||
* @global object $RBAC
|
||||
*/
|
||||
private function settingUserLogged()
|
||||
{
|
||||
global $RBAC;
|
||||
|
||||
$user = User::where('USR_ID', '=', 1)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
|
||||
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC->initRBAC();
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
}
|
||||
/**
|
||||
* This allows multiple calls to the require_once statement, use the original
|
||||
* content by creating several documents in the temporary folder.
|
||||
* @global object $RBAC
|
||||
* @return string
|
||||
*/
|
||||
private function requireOnceForEmailServerAjax(): string
|
||||
{
|
||||
$fileName = PATH_METHODS . 'emailServer/emailServerAjax.php';
|
||||
$tempFile = tempnam(sys_get_temp_dir(), basename($fileName, '.php'));
|
||||
if ($tempFile !== false) {
|
||||
file_put_contents($tempFile, file_get_contents($fileName));
|
||||
|
||||
global $RBAC;
|
||||
$RBAC->authorizedActions[basename($tempFile)] = [
|
||||
'INS' => ['PM_SETUP'],
|
||||
'UPD' => ['PM_SETUP'],
|
||||
'DEL' => ['PM_SETUP'],
|
||||
'LST' => ['PM_SETUP'],
|
||||
'TEST' => ['PM_SETUP'],
|
||||
'createAuthUrl' => ['PM_SETUP']
|
||||
];
|
||||
ob_start();
|
||||
require_once $tempFile;
|
||||
return ob_get_clean();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the createAuthUrl option at the endpoint emailServerAjax.php.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_option_create_auth_url()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$post = [
|
||||
'option' => 'createAuthUrl',
|
||||
'clientID' => $faker->regexify('[0-9]{12}\-[a-zA-Z]{20}'),
|
||||
'clientSecret' => $faker->regexify('[a-zA-Z]{10}'),
|
||||
'emailEngine' => 'GMAILAPI',
|
||||
'fromAccount' => $faker->email,
|
||||
'senderEmail' => $faker->email,
|
||||
'senderName' => $faker->name,
|
||||
'sendTestMail' => 1,
|
||||
'mailTo' => $faker->email,
|
||||
'setDefaultConfiguration' => 1
|
||||
];
|
||||
$_POST = array_merge($_POST, $post);
|
||||
|
||||
$content = $this->requireOnceForEmailServerAjax();
|
||||
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->assertContains(200, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the INS option at the endpoint emailServerAjax.php.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_option_ins()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
$post = [
|
||||
'option' => 'INS',
|
||||
'cboEmailEngine' => 'PHPMAILER',
|
||||
'server' => 'smtp.gmail.com',
|
||||
'port' => '465',
|
||||
'incomingServer' => '',
|
||||
'incomingPort' => '',
|
||||
'reqAuthentication' => 1,
|
||||
'accountFrom' => $faker->email,
|
||||
'password' => $faker->password,
|
||||
'fromMail' => $faker->email,
|
||||
'fromName' => $faker->name,
|
||||
'smtpSecure' => 'ssl',
|
||||
'sendTestMail' => 1,
|
||||
'mailTo' => $faker->email,
|
||||
'emailServerDefault' => 1,
|
||||
];
|
||||
$_POST = array_merge($_POST, $post);
|
||||
|
||||
$content = $this->requireOnceForEmailServerAjax();
|
||||
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->assertContains("OK", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the UPD option at the endpoint emailServerAjax.php.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_option_upd()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->create([
|
||||
'MESS_ENGINE' => 'PHPMAILER',
|
||||
]);
|
||||
|
||||
$post = [
|
||||
'option' => 'UPD',
|
||||
'emailServerUid' => $emailServer->MESS_UID,
|
||||
'cboEmailEngine' => 'PHPMAILER',
|
||||
'server' => 'smtp.gmail.com',
|
||||
'port' => '465',
|
||||
'incomingServer' => '',
|
||||
'incomingPort' => '',
|
||||
'reqAuthentication' => 1,
|
||||
'accountFrom' => $faker->email,
|
||||
'password' => $faker->password,
|
||||
'fromMail' => $faker->email,
|
||||
'fromName' => $faker->name,
|
||||
'smtpSecure' => 'ssl',
|
||||
'sendTestMail' => 1,
|
||||
'mailTo' => $faker->email,
|
||||
'emailServerDefault' => 1,
|
||||
];
|
||||
$_POST = array_merge($_POST, $post);
|
||||
|
||||
$content = $this->requireOnceForEmailServerAjax();
|
||||
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->assertContains("OK", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the DEL option at the endpoint emailServerAjax.php.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_option_del()
|
||||
{
|
||||
$emailServer = factory(EmailServerModel::class)->create([
|
||||
'MESS_ENGINE' => 'PHPMAILER',
|
||||
]);
|
||||
|
||||
$post = [
|
||||
'option' => 'DEL',
|
||||
'emailServerUid' => $emailServer->MESS_UID
|
||||
];
|
||||
$_POST = array_merge($_POST, $post);
|
||||
|
||||
$content = $this->requireOnceForEmailServerAjax();
|
||||
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->assertContains("OK", $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* This tests the LST option at the endpoint emailServerAjax.php.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_option_lst()
|
||||
{
|
||||
$post = [
|
||||
'option' => 'LST',
|
||||
'pageSize' => 25,
|
||||
'search' => ''
|
||||
];
|
||||
$_POST = array_merge($_POST, $post);
|
||||
|
||||
$content = $this->requireOnceForEmailServerAjax();
|
||||
$data = json_decode($content, JSON_OBJECT_AS_ARRAY);
|
||||
|
||||
$this->assertContains("OK", $data);
|
||||
$this->assertTrue(isset($data["resultRoot"]));
|
||||
$this->assertTrue(is_array($data["resultRoot"]));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\methods\emailServer;
|
||||
|
||||
use Faker\Factory;
|
||||
use Google_Auth_Exception;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use ProcessMaker\GmailOAuth\GmailOAuth;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailServerGmailOAuthTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This test expects an error message stored in the cache.
|
||||
* The Google client requires valid codes to obtain the clientId from a request,
|
||||
* otherwise it will throw an exception.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_try_to_authenticate_on_google_oauth_with_a_fake_code()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
global $RBAC;
|
||||
|
||||
$user = User::where('USR_ID', '=', 1)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
|
||||
$_POST['USR_UID'] = $user['USR_UID'];
|
||||
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC->initRBAC();
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
|
||||
$_SESSION['gmailOAuth'] = new GmailOAuth();
|
||||
|
||||
/**
|
||||
* This gets a fake code, according to the nomenclature.
|
||||
*/
|
||||
$_GET['code'] = $faker->regexify("/[1-9]\/[a-zA-Z]{25}-[a-zA-Z]{16}_[a-zA-Z]{19}-[a-zA-Z]{24}/");
|
||||
|
||||
require_once PATH_METHODS . 'emailServer/emailServerGmailOAuth.php';
|
||||
$this->assertTrue(Cache::has('errorMessageIfNotAuthenticate'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\methods\emailServer;
|
||||
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailServerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This test ensures that the script output generates the javascript variable
|
||||
* EMAILSERVER_LICENSED.
|
||||
* @test
|
||||
*/
|
||||
public function it_should_verify_the_script_output_contains_javascript_variable()
|
||||
{
|
||||
global $RBAC;
|
||||
|
||||
$user = User::where('USR_ID', '=', 1)
|
||||
->get()
|
||||
->first();
|
||||
|
||||
$_SESSION['USER_LOGGED'] = $user['USR_UID'];
|
||||
$_POST['USR_UID'] = $user['USR_UID'];
|
||||
|
||||
$RBAC = RBAC::getSingleton(PATH_DATA, session_id());
|
||||
$RBAC->initRBAC();
|
||||
$RBAC->loadUserRolePermission('PROCESSMAKER', $_SESSION['USER_LOGGED']);
|
||||
|
||||
ob_start();
|
||||
require_once PATH_METHODS . 'emailServer/emailServer.php';
|
||||
$content = ob_get_clean();
|
||||
|
||||
$this->assertContains("EMAILSERVER_LICENSED", $content);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
|
||||
|
||||
use Exception;
|
||||
use Faker\Factory;
|
||||
use G;
|
||||
use ProcessMaker\BusinessModel\EmailServer;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailServerTest extends TestCase
|
||||
{
|
||||
private $emailServer;
|
||||
private $faker;
|
||||
|
||||
/**
|
||||
* set up function.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->emailServer = new EmailServer();
|
||||
$this->faker = Factory::create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get structure for registry the EMAIL_SERVER.
|
||||
* @return array
|
||||
*/
|
||||
private function getDataForEmailServerRegistry(): array
|
||||
{
|
||||
$faker = $this->faker;
|
||||
return [
|
||||
'MESS_ENGINE' => 'PHPMAILER',
|
||||
'MESS_SERVER' => 'smtp.' . $faker->domainName,
|
||||
'MESS_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
'MESS_INCOMING_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_RAUTH' => 1,
|
||||
'MESS_ACCOUNT' => $faker->email,
|
||||
'MESS_PASSWORD' => $faker->password,
|
||||
'MESS_FROM_MAIL' => $faker->email,
|
||||
'MESS_FROM_NAME' => $faker->name,
|
||||
'SMTPSECURE' => 'ssl',
|
||||
'MESS_TRY_SEND_INMEDIATLY' => 1,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 1,
|
||||
'OAUTH_CLIENT_ID' => '',
|
||||
'OAUTH_CLIENT_SECRET' => '',
|
||||
'OAUTH_REFRESH_TOKEN' => '',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates a record in the EMAIL_SERVER table.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::create()
|
||||
*/
|
||||
public function it_should_create()
|
||||
{
|
||||
$faker = $this->faker;
|
||||
$expected = $this->getDataForEmailServerRegistry();
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$actual = $this->emailServer->create($expected);
|
||||
|
||||
$this->assertTrue(isset($actual['MESS_UID']));
|
||||
$this->assertTrue(is_string($actual['MESS_UID']));
|
||||
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
|
||||
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
|
||||
|
||||
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password, 'EMAILENCRYPT');
|
||||
$actual = $this->emailServer->create($expected);
|
||||
|
||||
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password . 'hash:', 'EMAILENCRYPT');
|
||||
$actual = $this->emailServer->create($expected);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$this->emailServer->create([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* This updates a record in the EMAIL_SERVER table.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::update()
|
||||
*/
|
||||
public function it_should_update()
|
||||
{
|
||||
$faker = $this->faker;
|
||||
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
|
||||
$data = $emailServer->toArray();
|
||||
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
|
||||
$expected = [
|
||||
'MESS_ENGINE' => 'PHPMAILER',
|
||||
'MESS_SERVER' => 'smtp.' . $faker->domainName,
|
||||
'MESS_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
'MESS_INCOMING_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_RAUTH' => 1,
|
||||
'MESS_ACCOUNT' => $faker->email,
|
||||
'MESS_PASSWORD' => $faker->password,
|
||||
'MESS_FROM_MAIL' => $faker->email,
|
||||
'MESS_FROM_NAME' => $faker->name,
|
||||
'SMTPSECURE' => 'ssl',
|
||||
'MESS_TRY_SEND_INMEDIATLY' => 1,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 1,
|
||||
];
|
||||
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
|
||||
|
||||
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
|
||||
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
|
||||
|
||||
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password, 'EMAILENCRYPT');
|
||||
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
|
||||
|
||||
$expected['MESS_PASSWORD'] = G::encrypt('hash:' . $faker->password . 'hash:', 'EMAILENCRYPT');
|
||||
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
|
||||
|
||||
$this->emailServer->setFormatFieldNameInUppercase(false);
|
||||
$this->expectException(Exception::class);
|
||||
$actual = $this->emailServer->update($data['MESS_UID'], $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data of a from a record EMAIL_SERVER.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServerDataFromRecord()
|
||||
*/
|
||||
public function it_should_get_email_server_data_from_record()
|
||||
{
|
||||
$faker = $this->faker;
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$expected = $this->getDataForEmailServerRegistry();
|
||||
$expected['MESS_UID'] = $faker->regexify("/[a-zA-Z]{32}/");
|
||||
|
||||
$actual = $this->emailServer->getEmailServerDataFromRecord($expected);
|
||||
|
||||
$this->assertEquals($expected['MESS_ENGINE'], $actual['MESS_ENGINE']);
|
||||
$this->assertEquals($expected['MESS_ACCOUNT'], $actual['MESS_ACCOUNT']);
|
||||
|
||||
unset($expected['MESS_ENGINE']);
|
||||
$this->expectException(Exception::class);
|
||||
$actual = $this->emailServer->getEmailServerDataFromRecord($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test obtains the configuration record that is marked by default.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServerDefault()
|
||||
*/
|
||||
public function it_should_get_email_server_default()
|
||||
{
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$actual = $this->emailServer->getEmailServerDefault();
|
||||
$this->assertNotEmpty($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test gets the records from the "EMAIL_SERVER" table.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServers()
|
||||
*/
|
||||
public function it_should_get_email_servers()
|
||||
{
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$actual = $this->emailServer->getEmailServers();
|
||||
$this->assertNotEmpty($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test gets the records from the "EMAIL_SERVER" table with parameters.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServers()
|
||||
*/
|
||||
public function it_should_get_email_servers_with_parameters()
|
||||
{
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, null, null, null, 0);
|
||||
$this->assertEmpty($actual);
|
||||
|
||||
$faker = $this->faker;
|
||||
$actual = $this->emailServer->getEmailServers(['filter' => $faker->text]);
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, $faker->text);
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER");
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC");
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", 0);
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", 0, 10);
|
||||
$this->assertNotEmpty($actual);
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$actual = $this->emailServer->getEmailServers(null, "MESS_SERVER", "DESC", -1, -10);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test gets a record of the EMAIL_SERVER table.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServer()
|
||||
*/
|
||||
public function it_should_get_email_server()
|
||||
{
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
|
||||
$emailServerUid = $emailServer->MESS_UID;
|
||||
$actual = $this->emailServer->getEmailServer($emailServerUid);
|
||||
$this->assertNotEmpty($actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test should throw an exception when a record is not found.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\EmailServer::getEmailServer()
|
||||
*/
|
||||
public function it_should_get_email_server_when_not_exist_registry()
|
||||
{
|
||||
$faker = $this->faker;
|
||||
$this->emailServer->setContextLog([
|
||||
'workspace' => 'workflow'
|
||||
]);
|
||||
$emailServer = factory(EmailServerModel::class)->create($this->getDataForEmailServerRegistry());
|
||||
$emailServerUid = $faker->regexify("/[a-zA-Z]{32}/");
|
||||
|
||||
$this->expectException(Exception::class);
|
||||
$actual = $this->emailServer->getEmailServer($emailServerUid);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace Tests\unit\workflow\engine\src\ProcessMaker\Core;
|
||||
use G;
|
||||
use Faker\Factory;
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SystemTest extends TestCase
|
||||
@@ -19,9 +20,9 @@ class SystemTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the initLaravel method
|
||||
*
|
||||
* It tests the initLaravel method.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::initLaravel()
|
||||
*/
|
||||
public function it_should_init_laravel_configurations()
|
||||
{
|
||||
@@ -37,6 +38,32 @@ class SystemTest extends TestCase
|
||||
$this->assertEquals(DB_PASS, config('database.connections.workflow.password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* This gets the settings for sending email.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getEmailConfiguration()
|
||||
*/
|
||||
public function it_should_get_email_configuration()
|
||||
{
|
||||
$system = new System();
|
||||
|
||||
//default values
|
||||
EmailServerModel::truncate();
|
||||
$actual = $system->getEmailConfiguration();
|
||||
$this->assertEmpty($actual);
|
||||
|
||||
//new instance
|
||||
$emailServer = factory(EmailServerModel::class)->create([
|
||||
'MESS_DEFAULT' => 1
|
||||
]);
|
||||
$actual = $system->getEmailConfiguration();
|
||||
$this->assertNotEmpty($actual);
|
||||
$this->assertArrayHasKey('MESS_ENGINE', $actual);
|
||||
$this->assertArrayHasKey('OAUTH_CLIENT_ID', $actual);
|
||||
$this->assertArrayHasKey('OAUTH_CLIENT_SECRET', $actual);
|
||||
$this->assertArrayHasKey('OAUTH_REFRESH_TOKEN', $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return default system configuration parameters.
|
||||
* @test
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -86,4 +86,4 @@ class EmailServerModelTest extends TestCase
|
||||
//Assert the result es not empty
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user