db = Query('test_sqlite'); } // -------------------------------------------------------------------------- // ! Util Method tests // -------------------------------------------------------------------------- public function testCreateTable() { $this->db->exec(file_get_contents(QTEST_DIR.'/db_files/sqlite.sql')); //Check $dbs = $this->db->get_tables(); $this->assertTrue(in_array('TEST1', $dbs)); $this->assertTrue(in_array('TEST2', $dbs)); $this->assertTrue(in_array('NUMBERS', $dbs)); $this->assertTrue(in_array('NEWTABLE', $dbs)); $this->assertTrue(in_array('create_test', $dbs)); $this->assertTrue(in_array('create_join', $dbs)); $this->assertTrue(in_array('create_delete', $dbs)); } // -------------------------------------------------------------------------- /*public function testBackupData() { $sql = mb_trim($this->db->util->backup_data(array('create_join', 'create_test'))); $sql_array = explode("\n", $sql); $expected = <<assertEqual($expected_array, $sql_array); }*/ // -------------------------------------------------------------------------- public function testBackupStructure() { $sql = mb_trim($this->db->util->backup_structure()); $expected = << 100; SQL; $expected_array = explode("\n", $expected); $result_array = explode("\n", $sql); $this->assertEqual($expected_array, $result_array); } // -------------------------------------------------------------------------- public function testDeleteTable() { $sql = $this->db->util->delete_table('create_delete'); $this->db->query($sql); //Check $dbs = $this->db->get_tables(); $this->assertFalse(in_array('create_delete', $dbs)); } // -------------------------------------------------------------------------- // ! General tests // -------------------------------------------------------------------------- public function testConnection() { $db = new \Query\Driver\SQLite(QTEST_DIR.QDS.'db_files'.QDS.'test_sqlite.db'); $this->assertIsA($db, '\\Query\\Driver\\SQLite'); $this->assertIsA($this->db->db, '\\Query\\Driver\\SQLite'); unset($db); } // -------------------------------------------------------------------------- public function testTruncate() { $this->db->truncate('create_test'); } // -------------------------------------------------------------------------- public function testPreparedStatements() { $sql = <<db->prepare_query($sql, array(1,"boogers", "Gross")); $statement->execute(); } // -------------------------------------------------------------------------- public function testPrepareExecute() { $sql = <<db->prepare_execute($sql, array( 2, "works", 'also?' )); } // -------------------------------------------------------------------------- public function testCommitTransaction() { $res = $this->db->beginTransaction(); $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (10, 12, 14)'; $this->db->query($sql); $res = $this->db->commit(); $this->assertTrue($res); } // -------------------------------------------------------------------------- public function testRollbackTransaction() { $res = $this->db->beginTransaction(); $sql = 'INSERT INTO "create_test" ("id", "key", "val") VALUES (182, 96, 43)'; $this->db->query($sql); $res = $this->db->rollback(); $this->assertTrue($res); } // -------------------------------------------------------------------------- public function testGetDBs() { $this->assertTrue(is_array($this->db->get_dbs())); } // -------------------------------------------------------------------------- public function testGetSchemas() { $this->assertNull($this->db->get_schemas()); } // -------------------------------------------------------------------------- // ! SQL tests // -------------------------------------------------------------------------- public function testNullMethods() { $sql = $this->db->sql->system_table_list(); $this->assertEqual(NULL, $sql); $sql = $this->db->sql->trigger_list(); $this->assertEqual(NULL, $sql); $sql = $this->db->sql->function_list(); $this->assertEqual(NULL, $sql); $sql = $this->db->sql->procedure_list(); $this->assertEqual(NULL, $sql); $sql = $this->db->sql->sequence_list(); $this->assertEqual(NULL, $sql); } }