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) {
......
......@@ -16,7 +16,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
*/
public function testGetProcessFilter() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$build = new \qfq\BuildFormPlain(array(), array(), array(), $this->dbArray);
$this->assertEquals(FORM_ELEMENTS_NATIVE, $build->getProcessFilter());
}
......@@ -25,7 +25,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
*
*/
public function testGetFormId() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$build = new \qfq\BuildFormPlain(array(), array(), array(), $this->dbArray);
$formId1 = $build->getFormId();
$this->assertRegExp('/qfq-form-[0-9a-f]{13}/', $formId1);
......@@ -39,7 +39,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
*
*/
public function testWrapItem() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$build = new \qfq\BuildFormPlain(array(), array(), array(), $this->dbArray);
$result = $build->wrapItem(WRAP_SETUP_ELEMENT, 'Hello World', false);
$this->assertEquals('<p>Hello World</p>', $result);
......@@ -58,7 +58,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
*
*/
public function testBuildLabel() {
$build = new \qfq\BuildFormPlain(array(), array(), array());
$build = new \qfq\BuildFormPlain(array(), array(), array(), $this->dbArray);
$result = $build->buildLabel('myLabel:123', "Hello World");
$this->assertEquals('<label for="myLabel:123" class="control-label" >Hello World</label>', $result);
......@@ -74,7 +74,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->templateFormNFormElement($form, $formElement);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$label['123-l'][API_ELEMENT_CONTENT] = '<label for="name:1" class="control-label" >Name</label>';
$label['123-r'][API_ELEMENT_ATTRIBUTE] = ['class' => ''];
......@@ -181,7 +181,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->templateFormNFormElement($form, $formElement);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$formElement[FE_CHECK_TYPE] = SANITIZE_ALLOW_MIN_MAX;
$formElement[FE_CHECK_PATTERN] = '';
......@@ -198,7 +198,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->templateFormNFormElement($form, $formElement);
$formElement['name'] = 'deleted';
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$keys = array();
$values = array();
......@@ -252,7 +252,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
unset($formElement['emptyItemAtEnd']);
// SQL
$formElement['sql1'] = $this->db->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
// $expect = ['form', 'formElement', 'phpunit_person'];
$expect = ['form', 'formElement', 'copyForm'];
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
......@@ -261,7 +261,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// SQL (one column, no keyword) + emptyItemAtStart
$formElement[FE_EMPTY_ITEM_AT_START] = '';
$formElement['sql1'] = $this->db->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
// $expect = ['', 'form', 'formElement', 'phpunit_person'];
$expect = ['', 'form', 'formElement', 'copyForm'];
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
......@@ -272,7 +272,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// SQL (4 columns, none 'id' nor 'label') - Take the first two columns
$expectKeys = ['10', '20', '30'];
$expectValues = ['basic', 'access', 'various'];
$formElement['sql1'] = $this->db->sql('SELECT ord, name, created, modified FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT ord, name, created, modified FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
$this->assertEquals($expectKeys, $keys);
$this->assertEquals($expectValues, $values);
......@@ -280,7 +280,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// SQL (4 columns, none 'id', one 'label' ) - Take the first and the fourth two columns
$expectKeys = ['10', '20', '30'];
$expectValues = ['basic', 'access', 'various'];
$formElement['sql1'] = $this->db->sql('SELECT ord, created, modified, name AS label FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT ord, created, modified, name AS label FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
$this->assertEquals($expectKeys, $keys);
$this->assertEquals($expectValues, $values);
......@@ -288,7 +288,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
// SQL (4 columns, none 'id', one 'label' ) - Take the first and the fourth two columns
$expectKeys = ['1', '2', '3'];
$expectValues = ['basic', 'access', 'various'];
$formElement['sql1'] = $this->db->sql('SELECT ord, created, modified, name AS label, id FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT ord, created, modified, name AS label, id FROM FormElement AS fe ORDER BY fe.id LIMIT 3');
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
$this->assertEquals($expectKeys, $keys);
$this->assertEquals($expectValues, $values);
......@@ -304,7 +304,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->templateFormNFormElement($form, $formElement);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
$formElement['name'] = 'noteInternal';
$keys = array();
......@@ -325,111 +325,111 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement = \qfq\Support::setFeDefaults($formElement);
// CheckType
$build = new \qfq\BuildFormPlain($form, array(), [$formElement]);
$build = new \qfq\BuildFormPlain($form, array(), [$formElement], $this->dbArray);
// id: 1, firstName: John, name: Doe
$formElement['sql1'] = $this->db->sql('SELECT id, name, firstName FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, name, firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>id</th><th>name</th><th>firstName</th></tr></thead><tbody><tr class="record" ><td>1</td><td>Doe</td><td>John</td></tr><tr class="record" ><td>2</td><td>Smith</td><td>Jane</td></tr></tbody></table>', $result);
// _id: 1, name: Doe,
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe,title=''
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "title=" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, column: _Person
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "unused|width=2|title=_Person", firstName FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "unused|width=2|title=_Person", firstName FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>firstName</th></tr></thead><tbody><tr class="record" ><td>John</td></tr><tr class="record" ><td>Jane</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, title: PERSON
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PERSON</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, "This is a much longer text than necessary": Default max:20
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "This is a much longer text than necessary" FROM Person ORDER BY id LIMIT 1');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", "This is a much longer text than necessary" FROM Person ORDER BY id LIMIT 1');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>This is a much longe</th></tr></thead><tbody><tr class="record" ><td>This is a much longe</td></tr></tbody></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th></th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: Jo (width:2)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "2|PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PE</th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: Doe ('width':3)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "Name|width=3" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Nam</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
// _id: 1, name: Doe (width:3, title:PERSON)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name AS "3|title=PERSON" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>PER</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smi</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b>
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tbody><tr class="record" ><td>Doe</td></tr><tr class="record" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b>, width=2
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|2" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|2" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Na</th></tr></thead><tbody><tr class="record" ><td>Do</td></tr><tr class="record" ><td>Sm</td></tr></tbody></table>', $result);
// _id: 1, name: <b>Doe</b> , nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|nostrip" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", CONCAT("<b>", name, "</b>") AS "Name|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Name</th></tr></thead><tbody><tr class="record" ><td><b>Doe</b></td></tr><tr class="record" ><td><b>Smith</b></td></tr></tbody></table>', $result);
// _id: 1, icon: bullet-green.gif
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "bullet-green.gif" AS "Status|icon" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", "bullet-green.gif" AS "Status|icon" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>Status</th></tr></thead><tbody><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr><tr class="record" ><td><image src=\'typo3conf/ext/qfq/Resources/Public/icons/bullet-green.gif\'></td></tr></tbody></table>', $result);
// _id: 1, mailto: john@doe.com
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "john@doe.com" AS "EMail|mailto" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", "john@doe.com" AS "EMail|mailto" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>EMail</th></tr></thead><tbody><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr><tr class="record" ><td><a href="mailto:john@doe.com" >john@doe.com</a></td></tr></tbody></table>', $result);
// _id: 1, url: www.uzh.ch
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", "www.uzh.ch" AS "URL|url" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", "www.uzh.ch" AS "URL|url" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>URL</th></tr></thead><tbody><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr><tr class="record" ><td><a href="www.uzh.ch" >www.uzh.ch</a></td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowclass (text)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning", "text-danger") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name, IF(id=1,"text-warning", "text-danger") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record text-warning" ><td>Doe</td></tr><tr class="record text-danger" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowClass (text & background)
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, IF(id=1,"text-warning active", "text-danger success") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name, IF(id=1,"text-warning active", "text-danger success") AS _rowClass FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record text-warning active" ><td>Doe</td></tr><tr class="record text-danger success" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, _rowTitle
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name, firstName AS _rowTitle FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th></tr></thead><tbody><tr class="record" title="John" ><td>Doe</td></tr><tr class="record" title="Jane" ><td>Smith</td></tr></tbody></table>', $result);
// _id: 1, name: Doe, title, width, nostrip
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, "<b>This again is a very long text</b>" AS "title=Important|width=10|nostrip" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name, "<b>This again is a very long text</b>" AS "title=Important|width=10|nostrip" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th>Important</th></tr></thead><tbody><tr class="record" ><td>Doe</td><td><b>This again is a very long text</b></td></tr><tr class="record" ><td>Smith</td><td><b>This again is a very long text</b></td></tr></tbody></table>', $result);
// _id: 1, name: Doe, link
$formElement['sql1'] = $this->db->sql('SELECT id AS "_id", name, CONCAT("s:1|p:form&form=person&r=" , id , "|t:", name) AS "link" FROM Person ORDER BY id LIMIT 2');
$formElement['sql1'] = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id AS "_id", name, CONCAT("s:1|p:form&form=person&r=" , id , "|t:", name) AS "link" FROM Person ORDER BY id LIMIT 2');
$result = $build->buildSubrecord($formElement, 'name:1', '', $json);
$this->assertEquals('<table class="table table-hover" ><thead><tr><th>name</th><th></th></tr></thead><tbody><tr class="record" ><td>Doe</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Doe</a></td></tr><tr class="record" ><td>Smith</td><td><a href="index.php?id=form&s=badcaffee1234" class="internal" >Smith</a></td></tr></tbody></table>', $result);
}
......@@ -510,8 +510,8 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
parent::setUp();
// Use always the latest (production) FormEditor: played during QuickFormQuery()
$this->db->sql("DROP TABLE IF EXISTS `Form`");
$this->db->sql("DROP TABLE IF EXISTS `FormElement`");
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("DROP TABLE IF EXISTS `Form`");
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("DROP TABLE IF EXISTS `FormElement`");
$this->executeSQLFile(__DIR__ . '/../../sql/formEditor.sql', true);
$this->store->unsetStore(STORE_ADDITIONAL_FORM_ELEMENTS);
......@@ -527,7 +527,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$form = new \qfq\QuickFormQuery(['bodytext' => "form=form\nr=3", 'uid' => 1234], true);
// After instantiating QuickFormQuery, the latest updates will be played. The SIP is by default activated which breaks current tests.
$this->db->sql("UPDATE Form SET permitNew='always', permitEdit='always' WHERE name='form' ");
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql("UPDATE Form SET permitNew='always', permitEdit='always' WHERE name='form' ");
$form->process();
}
}
......
......@@ -13,7 +13,7 @@ class DatabaseTest extends AbstractDatabaseTest {
* @throws \qfq\DbException
*/
public function testFetchAll() {
$allRows = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
$allRows = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
$this->assertCount(2, $allRows);
$this->assertEquals(1, $allRows[0]['id']);
......@@ -24,7 +24,7 @@ class DatabaseTest extends AbstractDatabaseTest {
* @throws \qfq\DbException
*/
public function testFetchAllEmpty() {
$allRows = $this->db->sql('SELECT * FROM Person WHERE id=0 ORDER BY id');
$allRows = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE id=0 ORDER BY id');
$this->assertEquals(array(), $allRows);
}
......@@ -55,12 +55,12 @@ class DatabaseTest extends AbstractDatabaseTest {
// Check read rows
$dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 1');
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 1');
// Check count
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check read rows
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2');
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2');
// Check count
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
......@@ -69,68 +69,68 @@ class DatabaseTest extends AbstractDatabaseTest {
// Check rows
// Same as above, but specify 'ROW_REGULAR'
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals($expected, $dataArray);
// ROW_EXPECT_0
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0);
$this->assertEquals(0, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals(array(), $dataArray);
// ROW_EXPECT_1
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_1);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_1);
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals($expected[0], $dataArray);
// ROW_EXPECT_0_1: 1
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_0_1);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_0_1);
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals($expected[0], $dataArray);
// ROW_EXPECT_0_1: 0
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0_1);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE id=0', ROW_EXPECT_0_1);
$this->assertEquals(0, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals(array(), $dataArray);
//ROW_EXPECT_GE_1 - one record
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_GE_1);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id=1', ROW_EXPECT_GE_1);
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals([$expected[0]], $dataArray);
// ROW_EXPECT_GE_1 - two records
$dataArray = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_EXPECT_GE_1);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_EXPECT_GE_1);
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check rows
$this->assertEquals($expected, $dataArray);
// Check Implode: 2 records
$data = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$this->assertEquals(implode($expected[0]) . implode($expected[1]), $data);
// Check Implode: 1 record
$data = $this->db->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id,name,firstName,adrId,gender,groups FROM Person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
$this->assertEquals(implode($expected[0]), $data);
// Check Implode 0 record
$data = $this->db->sql('SELECT * FROM Person WHERE id=0 ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE id=0 ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$this->assertEquals('', $data);
$data = $this->db->sql('SELECT "a", "b", "c"', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT "a", "b", "c"', ROW_IMPLODE_ALL);
$this->assertEquals('abc', $data);
// Multiple columns with same columnname
$data = $this->db->sql('SELECT "a", "b", "a"', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT "a", "b", "a"', ROW_IMPLODE_ALL);
$this->assertEquals('aba', $data);
// Multiple columns with same columnname
$data = $this->db->sql('SELECT id, name, firstname, name, id FROM Person', ROW_IMPLODE_ALL);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT id, name, firstname, name, id FROM Person', ROW_IMPLODE_ALL);
$this->assertEquals('1DoeJohnDoe12SmithJaneSmith2', $data);
}
......@@ -143,22 +143,22 @@ class DatabaseTest extends AbstractDatabaseTest {
$dummy = array();
// Parameter Susbstitution by '?'
$dataArray = $this->db->sql('SELECT * FROM Person WHERE name LIKE ? ORDER BY id', ROW_REGULAR, ['Smith']);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person WHERE name LIKE ? ORDER BY id', ROW_REGULAR, ['Smith']);
// Check count
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
$dataArray = $this->db->sql('UPDATE Person SET groups = ?', ROW_REGULAR, ['a,b,c']);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('UPDATE Person SET groups = ?', ROW_REGULAR, ['a,b,c']);
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
$dataArray = $this->db->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'John', 'a'], 'fake', $dummy, $stat);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'John', 'a'], 'fake', $dummy, $stat);
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
$this->assertEquals(3, $stat[DB_INSERT_ID]);
$dataArray = $this->db->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'Jan', 'b'], 'fake', $dummy, $stat);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('INSERT INTO Person (`name`, `firstname`, `groups`) VALUES ( ?, ? ,? )', ROW_REGULAR, ['Meier', 'Jan', 'b'], 'fake', $dummy, $stat);
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
$this->assertEquals(4, $stat[DB_INSERT_ID]);
$dataArray = $this->db->sql('DELETE FROM Person WHERE name = ?', ROW_REGULAR, ['Meier']);
$dataArray = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('DELETE FROM Person WHERE name = ?', ROW_REGULAR, ['Meier']);
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
}
......@@ -167,42 +167,42 @@ class DatabaseTest extends AbstractDatabaseTest {
* @expectedException \qfq\DbException
*/
public function testSqlExceptionExpect0() {
$data = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 1', ROW_EXPECT_0);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 1', ROW_EXPECT_0);
}
/**
* @expectedException \qfq\DbException
*/
public function testSqlExceptionExpect1_0() {
$data = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_1);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_1);
}
/**
* @expectedException \qfq\DbException
*/
public function testSqlExceptionExpect1_2() {
$data = $this->db->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_1);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_1);
}
/**
* @expectedException \qfq\DbException
*/
public function testSqlExceptionExpect01() {
$data = $this->db->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_0_1);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id ', ROW_EXPECT_0_1);
}
/**
* @expectedException \qfq\DbException
*/
public function testSqlExceptionExpectGE1() {
$data = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_GE_1);
$data = $this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 0', ROW_EXPECT_GE_1);
}
/**
* @expectedException \qfq\DbException
*/
public function testSanitizeException() {
$this->db->sql('some garbage');
$this->dbArray[DB_INDEX_DATA_DEFAULT]->sql('some garbage');
}
/**
......@@ -218,12 +218,12 @@ class DatabaseTest extends AbstractDatabaseTest {
*
*/
public function testGetSetValueList() {
$valueList = $this->db->getEnumSetValueList('Person', 'gender');
$valueList = $this->dbArray[DB_INDEX_DATA_DEFAULT]->getEnumSetValueList('Person', 'gender');
$expected = [0 => '', 1 => 'male', 2 => 'female'];
$this->assertEquals($expected, $valueList);
$expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c'];
$valueList = $this->db->getEnumSetValueList('Person', 'groups');
$valueList = $this->dbArray[DB_INDEX_DATA_DEFAULT]->getEnumSetValueList('Person', 'groups');
$this->assertEquals($expected, $valueList);