diff options
Diffstat (limited to 'tests/simple_unit/TableGateway')
-rw-r--r-- | tests/simple_unit/TableGateway/BaseGatewayTest.php | 93 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/CountTest.php | 15 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/DeleteByPkTest.php | 51 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/MagicCallTest.php | 30 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php | 55 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/TableInfoGatewayTest.php | 16 | ||||
-rw-r--r-- | tests/simple_unit/TableGateway/TestFindByPk.php | 47 |
7 files changed, 0 insertions, 307 deletions
diff --git a/tests/simple_unit/TableGateway/BaseGatewayTest.php b/tests/simple_unit/TableGateway/BaseGatewayTest.php deleted file mode 100644 index f3117ed2..00000000 --- a/tests/simple_unit/TableGateway/BaseGatewayTest.php +++ /dev/null @@ -1,93 +0,0 @@ -<?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('1=1'); - } -}
\ No newline at end of file diff --git a/tests/simple_unit/TableGateway/CountTest.php b/tests/simple_unit/TableGateway/CountTest.php deleted file mode 100644 index 97211e3c..00000000 --- a/tests/simple_unit/TableGateway/CountTest.php +++ /dev/null @@ -1,15 +0,0 @@ -<?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 deleted file mode 100644 index 49b2d86c..00000000 --- a/tests/simple_unit/TableGateway/DeleteByPkTest.php +++ /dev/null @@ -1,51 +0,0 @@ -<?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 deleted file mode 100644 index 87f9e785..00000000 --- a/tests/simple_unit/TableGateway/MagicCallTest.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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 deleted file mode 100644 index 96c9351d..00000000 --- a/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php +++ /dev/null @@ -1,55 +0,0 @@ -<?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()->findAllBySql('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/TableInfoGatewayTest.php b/tests/simple_unit/TableGateway/TableInfoGatewayTest.php deleted file mode 100644 index 6c85248c..00000000 --- a/tests/simple_unit/TableGateway/TableInfoGatewayTest.php +++ /dev/null @@ -1,16 +0,0 @@ -<?php - -require_once(dirname(__FILE__).'/BaseGatewayTest.php'); - -class TableInfoGatewayTest extends BaseGatewayTest -{ - function test_table_info() - { - $conn = $this->getGateway()->getDbConnection(); - $this->add_record1(); - $this->add_record2(); - $info = TDbMetaData::getInstance($conn)->getTableInfo('address'); - $table = new TTableGateway($info, $conn); - $this->assertEqual(count($table->findAll()->readAll()), 2); - } -}
\ No newline at end of file diff --git a/tests/simple_unit/TableGateway/TestFindByPk.php b/tests/simple_unit/TableGateway/TestFindByPk.php deleted file mode 100644 index 3756d35a..00000000 --- a/tests/simple_unit/TableGateway/TestFindByPk.php +++ /dev/null @@ -1,47 +0,0 @@ -<?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 |