summaryrefslogtreecommitdiff
path: root/tests/simple_unit
diff options
context:
space:
mode:
authorwei <>2007-04-12 08:05:03 +0000
committerwei <>2007-04-12 08:05:03 +0000
commitdc3bf922d9715bfd1b2105be04a9aabc84a1d7d4 (patch)
treeff97362f718b6ebb482128527402efe03fe1ac43 /tests/simple_unit
parent6178a99df0c722581bc61e35559ac5f8af1cc6e8 (diff)
Refactor and add TTableGateway, System.Data.Common, System.Data.DataGateway
Diffstat (limited to 'tests/simple_unit')
-rw-r--r--tests/simple_unit/ActiveRecord/RecordEventTestCase.php33
-rw-r--r--tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php19
-rw-r--r--tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php77
-rw-r--r--tests/simple_unit/DbCommon/MysqlColumnTest.php270
-rw-r--r--tests/simple_unit/DbCommon/PgsqlColumnTest.php147
-rw-r--r--tests/simple_unit/I18N/MysqlMessageSourceTestCase.php43
-rw-r--r--tests/simple_unit/SqlMap/queryForListLimitTest.php32
-rw-r--r--tests/simple_unit/TableGateway/BaseGatewayTest.php94
-rw-r--r--tests/simple_unit/TableGateway/CountTest.php16
-rw-r--r--tests/simple_unit/TableGateway/DeleteByPkTest.php52
-rw-r--r--tests/simple_unit/TableGateway/MagicCallTest.php31
-rw-r--r--tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php56
-rw-r--r--tests/simple_unit/TableGateway/TestFindByPk.php48
13 files changed, 918 insertions, 0 deletions
diff --git a/tests/simple_unit/ActiveRecord/RecordEventTestCase.php b/tests/simple_unit/ActiveRecord/RecordEventTestCase.php
new file mode 100644
index 00000000..c669bb72
--- /dev/null
+++ b/tests/simple_unit/ActiveRecord/RecordEventTestCase.php
@@ -0,0 +1,33 @@
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/UserRecord.php');
+
+class RecordEventTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->setDbConnection($conn);
+ }
+
+ function testFindByPk()
+ {
+ $user1 = UserRecord::finder()->findByPk('admin');
+ $this->assertNotNull($user1);
+ }
+
+ function test_same_data_returns_same_object()
+ {
+ $criteria = new TActiveRecordCriteria('username = ?', 'admin');
+ $criteria->OnSelect = array($this, 'logger');
+ $user1 = UserRecord::finder()->find($criteria);
+ //var_dump($user1);
+ }
+
+ function logger($sender, $param)
+ {
+ var_dump($param->Command->Text);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php b/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php
new file mode 100644
index 00000000..500d5277
--- /dev/null
+++ b/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php
@@ -0,0 +1,19 @@
+<?php
+Prado::using('System.Data.*');
+Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
+
+class CommandBuilderMysqlTest extends UnitTestCase
+{
+ function mysql_meta_data()
+ {
+ $conn = new TDbConnection('mysql:host=localhost;dbname=tests', 'test','test');
+ return new TMysqlMetaData($conn);
+ }
+
+ function test()
+ {
+ $this->mysql_meta_data()->getTableInfo("tests.table1");
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php b/tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php
new file mode 100644
index 00000000..8bf2848e
--- /dev/null
+++ b/tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php
@@ -0,0 +1,77 @@
+<?php
+
+Prado::using('System.Data.*');
+Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
+
+class CommandBuilderPgsqlTest extends UnitTestCase
+{
+ function pgsql_meta_data()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ return new TPgsqlMetaData($conn);
+ }
+
+ function test_insert_command_using_named_array()
+ {
+ $builder = $this->pgsql_meta_data()->createCommandBuilder('address');
+ $address=array(
+ 'username' => 'Username',
+ 'phone' => 121987,
+ 'field1_boolean' => true,
+ 'field2_date' => '1213',
+ 'field3_double' => 121.1,
+ 'field4_integer' => 345,
+ 'field6_time' => time(),
+ 'field7_timestamp' => time(),
+ 'field8_money' => '121.12',
+ 'field9_numeric' => 984.22,
+ 'int_fk1'=>1,
+ 'int_fk2'=>1,
+ );
+ $insert = $builder->createInsertCommand($address);
+ $sql = 'INSERT INTO public.address("username", "phone", "field1_boolean", "field2_date", "field3_double", "field4_integer", "field6_time", "field7_timestamp", "field8_money", "field9_numeric", "int_fk1", "int_fk2") VALUES (:username, :phone, :field1_boolean, :field2_date, :field3_double, :field4_integer, :field6_time, :field7_timestamp, :field8_money, :field9_numeric, :int_fk1, :int_fk2)';
+ $this->assertEqual($sql, $insert->Text);
+ }
+
+ function test_update_command()
+ {
+ $builder = $this->pgsql_meta_data()->createCommandBuilder('address');
+ $data = array(
+ 'phone' => 9809,
+ 'int_fk1' => 1212,
+ );
+ $update = $builder->createUpdateCommand($data, '1');
+ $sql = 'UPDATE public.address SET "phone" = :phone, "int_fk1" = :int_fk1 WHERE 1';
+ $this->assertEqual($sql, $update->Text);
+ }
+
+ function test_delete_command()
+ {
+ $builder = $this->pgsql_meta_data()->createCommandBuilder('address');
+ $where = 'phone is NULL';
+ $delete = $builder->createDeleteCommand($where);
+ $sql = 'DELETE FROM public.address WHERE phone is NULL';
+ $this->assertEqual($sql, $delete->Text);
+ }
+
+ function test_select_limit()
+ {
+ $meta = $this->pgsql_meta_data();
+ $builder = $meta->createCommandBuilder('address');
+ $query = 'SELECT * FROM '.$meta->getTableInfo('address')->getTableFullName();
+
+ $limit = $builder->createLimitCondition($query, 1);
+ $expect = $query.' LIMIT 1';
+ $this->assertEqual($expect, $limit);
+
+ $limit = $builder->createLimitCondition($query, -1, 10);
+ $expect = $query.' OFFSET 10';
+ $this->assertEqual($expect, $limit);
+
+ $limit = $builder->createLimitCondition($query, 2, 3);
+ $expect = $query.' LIMIT 2 OFFSET 3';
+ $this->assertEqual($expect, $limit);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/DbCommon/MysqlColumnTest.php b/tests/simple_unit/DbCommon/MysqlColumnTest.php
new file mode 100644
index 00000000..d8bb8194
--- /dev/null
+++ b/tests/simple_unit/DbCommon/MysqlColumnTest.php
@@ -0,0 +1,270 @@
+<?php
+
+Prado::using('System.Data.*');
+Prado::using('System.Data.Common.Mysql.TMysqlMetaData');
+
+class MysqlColumnTest extends UnitTestCase
+{
+ function create_meta_data()
+ {
+ $conn = new TDbConnection('mysql:host=localhost;dbname=tests', 'test','test');
+ return new TMysqlMetaData($conn);
+ }
+
+ function test_columns()
+ {
+ $table = $this->create_meta_data()->getTableInfo('table1');
+ $this->assertEqual(count($table->getColumns()), 18);
+
+ $columns['id'] = array(
+ 'ColumnName' => '`id`',
+ 'ColumnSize' => 10,
+ 'ColumnIndex' => 0,
+ 'DbType' => 'int unsigned',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => true,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => true,
+ );
+
+ $columns['name'] = array(
+ 'ColumnName' => '`name`',
+ 'ColumnSize' => 45,
+ 'ColumnIndex' => 1,
+ 'DbType' => 'varchar',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => true,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field1'] = array(
+ 'ColumnName' => '`field1`',
+ 'ColumnSize' => 4,
+ 'ColumnIndex' => 2,
+ 'DbType' => 'tinyint',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field2_text'] = array(
+ 'ColumnName' => '`field2_text`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 3,
+ 'DbType' => 'text',
+ 'AllowNull' => true,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field3_date'] = array(
+ 'ColumnName' => '`field3_date`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 4,
+ 'DbType' => 'date',
+ 'AllowNull' => true,
+ 'DefaultValue' => '2007-02-25',
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field4_float'] = array(
+ 'ColumnName' => '`field4_float`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 5,
+ 'DbType' => 'float',
+ 'AllowNull' => false,
+ 'DefaultValue' => 10,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field5_float'] = array(
+ 'ColumnName' => '`field5_float`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 6,
+ 'DbType' => 'float',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => 5,
+ 'NumericScale' => 4,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field6_double'] = array(
+ 'ColumnName' => '`field6_double`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 7,
+ 'DbType' => 'double',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field7_datetime'] = array(
+ 'ColumnName' => '`field7_datetime`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 8,
+ 'DbType' => 'datetime',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field8_timestamp'] = array(
+ 'ColumnName' => '`field8_timestamp`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 9,
+ 'DbType' => 'timestamp',
+ 'AllowNull' => true,
+ 'DefaultValue' => 'CURRENT_TIMESTAMP',
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field9_time'] = array(
+ 'ColumnName' => '`field9_time`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 10,
+ 'DbType' => 'time',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field10_year'] = array(
+ 'ColumnName' => '`field10_year`',
+ 'ColumnSize' => 4,
+ 'ColumnIndex' => 11,
+ 'DbType' => 'year',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ );
+
+ $columns['field11_enum'] = array(
+ 'ColumnName' => '`field11_enum`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 12,
+ 'DbType' => 'enum',
+ 'AllowNull' => false,
+ 'DefaultValue' => 'one',
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ 'DbTypeValues' => array('one', 'two', 'three'),
+ );
+
+ $columns['field12_SET'] = array(
+ 'ColumnName' => '`field12_SET`',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 13,
+ 'DbType' => 'set',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ 'AutoIncrement' => false,
+ 'DbTypeValues' => array('blue', 'red', 'green'),
+ );
+
+ $this->assertColumn($columns, $table);
+
+ $this->assertNull($table->getSchemaName());
+ $this->assertEqual('table1', $table->getTableName());
+ $this->assertEqual(array('id', 'name'), $table->getPrimaryKeys());
+ $this->assertEqual(array('fk3'), $table->getUniqueKeys());
+ }
+
+ function assertColumn($columns, $table)
+ {
+ foreach($columns as $id=>$asserts)
+ {
+ $column = $table->Columns[$id];
+ foreach($asserts as $property=>$assert)
+ {
+ $ofAssert= var_export($assert,true);
+ $value = $column->{$property};
+ $ofValue = var_export($value, true);
+ $this->assertEqual($value, $assert,
+ "Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
+ }
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/DbCommon/PgsqlColumnTest.php b/tests/simple_unit/DbCommon/PgsqlColumnTest.php
new file mode 100644
index 00000000..0f633725
--- /dev/null
+++ b/tests/simple_unit/DbCommon/PgsqlColumnTest.php
@@ -0,0 +1,147 @@
+<?php
+
+Prado::using('System.Data.*');
+Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData');
+class PgsqlColumnTest extends UnitTestCase
+{
+ function create_meta_data()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ return new TPgsqlMetaData($conn);
+ }
+
+ function test_text_column_def()
+ {
+ $table = $this->create_meta_data()->getTableInfo('public.address');
+ $this->assertEqual(count($table->getColumns()), 14);
+
+ $columns['id'] = array(
+ 'ColumnName' => '"id"',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 0,
+ 'DbType' => 'integer',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => true,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => 'public.address_id_seq',
+ );
+
+ $columns['username'] = array(
+ 'ColumnName' => '"username"',
+ 'ColumnSize' => 128,
+ 'ColumnIndex' => 1,
+ 'DbType' => 'character varying',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => true,
+ 'SequenceName' => null,
+ );
+
+ $columns['phone'] = array(
+ 'ColumnName' => '"phone"',
+ 'ColumnSize' => 40,
+ 'ColumnIndex' => 2,
+ 'DbType' => 'character',
+ 'AllowNull' => false,
+ 'DefaultValue' => "'hello'::bpchar",
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => true,
+ 'SequenceName' => null,
+ );
+
+ $columns['field1_boolean'] = array(
+ 'ColumnName' => '"field1_boolean"',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 3,
+ 'DbType' => 'boolean',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ );
+
+ $columns['field4_integer'] = array(
+ 'ColumnName' => '"field4_integer"',
+ 'ColumnSize' => null,
+ 'ColumnIndex' => 6,
+ 'DbType' => 'integer',
+ 'AllowNull' => false,
+ 'DefaultValue' => "1",
+ 'NumericPrecision' => null,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => true,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ );
+
+ $columns['field7_timestamp'] = array(
+ 'ColumnName' => '"field7_timestamp"',
+ 'ColumnSize' => 2,
+ 'ColumnIndex' => 9,
+ 'DbType' => 'timestamp without time zone',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => 6,
+ 'NumericScale' => null,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ );
+
+ $columns['field9_numeric'] = array(
+ 'ColumnName' => '"field9_numeric"',
+ 'ColumnSize' => 393220,
+ 'ColumnIndex' => 11,
+ 'DbType' => 'numeric',
+ 'AllowNull' => false,
+ 'DefaultValue' => TDbTableColumn::UNDEFINED_VALUE,
+ 'NumericPrecision' => 6,
+ 'NumericScale' => 4,
+ 'IsPrimaryKey' => false,
+ 'IsForeignKey' => false,
+ 'IsUnique' => false,
+ 'SequenceName' => null,
+ );
+ $this->assertColumn($columns, $table);
+
+ $this->assertEqual('public', $table->getSchemaName());
+ $this->assertEqual('address', $table->getTableName());
+ $this->assertEqual(array('id'), $table->getPrimaryKeys());
+ $this->assertEqual(array('username', 'phone'), $table->getUniqueKeys());
+ }
+
+ function assertColumn($columns, $table)
+ {
+ foreach($columns as $id=>$asserts)
+ {
+ $column = $table->Columns[$id];
+ foreach($asserts as $property=>$assert)
+ {
+ $ofAssert= var_export($assert,true);
+ $value = $column->{$property};
+ $ofValue = var_export($value, true);
+ $this->assertEqual($value, $assert,
+ "Column [{$id}] {$property} value {$ofValue} did not match {$ofAssert}");
+ }
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php b/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php
new file mode 100644
index 00000000..9f48d499
--- /dev/null
+++ b/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php
@@ -0,0 +1,43 @@
+<?php
+
+Prado::using('System.I18N.core.MessageSource_MySQL');
+Prado::using('System.I18N.core.MessageFormat');
+
+class MysqlMessageSourceTestCase extends UnitTestCase
+{
+ private $_source;
+
+ function get_source()
+ {
+ if($this->_source===null)
+ {
+ $this->_source = new MessageSource_MySQL('mysq://prado:prado@localhost/i18n_test');
+ $this->_source->setCulture('en_AU');
+ }
+ return $this->_source;
+ }
+
+ function test_source()
+ {
+ $source = $this->get_source();
+ $this->assertEqual(3, count($source->catalogues()));
+ }
+
+ function test_load_source()
+ {
+ $source = $this->get_source();
+ $this->assertTrue($source->load());
+ }
+
+ function test_message_format()
+ {
+ $formatter = new MessageFormat($this->get_source());
+ var_dump($formatter->format('Hello'));
+ var_dump($formatter->format('Goodbye'));
+ //$this->assertEqual($formatter->format('Hello'),'G\'day Mate!');
+
+ //$this->assertEqual($formatter->format('Goodbye'), 'Goodbye');
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/SqlMap/queryForListLimitTest.php b/tests/simple_unit/SqlMap/queryForListLimitTest.php
new file mode 100644
index 00000000..ceacbcdc
--- /dev/null
+++ b/tests/simple_unit/SqlMap/queryForListLimitTest.php
@@ -0,0 +1,32 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseCase.php');
+
+/**
+ * @package System.DataAccess.SQLMap
+ */
+class queryForListLimitTest extends BaseCase
+{
+ function __construct()
+ {
+ parent::__construct();
+
+ $this->initSqlMap();
+
+ //force autoload
+ new Account;
+ }
+
+ function resetDatabase()
+ {
+ $this->initScript('account-init.sql');
+ }
+
+ function test_accounts_limit_2()
+ {
+ $list1 = $this->sqlmap->queryForList('GetAllAccountsAsArrayListViaResultClass', null, null, 2);
+ //var_dump($list1);
+ }
+}
+
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/BaseGatewayTest.php b/tests/simple_unit/TableGateway/BaseGatewayTest.php
new file mode 100644
index 00000000..825f2d0e
--- /dev/null
+++ b/tests/simple_unit/TableGateway/BaseGatewayTest.php
@@ -0,0 +1,94 @@
+<?php
+Prado::using('System.Data.*');
+Prado::using('System.Data.DataGateway.TTableGateway');
+
+class BaseGatewayTest extends UnitTestCase
+{
+ protected $gateway1;
+ protected $gateway2;
+
+ /**
+ * @return TTableGateway
+ */
+ function getGateway()
+ {
+ if($this->gateway1===null)
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ $this->gateway1 = new TTableGateway('address', $conn);
+ }
+ return $this->gateway1;
+ }
+
+ /**
+ * @return TTableGateway
+ */
+ function getGateway2()
+ {
+ if($this->gateway2===null)
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ $this->gateway2 = new TTableGateway('department_sections', $conn);
+ }
+ return $this->gateway2;
+ }
+
+ function setup()
+ {
+ $this->delete_all();
+ }
+
+ function add_record1()
+ {
+ $result = $this->getGateway()->insert($this->get_record1());
+ $this->assertTrue(intval($result) > 0);
+ }
+ function add_record2()
+ {
+ $result = $this->getGateway()->insert($this->get_record2());
+ $this->assertTrue(intval($result) > 0);
+ }
+ function get_record1()
+ {
+ return array(
+ 'username' => 'Username',
+ 'phone' => 121987,
+ 'field1_boolean' => true,
+ 'field2_date' => '2007-12-25',
+ 'field3_double' => 121.1,
+ 'field4_integer' => 3,
+ 'field5_text' => 'asdasd',
+ 'field6_time' => '12:40:00',
+ 'field7_timestamp' => 'NOW',
+ 'field8_money' => '$121.12',
+ 'field9_numeric' => 98.2232,
+ 'int_fk1'=>1,
+ 'int_fk2'=>1,
+ );
+ }
+
+
+ function get_record2()
+ {
+ return array(
+ 'username' => 'record2',
+ 'phone' => 45233,
+ 'field1_boolean' => false,
+ 'field2_date' => '2004-10-05',
+ 'field3_double' => 1221.1,
+ 'field4_integer' => 2,
+ 'field5_text' => 'hello world',
+ 'field6_time' => '22:40:00',
+ 'field7_timestamp' => 'NOW',
+ 'field8_money' => '$1121.12',
+ 'field9_numeric' => 8.2213,
+ 'int_fk1'=>1,
+ 'int_fk2'=>1,
+ );
+ }
+ function delete_all()
+ {
+ $this->getGateway()->deleteAll('true');
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/CountTest.php b/tests/simple_unit/TableGateway/CountTest.php
new file mode 100644
index 00000000..56ffb19b
--- /dev/null
+++ b/tests/simple_unit/TableGateway/CountTest.php
@@ -0,0 +1,16 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseGatewayTest.php');
+
+class CountTest extends BaseGatewayTest
+{
+ function test_simple_count()
+ {
+ $result = $this->getGateway2()->count();
+ $this->assertEqual(44,$result);
+
+ $result = $this->getGateway2()->count('department_id = ?', 1);
+ $this->assertEqual(4, $result);
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/DeleteByPkTest.php b/tests/simple_unit/TableGateway/DeleteByPkTest.php
new file mode 100644
index 00000000..120b63e9
--- /dev/null
+++ b/tests/simple_unit/TableGateway/DeleteByPkTest.php
@@ -0,0 +1,52 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseGatewayTest.php');
+
+class DeleteByPkTest extends BaseGatewayTest
+{
+ function test_delete_by_1_pk()
+ {
+ $this->add_record1();
+ $id = $this->getGateway()->getLastInsertId();
+ $deleted = $this->getGateway()->deleteByPk($id);
+
+ $this->assertEqual(1, $deleted);
+ }
+
+ function test_delete_by_multiple_pk()
+ {
+ $this->add_record1();
+ $id1 = $this->getGateway()->getLastInsertId();
+ $this->add_record2();
+ $id2 = $this->getGateway()->getLastInsertId();
+
+ $deleted = $this->getGateway()->deleteByPk($id1, $id2);
+
+ $this->assertEqual(2, $deleted);
+ }
+
+ function test_delete_by_multiple_pk2()
+ {
+ $this->add_record1();
+ $id1 = $this->getGateway()->getLastInsertId();
+ $this->add_record2();
+ $id2 = $this->getGateway()->getLastInsertId();
+
+ $deleted = $this->getGateway()->deleteByPk(array($id1, $id2));
+
+ $this->assertEqual(2, $deleted);
+ }
+
+ function test_delete_by_multiple_pk3()
+ {
+ $this->add_record1();
+ $id1 = $this->getGateway()->getLastInsertId();
+ $this->add_record2();
+ $id2 = $this->getGateway()->getLastInsertId();
+
+ $deleted = $this->getGateway()->deleteByPk(array(array($id1), array($id2)));
+
+ $this->assertEqual(2, $deleted);
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/MagicCallTest.php b/tests/simple_unit/TableGateway/MagicCallTest.php
new file mode 100644
index 00000000..c0df313d
--- /dev/null
+++ b/tests/simple_unit/TableGateway/MagicCallTest.php
@@ -0,0 +1,31 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseGatewayTest.php');
+
+class MagicCallTest extends BaseGatewayTest
+{
+ function test_magic_call()
+ {
+ $this->add_record1(); $this->add_record2();
+
+ $result = $this->getGateway()->findByUsername("record2");
+ $this->assertEqual($result['username'], 'record2');
+ }
+
+ function test_combined_and_or()
+ {
+ $this->add_record1(); $this->add_record2();
+
+ $result = $this->getGateway()->findAllByUsername_OR_phone('Username', '45233')->readAll();
+ $this->assertEqual(2, count($result));
+ }
+
+ function test_no_result()
+ {
+ $this->add_record1(); $this->add_record2();
+ $result = $this->getGateway()->findAllByUsername_and_phone('Username', '45233')->readAll();
+
+ $this->assertEqual(0, count($result));
+ }
+}
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php b/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php
new file mode 100644
index 00000000..973e8d21
--- /dev/null
+++ b/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php
@@ -0,0 +1,56 @@
+<?php
+require_once(dirname(__FILE__).'/BaseGatewayTest.php');
+
+class TableGatewayPgsqlTest extends BaseGatewayTest
+{
+
+ function test_update()
+ {
+ $this->add_record1();
+ $address = array('username' => 'tester 1', 'field5_text'=>null);
+ $result = $this->getGateway()->update($address, 'username = ?', 'Username');
+ $this->assertTrue($result);
+
+ $test = $this->getGateway()->find('username = ?', 'tester 1');
+ unset($test['id']);
+ $expect = $this->get_record1();
+ $expect['username'] = 'tester 1';
+ $expect['field5_text'] = null;
+ unset($expect['field7_timestamp']); unset($test['field7_timestamp']);
+ $this->assertEqual($expect, $test);
+
+ $this->assertTrue($this->getGateway()->deleteAll('username = ?', 'tester 1'));
+ }
+
+ function test_update_named()
+ {
+ $this->add_record1();
+ $address = array('username' => 'tester 1', 'field5_text'=>null);
+ $result = $this->getGateway()->update($address, 'username = :name', array(':name'=>'Username'));
+ $this->assertTrue($result);
+
+ $test = $this->getGateway()->find('username = :name', array(':name'=>'tester 1'));
+ unset($test['id']);
+ $expect = $this->get_record1();
+ $expect['username'] = 'tester 1';
+ $expect['field5_text'] = null;
+ unset($expect['field7_timestamp']); unset($test['field7_timestamp']);
+ $this->assertEqual($expect, $test);
+
+ $this->assertTrue($this->getGateway()->deleteAll('username = :name', array(':name'=>'tester 1')));
+ }
+
+ function test_find_all()
+ {
+ $this->add_record1();
+ $this->add_record2();
+
+ $results = $this->getGateway()->findAll('true')->readAll();
+ $this->assertEqual(count($results), 2);
+
+ $result = $this->getGateway()->findBySql('SELECT username FROM address WHERE phone = ?', '45233')->read();
+ $this->assertEqual($result['username'], 'record2');
+ }
+
+}
+?> \ No newline at end of file
diff --git a/tests/simple_unit/TableGateway/TestFindByPk.php b/tests/simple_unit/TableGateway/TestFindByPk.php
new file mode 100644
index 00000000..b9a25edf
--- /dev/null
+++ b/tests/simple_unit/TableGateway/TestFindByPk.php
@@ -0,0 +1,48 @@
+<?php
+
+require_once(dirname(__FILE__).'/BaseGatewayTest.php');
+
+class TestFindByPk extends BaseGatewayTest
+{
+ function test_one_key()
+ {
+ $this->add_record1();
+ $id = $this->getGateway()->getLastInsertId();
+ $result = $this->getGateway()->findByPk($id);
+
+ $record1 = $this->get_record1();
+
+ //clean and ignore some fields
+ unset($result['id']);
+ unset($result['field7_timestamp']);
+ unset($record1['field7_timestamp']);
+ $result['phone'] = intval($result['phone']);
+ $result['field9_numeric'] = floatval($result['field9_numeric']);
+
+ $this->assertEqual($record1, $result);
+ }
+
+ function test_composite_key()
+ {
+ $gateway = $this->getGateway2();
+
+ $result = $gateway->findByPk(1,1);
+ $expect = array("department_id" => 1, "section_id" => 1, "order" => 0);
+ $this->assertEqual($expect, $result);
+ }
+
+ function test_find_all_keys()
+ {
+ $gateway = $this->getGateway2();
+
+ $result = $gateway->findAllByPks(array(1,1), array(3,13))->readAll();
+
+ $expect = array(
+ array("department_id" => 1, "section_id" => 1, "order" => 0),
+ array("department_id" => 3, "section_id" => 13, "order" => 0));
+
+ $this->assertEqual($expect, $result);
+
+ }
+}
+?> \ No newline at end of file