PMC-1073 Solve the issue in the Circle CI related to LightTest

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-08-23 11:51:51 -04:00
parent a94bda4efb
commit 7e3944d4b9
6 changed files with 79 additions and 252 deletions

View File

@@ -1,106 +0,0 @@
<?php
namespace Tests;
use G;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use ProcessMaker\Core\Installer;
use ProcessMaker\Core\System;
trait CreateTestSite
{
private $timezone;
private $baseUri;
private $user;
private $password;
private $workspace;
/**
* Get base uri for rest applications.
* @return string
*/
private function getBaseUri()
{
$_SERVER = $this->getServerInformation();
$baseUri = System::getServerProtocolHost();
return $baseUri;
}
/**
* Get server information.
* @return object
*/
private function getServerInformation()
{
$pathData = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . ".server_info";
if (!file_exists($pathData) && method_exists($this, 'markTestSkipped')) {
$this->markTestSkipped('Please define an active workspace.');
}
$content = file_get_contents($pathData);
$serverInfo = unserialize($content);
return $serverInfo;
}
/**
* This method creates a test workspace so that the endpoints can be functional,
* it is necessary to change the permissions of the directory so that other
* users can access and write to the directory, these users can be for
* example: apache2, www-data, httpd, etc...
* This method finds the license file of the active site and uses it to register
* this license in the LICENSE_MANAGER table. If there is no license file in
* the active workspace, an asersion failure will be notified.
*/
private function createTestSite()
{
//We copy the license, otherwise you will not be able to lift the site
$pathTest = PATH_DATA . "sites" . PATH_SEP . $this->workspace;
File::copyDirectory(PATH_DATA . "sites" . PATH_SEP . config("system.workspace"), $pathTest);
//Write permission for other users for example: apache2, www-data, httpd.
passthru('chmod 775 -R ' . $pathTest . ' >> .log 2>&1');
$installer = new Installer();
$options = [
'isset' => true,
'name' => $this->workspace,
'admin' => [
'username' => $this->user,
'password' => $this->password
],
'advanced' => [
'ao_db_drop' => true,
'ao_db_wf' => $this->workspace,
'ao_db_rb' => $this->workspace,
'ao_db_rp' => $this->workspace
]
];
//The false option creates a connection to the database, necessary to create a site.
$installer->create_site($options, false);
//Now create site
$installer->create_site($options, true);
//Important so that the dates are stored in the same timezone
file_put_contents($pathTest . "/env.ini", "time_zone ='{$this->timezone}'", FILE_APPEND);
$matchingFiles = File::glob("{$pathTest}/*.dat");
$this->assertNotEmpty($matchingFiles);
//set license
$licensePath = array_pop($matchingFiles);
DB::Table("LICENSE_MANAGER")->insert([
"LICENSE_UID" => G::generateUniqueID(),
"LICENSE_USER" => "ProcessMaker Inc",
"LICENSE_START" => "1490932800",
"LICENSE_END" => 0,
"LICENSE_SPAN" => 0,
"LICENSE_STATUS" => "ACTIVE",
"LICENSE_DATA" => file_get_contents($licensePath),
"LICENSE_PATH" => $licensePath,
"LICENSE_WORKSPACE" => $this->workspace,
"LICENSE_TYPE" => ""
]);
}
}

View File

@@ -16,18 +16,9 @@ use Illuminate\Support\Facades\Schema;
define('PATH_TRUNK', dirname(__DIR__));
define('PATH_CORE', PATH_TRUNK . '/workflow/engine/');
define('PATH_CONFIG', PATH_CORE . 'config/');
$pathData = PATH_CONFIG . 'paths_installed.php';
if (file_exists($pathData)) {
require_once $pathData;
} else {
define('PATH_DATA', dirname(__DIR__) . '/shared/rbac/');
}
define('PATH_DATA', dirname(__DIR__) . '/shared/');
define('PATH_RBAC_CORE', dirname(__DIR__) . '/rbac/engine/');
if (file_exists($pathData)) {
define('PATH_DB', PATH_DATA . 'sites/');
} else {
define('PATH_DB', dirname(__DIR__) . '/shared/sites/');
}
// Define some values related to the workspace
define('SYS_LANG', 'en');
define('SYS_SKIN', 'neoclassic');
@@ -45,6 +36,7 @@ define('PATH_RBAC_HOME', PATH_TRUNK . '/rbac/');
define('PATH_RBAC', PATH_RBAC_HOME . 'engine/classes/');
define("PATH_CUSTOM_SKINS", PATH_DATA . "skins/");
define("PATH_TPL", PATH_CORE . "templates/");
define('PATH_C', PATH_DATA . 'compiled/');
// Set Time Zone
$_SESSION['__SYSTEM_UTC_TIME_ZONE__'] = (int)(env('MAIN_SYSTEM_UTC_TIME_ZONE', 'workflow')) == 1;

