PMCORE-1470 Custom Port not included when using MSSQL instance name in the DB connection
This commit is contained in:
111
tests/unit/workflow/engine/classes/DbConnectionsTest.php
Normal file
111
tests/unit/workflow/engine/classes/DbConnectionsTest.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\unit\workflow\engine\classes;
|
||||
|
||||
use DbConnections;
|
||||
use G;
|
||||
use ProcessMaker\Model\DbSource;
|
||||
use ProcessMaker\Model\Process;
|
||||
use Propel;
|
||||
use Tests\TestCase;
|
||||
|
||||
class DbConnectionsTest extends TestCase
|
||||
{
|
||||
private $dbConnections;
|
||||
|
||||
/**
|
||||
* Setup method.
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
$this->dbConnections = new DbConnections();
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify loadAdditionalConnections method.
|
||||
* @test
|
||||
* @covers DbConnections::loadAdditionalConnections
|
||||
*/
|
||||
public function it_should_test_loadAdditionalConnections_method()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
|
||||
$dbName = env('DB_DATABASE');
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'DBS_TYPE' => 'mysql',
|
||||
'DBS_SERVER' => env('DB_HOST'),
|
||||
'DBS_DATABASE_NAME' => $dbName,
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), $dbName) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
]);
|
||||
|
||||
$a = Propel::getConfiguration();
|
||||
|
||||
|
||||
$_SESSION['PROCESS'] = $process->PRO_UID;
|
||||
$this->dbConnections->loadAdditionalConnections();
|
||||
|
||||
$actual = Propel::getConfiguration();
|
||||
|
||||
$this->assertArrayHasKey($dbSource->DBS_UID, $actual['datasources']);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify loadAdditionalConnections method with option true.
|
||||
* @test
|
||||
* @covers DbConnections::loadAdditionalConnections
|
||||
*/
|
||||
public function it_should_test_loadAdditionalConnections_method_with_force_option_true()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
|
||||
$dbName = env('DB_DATABASE');
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'DBS_TYPE' => 'mysql',
|
||||
'DBS_SERVER' => env('DB_HOST'),
|
||||
'DBS_DATABASE_NAME' => $dbName,
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), $dbName) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
]);
|
||||
|
||||
$_SESSION['PROCESS'] = $process->PRO_UID;
|
||||
$this->dbConnections->loadAdditionalConnections(true);
|
||||
|
||||
$actual = Propel::getConfiguration();
|
||||
|
||||
$this->assertArrayHasKey($dbSource->DBS_UID, $actual['datasources']);
|
||||
}
|
||||
|
||||
/**
|
||||
* This test verify loadAdditionalConnections method with option false.
|
||||
* @test
|
||||
* @covers DbConnections::loadAdditionalConnections
|
||||
*/
|
||||
public function it_should_test_loadAdditionalConnections_method_with_force_option_false()
|
||||
{
|
||||
$process = factory(Process::class)->create();
|
||||
|
||||
$dbName = env('DB_DATABASE');
|
||||
$dbSource = factory(DbSource::class)->create([
|
||||
'PRO_UID' => $process->PRO_UID,
|
||||
'DBS_TYPE' => 'mysql',
|
||||
'DBS_SERVER' => env('DB_HOST'),
|
||||
'DBS_DATABASE_NAME' => $dbName,
|
||||
'DBS_USERNAME' => env('DB_USERNAME'),
|
||||
'DBS_PASSWORD' => G::encrypt(env('DB_PASSWORD'), $dbName) . "_2NnV3ujj3w",
|
||||
'DBS_PORT' => '3306',
|
||||
]);
|
||||
|
||||
$_SESSION['PROCESS'] = $process->PRO_UID;
|
||||
$this->dbConnections->loadAdditionalConnections(false);
|
||||
|
||||
$actual = Propel::getConfiguration();
|
||||
|
||||
$this->assertArrayHasKey($dbSource->DBS_UID, $actual['datasources']);
|
||||
}
|
||||
}
|
||||
@@ -226,16 +226,11 @@ class DbConnections
|
||||
// Not TNS, build a standard configuration
|
||||
$dbsPort = ($externalDb->DBS_PORT == '') ? ('') : (':' . $externalDb->DBS_PORT);
|
||||
$encoding = (trim($externalDb->DBS_ENCODE) == '') ? '' : '?encoding=' . $externalDb->DBS_ENCODE;
|
||||
if (strpos($externalDb->DBS_SERVER, "\\") && $externalDb->DBS_TYPE == 'mssql') {
|
||||
// This is a microsoft SQL server which is using a netbios connection string
|
||||
$conf['datasources'][$externalDb->DBS_UID]['connection'] = $externalDb->DBS_TYPE . '://'
|
||||
. $externalDb->DBS_USERNAME . ':' . $passw . '@' . $externalDb->DBS_SERVER . '/'
|
||||
. $externalDb->DBS_DATABASE_NAME . $encoding;
|
||||
} else {
|
||||
$conf['datasources'][$externalDb->DBS_UID]['connection'] = $externalDb->DBS_TYPE . '://'
|
||||
. $externalDb->DBS_USERNAME . ':' . $passw . '@' . $externalDb->DBS_SERVER . $dbsPort . '/'
|
||||
. $externalDb->DBS_DATABASE_NAME . $encoding;
|
||||
}
|
||||
|
||||
$conf['datasources'][$externalDb->DBS_UID]['connection'] = $externalDb->DBS_TYPE . '://'
|
||||
. $externalDb->DBS_USERNAME . ':' . $passw . '@' . $externalDb->DBS_SERVER . $dbsPort . '/'
|
||||
. $externalDb->DBS_DATABASE_NAME . $encoding;
|
||||
|
||||
$laravelConfig = [
|
||||
'driver' => $externalDb->DBS_TYPE === 'mssql' ? 'sqlsrv' : $externalDb->DBS_TYPE, // MSSQL driver is not supported anymore, only SQLSRV
|
||||
'host' => $externalDb->DBS_SERVER,
|
||||
|
||||
Reference in New Issue
Block a user