Commit 1d14fae0 authored by Carsten  Rose's avatar Carsten Rose
Browse files

phpunit test: update several tests for latest changes

parent 68756afd
......@@ -28,12 +28,12 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
*/
protected $db = null;
/*
/**
* @var qfq\Store
*/
protected $store = null;
/*
/**
* @var qfq\Sip
*/
protected $sip = null;
......
<?php
/**
* @author Rafael Ostertag <rafael.ostertag@math.uzh.ch>
*/
//use qfq\Store;
require_once(__DIR__ . '/../../qfq/BuildFormPlain.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
require_once(__DIR__ . '/AbstractDatabaseTest.php');
require_once(__DIR__ . '/../../qfq/store/Store.php');
require_once(__DIR__ . '/../../qfq/database/Database.php');
require_once(__DIR__ . '/../../qfq/exceptions/DbException.php');
require_once(__DIR__ . '/../../qfq/QuickFormQuery.php');
/**
* Created by PhpStorm.
* User: crose
* Date: 2/2/16
* Time: 10:07 PM
*/
class BuildFormPlainTest extends AbstractDatabaseTest {
/**
......@@ -175,63 +170,6 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals(['disabled' => false, FE_MODE_REQUIRED => '', 'form-element' => 'name:1', 'value' => 'Hello World', 'disabled' => false, API_ELEMENT_UPDATE => $label], $json);
}
/**
*
*/
private function templateFormNFormElement(array &$form, array &$formElement) {
$form = [
'id' => '1',
'name' => 'form',
'title' => 'Form Editor: {{SELECT id, " / ", title FROM Form WHERE id => {{recordId:S0}}}}',
'noteInternal' => 'Please secure the form',
'tableName' => 'Form',
'permitNew' => 'always',
'permitEdit' => 'always',
'permitUrlParameter' => '',
'render' => 'bootstrap',
'multiMode' => 'none',
'multiSql' => '',
'multiDetailForm' => '',
'multiDetailFormParameter' => '',
F_FORWARD_MODE => 'auto',
F_FORWARD_PAGE => '',
'bsLabelColumns' => '',
'bsInputColumns' => '',
'bsNoteColumns' => '',
'parameter' => 'maxVisiblePill=>3',
'deleted' => 'no',
];
$formElement = [
'id' => 123,
FE_ID => 1,
FE_ID_CONTAINER => 0,
FE_DYNAMIC_UPDATE => 'no',
'enabled' => 'yes',
FE_NAME => 'name',
FE_LABEL => 'Name',
FE_MODE => 'show',
'class' => 'native',
FE_TYPE => 'input',
'value' => '',
'sql1' => '',
'parameter' => '',
'debug' => 'no',
'deleted' => 'no',
'size' => '',
'maxLength' => '255',
'tooltip' => '',
'placeholder' => '',
FE_CHECK_TYPE => '',
FE_CHECK_PATTERN => '',
FE_HTML_ID => '123',
FE_HIDE_ZERO => '0',
'tabindex' => 0
];
}
/**
* @expectedException \qfq\UserFormException
*
......@@ -493,6 +431,72 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals('<table class="table table-hover"><tr><th>name</th><th></th></tr><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></table>', $result);
}
/**
*
*/
private function templateFormNFormElement(array &$form, array &$formElement) {
$form = [
'id' => '1',
'name' => 'form',
'title' => 'Form Editor: {{SELECT id, " / ", title FROM Form WHERE id => {{recordId:S0}}}}',
'noteInternal' => 'Please secure the form',
'tableName' => 'Form',
'permitNew' => 'always',
'permitEdit' => 'always',
'permitUrlParameter' => '',
'render' => 'bootstrap',
'multiMode' => 'none',
'multiSql' => '',
'multiDetailForm' => '',
'multiDetailFormParameter' => '',
F_FORWARD_MODE => 'auto',
F_FORWARD_PAGE => '',
'bsLabelColumns' => '',
'bsInputColumns' => '',
'bsNoteColumns' => '',
'parameter' => 'maxVisiblePill=>3',
'deleted' => 'no',
];
$formElement = [
'id' => 123,
FE_ID => 1,
FE_ID_CONTAINER => 0,
FE_DYNAMIC_UPDATE => 'no',
'enabled' => 'yes',
FE_NAME => 'name',
FE_LABEL => 'Name',
FE_MODE => 'show',
'class' => 'native',
FE_TYPE => 'input',
'value' => '',
'sql1' => '',
'parameter' => '',
'debug' => 'no',
'deleted' => 'no',
'size' => '',
'maxLength' => '255',
'tooltip' => '',
'placeholder' => '',
FE_CHECK_TYPE => '',
FE_CHECK_PATTERN => '',
FE_HTML_ID => '123',
FE_HIDE_ZERO => '0',
'tabindex' => 0
];
}
// /**
// * @throws Exception
// */
// protected function setUp() {
// parent::setUp();
//
// $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
// }
/**
* @throws Exception
*/
......@@ -531,3 +535,4 @@ class FakeTSFEBuildPlain {
}
......@@ -60,7 +60,7 @@ class DatabaseTest extends AbstractDatabaseTest {
$this->assertEquals(1, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Check read rows
$dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
$dataArray = $this->db->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,7 +69,7 @@ class DatabaseTest extends AbstractDatabaseTest {
// Check rows
// Same as above, but specify 'ROW_REGULAR'
$dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
$dataArray = $this->db->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);
......@@ -81,13 +81,13 @@ class DatabaseTest extends AbstractDatabaseTest {
$this->assertEquals(array(), $dataArray);
// ROW_EXPECT_1
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EXPECT_1);
$dataArray = $this->db->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 * FROM Person WHERE id=1', ROW_EXPECT_0_1);
$dataArray = $this->db->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);
......@@ -99,23 +99,23 @@ class DatabaseTest extends AbstractDatabaseTest {
$this->assertEquals(array(), $dataArray);
//ROW_EXPECT_GE_1 - one record
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EXPECT_GE_1);
$dataArray = $this->db->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 * FROM Person ORDER BY id LIMIT 2', ROW_EXPECT_GE_1);
$dataArray = $this->db->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 * FROM Person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$data = $this->db->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 * FROM Person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
$data = $this->db->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
......@@ -255,7 +255,7 @@ class DatabaseTest extends AbstractDatabaseTest {
$rc = $this->db->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
// DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
$this->assertEquals(8, $stat[DB_NUM_ROWS]);
$this->assertEquals(9, $stat[DB_NUM_ROWS]);
}
/**
......@@ -270,7 +270,7 @@ class DatabaseTest extends AbstractDatabaseTest {
$rc = $this->db->sql($sql, ROW_REGULAR, $dummy, 'fake', $dummy, $stat);
// DB_NUM_ROWS | DB_INSERT_ID | DB_AFFECTED_ROWS
$this->assertEquals(6, $stat[DB_NUM_ROWS]);
$this->assertEquals(8, $stat[DB_NUM_ROWS]);
}
/**
......@@ -368,6 +368,8 @@ class DatabaseTest extends AbstractDatabaseTest {
['Field' => 'adrId', 'Type' => 'int(11)', 'Null' => 'NO', 'Key' => '', 'Default' => '0', 'Extra' => ''],
['Field' => 'gender', 'Type' => "enum('','male','female')", 'Null' => 'NO', 'Key' => '', 'Default' => 'male', 'Extra' => ''],
['Field' => 'groups', 'Type' => "set('','a','b','c')", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
['Field' => 'modified', 'Type' => "timestamp", 'Null' => 'NO', 'Key' => '', 'Default' => 'CURRENT_TIMESTAMP', 'Extra' => 'on update CURRENT_TIMESTAMP'],
['Field' => 'created', 'Type' => "datetime", 'Null' => 'NO', 'Key' => '', 'Default' => '', 'Extra' => ''],
];
$this->assertEquals($expected, $this->db->getTableDefinition('Person'));
......
......@@ -46,14 +46,14 @@ class EvaluateTest extends \AbstractDatabaseTest {
$eval = new \qfq\Evaluate($this->store, $this->db);
// database: lower case
$this->assertEquals('1DoeJohn0malec2SmithJane0femalea,c', $eval->parse('{{select * 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}}'));
// database: upper case
$this->assertEquals('1DoeJohn0malec2SmithJane0femalea,c', $eval->parse('{{SELECT * 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}}'));
$this->store->setVar('sql', 'SELECT * FROM Person WHERE id < 3 ORDER BY id', 'C');
$this->assertEquals('SELECT * FROM Person WHERE id < 3 ORDER BY id', $eval->parse('{{sql:C:all}}'));
$this->store->setVar('sql', 'SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id < 3 ORDER BY id', 'C');
$this->assertEquals('SELECT id,name,firstName,adrId,gender,groups FROM Person WHERE id < 3 ORDER BY id', $eval->parse('{{sql:C:all}}'));
$this->assertEquals('1DoeJohn0malec2SmithJane0femalea,c', $eval->parse('{{{{sql:C:all}}}}'));
// Get 2 row Array
......@@ -86,7 +86,7 @@ class EvaluateTest extends \AbstractDatabaseTest {
$this->assertEquals('1', $eval->parse('{{SELECT count(id) FROM Person WHERE name="Zappa" AND firstname="Frank"}}'));
// SHOW tables
$expected = "idbigint(20)NOPRIauto_incrementnamevarchar(128)YESfirstNamevarchar(128)YESadrIdint(11)NO0genderenum('','male','female')NOmalegroupsset('','a','b','c')NO";
$expected = "idbigint(20)NOPRIauto_incrementnamevarchar(128)YESfirstNamevarchar(128)YESadrIdint(11)NO0genderenum('','male','female')NOmalegroupsset('','a','b','c')NOmodifiedtimestampNOCURRENT_TIMESTAMPon update CURRENT_TIMESTAMPcreateddatetimeNO";
$this->assertEquals($expected, $eval->parse('{{SHOW COLUMNS FROM Person}}'));
......@@ -348,14 +348,16 @@ class EvaluateTest extends \AbstractDatabaseTest {
// LDAP_ESCAPE_FILTER => array('\\', '*', '(', ')', "\x00"),
// LDAP_ESCAPE_DN => array('\\', ',', '=', '+', '<', '>', ';', '"', '#'),
$this->store->setVar('a', ' hello world ', STORE_FORM, true);
$this->assertEquals('\20hello world\20', $eval->substitute('a:F:all:L', $foundInStore));
// $this->assertEquals('\20hello world\20', $eval->substitute('a:F:all:L', $foundInStore));
$this->assertEquals(' hello world ', $eval->substitute('a:F:all:L', $foundInStore));
$this->store->setVar('a', 'h\e,l=l+o< >w;o"r#ld', STORE_FORM, true);
$this->assertEquals('h\5ce\2cl\3dl\2bo\3c \3ew\3bo\22r\23ld', $eval->substitute('a:F:all:L', $foundInStore));
$this->store->setVar('a', ' hel;lo world ', STORE_FORM, true);
$this->assertEquals('\20hel\3blo world\20', $eval->substitute('a:F:all:sL', $foundInStore));
// $this->assertEquals('\20hel\3blo world\20', $eval->substitute('a:F:all:sL', $foundInStore));
$this->assertEquals(' hel\3blo world ', $eval->substitute('a:F:all:sL', $foundInStore));
}
......
......@@ -151,7 +151,8 @@ class OnArrayTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals(array(), OnArray::getArrayItemKeyNameStartWith(array(), ''));
$this->assertEquals(['a' => 'hello'], OnArray::getArrayItemKeyNameStartWith(['a' => 'hello'], ''));
$this->assertEquals(array(), OnArray::getArrayItemKeyNameStartWith(['a' => 'hello'], 'b'));
$this->assertEquals([0 => 'hello'], OnArray::getArrayItemKeyNameStartWith(['a' => 'hello'], 'a'));
// $this->assertEquals([0 => 'hello'], OnArray::getArrayItemKeyNameStartWith(['a' => 'hello'], 'a'));
$this->assertEquals(['' => 'hello'], OnArray::getArrayItemKeyNameStartWith(['a' => 'hello'], 'a'));
$this->assertEquals(['b' => 'hello'], OnArray::getArrayItemKeyNameStartWith(['ab' => 'hello'], 'a'));
$this->assertEquals(array(), OnArray::getArrayItemKeyNameStartWith(['ba' => 'hello'], 'a'));
$this->assertEquals(['a' => 'is', 'b' => 'john'], OnArray::getArrayItemKeyNameStartWith(['1_a' => 'my', '1_b' => 'name', '2_a' => 'is', '2_b' => 'john'], '2_'));
......
......@@ -24,10 +24,11 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
* @var Store
*/
private $store = null;
private $setUpDone = false;
public function setUp() {
// Client Variables has to setup before the first instantiation of 'Store'
// Client Variables has to setup before the first instantiation of 'Store'
$_GET[CLIENT_RECORD_ID] = '1234';
// $_GET[CLIENT_SIP] = '12badcaffee34';
$_GET['key01'] = '1234';
......@@ -118,12 +119,12 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
public function testStorePriority() {
//default prio FSRD
//default prio FSRVD
$this->store->unsetStore(STORE_RECORD);
$this->store->fillStoreTableDefaultColumnType('Person');
$this->assertEquals('male', $this->store->getVar('gender'), "Get default definition from table person.gender");
// $this->assertEquals('male', $this->store->getVar('gender','','alnumx'), "Get default definition from table person.gender");
$this->store->setVar('gender', 'female', STORE_RECORD);
$this->assertEquals('female', $this->store->getVar('gender'), "Retrieve 'gender' from STORE_RECORD");
......@@ -295,6 +296,8 @@ EOT;
SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS => SYSTEM_RECORD_LOCK_TIMEOUT_SECONDS_DEFAULT,
DOCUMENTATION_QFQ => DOCUMENTATION_QFQ_URL,
SYSTEM_VAR_ADD_BY_SQL => 'SELECT id AS periodId FROM Period WHERE start<=NOW() ORDER BY start DESC LIMIT 1',
];
$fileName = $this->createFile($body);
......@@ -356,5 +359,4 @@ EOT;
$this->assertEquals(array(), $this->store->getStore('unknownstore'));
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment