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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user