Commit 85c4b711 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Update phpUnit Tests to new multi database setup

parent 2c66362d
......@@ -350,7 +350,12 @@ const SYSTEM_DB_USER = 'DB_USER';
const SYSTEM_DB_SERVER = 'DB_SERVER';
const SYSTEM_DB_PASSWORD = 'DB_PASSWORD';
const SYSTEM_DB_NAME = 'DB_NAME';
const SYSTEM_DB_NAME_TEST = 'DB_NAME_TEST';
const SYSTEM_DB_1_USER = 'DB_1_USER';
const SYSTEM_DB_1_SERVER = 'DB_1_SERVER';
const SYSTEM_DB_1_PASSWORD = 'DB_1_PASSWORD';
const SYSTEM_DB_1_NAME = 'DB_1_NAME';
const SYSTEM_DB_INIT = 'DB_INIT';
const SYSTEM_DB_INDEX_DATA = "DB_INDEX_DATA";
......@@ -751,6 +756,9 @@ const F_FE_DATA_ERROR = 'data-error';
const F_PARAMETER = 'parameter'; // valid for F_ and FE_
// Form columns: via parameter field
const F_DB_INDEX_DATA = 'dbIndexData';
const DB_INDEX_DATA_DEFAULT = "1";
const F_LDAP_SERVER = 'ldapServer';
const F_LDAP_BASE_DN = 'ldapBaseDn';
const F_LDAP_SEARCH = 'ldapSearch';
......
......@@ -640,6 +640,19 @@ class QuickFormQuery {
$formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec, F_PARAMETER);
// Setting defaults later is to late.
if (!isset($formSpec[F_DB_INDEX_DATA])) {
$formSpec[F_DB_INDEX_DATA] = $this->dbIndexData;
}
// Some forms load/save the form data on extra defined databases.
if ($this->dbIndexData != $formSpec[F_DB_INDEX_DATA]) {
if (!isset($this->dbArray[$formSpec[F_DB_INDEX_DATA]])) {
$this->dbArray[$formSpec[F_DB_INDEX_DATA]] = new Database($formSpec[F_DB_INDEX_DATA]);
}
$this->dbIndexData = $formSpec[F_DB_INDEX_DATA];
}
$parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);
$formSpec = HelperFormElement::setLanguage($formSpec, $parameterLanguageFieldName);
......@@ -936,6 +949,7 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_BUTTON_ON_CHANGE_CLASS, '');
Support::setIfNotSet($formSpec, F_LDAP_USE_BIND_CREDENTIALS, '');
Support::setIfNotSet($formSpec, F_MODE, '');
Support::setIfNotSet($formSpec, F_DB_INDEX_DATA, $this->store->getVar(F_DB_INDEX_DATA, STORE_SYSTEM));
// In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
if ($formSpec[F_MODE] == '') {
......
......@@ -136,8 +136,8 @@ class Config {
*/
private static function setDefaults(array $config) {
// Defaults
Support::setIfNotSet($config, SYSTEM_DB_INDEX_DATA, '1');
Support::setIfNotSet($config, SYSTEM_DB_INDEX_QFQ, '1');
Support::setIfNotSet($config, SYSTEM_DB_INDEX_DATA, DB_INDEX_DATA_DEFAULT);
Support::setIfNotSet($config, SYSTEM_DB_INDEX_QFQ, DB_INDEX_DATA_DEFAULT);
Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd');
Support::setIfNotSet($config, SYSTEM_SHOW_DEBUG_INFO, SYSTEM_SHOW_DEBUG_INFO_AUTO);
......
......@@ -26,7 +26,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
/**
* @var qfq\Database
*/
protected $db = null;
protected $dbArray = array();
/**
* @var qfq\Store
......@@ -71,17 +71,18 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
$this->sip->sipUniqId('badcaffee1234');
// SWITCH to TestDB
$this->store->setVar(SYSTEM_DB_NAME, $this->store->getVar(SYSTEM_DB_NAME_TEST, STORE_SYSTEM), STORE_SYSTEM);
$dbName = $this->store->getVar('DB_1_NAME', STORE_SYSTEM);
$this->store->setVar('DB_1_NAME', $dbName, STORE_SYSTEM);
if ($this->db === null) {
$this->db = new qfq\Database();
if (empty($this->dbArray)) {
$this->dbArray[DB_INDEX_DATA_DEFAULT] = new qfq\Database();
}
/// Establish additional mysqli access
$dbserver = $this->store->getVar(SYSTEM_DB_SERVER, STORE_SYSTEM);
$dbuser = $this->store->getVar(SYSTEM_DB_USER, STORE_SYSTEM);
$db = $this->store->getVar(SYSTEM_DB_NAME, STORE_SYSTEM);
$dbpw = $this->store->getVar(SYSTEM_DB_PASSWORD, STORE_SYSTEM);
$dbserver = $this->store->getVar('DB_1_SERVER', STORE_SYSTEM);
$dbuser = $this->store->getVar('DB_1_USER', STORE_SYSTEM);
$db = $this->store->getVar('DB_1_NAME', STORE_SYSTEM);
$dbpw = $this->store->getVar('DB_1_PASSWORD', STORE_SYSTEM);
if (self::$mysqli === null) {
......
......@@ -82,7 +82,7 @@ class DirtyTest extends \AbstractDatabaseTest {
/**
* @var \qfq\Database instantiated class
*/
protected $db = null;
protected $dbArray = null;
/**********************************************************************
* 1. DirtyMode: none
......@@ -104,7 +104,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -113,7 +113,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -131,7 +131,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -141,7 +141,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -158,7 +158,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob) - but there is no lockrecord!
$this->db->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
// Alice lock again
$result = $dirty->process();
......@@ -187,7 +187,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -196,7 +196,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -214,7 +214,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_1);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_1);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -224,7 +224,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -243,7 +243,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result);
// Timeout
$rc = $this->db->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00'", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00'", ROW_REGULAR);
$this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice release
......@@ -254,7 +254,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -269,12 +269,12 @@ class DirtyTest extends \AbstractDatabaseTest {
$expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900];
$dirty = new \qfq\Dirty();
$this->db->sql("UPDATE Person SET modified='2001-01-01 13:14:15' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Person SET modified='2001-01-01 13:14:15' WHERE id=1", ROW_REGULAR);
$result = $dirty->process();
$this->assertEquals($expected, $result);
// change modified
$this->db->sql("UPDATE Person SET modified='2002-02-02 16:17:18' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Person SET modified='2002-02-02 16:17:18' WHERE id=1", ROW_REGULAR);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -301,7 +301,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob)
$this->db->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
// Alice lock again
$result = $dirty->process();
......@@ -332,7 +332,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result);
// Set timeout to expired, Change Alice to Bob
$rc = $this->db->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00', qfqUserSessionCookie='SessionCookieBob'", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00', qfqUserSessionCookie='SessionCookieBob'", ROW_REGULAR);
$this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice lock
......@@ -369,7 +369,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$_COOKIE[SESSION_NAME] = 'SessionCookieBob';
// Create third Person record
$rc = $this->db->sql("INSERT INTO Person (`name`, `firstName`) VALUES ('no', 'name')", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("INSERT INTO Person (`name`, `firstName`) VALUES ('no', 'name')", ROW_REGULAR);
// Bob lock 3
$_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockAdvisory", RETURN_SIP);
......@@ -473,7 +473,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -482,7 +482,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -503,7 +503,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_1);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_1);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -513,7 +513,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -532,7 +532,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result);
// Timeout
$rc = $this->db->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00'", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00'", ROW_REGULAR);
$this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice release
......@@ -543,7 +543,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
$this->assertEquals($expected, $result);
$this->db->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id FROM Dirty", ROW_EXPECT_0);
}
/**
......@@ -572,12 +572,12 @@ class DirtyTest extends \AbstractDatabaseTest {
$expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900];
$dirty = new \qfq\Dirty();
$this->db->sql("UPDATE Person SET modified='2001-01-01 13:14:15' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Person SET modified='2001-01-01 13:14:15' WHERE id=1", ROW_REGULAR);
$result = $dirty->process();
$this->assertEquals($expected, $result);
// change modified
$this->db->sql("UPDATE Person SET modified='2002-02-02 16:17:18' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Person SET modified='2002-02-02 16:17:18' WHERE id=1", ROW_REGULAR);
// Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
......@@ -604,7 +604,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob)
$this->db->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET qfqUserSessionCookie='SessionCookieBob' WHERE id=1", ROW_REGULAR);
// Alice lock again
$result = $dirty->process();
......@@ -634,7 +634,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result);
// Set timeout to expired, Change Alice to Bob
$rc = $this->db->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00', qfqUserSessionCookie='SessionCookieBob'", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Dirty SET expire='2001-01-01 00:00:00', qfqUserSessionCookie='SessionCookieBob'", ROW_REGULAR);
$this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice lock
......@@ -671,7 +671,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$_COOKIE[SESSION_NAME] = 'SessionCookieBob';
// Create third Person record
$rc = $this->db->sql("INSERT INTO Person (`name`, `firstName`) VALUES ('no', 'name')", ROW_REGULAR);
$rc = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("INSERT INTO Person (`name`, `firstName`) VALUES ('no', 'name')", ROW_REGULAR);
// Bob lock 3
$_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockExclusive", RETURN_SIP);
......@@ -981,7 +981,7 @@ class DirtyTest extends \AbstractDatabaseTest {
*/
public function testExpireTime() {
$this->db->sql("DELETE FROM Dirty", ROW_REGULAR);
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("DELETE FROM Dirty", ROW_REGULAR);
$_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=1&form=lockExclusive", RETURN_SIP);
// Alice lock
......@@ -991,7 +991,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process();
// Check that the expire time is correctly computed
$row = $this->db->sql("SELECT expire FROM Dirty", ROW_EXPECT_1);
$row = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT expire FROM Dirty", ROW_EXPECT_1);
$secs = abs(strtotime($row[DIRTY_EXPIRE]) - strtotime(date('Y-m-d H:i:s')) - 900);
$this->assertLessThan(2, $secs);
}
......
......@@ -18,7 +18,7 @@ require_once(__DIR__ . '/../../qfq/store/Store.php');
class EvaluateTest extends \AbstractDatabaseTest {
public function testVars() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
// no variable
$this->assertEquals('nothing', $eval->parse('nothing'));
......@@ -42,7 +42,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testParse() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
// database: lower case
$this->assertEquals('1DoeJohn0malec2SmithJane0femalea,c', $eval->parse('{{select id,name,firstName,adrId,gender,groups from Person where id < 3 order by id}}'));
......@@ -93,7 +93,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testDbVars() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$eval->parse('{{INSERT INTO Person (name, firstname) VALUES (\'Holiday\', \'Billie\')}}');
$this->store->setVar('a', '{{b:C:all}}', 'C');
......@@ -102,7 +102,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testParseArray() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$data = [
'formName' => 'MyTestForm',
......@@ -133,7 +133,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
public function testParseArrayOfArray() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$data = [
[
'formName' => 'MyTestForm',
......@@ -159,7 +159,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testSubstituteSql() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$expectArr = [0 => ['name' => 'Holiday', 'firstname' => 'Billie'], 1 => ['name' => 'Holiday', 'firstname' => 'Billie']];
......@@ -202,7 +202,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testSubstituteVar() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
// Retrieve in PRIO `FSRD`
$this->store->setVar('a', '1234', STORE_TABLE_DEFAULT, true);
......@@ -271,7 +271,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
}
public function testSubstituteVarEscape() {
$eval = new \qfq\Evaluate($this->store, $this->db);
$eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
// No escape
$this->store->setVar('a', 'hello', STORE_FORM, true);
......
......@@ -15,7 +15,7 @@ class FormActionTest extends \AbstractDatabaseTest {
public function testBeforeLoad() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
// Nothing to do: should not throw an exception
$formAction->elements(0, array(), '');
......@@ -53,7 +53,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException1() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
......@@ -69,7 +69,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException0() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
......@@ -85,7 +85,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException2() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_BEFORE_LOAD;
......@@ -101,7 +101,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException3() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_AFTER_UPDATE;
......@@ -116,7 +116,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException4() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_AFTER_UPDATE;
......@@ -142,7 +142,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException5() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$this->store->setVar('city', 'New York', STORE_FORM, true);
$feSpecAction[FE_NAME] = '';
......@@ -158,7 +158,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoad2() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_AFTER_LOAD;
......@@ -174,7 +174,7 @@ class FormActionTest extends \AbstractDatabaseTest {
**/
public function testBeforeLoadException6() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_AFTER_LOAD;
......@@ -192,7 +192,7 @@ class FormActionTest extends \AbstractDatabaseTest {
public function testInsert() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$feSpecAction[FE_NAME] = '';
$feSpecAction[FE_TYPE] = FE_TYPE_AFTER_SAVE;
......@@ -205,19 +205,19 @@ class FormActionTest extends \AbstractDatabaseTest {
// slaveId: 0
$feSpecAction[FE_SLAVE_ID] = '0';
$result = $this->db->sql('TRUNCATE Address');
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('TRUNCATE Address');
$formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);
$result = $this->db->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$this->assertEquals('1Downtown2', $result);
// slaveId: SELECT ... >> ''
$feSpecAction[FE_SLAVE_ID] = '{{SELECT id FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}';
$result = $this->db->sql('TRUNCATE Address');
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('TRUNCATE Address');
$formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);
$result = $this->db->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$this->assertEquals('1Downtown2', $result);
......@@ -226,14 +226,14 @@ class FormActionTest extends \AbstractDatabaseTest {
$feSpecAction[FE_NAME] = 'adrId';
$feSpecAction[FE_SLAVE_ID] = '';
$result = $this->db->sql('TRUNCATE Address');
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('TRUNCATE Address');
$formAction->elements(2, [$feSpecAction], FE_TYPE_AFTER_SAVE);
// get the new slave record
$result = $this->db->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, city, personId FROM Address', ROW_IMPLODE_ALL);
$this->assertEquals('1Downtown2', $result);
// get the updated id in the master record
$result = $this->db->sql('SELECT id, name, adrId FROM Person WHERE id=2', ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, name, adrId FROM Person WHERE id=2', ROW_IMPLODE_ALL);
$this->assertEquals('2Smith1', $result);
}
......@@ -243,7 +243,7 @@ class FormActionTest extends \AbstractDatabaseTest {
public function testUpdate() {
$formSpec[F_TABLE_NAME] = 'Person';
$formAction = new FormAction($formSpec, $this->db, true);
$formAction = new FormAction($formSpec, $this->dbArray[DB_INDEX_DATA_DEFAULT], true);
$masterId = 2;
......@@ -252,10 +252,10 @@ class FormActionTest extends \AbstractDatabaseTest {
$feSpecAction[FE_SQL_INSERT] = "{{ INSERT INTO Address (city, personId) VALUES ('invalid', {{r}}) }} ";
$feSpecAction[FE_SQL_UPDATE] = "{{ UPDATE Address SET city='Uptown' WHERE id={{slaveId:V}} }} ";
$result = $this->db->sql("TRUNCATE Address");
$result = $this->db->sql("INSERT INTO Address (city, personId) VALUES ('Downtown1', 1)");
$result = $this->db->sql("INSERT INTO Address (city, personId) VALUES ('Downtown2', 1)");
$result = $this->db->sql("INSERT INTO Address (city, personId) VALUES ('Downtown3', $masterId)");
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("TRUNCATE Address");
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown1', 1)");
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown2', 1)");
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("INSERT INTO Address (city, personId) VALUES ('Downtown3', $masterId)");
$this->store->setVar('r', "$masterId", STORE_SIP, true);
......@@ -263,7 +263,7 @@ class FormActionTest extends \AbstractDatabaseTest {
$feSpecAction[FE_SLAVE_ID] = '3';
$formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);
$result = $this->db->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
$this->assertEquals('3Uptown' . $masterId, $result);
......@@ -271,23 +271,23 @@ class FormActionTest extends \AbstractDatabaseTest {
$feSpecAction[FE_SLAVE_ID] = "{{SELECT id FROM Address WHERE personId={{r}} ORDER BY id LIMIT 1}}";
$formAction->elements($masterId, [$feSpecAction], FE_TYPE_AFTER_SAVE);
$result = $this->db->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
$result = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("SELECT id, city, personId FROM Address WHERE personId=$masterId", ROW_IMPLODE_ALL);
$this->assertEquals('3Uptown' . $masterId, $result);
// slaveId: column in master record