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'; ...@@ -350,7 +350,12 @@ const SYSTEM_DB_USER = 'DB_USER';
const SYSTEM_DB_SERVER = 'DB_SERVER'; const SYSTEM_DB_SERVER = 'DB_SERVER';
const SYSTEM_DB_PASSWORD = 'DB_PASSWORD'; const SYSTEM_DB_PASSWORD = 'DB_PASSWORD';
const SYSTEM_DB_NAME = 'DB_NAME'; 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_INIT = 'DB_INIT';
const SYSTEM_DB_INDEX_DATA = "DB_INDEX_DATA"; const SYSTEM_DB_INDEX_DATA = "DB_INDEX_DATA";
...@@ -751,6 +756,9 @@ const F_FE_DATA_ERROR = 'data-error'; ...@@ -751,6 +756,9 @@ const F_FE_DATA_ERROR = 'data-error';
const F_PARAMETER = 'parameter'; // valid for F_ and FE_ const F_PARAMETER = 'parameter'; // valid for F_ and FE_
// Form columns: via parameter field // 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_SERVER = 'ldapServer';
const F_LDAP_BASE_DN = 'ldapBaseDn'; const F_LDAP_BASE_DN = 'ldapBaseDn';
const F_LDAP_SEARCH = 'ldapSearch'; const F_LDAP_SEARCH = 'ldapSearch';
......
...@@ -640,6 +640,19 @@ class QuickFormQuery { ...@@ -640,6 +640,19 @@ class QuickFormQuery {
$formSpec = $this->eval->parseArray($form); $formSpec = $this->eval->parseArray($form);
HelperFormElement::explodeParameter($formSpec, F_PARAMETER); 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); $parameterLanguageFieldName = $this->store->getVar(SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME, STORE_SYSTEM);
$formSpec = HelperFormElement::setLanguage($formSpec, $parameterLanguageFieldName); $formSpec = HelperFormElement::setLanguage($formSpec, $parameterLanguageFieldName);
...@@ -936,6 +949,7 @@ class QuickFormQuery { ...@@ -936,6 +949,7 @@ class QuickFormQuery {
Support::setIfNotSet($formSpec, F_BUTTON_ON_CHANGE_CLASS, ''); Support::setIfNotSet($formSpec, F_BUTTON_ON_CHANGE_CLASS, '');
Support::setIfNotSet($formSpec, F_LDAP_USE_BIND_CREDENTIALS, ''); Support::setIfNotSet($formSpec, F_LDAP_USE_BIND_CREDENTIALS, '');
Support::setIfNotSet($formSpec, F_MODE, ''); 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. // In case there is no F_MODE defined on the form, check if there is one in STORE_SIP.
if ($formSpec[F_MODE] == '') { if ($formSpec[F_MODE] == '') {
......
...@@ -136,8 +136,8 @@ class Config { ...@@ -136,8 +136,8 @@ class Config {
*/ */
private static function setDefaults(array $config) { private static function setDefaults(array $config) {
// Defaults // Defaults
Support::setIfNotSet($config, SYSTEM_DB_INDEX_DATA, '1'); Support::setIfNotSet($config, SYSTEM_DB_INDEX_DATA, DB_INDEX_DATA_DEFAULT);
Support::setIfNotSet($config, SYSTEM_DB_INDEX_QFQ, '1'); Support::setIfNotSet($config, SYSTEM_DB_INDEX_QFQ, DB_INDEX_DATA_DEFAULT);
Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd'); Support::setIfNotSet($config, SYSTEM_DATE_FORMAT, 'yyyy-mm-dd');
Support::setIfNotSet($config, SYSTEM_SHOW_DEBUG_INFO, SYSTEM_SHOW_DEBUG_INFO_AUTO); Support::setIfNotSet($config, SYSTEM_SHOW_DEBUG_INFO, SYSTEM_SHOW_DEBUG_INFO_AUTO);
......
...@@ -26,7 +26,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase { ...@@ -26,7 +26,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
/** /**
* @var qfq\Database * @var qfq\Database
*/ */
protected $db = null; protected $dbArray = array();
/** /**
* @var qfq\Store * @var qfq\Store
...@@ -71,17 +71,18 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase { ...@@ -71,17 +71,18 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
$this->sip->sipUniqId('badcaffee1234'); $this->sip->sipUniqId('badcaffee1234');
// SWITCH to TestDB // 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) { if (empty($this->dbArray)) {
$this->db = new qfq\Database(); $this->dbArray[DB_INDEX_DATA_DEFAULT] = new qfq\Database();
} }
/// Establish additional mysqli access /// Establish additional mysqli access
$dbserver = $this->store->getVar(SYSTEM_DB_SERVER, STORE_SYSTEM); $dbserver = $this->store->getVar('DB_1_SERVER', STORE_SYSTEM);
$dbuser = $this->store->getVar(SYSTEM_DB_USER, STORE_SYSTEM); $dbuser = $this->store->getVar('DB_1_USER', STORE_SYSTEM);
$db = $this->store->getVar(SYSTEM_DB_NAME, STORE_SYSTEM); $db = $this->store->getVar('DB_1_NAME', STORE_SYSTEM);
$dbpw = $this->store->getVar(SYSTEM_DB_PASSWORD, STORE_SYSTEM); $dbpw = $this->store->getVar('DB_1_PASSWORD', STORE_SYSTEM);
if (self::$mysqli === null) { if (self::$mysqli === null) {
......
...@@ -82,7 +82,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -82,7 +82,7 @@ class DirtyTest extends \AbstractDatabaseTest {
/** /**
* @var \qfq\Database instantiated class * @var \qfq\Database instantiated class
*/ */
protected $db = null; protected $dbArray = null;
/********************************************************************** /**********************************************************************
* 1. DirtyMode: none * 1. DirtyMode: none
...@@ -104,7 +104,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -104,7 +104,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -113,7 +113,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -113,7 +113,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -131,7 +131,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -141,7 +141,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -141,7 +141,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -158,7 +158,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob) - but there is no lockrecord! // 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 // Alice lock again
$result = $dirty->process(); $result = $dirty->process();
...@@ -187,7 +187,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -187,7 +187,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -196,7 +196,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -196,7 +196,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -214,7 +214,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -224,7 +224,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -224,7 +224,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -243,7 +243,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// Timeout // 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'); $this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice release // Alice release
...@@ -254,7 +254,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -254,7 +254,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -269,12 +269,12 @@ class DirtyTest extends \AbstractDatabaseTest {
$expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900]; $expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900];
$dirty = new \qfq\Dirty(); $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(); $result = $dirty->process();
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// change modified // 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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -301,7 +301,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -301,7 +301,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob) // 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 // Alice lock again
$result = $dirty->process(); $result = $dirty->process();
...@@ -332,7 +332,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -332,7 +332,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// Set timeout to expired, Change Alice to Bob // 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'); $this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice lock // Alice lock
...@@ -369,7 +369,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -369,7 +369,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$_COOKIE[SESSION_NAME] = 'SessionCookieBob'; $_COOKIE[SESSION_NAME] = 'SessionCookieBob';
// Create third Person record // 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 // Bob lock 3
$_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockAdvisory", RETURN_SIP); $_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockAdvisory", RETURN_SIP);
...@@ -473,7 +473,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -473,7 +473,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -482,7 +482,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -482,7 +482,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -503,7 +503,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -513,7 +513,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -513,7 +513,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -532,7 +532,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// Timeout // 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'); $this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice release // Alice release
...@@ -543,7 +543,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -543,7 +543,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
$this->assertEquals($expected, $result); $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 { ...@@ -572,12 +572,12 @@ class DirtyTest extends \AbstractDatabaseTest {
$expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900]; $expected = [API_STATUS => API_ANSWER_STATUS_SUCCESS, API_MESSAGE => '', API_LOCK_TIMEOUT => 900];
$dirty = new \qfq\Dirty(); $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(); $result = $dirty->process();
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// change modified // 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 // Alice release
$_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE; $_GET[DIRTY_API_ACTION] = DIRTY_API_ACTION_RELEASE;
...@@ -604,7 +604,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -604,7 +604,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
// move lock to another owner (Alice fake becomes Bob) // 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 // Alice lock again
$result = $dirty->process(); $result = $dirty->process();
...@@ -634,7 +634,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -634,7 +634,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$this->assertEquals($expected, $result); $this->assertEquals($expected, $result);
// Set timeout to expired, Change Alice to Bob // 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'); $this->assertEquals(1, $rc, 'Expect that exactly one record has been updated');
// Alice lock // Alice lock
...@@ -671,7 +671,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -671,7 +671,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$_COOKIE[SESSION_NAME] = 'SessionCookieBob'; $_COOKIE[SESSION_NAME] = 'SessionCookieBob';
// Create third Person record // 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 // Bob lock 3
$_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockExclusive", RETURN_SIP); $_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=3&form=lockExclusive", RETURN_SIP);
...@@ -981,7 +981,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -981,7 +981,7 @@ class DirtyTest extends \AbstractDatabaseTest {
*/ */
public function testExpireTime() { 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); $_GET[CLIENT_SIP] = $this->sip->queryStringToSip("?id=input&r=1&form=lockExclusive", RETURN_SIP);
// Alice lock // Alice lock
...@@ -991,7 +991,7 @@ class DirtyTest extends \AbstractDatabaseTest { ...@@ -991,7 +991,7 @@ class DirtyTest extends \AbstractDatabaseTest {
$result = $dirty->process(); $result = $dirty->process();
// Check that the expire time is correctly computed // 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); $secs = abs(strtotime($row[DIRTY_EXPIRE]) - strtotime(date('Y-m-d H:i:s')) - 900);
$this->assertLessThan(2, $secs); $this->assertLessThan(2, $secs);
} }
......
...@@ -18,7 +18,7 @@ require_once(__DIR__ . '/../../qfq/store/Store.php'); ...@@ -18,7 +18,7 @@ require_once(__DIR__ . '/../../qfq/store/Store.php');
class EvaluateTest extends \AbstractDatabaseTest { class EvaluateTest extends \AbstractDatabaseTest {
public function testVars() { 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 // no variable
$this->assertEquals('nothing', $eval->parse('nothing')); $this->assertEquals('nothing', $eval->parse('nothing'));
...@@ -42,7 +42,7 @@ class EvaluateTest extends \AbstractDatabaseTest { ...@@ -42,7 +42,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
} }
public function testParse() { 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 // database: lower case
$this->assertEquals('1DoeJohn0malec2SmithJane0femalea,c', $eval->parse('{{select id,name,firstName,adrId,gender,groups from Person where id < 3 order by id}}')); $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 { ...@@ -93,7 +93,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
} }
public function testDbVars() { 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\')}}'); $eval->parse('{{INSERT INTO Person (name, firstname) VALUES (\'Holiday\', \'Billie\')}}');
$this->store->setVar('a', '{{b:C:all}}', 'C'); $this->store->setVar('a', '{{b:C:all}}', 'C');
...@@ -102,7 +102,7 @@ class EvaluateTest extends \AbstractDatabaseTest { ...@@ -102,7 +102,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
} }
public function testParseArray() { public function testParseArray() {
$eval = new \qfq\Evaluate($this->store, $this->db); $eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$data = [ $data = [
'formName' => 'MyTestForm', 'formName' => 'MyTestForm',
...@@ -133,7 +133,7 @@ class EvaluateTest extends \AbstractDatabaseTest { ...@@ -133,7 +133,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
public function testParseArrayOfArray() { public function testParseArrayOfArray() {
$eval = new \qfq\Evaluate($this->store, $this->db); $eval = new \qfq\Evaluate($this->store, $this->dbArray[DB_INDEX_DATA_DEFAULT]);
$data = [ $data = [
[ [
'formName' => 'MyTestForm', 'formName' => 'MyTestForm',
...@@ -159,7 +159,7 @@ class EvaluateTest extends \AbstractDatabaseTest { ...@@ -159,7 +159,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
} }