diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
commit | a3388622287e218beddfa14a47ed677d4307b36b (patch) | |
tree | 1b4c7ac8597b1cc798b6683d4a81c90d38de12f6 /tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php | |
parent | c7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 (diff) |
Removed simpletest and moved all tests in the unit tree
Tests are executed now, but a lot of them need fixing.
Diffstat (limited to 'tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php')
-rw-r--r-- | tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php b/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php new file mode 100644 index 00000000..389ad0e1 --- /dev/null +++ b/tests/unit/Data/DbCommon/CommandBuilderPgsqlTest.php @@ -0,0 +1,77 @@ +<?php +Prado::using('System.Data.*'); +Prado::using('System.Data.Common.Pgsql.TPgsqlMetaData'); + +/** + * @package System.Data.DbCommon + */ +class CommandBuilderPgsqlTest extends PHPUnit_Framework_TestCase +{ + 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->applyLimitOffset($query, 1); + $expect = $query.' LIMIT 1'; + $this->assertEqual($expect, $limit); + + $limit = $builder->applyLimitOffset($query, -1, 10); + $expect = $query.' OFFSET 10'; + $this->assertEqual($expect, $limit); + + $limit = $builder->applyLimitOffset($query, 2, 3); + $expect = $query.' LIMIT 2 OFFSET 3'; + $this->assertEqual($expect, $limit); + } +} |