/**
  *
  */
 public function test_build_new()
 {
     // arrange
     $testdata = array();
     $testdata['new']['new1']['sort'] = 70;
     $testdata['new']['new1']['label'] = 'testcolumn';
     $testdata['new']['new1']['ismulti'] = 0;
     $testdata['new']['new1']['config'] = '{"prefix": "", "postfix": ""}';
     $testdata['new']['new1']['class'] = 'Text';
     $testdata['new']['new1']['isenabled'] = '1';
     $testdata['new']['new2']['sort'] = 40;
     $testdata['new']['new2']['label'] = 'testMulitColumn';
     $testdata['new']['new2']['ismulti'] = 1;
     $testdata['new']['new2']['config'] = '{"prefix": "pre", "postfix": "post"}';
     $testdata['new']['new2']['class'] = 'Text';
     $testdata['new']['new2']['isenabled'] = '1';
     $testname = 'testTable';
     $testname = Schema::cleanTableName($testname);
     // act
     $builder = new SchemaBuilder($testname, $testdata);
     $result = $builder->build();
     /** @noinspection SqlResolve */
     $res = $this->sqlite->query("SELECT sql FROM sqlite_master WHERE type='table' AND name=?", 'data_' . $testname);
     $tableSQL = $this->sqlite->res2single($res);
     $this->sqlite->res_close($res);
     $expected_tableSQL = "CREATE TABLE data_testtable (\n                    pid NOT NULL,\n                    rev INTEGER NOT NULL,\n                    latest BOOLEAN NOT NULL DEFAULT 0, col1 DEFAULT '', col2 DEFAULT '',\n                    PRIMARY KEY(pid, rev)\n                )";
     $res = $this->sqlite->query("SELECT * FROM types");
     $actual_types = $this->sqlite->res2arr($res);
     $this->sqlite->res_close($res);
     $expected_types = array(array('id' => "1", 'class' => 'Text', 'ismulti' => "0", 'label' => "testcolumn", 'config' => '{"prefix": "", "postfix": ""}'), array('id' => "2", 'class' => 'Text', 'ismulti' => "1", 'label' => "testMulitColumn", 'config' => '{"prefix": "pre", "postfix": "post"}'));
     $res = $this->sqlite->query("SELECT * FROM schema_cols");
     $actual_cols = $this->sqlite->res2arr($res);
     $this->sqlite->res_close($res);
     $expected_cols = array(array('sid' => "1", 'colref' => "1", 'enabled' => "1", 'tid' => "1", 'sort' => "70"), array('sid' => "1", 'colref' => "2", 'enabled' => "1", 'tid' => "2", 'sort' => "40"));
     $res = $this->sqlite->query("SELECT * FROM schemas");
     $actual_schema = $this->sqlite->res2row($res);
     $this->sqlite->res_close($res);
     $this->assertSame('1', $result);
     $this->assertEquals($expected_tableSQL, $tableSQL);
     $this->assertEquals($expected_types, $actual_types);
     $this->assertEquals($expected_cols, $actual_cols);
     $this->assertEquals('1', $actual_schema['id']);
     $this->assertEquals($testname, $actual_schema['tbl']);
     $this->assertEquals('', $actual_schema['chksum']);
     $this->assertTrue((int) $actual_schema['ts'] > 0, 'timestamp should be larger than 0');
 }
 public function test_saveData()
 {
     // arrange
     $testdata = array('testcolumn' => 'value1_saved', 'testMulitColumn' => array("value2.1_saved", "value2.2_saved", "value2.3_saved"));
     // act
     $schemaData = meta\AccessTable::byTableName('testtable', 'testpage', time());
     $result = $schemaData->saveData($testdata);
     // assert
     /** @noinspection SqlResolve */
     $res = $this->sqlite->query("SELECT pid, col1, col2 FROM data_testtable WHERE pid = ? ORDER BY rev DESC LIMIT 1", array('testpage'));
     $actual_saved_single = $this->sqlite->res2row($res);
     $expected_saved_single = array('pid' => 'testpage', 'col1' => 'value1_saved', 'col2' => 'value2.1_saved');
     /** @noinspection SqlResolve */
     $res = $this->sqlite->query("SELECT colref, row, value FROM multi_testtable WHERE pid = ? ORDER BY rev DESC LIMIT 3", array('testpage'));
     $actual_saved_multi = $this->sqlite->res2arr($res);
     $expected_saved_multi = array(array('colref' => '2', 'row' => '1', 'value' => "value2.1_saved"), array('colref' => '2', 'row' => '2', 'value' => "value2.2_saved"), array('colref' => '2', 'row' => '3', 'value' => "value2.3_saved"));
     $this->assertTrue($result, 'should be true on success');
     $this->assertEquals($expected_saved_single, $actual_saved_single, 'single value fields');
     $this->assertEquals($expected_saved_multi, $actual_saved_multi, 'multi value fields');
 }