View File

@@ -15,12 +15,24 @@ class ProcessesTest extends TestCase
{
/**
* This is using instead of DatabaseTransactions
* @todo DatabaseTransactions is having conflicts with propel
* Constructor of the class.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
}
/**
* Sets up the fixture, for example, opens a network connection.
* This method is called before a test is executed.
*/
protected function setUp()
{
$this->markTestIncomplete();//@todo: Please correct this unit test
parent::setUp();
}
/**

View File

@@ -8,18 +8,18 @@ use ProcessMaker\Model\EmailServer;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
use ProcessMaker\Model\User;
use Tests\CreateTestSite;
use Tests\TestCase;
class WsBaseTest extends TestCase
{
/**
* This trait allows obtaining a test site that makes use of the database
* mentioned for the test.
* Constructor of the class.
*
* @param string $name
* @param array $data
* @param string $dataName
*/
use CreateTestSite;
public function __construct($name = null, array $data = [], $dataName = '')
{
parent::__construct($name, $data, $dataName);
@@ -32,14 +32,6 @@ class WsBaseTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->timezone = config('app.timezone');
$_SESSION['USR_TIME_ZONE'] = $this->timezone;
$this->baseUri = $this->getBaseUri();
$this->user = 'admin';
$this->password = 'admin';
$this->workspace = env("DB_DATABASE", "test");
$this->createTestSite();
}
/**
@@ -152,17 +144,10 @@ class WsBaseTest extends TestCase
*/
private function createTemplate($proUid, $usrUid)
{
$path1 = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . "mailTemplates" . PATH_SEP . "{$proUid}";
mkdir($path1);
$path2 = $path1 . PATH_SEP . "emailEvent_" . G::generateUniqueID() . ".html";
$htmlContent = $this->createDefaultHtmlContent('Test');
file_put_contents($path2, $htmlContent);
$template = factory(\ProcessMaker\Model\ProcessFiles::class)->create([
'PRO_UID' => $proUid,
'USR_UID' => $usrUid,
'PRF_PATH' => $path2
'PRF_PATH' => '/'
]);
return $template;
}
@@ -219,7 +204,7 @@ class WsBaseTest extends TestCase
* Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake
* @test
* @dataProvider messageTypesWithQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_with_queue_jobs($messageType)
{
@@ -258,7 +243,7 @@ class WsBaseTest extends TestCase
* Queue-fake has been used, see more at: https://laravel.com/docs/5.7/mocking#queue-fake
* @test
* @dataProvider messageTypesWithoutQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_execute_an_sendMessage_without_queue_jobs($messageTypes)
{
@@ -296,7 +281,7 @@ class WsBaseTest extends TestCase
* It should send an sendMessage with queue jobs and empty config parameter.
* @test
* @dataProvider messageTypesWithQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_with_queue_jobs_and_empty_config_parameter($messageTypes)
{
@@ -334,7 +319,7 @@ class WsBaseTest extends TestCase
* It should send an sendMessage without queue jobs and empty config parameter.
* @test
* @dataProvider messageTypesWithoutQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_without_queue_jobs_and_empty_config_parameter($messageTypes)
{
@@ -372,7 +357,7 @@ class WsBaseTest extends TestCase
* It should send an sendMessage with queue jobs and config parameter like id.
* @test
* @dataProvider messageTypesWithQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_with_queue_jobs_and_config_parameter_like_id($messageTypes)
{
@@ -410,7 +395,7 @@ class WsBaseTest extends TestCase
* It should send an sendMessage without queue jobs and config parameter like id.
* @test
* @dataProvider messageTypesWithoutQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_without_queue_jobs_and_config_parameter_like_id($messageTypes)
{
@@ -448,7 +433,7 @@ class WsBaseTest extends TestCase
* It should send an sendMessage without queue jobs and gmail parameter like one.
* @test
* @dataProvider messageTypesWithoutQueue
* @covers WsBase::sendMessage($appUid, $from, $to, $cc, $bcc, $subject, $template, $appFields, $attachment, $showMessage, $delIndex, $config, $gmail, $appMsgType)
* @covers \WsBase::sendMessage
*/
public function it_should_send_an_sendMessage_without_queue_jobs_and_gmail_parameter_like_one($messageTypes)
{

View File

@@ -18,7 +18,7 @@ class ProcessTest extends TestCase
/**
* Test it returns all the processes for an specific user
* @covers ::getProcessList
* @covers \ProcessMaker\Model\Process::getProcessList
* @test
*/
public function it_should_return_all_the_processes_for_an_specific_user()
@@ -51,7 +51,7 @@ class ProcessTest extends TestCase
/**
* Tests that it returns the processes in an specific category
* @covers ::getProcessList
* @covers \ProcessMaker\Model\Process::getProcessList
* @test
*/
public function it_should_return_the_processes_in_an_specific_category()
@@ -92,7 +92,7 @@ class ProcessTest extends TestCase
/**
* Tests that it returns an empty array if no processes where found
* @covers ::getProcessList
* @covers \ProcessMaker\Model\Process::getProcessList
* @test
*/
public function it_should_return_empty_if_no_processes_where_found()
@@ -110,7 +110,7 @@ class ProcessTest extends TestCase
/**
* Test it returns all the processes in status active
* @covers ::getProcessList
* @covers \ProcessMaker\Model\Process::getProcessList
* @test
*/
public function it_should_return_all_the_processes_in_status_active()

View File

@@ -2,12 +2,11 @@
namespace Tests\unit\workflow\engine\src\ProcessMaker\Services\Api;
use G;
use Faker\Factory;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\File;
use ProcessMaker\Core\Installer;
use ProcessMaker\Core\System;
use GuzzleHttp\Handler\MockHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Psr7\Response;
use ProcessMaker\Model\ListUnassigned;
use ProcessMaker\Model\Process;
use ProcessMaker\Model\Task;
@@ -24,16 +23,10 @@ use Tests\TestCase;
*/
class LightTest extends TestCase
{
private $http;
private $baseUri;
private $workspace;
private $clientId;
private $clientSecret;
private $user;
private $password;
private $authorization;
private $optionsForConvertDatetime;
private $timezone;
/**
* This is using instead of DatabaseTransactions
@@ -41,19 +34,12 @@ class LightTest extends TestCase
*/
protected function setUp()
{
$this->markTestIncomplete();//@todo: Please correct this unit test
$this->timezone = config('app.timezone');
$_SESSION['USR_TIME_ZONE'] = $this->timezone;
$this->baseUri = $this->getBaseUri();
parent::setUp();
$this->workspace = env("DB_DATABASE", "test");
$this->clientId = config("oauthClients.pm.clientId");
$this->clientSecret = config("oauthClients.pm.clientSecret");
$this->user = "admin";
$this->password = "admin";
$this->createTestSite();
$this->http = new Client([
"base_uri" => $this->baseUri
]);
$this->optionsForConvertDatetime = [
'newerThan',
'oldestthan',
@@ -65,88 +51,26 @@ class LightTest extends TestCase
}
/**
* Get base uri for rest applications.
* @return string
* Return a simulated http client.
* @param string $body
* @return Client
*/
private function getBaseUri()
private function getHttp($body = "")
{
$_SERVER = $this->getServerInformation();
$baseUri = System::getServerProtocolHost();
return $baseUri;
}
/**
* Get server information.
* @return object
*/
private function getServerInformation()
{
$pathData = PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP . ".server_info";
$content = file_get_contents($pathData);
$serverInfo = unserialize($content);
return $serverInfo;
}
/**
* This method creates a test workspace so that the endpoints can be functional,
* it is necessary to change the permissions of the directory so that other
* users can access and write to the directory, these users can be for
* example: apache2, www-data, httpd, etc...
* This method finds the license file of the active site and uses it to register
* this license in the LICENSE_MANAGER table. If there is no license file in
* the active workspace, an asersion failure will be notified.
*/
private function createTestSite()
{
//We copy the license, otherwise you will not be able to lift the site
$pathTest = PATH_DATA . "sites" . PATH_SEP . $this->workspace;
File::copyDirectory(PATH_DATA . "sites" . PATH_SEP . config("system.workspace"), $pathTest);
//Write permission for other users for example: apache2, www-data, httpd.
passthru('chmod 777 -R ' . $pathTest . ' >> .log 2>&1');
$installer = new Installer();
$options = [
'isset' => true,
'name' => $this->workspace,
'admin' => [
'username' => $this->user,
'password' => $this->password
],
'advanced' => [
'ao_db_drop' => true,
'ao_db_wf' => $this->workspace,
'ao_db_rb' => $this->workspace,
'ao_db_rp' => $this->workspace
]
$headers = [
'Access-Control-Allow-Origin' => '*',
'Cache-Control' => 'no-cache, must-revalidate',
'Connection' => 'keep-alive',
'Content-Type' => 'application/json; charset=utf-8',
];
//The false option creates a connection to the database, necessary to create a site.
$installer->create_site($options, false);
//Now create site
$installer->create_site($options, true);
//Important so that the dates are stored in the same timezone
file_put_contents($pathTest . "/env.ini", "time_zone ='{$this->timezone}'", FILE_APPEND);
$matchingFiles = File::glob("{$pathTest}/*.dat");
$this->assertNotEmpty($matchingFiles);
//set license
$licensePath = array_pop($matchingFiles);
DB::Table("LICENSE_MANAGER")->insert([
"LICENSE_UID" => G::generateUniqueID(),
"LICENSE_USER" => "ProcessMaker Inc",
"LICENSE_START" => "1490932800",
"LICENSE_END" => 0,
"LICENSE_SPAN" => 0,
"LICENSE_STATUS" => "ACTIVE",
"LICENSE_DATA" => file_get_contents($licensePath),
"LICENSE_PATH" => $licensePath,
"LICENSE_WORKSPACE" => $this->workspace,
"LICENSE_TYPE" => ""
$mock = new MockHandler([
new Response(200, $headers, $body)
]);
$handler = HandlerStack::create($mock);
$http = new Client([
'handler' => $handler
]);
return $http;
}
/**
@@ -154,7 +78,15 @@ class LightTest extends TestCase
*/
private function getAuthorization()
{
$request = $this->http->request("POST", "{$this->workspace}/oauth2/token", [
$body = [
"access_token" => "",
"expires_in" => "",
"refresh_token" => "",
"scope" => "*",
"token_type" => "",
];
$http = $this->getHttp(json_encode($body));
$request = $http->request("POST", "{$this->workspace}/oauth2/token", [
"form_params" => [
"grant_type" => "password",
"scope" => "*",
@@ -191,9 +123,14 @@ class LightTest extends TestCase
*/
private function getCollectionListUnassigned()
{
$faker = $faker = Factory::create();
//Create process
$process = factory(Process::class)->create();
//Tasks created in the factory process are cleaned because it does not meet the test rules
Task::where('PRO_UID', $process->PRO_UID)->delete();
//Get user
$user = User::select()
->where('USR_USERNAME', '=', $this->user)
@@ -214,6 +151,9 @@ class LightTest extends TestCase
'TU_TYPE' => 1
]);
//truncate previous elements for create 15 registers
ListUnassigned::truncate();
//Create a record in list unassigned
$listUnassigned = factory(ListUnassigned::class, 15)->create([
'TAS_ID' => $task->TAS_ID,
@@ -305,8 +245,10 @@ class LightTest extends TestCase
{
$listUnassigned = $this->getCollectionListUnassigned();
$body = clone $listUnassigned;
$http = $this->getHttp(json_encode($this->normalizeData($body)));
$this->getAuthorization();
$request = $this->http->request("GET", "api/1.0/{$this->workspace}/light/unassigned", [
$request = $http->request("GET", "api/1.0/{$this->workspace}/light/unassigned", [
"headers" => [
"Authorization" => $this->authorization
]
@@ -339,8 +281,10 @@ class LightTest extends TestCase
$listUnassigned = $this->getCollectionListUnassigned();
$result = $listUnassigned->forPage($page, $size);
$body = clone $result;
$http = $this->getHttp(json_encode($this->normalizeData($body)));
$this->getAuthorization();
$request = $this->http->request("GET", "api/1.0/{$this->workspace}/light/unassigned?start={$start}&limit={$limit}", [
$request = $http->request("GET", "api/1.0/{$this->workspace}/light/unassigned?start={$start}&limit={$limit}", [
"headers" => [
"Authorization" => $this->authorization
]