Commit 52135413 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixes #7603: Unit test if DatabaseUpdate() plays well. Especially that...

Fixes #7603: Unit test if DatabaseUpdate() plays well. Especially that formEditor.sql is running fine.
parent ba10bb18
Pipeline #1279 passed with stage
in 1 minute and 39 seconds
......@@ -119,7 +119,7 @@ abstract class AbstractBuildForm {
* @param array $formSpec
* @param array $feSpecAction
* @param array $feSpecNative
* @param array $db
* @param array Database $db
* @throws CodeException
* @throws UserFormException
* @throws UserReportException
......
......@@ -284,10 +284,10 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$this->assertEquals($expectValues, $values);
unset($formElement['emptyItemAtEnd']);
// SQL
// SQL: any content is fine, but should always be the same to do checks
$formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
// $expect = ['form', 'formElement', 'phpunit_person'];
$expect = ['form', 'formElement', 'phpunit_person'];
$expect = ['form', 'formElement', 'copyForm'];
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
$this->assertEquals($expect, $keys);
$this->assertEquals($expect, $values);
......@@ -296,7 +296,7 @@ class BuildFormPlainTest extends AbstractDatabaseTest {
$formElement[FE_EMPTY_ITEM_AT_START] = '';
$formElement['sql1'] = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT name FROM Form AS f ORDER BY f.id LIMIT 3');
// $expect = ['', 'form', 'formElement', 'phpunit_person'];
$expect = ['', 'form', 'formElement', 'phpunit_person'];
$expect = ['', 'form', 'formElement', 'copyForm'];
$build->getKeyValueListFromSqlEnumSpec($formElement, $keys, $values);
$this->assertEquals($expect, $keys);
$this->assertEquals($expect, $values);
......
<?php
/**
* @author Carsten Rose <carsten.rose@math.uzh.ch>
*/
namespace qfq;
require_once(__DIR__ . '/AbstractDatabaseTest.php');
/**
* Class DatabaseTest
*/
class DatabaseUpdateTest extends AbstractDatabaseTest {
// /**
// */
// public function testFetchAll() {
// $allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
//
// $this->assertCount(2, $allRows);
// $this->assertEquals(1, $allRows[0]['id']);
// $this->assertEquals(2, $allRows[1]['id']);
// }
/**
* @throws CodeException
* @throws DbException
* @throws UserFormException
*/
public function testCheckNupdate() {
$countQfqTables = 9;
$dbUpdate = new DatabaseUpdate($this->dbArray[DB_INDEX_DEFAULT]);
$dbUpdate->checkNupdate(SYSTEM_DB_UPDATE_NEVER);
$allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SHOW tables;');
$this->assertCount(0, $allRows);
$dbUpdate->checkNupdate(SYSTEM_DB_UPDATE_AUTO);
$allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SHOW tables;');
$this->assertCount($countQfqTables, $allRows);
// After deleting FormElement, but keeping Form, the update should not played with 'AUTO'
$this->dbArray[DB_INDEX_DEFAULT]->sql('DROP TABLE FormElement;');
$dbUpdate->checkNupdate(SYSTEM_DB_UPDATE_AUTO);
$allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SHOW tables;');
$this->assertCount($countQfqTables - 1, $allRows);
// Now we should have all tables again
$dbUpdate->checkNupdate(SYSTEM_DB_UPDATE_ALWAYS);
$allRows = $this->dbArray[DB_INDEX_DEFAULT]->sql('SHOW tables;');
$this->assertCount($countQfqTables, $allRows);
}
/**
* @throws CodeException
* @throws DbException
* @throws UserFormException
* @throws UserReportException
*/
protected function setUp() {
parent::setUp();
// remove existing tables
$allTables = $this->dbArray[DB_INDEX_DEFAULT]->sql("SHOW TABLES", ROW_REGULAR);
foreach ($allTables AS $val) {
$table = current($val);
$this->dbArray[DB_INDEX_DEFAULT]->sql("DROP TABLE $table");
}
// $this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
}
}
Markdown is supported
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