This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
OpenSQLManager/tests/databases/sqlite-qb.php

203 lines
4.0 KiB
PHP
Raw Normal View History

2012-03-09 16:17:21 -05:00
<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
* @author Timothy J. Warren
* @copyright Copyright (c) 2012
* @link https://github.com/aviat4ion/OpenSQLManager
* @license http://philsturgeon.co.uk/code/dbad-license
*/
// --------------------------------------------------------------------------
/**
* Class for testing Query Builder with SQLite
*/
class SQLiteQBTest extends UnitTestCase {
2012-03-13 12:57:12 -04:00
function __construct()
{
parent::__construct();
$path = TEST_DIR.DS.'test_dbs'.DS.'test_sqlite.db';
2012-03-09 16:17:21 -05:00
$params = new Stdclass();
$params->type = 'sqlite';
$params->file = $path;
$params->host = 'localhost';
$this->db = new Query_Builder($params);
2012-03-13 12:57:12 -04:00
echo '<hr /> SQLite Queries <hr />';
2012-03-13 12:57:12 -04:00
}
2012-03-09 16:17:21 -05:00
function TestGet()
{
$query = $this->db->get('create_test ct');
2012-03-09 16:17:21 -05:00
$this->assertIsA($query, 'PDOStatement');
}
function TestGetLimit()
{
$query = $this->db->get('create_test', 2);
2012-03-09 16:17:21 -05:00
$this->assertIsA($query, 'PDOStatement');
}
function TestGetLimitSkip()
{
$query = $this->db->get('create_test', 2, 1);
2012-03-09 16:17:21 -05:00
$this->assertIsA($query, 'PDOStatement');
}
function TestSelectWhereGet()
{
$query = $this->db->select('id, key as k, val')
2012-03-09 16:17:21 -05:00
->where('id >', 1)
->where('id <', 900)
->get('create_test', 2, 1);
$this->assertIsA($query, 'PDOStatement');
}
function TestSelectWhereGet2()
{
$query = $this->db->select('id, key as k, val')
2012-03-09 16:17:21 -05:00
->where('id !=', 1)
->get('create_test', 2, 1);
$this->assertIsA($query, 'PDOStatement');
}
function TestSelectGet()
{
$query = $this->db->select('id, key as k, val')
2012-03-09 16:17:21 -05:00
->get('create_test', 2, 1);
$this->assertIsA($query, 'PDOStatement');
}
function TestSelectFromGet()
{
$query = $this->db->select('id, key as k, val')
2012-03-09 16:17:21 -05:00
->from('create_test ct')
->where('id >', 1)
->get();
$this->assertIsA($query, 'PDOStatement');
}
function TestSelectFromLimitGet()
{
$query = $this->db->select('id, key as k, val')
2012-03-09 16:17:21 -05:00
->from('create_test ct')
->where('id >', 1)
->limit(3)
->get();
$this->assertIsA($query, 'PDOStatement');
}
2012-03-13 12:28:51 -04:00
2012-03-13 14:57:01 -04:00
function TestOrderBy()
{
$query = $this->db->select('id, key as k, val')
2012-03-13 14:57:01 -04:00
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->order_by('id', 'DESC')
->order_by('k', 'ASC')
->limit(5,2)
->get();
$this->assertIsA($query, 'PDOStatement');
}
function TestOrderByRandom()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->order_by('id', 'rand')
->limit(5,2)
->get();
$this->assertIsA($query, 'PDOStatement');
}
function TestGroupBy()
{
$query = $this->db->select('id, key as k, val')
->from('create_test')
->where('id >', 0)
->where('id <', 9000)
->group_by('k')
->group_by('val')
->order_by('id', 'DESC')
->order_by('k', 'ASC')
->limit(5,2)
->get();
$this->assertIsA($query, 'PDOStatement');
}
2012-03-14 10:52:11 -04:00
function TestOrWhere()
{
$query = $this->db->select('id, key as k, val')
2012-03-14 10:52:11 -04:00
->from('create_test')
->where(' id ', 1)
->or_where('key >', 0)
->limit(2, 1)
->get();
$this->assertIsA($query, 'PDOStatement');
}
function TestLike()
{
$query = $this->db->from('create_test')
2012-03-14 10:52:11 -04:00
->like('key', 'og')
->get();
$this->assertIsA($query, 'PDOStatement');
}
2012-03-14 15:46:54 -04:00
function TestJoin()
{
$query = $this->db->from('create_test')
->join('create_join cj', 'cj.id = create_test.id')
->get();
$this->assertIsA($query, 'PDOStatement');
}
2012-03-13 12:28:51 -04:00
function TestInsert()
{
$query = $this->db->set('id', 4)
2012-03-13 12:28:51 -04:00
->set('key', 4)
->set('val', 5)
->insert('create_test');
$this->assertIsA($query, 'PDOStatement');
}
2012-03-13 12:57:12 -04:00
function TestUpdate()
{
$query = $this->db->set('id', 4)
2012-03-13 12:57:12 -04:00
->set('key', 'gogle')
->set('val', 'non-word')
->where('id', 4)
->update('create_test');
$this->assertIsA($query, 'PDOStatement');
}
2012-03-13 13:38:47 -04:00
function TestDelete()
{
$query = $this->db->where('id', 4)->delete('create_test');
2012-03-13 13:38:47 -04:00
$this->assertIsA($query, 'PDOStatement');
}
2012-03-09 16:17:21 -05:00
}