PMC-1378 Create/Fix unit tests for the feature "GMail API email server"
This commit is contained in:
37
database/factories/AppMessageFactory.php
Normal file
37
database/factories/AppMessageFactory.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
use Faker\Generator as Faker;
|
||||
|
||||
$factory->define(\ProcessMaker\Model\AppMessage::class, function(Faker $faker) {
|
||||
return [
|
||||
'APP_MSG_UID' => G::generateUniqueID(),
|
||||
'MSG_UID' => '',
|
||||
'APP_UID' => function() {
|
||||
return factory(\ProcessMaker\Model\Application::class)->create()->APP_UID;
|
||||
},
|
||||
'DEL_INDEX' => 1,
|
||||
'APP_MSG_TYPE' => 'ROUTING',
|
||||
'APP_MSG_TYPE_ID' => 0,
|
||||
'APP_MSG_SUBJECT' => $faker->title,
|
||||
'APP_MSG_FROM' => $faker->email,
|
||||
'APP_MSG_TO' => $faker->email,
|
||||
'APP_MSG_BODY' => $faker->text,
|
||||
'APP_MSG_DATE' => $faker->dateTime(),
|
||||
'APP_MSG_CC' => '',
|
||||
'APP_MSG_BCC' => '',
|
||||
'APP_MSG_TEMPLATE' => '',
|
||||
'APP_MSG_STATUS' => 'pending',
|
||||
'APP_MSG_STATUS_ID' => 1,
|
||||
'APP_MSG_ATTACH' => '',
|
||||
'APP_MSG_SEND_DATE' => $faker->dateTime(),
|
||||
'APP_MSG_SHOW_MESSAGE' => 1,
|
||||
'APP_MSG_ERROR' => '',
|
||||
'PRO_ID' => function() {
|
||||
return factory(\ProcessMaker\Model\Process::class)->create()->PRO_ID;
|
||||
},
|
||||
'TAS_ID' => function() {
|
||||
return factory(\ProcessMaker\Model\Task::class)->create()->TAS_ID;
|
||||
},
|
||||
'APP_NUMBER' => 1
|
||||
];
|
||||
});
|
||||
@@ -5,7 +5,7 @@ use Faker\Generator as Faker;
|
||||
$factory->define(\ProcessMaker\Model\EmailServerModel::class, function(Faker $faker) {
|
||||
return [
|
||||
'MESS_UID' => G::generateUniqueID(),
|
||||
'MESS_ENGINE' => '',
|
||||
'MESS_ENGINE' => 'MAIL',
|
||||
'MESS_SERVER' => '',
|
||||
'MESS_PORT' => 0,
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
@@ -19,5 +19,96 @@ $factory->define(\ProcessMaker\Model\EmailServerModel::class, function(Faker $fa
|
||||
'MESS_TRY_SEND_INMEDIATLY' => 0,
|
||||
'MAIL_TO' => '',
|
||||
'MESS_DEFAULT' => 0,
|
||||
'OAUTH_CLIENT_ID' => '',
|
||||
'OAUTH_CLIENT_SECRET' => '',
|
||||
'OAUTH_REFRESH_TOKEN' => ''
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'PHPMAILER', function ($faker) {
|
||||
return [
|
||||
'MESS_UID' => G::generateUniqueID(),
|
||||
'MESS_ENGINE' => 'PHPMAILER',
|
||||
'MESS_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
'MESS_INCOMING_PORT' => 0,
|
||||
'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' => 0,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 0,
|
||||
'OAUTH_CLIENT_ID' => '',
|
||||
'OAUTH_CLIENT_SECRET' => '',
|
||||
'OAUTH_REFRESH_TOKEN' => ''
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'IMAP', function ($faker) {
|
||||
return [
|
||||
'MESS_UID' => G::generateUniqueID(),
|
||||
'MESS_ENGINE' => 'IMAP',
|
||||
'MESS_PORT' => $faker->numberBetween(400, 500),
|
||||
'MESS_INCOMING_SERVER' => 'imap.' . $faker->domainName,
|
||||
'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' => 0,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 0,
|
||||
'OAUTH_CLIENT_ID' => '',
|
||||
'OAUTH_CLIENT_SECRET' => '',
|
||||
'OAUTH_REFRESH_TOKEN' => ''
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'GMAILAPI', function ($faker) {
|
||||
return [
|
||||
'MESS_UID' => G::generateUniqueID(),
|
||||
'MESS_ENGINE' => 'GMAILAPI',
|
||||
'MESS_PORT' => 0,
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
'MESS_INCOMING_PORT' => 0,
|
||||
'MESS_RAUTH' => 1,
|
||||
'MESS_ACCOUNT' => $faker->email,
|
||||
'MESS_PASSWORD' => '',
|
||||
'MESS_FROM_MAIL' => $faker->email,
|
||||
'MESS_FROM_NAME' => $faker->name,
|
||||
'SMTPSECURE' => 'No',
|
||||
'MESS_TRY_SEND_INMEDIATLY' => 0,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 0,
|
||||
'OAUTH_CLIENT_ID' => $faker->regexify("/[0-9]{12}-[a-z]{32}\.apps\.googleusercontent\.com/"),
|
||||
'OAUTH_CLIENT_SECRET' => $faker->regexify("/[a-z]{24}/"),
|
||||
'OAUTH_REFRESH_TOKEN' => $faker->regexify("/[a-z]{7}[a-zA-Z0-9]{355}==/")
|
||||
];
|
||||
});
|
||||
|
||||
$factory->state(\ProcessMaker\Model\EmailServerModel::class, 'OPENMAIL', function ($faker) {
|
||||
return [
|
||||
'MESS_UID' => G::generateUniqueID(),
|
||||
'MESS_ENGINE' => 'OPENMAIL',
|
||||
'MESS_PORT' => 0,
|
||||
'MESS_INCOMING_SERVER' => '',
|
||||
'MESS_INCOMING_PORT' => 0,
|
||||
'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' => 0,
|
||||
'MAIL_TO' => $faker->email,
|
||||
'MESS_DEFAULT' => 0,
|
||||
'OAUTH_CLIENT_ID' => '',
|
||||
'OAUTH_CLIENT_SECRET' => '',
|
||||
'OAUTH_REFRESH_TOKEN' => ''
|
||||
];
|
||||
});
|
||||
|
||||
@@ -633,7 +633,7 @@ class G
|
||||
|
||||
try {
|
||||
$file = G::ExpandPath('skinEngine') . 'skinEngine.php';
|
||||
include $file;
|
||||
include_once $file;
|
||||
$skinEngine = new SkinEngine($G_TEMPLATE, $G_SKIN, $G_CONTENT);
|
||||
$skinEngine->setLayout($layout);
|
||||
$skinEngine->dispatch();
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
<directory suffix=".php">./gulliver</directory>
|
||||
<directory suffix=".php">./workflow/engine/classes</directory>
|
||||
<directory suffix=".php">./workflow/engine/src</directory>
|
||||
<directory suffix=".php">./workflow/engine/methods/emailServer/</directory>
|
||||
</whitelist>
|
||||
<exclude>
|
||||
<directory>./workflow/engine/classes/model/map</directory>
|
||||
|
||||
31
tests/unit/gulliver/system/rbacTest.php
Normal file
31
tests/unit/gulliver/system/rbacTest.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\gulliver\system;
|
||||
|
||||
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
||||
use G;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class rbacTest extends TestCase
|
||||
{
|
||||
use DatabaseTransactions;
|
||||
|
||||
/**
|
||||
* This tests the initialization of values.
|
||||
* @test
|
||||
* @covers \RBAC::__construct()
|
||||
*/
|
||||
public function it_should_initialize_properties_for_gmail_oauth()
|
||||
{
|
||||
$rbac = new RBAC();
|
||||
$authorizedActions = $rbac->authorizedActions;
|
||||
|
||||
$this->assertArrayHasKey("emailServerGmailOAuth.php", $authorizedActions);
|
||||
|
||||
$subset = [
|
||||
'code' => ['PM_SETUP']
|
||||
];
|
||||
$this->assertContains($subset, $authorizedActions);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,14 @@
|
||||
<?php
|
||||
|
||||
use Faker\Factory;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use ProcessMaker\Model\AppMessage;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SpoolRunTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Constructor of the class.
|
||||
*/
|
||||
@@ -16,7 +20,7 @@ class SpoolRunTest extends TestCase
|
||||
/**
|
||||
* Check if "envelope_cc" and "envelope_bcc" was set correctly in consecutive calls
|
||||
*
|
||||
* @covers SpoolRun::setData()
|
||||
* @covers \SpoolRun::setData()
|
||||
*
|
||||
* @test
|
||||
*/
|
||||
@@ -30,14 +34,14 @@ class SpoolRunTest extends TestCase
|
||||
|
||||
// Set a first set of data
|
||||
$spoolRun->setData(
|
||||
G::generateUniqueID(),
|
||||
$faker->words(3, true),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
G::generateUniqueID(),
|
||||
$faker->words(3, true),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
|
||||
// Build the "to", "cc" an "bcc" values
|
||||
@@ -45,14 +49,14 @@ class SpoolRunTest extends TestCase
|
||||
|
||||
// Set a second set of data
|
||||
$spoolRun->setData(
|
||||
G::generateUniqueID(),
|
||||
$faker->words(3, true),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
G::generateUniqueID(),
|
||||
$faker->words(3, true),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
|
||||
// Build the "to", "cc" an "bcc" values
|
||||
@@ -66,4 +70,302 @@ class SpoolRunTest extends TestCase
|
||||
$this->assertCount(1, $fileData['envelope_cc']);
|
||||
$this->assertCount(1, $fileData['envelope_bcc']);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test uses the GMAILAPI option in a simple way.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_gmail_oauth_option()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('GMAILAPI')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
$config['SMTPSecure'] = 'ssl';
|
||||
|
||||
$faker = Factory::create();
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test uses the MAIL option in a simple way.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_mail_option()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->create();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
|
||||
$faker = Factory::create();
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test uses the PHPMAILER option in a simple way.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_php_mailer_option()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
$config['SMTPSecure'] = 'ssl';
|
||||
|
||||
$faker = Factory::create();
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test uses the OPENMAIL option in a simple way.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_open_mail_option()
|
||||
{
|
||||
$this->markTestIncomplete("The OPENMAIL depends on the package class but this is not found in the environment.");
|
||||
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('OPENMAIL')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
|
||||
$faker = Factory::create();
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that characters that are not utf8 are converted properly,
|
||||
* for subject and body fields.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_utf8_characters()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
$config['SMTPSecure'] = 'ssl';
|
||||
|
||||
$faker = Factory::create();
|
||||
$subject = "\xf8foo";
|
||||
$body = "\xf8foo\xf8foo";
|
||||
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$subject,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$body,
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verifies the sending of attachments to the email.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_attachment_files()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
$config['SMTPSecure'] = 'ssl';
|
||||
|
||||
$faker = Factory::create();
|
||||
|
||||
$file1 = UploadedFile::fake()->image('avatar.jpg', 400, 300);
|
||||
$file2 = UploadedFile::fake()->create('document.pdf', 200);
|
||||
|
||||
$files = [
|
||||
$file1->path(),
|
||||
$file2->path()
|
||||
];
|
||||
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->companyEmail,
|
||||
$faker->freeEmail,
|
||||
'',
|
||||
$files
|
||||
);
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that the EnvelopeTo field process is working.
|
||||
* @test
|
||||
* @covers \SpoolRun::__construct()
|
||||
* @covers \SpoolRun::setData()
|
||||
* @covers \SpoolRun::runHandleEnvelopeTo()
|
||||
* @covers \SpoolRun::handleEnvelopeTo()
|
||||
* @covers \SpoolRun::setConfig()
|
||||
* @covers \SpoolRun::sendMail()
|
||||
* @covers \SpoolRun::handleMail()
|
||||
*/
|
||||
public function it_should_handle_envelope_to()
|
||||
{
|
||||
$appMsgUid = G::generateUniqueID();
|
||||
factory(AppMessage::class)->create([
|
||||
'APP_MSG_UID' => $appMsgUid
|
||||
]);
|
||||
|
||||
$emailServer = factory(EmailServerModel::class)->states('PHPMAILER')->make();
|
||||
|
||||
$config = $emailServer->toArray();
|
||||
$config['SMTPSecure'] = 'ssl';
|
||||
|
||||
$faker = Factory::create();
|
||||
$spoolRun = new SpoolRun();
|
||||
$spoolRun->setData(
|
||||
$appMsgUid,
|
||||
$faker->title,
|
||||
$faker->name . "<" . $faker->companyEmail . "," . $faker->companyEmail . ">",
|
||||
$faker->name . "<" . $faker->freeEmail . "," . $faker->freeEmail . ">",
|
||||
$faker->text(),
|
||||
$faker->dateTime()->format('Y-m-d H:i:s'),
|
||||
$faker->name . "<" . $faker->companyEmail . "," . $faker->companyEmail . ">",
|
||||
$faker->name . "<" . $faker->freeEmail . "," . $faker->freeEmail . ">"
|
||||
);
|
||||
$spoolRun->runHandleEnvelopeTo();
|
||||
$spoolRun->setConfig($config);
|
||||
|
||||
$expected = $spoolRun->sendMail();
|
||||
|
||||
$this->assertTrue($expected);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,46 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\methods\emailServer;
|
||||
|
||||
use Faker\Factory;
|
||||
use Google_Auth_Exception;
|
||||
use ProcessMaker\GmailOAuth\GmailOAuth;
|
||||
use ProcessMaker\Model\User;
|
||||
use RBAC;
|
||||
use Tests\TestCase;
|
||||
|
||||
class EmailServerGmailOAuthTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* This test expects an exception from the Google client.
|
||||
* 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}/");
|
||||
|
||||
$this->expectException(Google_Auth_Exception::class);
|
||||
require_once PATH_METHODS . 'emailServer/emailServerGmailOAuth.php';
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,24 @@
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Core;
|
||||
|
||||
use ProcessMaker\Core\System;
|
||||
use ProcessMaker\Model\EmailServerModel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class SystemTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* Define the required variables
|
||||
*/
|
||||
protected function setUp()
|
||||
public function setUp()
|
||||
{
|
||||
$this->markTestIncomplete();//@todo: Please correct this unit test
|
||||
$config = config('database.connections.testexternal');
|
||||
define('DB_HOST', $config['host']);
|
||||
define('DB_NAME', $config['database']);
|
||||
define('DB_USER', $config['username']);
|
||||
define('DB_PASS', $config['password']);
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
/**
|
||||
* It tests the initLaravel method
|
||||
*
|
||||
* It tests the initLaravel method.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::initLaravel()
|
||||
*/
|
||||
public function it_should_init_laravel_configurations()
|
||||
{
|
||||
@@ -36,4 +33,30 @@ class SystemTest extends TestCase
|
||||
$this->assertEquals(DB_USER, config('database.connections.workflow.username'));
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,4 +86,4 @@ class EmailServerModelTest extends TestCase
|
||||
//Assert the result es not empty
|
||||
$this->assertNotEmpty($res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
12
workflow/engine/src/ProcessMaker/Model/AppMessage.php
Normal file
12
workflow/engine/src/ProcessMaker/Model/AppMessage.php
Normal file
@@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace ProcessMaker\Model;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class AppMessage extends Model
|
||||
{
|
||||
protected $table = 'APP_MESSAGE';
|
||||
public $timestamps = false;
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user