PMCORE-593 Action by email: when the authentication is incorrect we can see an error in the routing page.

This commit is contained in:
Roly Rudy Gutierrez Pinto
2020-06-09 12:50:12 -04:00
parent 19c4a93f33
commit 683c69ba81
8 changed files with 925 additions and 200 deletions

View File

@@ -0,0 +1,534 @@
<?php
use ProcessMaker\Model\AbeConfiguration;
use ProcessMaker\Model\Application;
use ProcessMaker\Model\Delegation;
use ProcessMaker\Model\Dynaform;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Tests\TestCase;
class ActionsByEmailCoreClassTest extends TestCase
{
private $actionsByEmailCoreClass;
/**
* Method set up.
*/
public function setUp()
{
parent::setUp();
if (!defined('PATH_IMAGES_ENVIRONMENT_USERS')) {
define('PATH_IMAGES_ENVIRONMENT_USERS', PATH_DATA_SITE . 'usersPhotographies' . PATH_SEP);
}
$path = PATH_HOME . 'public_html' . PATH_SEP . 'lib';
if (!file_exists($path)) {
mkdir($path);
}
$path = $path . PATH_SEP . 'pmdynaform';
if (!file_exists($path)) {
mkdir($path);
}
$path = $path . PATH_SEP . 'build';
if (!file_exists($path)) {
mkdir($path);
}
$path = $path . PATH_SEP . 'pmdynaform.html';
if (!file_exists($path)) {
file_put_contents($path, '');
}
}
/**
* This test checks if the sendActionsByEmail method throws an exception.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_with_exception()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
//assertion Exception
$this->expectException(Exception::class);
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->sendActionsByEmail($data, []);
}
/**
* This test checks if the sendActionsByEmail method handles an undefined configuration.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_if_abe_configuration_is_undefined()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$abeConfiguration = [
'ABE_EMAIL_SERVER_UID' => ''
];
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$result = $this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$this->assertNull($result);
}
/**
* This test checks if the sendActionsByEmail method throws an exception if
* the task properties do not exist.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_with_exception_if_task_property_is_undefined()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => '',
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'CUSTOM',
'ABE_CUSTOM_GRID' => serialize([])
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
//assertion Exception
$this->expectException(Exception::class);
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
}
/**
* This test checks if the sendActionsByEmail method throws an exception if the
* email address is empty.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_with_exception_if_email_to_is_empty()
{
$user = factory(User::class)->create([
'USR_EMAIL' => ''
]);
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'CUSTOM',
'ABE_CUSTOM_GRID' => serialize([]),
'ABE_EMAIL_FIELD' => ''
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$result = $this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$this->assertNull($result);
}
/**
* This test checks if the sendActionsByEmail method throws an exception if
* the email type is empty.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_with_exception_if_email_type_is_empty()
{
$user = factory(User::class)->create();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => '',
'ABE_CUSTOM_GRID' => serialize([]),
'ABE_EMAIL_FIELD' => ''
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$result = $this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$this->assertNull($result);
}
/**
* This test verifies if the sendActionsByEmail method supports the 'CUSTOM' setting.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_custom()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'CUSTOM',
'ABE_CUSTOM_GRID' => serialize([])
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$result = $this->actionsByEmailCoreClass->getAbeRequest();
$this->assertArrayHasKey('ABE_REQ_UID', $result);
}
/**
* This test verifies if the sendActionsByEmail method supports the 'RESPONSE' setting.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_response()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'RESPONSE',
'ABE_CUSTOM_GRID' => serialize([]),
'ABE_EMAIL_SERVER_RECEIVER_UID' => $emailServer->MESS_UID
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$result = $this->actionsByEmailCoreClass->getAbeRequest();
$this->assertArrayHasKey('ABE_REQ_UID', $result);
}
/**
* This test verifies if the sendActionsByEmail method supports the 'FIELD' setting.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_link()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'LINK',
'ABE_CUSTOM_GRID' => serialize([]),
'ABE_EMAIL_SERVER_RECEIVER_UID' => $emailServer->MESS_UID
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$result = $this->actionsByEmailCoreClass->getAbeRequest();
$this->assertArrayHasKey('ABE_REQ_UID', $result);
}
/**
* This test verifies if the sendActionsByEmail method supports the 'FIELD' setting.
* @test
* @covers \ActionsByEmailCoreClass::sendActionsByEmail
*/
public function it_should_test_send_actions_by_email_field()
{
$user = User::where('USR_UID', '=', '00000000000000000000000000000001')
->get()
->first();
$process = factory(Process::class)->create();
$task = factory(Task::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$dynaform = factory(Dynaform::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$emailServer = factory(ProcessMaker\Model\EmailServerModel::class)->create();
$abeConfiguration = factory(AbeConfiguration::class)->create([
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'DYN_UID' => $dynaform->DYN_UID,
'ABE_EMAIL_SERVER_UID' => $emailServer->MESS_UID,
'ABE_TYPE' => 'FIELD',
'ABE_CUSTOM_GRID' => serialize([]),
'ABE_EMAIL_SERVER_RECEIVER_UID' => $emailServer->MESS_UID
]);
$abeConfiguration = $abeConfiguration->toArray();
$application = factory(Application::class)->create([
'PRO_UID' => $process->PRO_UID
]);
$delegation = factory(Delegation::class)->create([
'APP_UID' => $application->APP_UID,
'PRO_UID' => $process->PRO_UID,
'TAS_UID' => $task->TAS_UID,
'USR_UID' => $user->USR_UID
]);
$data = [
'TAS_UID' => $task->TAS_UID,
'APP_UID' => $application->APP_UID,
'DEL_INDEX' => $delegation->DEL_INDEX,
'USR_UID' => $user->USR_UID,
'PREVIOUS_USR_UID' => $user->USR_UID
];
$data = (object) $data;
$_SERVER["REQUEST_URI"] = '';
$this->actionsByEmailCoreClass = new ActionsByEmailCoreClass();
$this->actionsByEmailCoreClass->setUser($user->USR_UID);
$this->actionsByEmailCoreClass->setIndex($delegation->DEL_INDEX);
$this->actionsByEmailCoreClass->sendActionsByEmail($data, $abeConfiguration);
$result = $this->actionsByEmailCoreClass->getAbeRequest();
$this->assertArrayHasKey('ABE_REQ_UID', $result);
}
}

View File

@@ -12,7 +12,6 @@ use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use ProcessMaker\Model\UserReporting;
use ProcessMaker\Util\WsMessageResponse;
use Tests\TestCase;
/**
@@ -22,6 +21,7 @@ use Tests\TestCase;
*/
class WsBaseTest extends TestCase
{
use DatabaseTransactions;
/**
@@ -65,21 +65,20 @@ class WsBaseTest extends TestCase
*/
private function createNewCase($applicationNumber = null)
{
$userUid = G::generateUniqueID();
$processUid = G::generateUniqueID();
$applicationUid = G::generateUniqueID();
if (empty($applicationNumber)) {
$faker = Factory::create();
$applicationNumber = $faker->unique()->numberBetween(1, 10000000);
}
$userUid = G::generateUniqueID();
$processUid = G::generateUniqueID();
$taskUid = G::generateUniqueID();
$applicationUid = G::generateUniqueID();
$appData = [
'SYS_LANG' => 'en',
'SYS_SKIN' => 'neoclassic',
'SYS_SYS' => 'workflow',
'APPLICATION' => G::generateUniqueID(),
'PROCESS' => G::generateUniqueID(),
'APPLICATION' => $applicationUid,
'PROCESS' => $processUid,
'TASK' => '',
'INDEX' => 2,
'USER_LOGGED' => $userUid,
@@ -108,16 +107,9 @@ class WsBaseTest extends TestCase
]);
$result = new stdClass();
$result->userUid = $userUid;
$result->processUid = $processUid;
$result->taskUid = $taskUid;
$result->applicationUid = $applicationUid;
$result->applicationNumber = $applicationNumber;
$result->appData = $appData;
$result->application = $application;
$result->user = $user;
$result->process = $process;
$result->task = $task;
$result->application = $application;
return $result;
}
@@ -229,7 +221,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
@@ -269,7 +261,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = "";
$cc = "";
@@ -308,7 +300,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
@@ -347,7 +339,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = "";
$cc = "";
@@ -386,7 +378,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
@@ -425,7 +417,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = "";
$cc = "";
@@ -464,7 +456,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = "";
$cc = "";
@@ -644,7 +636,7 @@ class WsBaseTest extends TestCase
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->applicationUid;
$appUid = $case->application->APP_UID;
$from = $faker->email;
$to = "";
$cc = "";
@@ -659,7 +651,131 @@ class WsBaseTest extends TestCase
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields);
//assertions
$this->assertInstanceOf(WsMessageResponse::class, $result);
$this->assertInstanceOf(WsResponse::class, $result);
}
/**
* This test ensures the response when the default configuration does not exist.
* @test
* @covers WsBase::sendMessage
*/
public function it_should_test_an_send_message_without_default_configuration()
{
//data
$emailServer = $this->createEmailServer();
$case = $this->createNewCase();
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
$bcc = "";
$subject = "test";
$templateName = basename($template->PRF_PATH);
$appFields = [];
$attachment = [];
$showMessage = true;
$delIndex = 0;
$config = [];
$gmail = 0;
$appMsgType = '';
//for empty configuration
EmailServerModel::truncate();
$wsBase = new WsBase();
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType);
//assertions
$this->assertObjectHasAttribute('status_code', $result);
$this->assertObjectHasAttribute('message', $result);
$this->assertObjectHasAttribute('timestamp', $result);
$this->assertObjectHasAttribute('extraParams', $result);
$this->assertEquals(29, $result->status_code);
}
/**
* This test ensures the response when the template is not found.
* @test
* @covers WsBase::sendMessage
*/
public function it_should_test_an_send_message_missing_template()
{
//data
$emailServer = $this->createEmailServer();
$case = $this->createNewCase();
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = $case->application->APP_UID;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
$bcc = "";
$subject = "test";
$templateName = basename($template->PRF_PATH);
$appFields = [];
$attachment = [];
$showMessage = true;
$delIndex = 0;
$config = $emailServer->toArray();
$gmail = 0;
$appMsgType = '';
//for a missing template
$templateName = 'MissingFile';
G::rm_dir(PATH_DATA_SITE . 'mailTemplates');
$wsBase = new WsBase();
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType);
//assertions
$this->assertObjectHasAttribute('status_code', $result);
$this->assertObjectHasAttribute('message', $result);
$this->assertObjectHasAttribute('timestamp', $result);
$this->assertObjectHasAttribute('extraParams', $result);
$this->assertEquals(28, $result->status_code);
}
/**
* This test ensures the response when there is an exception.
* @test
* @covers WsBase::sendMessage
*/
public function it_should_test_an_send_message_when_appears_an_exception()
{
//data
$emailServer = $this->createEmailServer();
$case = $this->createNewCase();
$template = $this->createTemplate($case->process->PRO_UID, $case->user->USR_UID);
//parameters
$appUid = null;
$from = $emailServer->MESS_ACCOUNT;
$to = $emailServer->MESS_ACCOUNT;
$cc = "";
$bcc = "";
$subject = "test";
$templateName = basename($template->PRF_PATH);
$appFields = [];
$attachment = [];
$showMessage = true;
$delIndex = 0;
$config = $emailServer->toArray();
$gmail = 0;
$appMsgType = '';
$wsBase = new WsBase();
$result = $wsBase->sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $templateName, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType);
//assertions
$this->assertObjectHasAttribute('status_code', $result);
$this->assertObjectHasAttribute('message', $result);
$this->assertObjectHasAttribute('timestamp', $result);
$this->assertObjectHasAttribute('extraParams', $result);
$this->assertEquals(100, $result->status_code);
}
/**
@@ -680,7 +796,7 @@ class WsBaseTest extends TestCase
]);
$_SESSION["APPLICATION"] = $delegation->APP_UID;
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->APP_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->APP_UID);
$this->assertEquals($ws->getFlagSameCase(), true);
$this->assertNotEmpty($response);
}
@@ -695,7 +811,7 @@ class WsBaseTest extends TestCase
{
$delegation = factory(Delegation::class)->states('foreign_keys')->create();
$ws = new WsBase();
$response = (object)$ws->cancelCase('', $delegation->DE_INDEX, $delegation->URS_UID);
$response = (object) $ws->cancelCase('', $delegation->DE_INDEX, $delegation->URS_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' caseUid');
}
@@ -718,7 +834,7 @@ class WsBaseTest extends TestCase
'APP_UID' => $application->APP_UID,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' DRAFT');
@@ -732,7 +848,7 @@ class WsBaseTest extends TestCase
'APP_UID' => $application->APP_UID,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' COMPLETED');
@@ -746,7 +862,7 @@ class WsBaseTest extends TestCase
'APP_UID' => $application->APP_UID,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DE_INDEX, $delegation->URS_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_CASE_IN_STATUS") . ' CANCELLED');
}
@@ -768,7 +884,7 @@ class WsBaseTest extends TestCase
'APP_UID' => $application->APP_UID,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, '', $delegation->USR_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, '', $delegation->USR_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' delIndex');
}
@@ -791,7 +907,7 @@ class WsBaseTest extends TestCase
'DEL_THREAD_STATUS' => 'CLOSED'
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, '');
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, '');
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_CASE_DELEGATION_ALREADY_CLOSED"));
}
@@ -813,7 +929,7 @@ class WsBaseTest extends TestCase
'APP_UID' => $application->APP_UID,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, '');
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, '');
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_REQUIRED_FIELD") . ' userUid');
}
@@ -857,7 +973,7 @@ class WsBaseTest extends TestCase
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, G::LoadTranslation("ID_CASE_CANCELLED_PARALLEL"));
}
@@ -904,7 +1020,7 @@ class WsBaseTest extends TestCase
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID);
$response = (object) $ws->cancelCase($delegation->APP_UID, $delegation->DEL_INDEX, $delegation->USR_UID);
$this->assertNotEmpty($response);
$this->assertObjectHasAttribute('status_code', $response);
$this->assertEquals($response->message, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
@@ -969,7 +1085,7 @@ class WsBaseTest extends TestCase
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($delegation->APP_UID, null, null);
$response = (object) $ws->cancelCase($delegation->APP_UID, null, null);
$this->assertNotEmpty($response);
$this->assertObjectHasAttribute('status_code', $response);
$this->assertEquals($response->message, G::LoadTranslation("ID_COMMAND_EXECUTED_SUCCESSFULLY"));
@@ -1002,7 +1118,7 @@ class WsBaseTest extends TestCase
'DEL_INDEX' => 2,
]);
$ws = new WsBase();
$response = (object)$ws->cancelCase($fakeApp, $delegation->DEL_INDEX, $delegation->USR_UID);
$response = (object) $ws->cancelCase($fakeApp, $delegation->DEL_INDEX, $delegation->USR_UID);
$this->assertEquals($response->status_code, 100);
$this->assertEquals($response->message, "The Application row '$fakeApp' doesn't exist!");
}

View File

@@ -0,0 +1,86 @@
<?php
use Tests\TestCase;
class WsResponseTest extends TestCase
{
private $wsResponse;
/**
* Set up method.
*/
public function setUp()
{
parent::setUp();
}
/**
* This test get a extra param.
* @test
* @covers \WsResponse::__construct
* @covers \WsResponse::getExtraParam
*/
public function it_should_test_get_extra_param()
{
$this->wsResponse = new WsResponse(0, '');
//assert
$actual = $this->wsResponse->getExtraParam('');
$this->assertEmpty($actual);
//assert
$actual = $this->wsResponse->getExtraParam('test');
$this->assertEmpty($actual);
//assert
$expected = 'test';
$this->wsResponse->addExtraParam('test', $expected);
$actual = $this->wsResponse->getExtraParam('test');
$this->assertEquals($expected, $actual);
}
/**
* This test the add extra param.
* @test
* @covers \WsResponse::addExtraParam
*/
public function it_should_test_add_extra_param()
{
$this->wsResponse = new WsResponse(0, '');
//assert
$expected = 'test';
$this->wsResponse->addExtraParam('test', $expected);
$actual = $this->wsResponse->getExtraParam('test');
$this->assertEquals($expected, $actual);
}
/**
* This test a get payload string.
* @test
* @covers \WsResponse::getPayloadString
*/
public function it_should_test_get_payload_string()
{
$this->wsResponse = new WsResponse(0, '');
//assert
$actual = $this->wsResponse->getPayloadString('test');
$this->assertContains('test', $actual);
}
/**
* @test
* @covers \WsResponse::getPayloadArray
*/
public function it_should_test_payload_array()
{
$this->wsResponse = new WsResponse(0, '');
//assert
$actual = $this->wsResponse->getPayloadArray();
$this->assertArrayHasKey('status_code', $actual);
$this->assertArrayHasKey('message', $actual);
$this->assertArrayHasKey('timestamp', $actual);
}
}