PMC-913 All existing Unit Tests are running correctly?

This commit is contained in:
Roly Rudy Gutierrez Pinto
2019-06-28 14:24:59 -04:00
parent fbcb996b11
commit 6de0b830a9
10 changed files with 166 additions and 84 deletions

View File

@@ -1,43 +1,56 @@
<?php
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Queue\Console\WorkCommand;
use Illuminate\Support\Facades\DB;
use ProcessMaker\Model\DbSource;
use ProcessMaker\Model\Process;
use Tests\TestCase;
use Propel;
use DbConnections;
class DBQueryTest extends TestCase
{
use DatabaseTransactions;
/**
* A basic cache example.
*
* @return void
* Sets up the unit tests.
*/
protected function setUp()
{
}
/**
* Verify the execution of a common SQL statement.
* @test
*/
public function testStandardExecuteQuery()
{
$results = executeQuery("SELECT * FROM USERS WHERE USR_UID = '00000000000000000000000000000001'");
$this->assertCount(1, $results);
// Note, we check index 1 because results from executeQuery are 1 indexed, not 0 indexed.
$this->assertArraySubset([
$expected = [
'USR_UID' => '00000000000000000000000000000001',
'USR_USERNAME' => 'admin'
], $results[1]);
];
$this->assertArraySubset($expected, $results[1]);
}
/**
* Verify the existence of the admin user.
* @test
*/
public function testDBFacadeQuery()
{
$record = DB::table('USERS')->where([
'USR_UID' => '00000000000000000000000000000001'
])->first();
$record = DB::table('USERS')->where('USR_UID', '=', '00000000000000000000000000000001')->first();
$this->assertEquals('admin', $record->USR_USERNAME);
}
/**
* Verify the execution of a SQL statement common to an MySQL external database.
* @test
*/
public function testStandardExecuteQueryWithExternalMySQLDatabase()
{
// Our test external database is created in our tests/bootstrap.php file
@@ -45,12 +58,12 @@ class DBQueryTest extends TestCase
$process = factory(Process::class)->create();
// Let's create an external DB to ourselves
$externalDB = factory(DbSource::class)->create([
'DBS_SERVER' => 'localhost',
'DBS_SERVER' => config('database.connections.testexternal.host'),
'DBS_PORT' => '3306',
'DBS_USERNAME' => env('DB_USERNAME'),
'DBS_USERNAME' => config('database.connections.testexternal.username'),
// Remember, we have to do some encryption here @see DbSourceFactory.php
'DBS_PASSWORD' => \G::encrypt( env('DB_PASSWORD'), 'testexternal') . "_2NnV3ujj3w",
'DBS_DATABASE_NAME' => 'testexternal',
'DBS_PASSWORD' => \G::encrypt(env('DB_PASSWORD'), config('database.connections.testexternal.database')) . "_2NnV3ujj3w",
'DBS_DATABASE_NAME' => config('database.connections.testexternal.database'),
'PRO_UID' => $process->PRO_UID
]);
@@ -65,9 +78,13 @@ class DBQueryTest extends TestCase
$this->assertEquals('testvalue', $results[1]['value']);
}
/**
* Verify the execution of a SQL statement common to an MSSQL external database.
* @test
*/
public function testStandardExecuteQueryWithExternalMSSqlDatabase()
{
if(!env('RUN_MSSQL_TESTS')) {
if (!env('RUN_MSSQL_TESTS')) {
$this->markTestSkipped('MSSQL Related Test Skipped');
}
// Our test external database is created in our tests/bootstrap.php file
@@ -80,8 +97,8 @@ class DBQueryTest extends TestCase
'DBS_TYPE' => 'mssql',
'DBS_USERNAME' => env('MSSQL_USERNAME'),
// Remember, we have to do some encryption here @see DbSourceFactory.php
'DBS_PASSWORD' => \G::encrypt( env('MSSQL_PASSWORD'), 'testexternal') . "_2NnV3ujj3w",
'DBS_DATABASE_NAME' => 'testexternal',
'DBS_PASSWORD' => \G::encrypt(env('MSSQL_PASSWORD'), env('MSSQL_DATABASE')) . "_2NnV3ujj3w",
'DBS_DATABASE_NAME' => env('MSSQL_DATABASE'),
'PRO_UID' => $process->PRO_UID
]);
// Now set our process ID
@@ -94,4 +111,4 @@ class DBQueryTest extends TestCase
$this->assertCount(1, $results);
$this->assertEquals('testvalue', $results[1]['value']);
}
}
}