PMC-1306 Add new attribute mobile_offline_tables_download_interval related to the env.ini configuration
This commit is contained in:
@@ -32,6 +32,7 @@ define('PMTABLE_KEY', 'pmtable');
|
||||
define('DB_ADAPTER', 'mysql');
|
||||
// Path related some specific directories
|
||||
define('PATH_SEP', '/');
|
||||
define("PATH_PLUGINS", PATH_CORE . "plugins" . PATH_SEP);
|
||||
define('PATH_WORKSPACE', PATH_TRUNK . '/shared/sites/' . SYS_SYS . '/');
|
||||
define('PATH_METHODS', dirname(__DIR__) . '/workflow/engine/methods/');
|
||||
define('PATH_WORKFLOW_MYSQL_DATA', PATH_TRUNK . '/workflow/engine/data/mysql/');
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\BusinessModel;
|
||||
|
||||
use Faker\Factory;
|
||||
use ProcessMaker\BusinessModel\Light;
|
||||
use Tests\TestCase;
|
||||
|
||||
class LightTest extends TestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* This verifies that the mobile_offline_tables_download_interval parameter
|
||||
* is defined in the result returned by the getConfiguration() method.
|
||||
*
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\Light::getConfiguration
|
||||
*/
|
||||
public function it_should_return_mobile_offline_tables_download_interval_from_get_configuration_method()
|
||||
{
|
||||
$param = [
|
||||
'fileLimit' => true,
|
||||
'tz' => true,
|
||||
];
|
||||
$light = new Light();
|
||||
|
||||
/**
|
||||
* In the getConfiguration() method, the next section:
|
||||
*
|
||||
* $postMaxSize = $this->return_bytes(ini_get('post_max_size'));
|
||||
* $uploadMaxFileSize = $this->return_bytes(ini_get('upload_max_filesize'));
|
||||
* if ($postMaxSize < $uploadMaxFileSize) {
|
||||
* $uploadMaxFileSize = $postMaxSize;
|
||||
* }
|
||||
*
|
||||
* It can only be tested if you change the values of "post_max_size" and "upload_max_filesize"
|
||||
* in php.ini, you can't use the ini_set() function.
|
||||
* The mode change of these directives is "PHP_INI_PERDIR", where is entry can be
|
||||
* set in php.ini, .htaccess, httpd.conf or .user.ini, see here:
|
||||
* https://www.php.net/manual/es/ini.list.php
|
||||
* https://www.php.net/manual/en/configuration.changes.modes.php
|
||||
*/
|
||||
$result = $light->getConfiguration($param);
|
||||
|
||||
$this->assertArrayHasKey('mobile_offline_tables_download_interval', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the value of mobile_offline_tables_download_interval
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\Light::getConfiguration
|
||||
*/
|
||||
public function this_should_return_mobile_offline_tables_download_interval_inside_env()
|
||||
{
|
||||
$oldContent = "";
|
||||
$path = PATH_CONFIG . "env.ini";
|
||||
if (file_exists($path)) {
|
||||
$oldContent = file_get_contents($path);
|
||||
}
|
||||
|
||||
$expected = 30;
|
||||
|
||||
$content = "mobile_offline_tables_download_interval = {$expected};";
|
||||
file_put_contents($path, $content);
|
||||
|
||||
$light = new Light();
|
||||
$result = $light->getConfiguration([]);
|
||||
$actual = $result['mobile_offline_tables_download_interval'];
|
||||
|
||||
file_put_contents($path, $oldContent);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* This returns the default value of mobile_offline_tables_download_interval.
|
||||
* @test
|
||||
* @covers \ProcessMaker\BusinessModel\Light::getConfiguration
|
||||
*/
|
||||
public function this_should_return_default_value_if_mobile_offline_tables_download_interval_inside_env_is_not_an_integer()
|
||||
{
|
||||
$oldContent = "";
|
||||
$path = PATH_CONFIG . "env.ini";
|
||||
if (file_exists($path)) {
|
||||
$oldContent = file_get_contents($path);
|
||||
}
|
||||
|
||||
$faker = $faker = Factory::create();
|
||||
$alphanumeric = $faker->regexify('[A-Za-z0-9]{20}');
|
||||
$content = "mobile_offline_tables_download_interval = '{$alphanumeric}';";
|
||||
file_put_contents($path, $content);
|
||||
|
||||
$light = new Light();
|
||||
$result = $light->getConfiguration([]);
|
||||
$expected = (string) $result['mobile_offline_tables_download_interval'];
|
||||
|
||||
file_put_contents($path, $oldContent);
|
||||
|
||||
$this->assertTrue(ctype_digit($expected));
|
||||
}
|
||||
}
|
||||
@@ -2,22 +2,20 @@
|
||||
|
||||
namespace Tests\unit\workflow\engine\src\ProcessMaker\Core;
|
||||
|
||||
use G;
|
||||
use Faker\Factory;
|
||||
use ProcessMaker\Core\System;
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -27,6 +25,8 @@ class SystemTest extends TestCase
|
||||
*/
|
||||
public function it_should_init_laravel_configurations()
|
||||
{
|
||||
$this->markTestIncomplete("@todo: Please correct this unit test");
|
||||
|
||||
$object = new System();
|
||||
$object->initLaravel();
|
||||
|
||||
@@ -36,4 +36,112 @@ class SystemTest extends TestCase
|
||||
$this->assertEquals(DB_USER, config('database.connections.workflow.username'));
|
||||
$this->assertEquals(DB_PASS, config('database.connections.workflow.password'));
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return default system configuration parameters.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getSystemConfiguration()
|
||||
*/
|
||||
public function it_should_return_default_system_configuration_parameters()
|
||||
{
|
||||
$result = System::getSystemConfiguration();
|
||||
|
||||
$this->assertArrayHasKey('server_hostname_requests_frontend', $result);
|
||||
$this->assertArrayHasKey('disable_php_upload_execution', $result);
|
||||
$this->assertArrayHasKey('mobile_offline_tables_download_interval', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return default system configuration parameters without workspace.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getSystemConfiguration()
|
||||
*/
|
||||
public function it_should_return_default_system_configuration_parameters_without_workspace()
|
||||
{
|
||||
config(["system.workspace" => '']);
|
||||
putenv("REQUEST_URI=/sysworkflow");
|
||||
|
||||
$result = System::getSystemConfiguration();
|
||||
|
||||
$this->assertArrayHasKey('server_hostname_requests_frontend', $result);
|
||||
$this->assertArrayHasKey('disable_php_upload_execution', $result);
|
||||
$this->assertArrayHasKey('mobile_offline_tables_download_interval', $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return system configuration parameters defined inside env file.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getSystemConfiguration()
|
||||
*/
|
||||
public function it_should_return_system_configuration_parameters_defined_inside_env_file()
|
||||
{
|
||||
$oldContent = "";
|
||||
$path = PATH_CONFIG . "env.ini";
|
||||
if (file_exists($path)) {
|
||||
$oldContent = file_get_contents($path);
|
||||
}
|
||||
|
||||
$expected = 30;
|
||||
|
||||
$content = "mobile_offline_tables_download_interval = {$expected};";
|
||||
file_put_contents($path, $content);
|
||||
|
||||
$result = System::getSystemConfiguration();
|
||||
$actual = $result['mobile_offline_tables_download_interval'];
|
||||
|
||||
file_put_contents($path, $oldContent);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return default system configuration parameters defined inside env file when is not integer.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getSystemConfiguration()
|
||||
*/
|
||||
public function it_should_return_default_system_configuration_parameters_defined_inside_env_file_when_is_not_an_integer()
|
||||
{
|
||||
$oldContent = "";
|
||||
$path = PATH_CONFIG . "env.ini";
|
||||
if (file_exists($path)) {
|
||||
$oldContent = file_get_contents($path);
|
||||
}
|
||||
|
||||
$faker = $faker = Factory::create();
|
||||
$alphanumeric = $faker->regexify('[A-Za-z0-9]{20}');
|
||||
$content = "mobile_offline_tables_download_interval = '{$alphanumeric}';";
|
||||
file_put_contents($path, $content);
|
||||
|
||||
$result = System::getSystemConfiguration();
|
||||
|
||||
$expected = (string) $result['mobile_offline_tables_download_interval'];
|
||||
|
||||
file_put_contents($path, $oldContent);
|
||||
|
||||
$this->assertTrue(is_numeric($expected));
|
||||
}
|
||||
|
||||
/**
|
||||
* It should return proxy_pass defined inside env file.
|
||||
* @test
|
||||
* @covers \ProcessMaker\Core\System::getSystemConfiguration()
|
||||
*/
|
||||
public function it_should_return_proxy_pass_defined_inside_env_file()
|
||||
{
|
||||
$oldContent = "";
|
||||
$path = PATH_CONFIG . "env.ini";
|
||||
if (file_exists($path)) {
|
||||
$oldContent = file_get_contents($path);
|
||||
}
|
||||
|
||||
$faker = $faker = Factory::create();
|
||||
$content = "proxy_pass = '{$faker->password}';";
|
||||
file_put_contents($path, $content);
|
||||
|
||||
$result = System::getSystemConfiguration();
|
||||
|
||||
file_put_contents($path, $oldContent);
|
||||
|
||||
$this->assertArrayHasKey("proxy_pass", $result);
|
||||
}
|
||||
}
|
||||
@@ -698,7 +698,6 @@ class Light
|
||||
$info = pathinfo($oAppDocument->getAppDocFilename());
|
||||
$ext = (isset($info['extension']) ? $info['extension'] : ''); //BUG fix: must handle files without any extension
|
||||
|
||||
//$app_uid = G::getPathFromUID($oAppDocument->Fields['APP_UID']);
|
||||
$file = G::getPathFromFileUID($oAppDocument->Fields['APP_UID'], $sAppDocUid);
|
||||
|
||||
$realPath = PATH_DOCUMENT . G::getPathFromUID($app_uid) . '/' . $file[0] . $file[1] . '_' . $iDocVersion . '.' . $ext;
|
||||
@@ -1358,6 +1357,8 @@ class Light
|
||||
*/
|
||||
public function getConfiguration($params)
|
||||
{
|
||||
$response = [];
|
||||
|
||||
$sysConf = Bootstrap::getSystemConfiguration('', '', config("system.workspace"));
|
||||
$multiTimeZone = false;
|
||||
//Set Time Zone
|
||||
@@ -1423,6 +1424,8 @@ class Light
|
||||
$response['tz'] = isset($_SESSION['USR_TIME_ZONE']) ? $_SESSION['USR_TIME_ZONE'] : $sysConf['time_zone'];
|
||||
}
|
||||
|
||||
$response['mobile_offline_tables_download_interval'] = $sysConf['mobile_offline_tables_download_interval'];
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
|
||||
@@ -73,7 +73,8 @@ class System
|
||||
'files_white_list' => '',
|
||||
'delay' => '0',
|
||||
'tries' => '10',
|
||||
'retry_after' => '90'
|
||||
'retry_after' => '90',
|
||||
'mobile_offline_tables_download_interval' => 24
|
||||
];
|
||||
|
||||
/**
|
||||
@@ -1203,6 +1204,15 @@ class System
|
||||
$config['proxy_pass'] = G::decrypt($config['proxy_pass'], 'proxy_pass');
|
||||
}
|
||||
|
||||
/**
|
||||
* Here if you validate if the type of data obtained from the configuration
|
||||
* files are valid, otherwise the default value is used.
|
||||
*/
|
||||
$value = (string) $config['mobile_offline_tables_download_interval'];
|
||||
if (!is_numeric($value)) {
|
||||
$config['mobile_offline_tables_download_interval'] = self::$defaultConfig['mobile_offline_tables_download_interval'];
|
||||
}
|
||||
|
||||
return $config;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user