summaryrefslogtreecommitdiff
path: root/tests/simple_unit/TableGateway
diff options
context:
space:
mode:
authorctrlaltca <>2012-07-12 11:21:01 +0000
committerctrlaltca <>2012-07-12 11:21:01 +0000
commit903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 (patch)
treee08bf04f0823650a231227ac3499121270172a23 /tests/simple_unit/TableGateway
parent3e4e6e66aeb3f8fea4e1eb4237498ef9d2358f63 (diff)
standardize the use of unix eol; use svn properties to enforce native eol
Diffstat (limited to 'tests/simple_unit/TableGateway')
-rw-r--r--tests/simple_unit/TableGateway/BaseGatewayTest.php182
-rw-r--r--tests/simple_unit/TableGateway/CountTest.php26
-rw-r--r--tests/simple_unit/TableGateway/DeleteByPkTest.php98
-rw-r--r--tests/simple_unit/TableGateway/MagicCallTest.php56
-rw-r--r--tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php106
-rw-r--r--tests/simple_unit/TableGateway/TableInfoGatewayTest.php28
-rw-r--r--tests/simple_unit/TableGateway/TestFindByPk.php90
7 files changed, 293 insertions, 293 deletions
diff --git a/tests/simple_unit/TableGateway/BaseGatewayTest.php b/tests/simple_unit/TableGateway/BaseGatewayTest.php
index ff7a58b0..98b236ee 100644
--- a/tests/simple_unit/TableGateway/BaseGatewayTest.php
+++ b/tests/simple_unit/TableGateway/BaseGatewayTest.php
@@ -1,94 +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('1=1');
- }
+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
index 56ffb19b..0e159ab0 100644
--- a/tests/simple_unit/TableGateway/CountTest.php
+++ b/tests/simple_unit/TableGateway/CountTest.php
@@ -1,16 +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);
- }
+
+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
index 120b63e9..57d9dd31 100644
--- a/tests/simple_unit/TableGateway/DeleteByPkTest.php
+++ b/tests/simple_unit/TableGateway/DeleteByPkTest.php
@@ -1,52 +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);
- }
+
+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
index c0df313d..8d42fba8 100644
--- a/tests/simple_unit/TableGateway/MagicCallTest.php
+++ b/tests/simple_unit/TableGateway/MagicCallTest.php
@@ -1,31 +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));
- }
+
+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
index 4d1077f7..f34dcefc 100644
--- a/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php
+++ b/tests/simple_unit/TableGateway/TableGatewayPgsqlTest.php
@@ -1,56 +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()->findAllBySql('SELECT username FROM address WHERE phone = ?', '45233')->read();
- $this->assertEqual($result['username'], 'record2');
- }
-
+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
index 2be848c5..51af7634 100644
--- a/tests/simple_unit/TableGateway/TableInfoGatewayTest.php
+++ b/tests/simple_unit/TableGateway/TableInfoGatewayTest.php
@@ -1,17 +1,17 @@
<?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);
- }
+
+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
index b9a25edf..5a7a081c 100644
--- a/tests/simple_unit/TableGateway/TestFindByPk.php
+++ b/tests/simple_unit/TableGateway/TestFindByPk.php
@@ -1,48 +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);
-
- }
+
+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