From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- .../ActiveRecordDynamicCallTestCase.php | 134 +- .../ActiveRecord/ActiveRecordFinderTestCase.php | 84 +- .../ActiveRecord/ActiveRecordMySql5TestCase.php | 88 +- .../ActiveRecord/ActiveRecordRegistryTestCase.php | 330 +-- .../ActiveRecord/BaseActiveRecordTestCase.php | 62 +- .../ActiveRecord/CountRecordsTestCase.php | 64 +- .../simple_unit/ActiveRecord/CriteriaTestCase.php | 98 +- .../ActiveRecord/DeleteByPkTestCase.php | 56 +- .../simple_unit/ActiveRecord/FindByPksTestCase.php | 124 +- .../simple_unit/ActiveRecord/FindBySqlTestCase.php | 88 +- .../ActiveRecord/ForeignKeyTestCase.php | 348 +-- .../ActiveRecord/ForeignObjectUpdateTest.php | 482 ++--- .../ActiveRecord/MultipleForeignKeyTestCase.php | 382 ++-- .../ActiveRecord/RecordEventTestCase.php | 72 +- tests/simple_unit/ActiveRecord/SqliteTestCase.php | 38 +- .../ActiveRecord/UserRecordTestCase.php | 130 +- .../ActiveRecord/ViewRecordTestCase.php | 146 +- tests/simple_unit/ActiveRecord/records/Blogs.php | 24 +- .../ActiveRecord/records/DepSections.php | 28 +- .../ActiveRecord/records/DepartmentRecord.php | 32 +- .../ActiveRecord/records/ItemRecord.php | 96 +- .../ActiveRecord/records/SimpleUser.php | 24 +- .../ActiveRecord/records/SqliteUsers.php | 28 +- .../ActiveRecord/records/UserRecord.php | 72 +- .../DbCommon/CommandBuilderMssqlTest.php | 86 +- .../DbCommon/CommandBuilderMysqlTest.php | 32 +- .../DbCommon/CommandBuilderPgsqlTest.php | 148 +- tests/simple_unit/DbCommon/MssqlColumnTest.php | 90 +- tests/simple_unit/DbCommon/Mysql4ColumnTest.php | 504 ++--- tests/simple_unit/DbCommon/MysqlColumnTest.php | 504 ++--- tests/simple_unit/DbCommon/PgsqlColumnTest.php | 272 +-- tests/simple_unit/DbCommon/SqliteColumnTest.php | 54 +- tests/simple_unit/I18N/ChoiceFormatTest.php | 194 +- tests/simple_unit/I18N/CultureInfoTest.php | 24 +- .../I18N/MysqlMessageSourceTestCase.php | 88 +- tests/simple_unit/Soap/ContactManager.php | 312 +-- tests/simple_unit/Soap/SoapTestCase.php | 182 +- .../simple_unit/SqlMap/ActiveRecordSqlMapTest.php | 172 +- tests/simple_unit/SqlMap/BaseCase.php | 522 ++--- tests/simple_unit/SqlMap/CacheTest.php | 326 +-- tests/simple_unit/SqlMap/DelegateTest.php | 126 +- tests/simple_unit/SqlMap/Dynamic/DynamicTest.php | 20 +- tests/simple_unit/SqlMap/GroupByTest.php | 84 +- tests/simple_unit/SqlMap/InheritanceTest.php | 288 +-- tests/simple_unit/SqlMap/ParameterMapTest.php | 496 ++--- tests/simple_unit/SqlMap/PropertyAccessTest.php | 152 +- tests/simple_unit/SqlMap/ResultClassTest.php | 496 ++--- tests/simple_unit/SqlMap/ResultMapTest.php | 544 ++--- tests/simple_unit/SqlMap/SelectKeyTest.php | 238 +- tests/simple_unit/SqlMap/SqlMapCacheTest.php | 152 +- tests/simple_unit/SqlMap/StatementExtendsTest.php | 56 +- tests/simple_unit/SqlMap/StatementTest.php | 2268 ++++++++++---------- tests/simple_unit/SqlMap/TestQueryForMap.php | 84 +- tests/simple_unit/SqlMap/common.php | 308 +-- tests/simple_unit/SqlMap/domain/A.php | 52 +- tests/simple_unit/SqlMap/domain/Account.php | 70 +- tests/simple_unit/SqlMap/domain/AccountBis.php | 24 +- .../SqlMap/domain/AccountCollection.php | 32 +- tests/simple_unit/SqlMap/domain/B.php | 44 +- tests/simple_unit/SqlMap/domain/Book.php | 20 +- tests/simple_unit/SqlMap/domain/C.php | 28 +- tests/simple_unit/SqlMap/domain/Category.php | 36 +- tests/simple_unit/SqlMap/domain/Complex.php | 20 +- tests/simple_unit/SqlMap/domain/D.php | 30 +- tests/simple_unit/SqlMap/domain/Document.php | 30 +- .../SqlMap/domain/DocumentCollection.php | 14 +- tests/simple_unit/SqlMap/domain/E.php | 30 +- tests/simple_unit/SqlMap/domain/F.php | 30 +- tests/simple_unit/SqlMap/domain/LineItem.php | 62 +- .../SqlMap/domain/LineItemCollection.php | 14 +- tests/simple_unit/SqlMap/domain/Newspaper.php | 22 +- tests/simple_unit/SqlMap/domain/Order.php | 140 +- tests/simple_unit/SqlMap/domain/Other.php | 44 +- tests/simple_unit/SqlMap/domain/Sample.php | 108 +- tests/simple_unit/SqlMap/domain/Search.php | 44 +- tests/simple_unit/SqlMap/domain/User.php | 52 +- tests/simple_unit/SqlMap/gen.php | 64 +- tests/simple_unit/SqlMap/queryForListLimitTest.php | 78 +- tests/simple_unit/TableGateway/BaseGatewayTest.php | 182 +- tests/simple_unit/TableGateway/CountTest.php | 26 +- tests/simple_unit/TableGateway/DeleteByPkTest.php | 98 +- tests/simple_unit/TableGateway/MagicCallTest.php | 56 +- .../TableGateway/TableGatewayPgsqlTest.php | 106 +- .../TableGateway/TableInfoGatewayTest.php | 28 +- tests/simple_unit/TableGateway/TestFindByPk.php | 90 +- tests/simple_unit/Tickets/Ticket589Test.php | 42 +- tests/simple_unit/unit.php | 16 +- tests/simple_unit/ws.php | 16 +- 88 files changed, 6800 insertions(+), 6800 deletions(-) (limited to 'tests/simple_unit') diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php index 07e810aa..8d7fa46a 100644 --- a/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php +++ b/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php @@ -1,69 +1,69 @@ -setDbConnection($conn); - } - - function test_multiple_field_and_or() - { - $finder = DepartmentRecord::finder(); - $r2 = $finder->findAllByName_And_Description_Or_Active_Or_Order('Facilities', null, false, 1); - $this->assertNotNull($r2); - } - - function test_dynamic_call() - { - $finder = DepartmentRecord::finder(); - $r2 = $finder->findByName('Facilities'); - $this->assertNotNull($r2); - } - - function test_dynamic_multiple_field_call() - { - $finder = DepartmentRecord::finder(); - $rs = $finder->findByNameAndActive('Marketing',true); - $this->assertNotNull($rs); - } - - function test_dynamic_call_missing_parameters_throws_exception() - { - $finder = DepartmentRecord::finder(); - try - { - $rs = $finder->findByNameAndActive('Marketing'); - $this->fail(); - } - catch(TDbException $e) - { - $this->pass(); - } - } - - function test_dynamic_call_extras_parameters_ok() - { - $finder = DepartmentRecord::finder(); - $rs = $finder->findByNameAndActive('Marketing',true,true); - $this->assertNotNull($rs); - } - - function test_dynamic_delete_by() - { - $finder = DepartmentRecord::finder(); - //$finder->RecordManager->OnDelete[] = array($this, 'assertDeleteSql'); - $this->assertEqual($finder->deleteByName('tasds'), 0); - } - - function assertDeleteSql($sender, $param) - { - var_dump($param); - } -} +setDbConnection($conn); + } + + function test_multiple_field_and_or() + { + $finder = DepartmentRecord::finder(); + $r2 = $finder->findAllByName_And_Description_Or_Active_Or_Order('Facilities', null, false, 1); + $this->assertNotNull($r2); + } + + function test_dynamic_call() + { + $finder = DepartmentRecord::finder(); + $r2 = $finder->findByName('Facilities'); + $this->assertNotNull($r2); + } + + function test_dynamic_multiple_field_call() + { + $finder = DepartmentRecord::finder(); + $rs = $finder->findByNameAndActive('Marketing',true); + $this->assertNotNull($rs); + } + + function test_dynamic_call_missing_parameters_throws_exception() + { + $finder = DepartmentRecord::finder(); + try + { + $rs = $finder->findByNameAndActive('Marketing'); + $this->fail(); + } + catch(TDbException $e) + { + $this->pass(); + } + } + + function test_dynamic_call_extras_parameters_ok() + { + $finder = DepartmentRecord::finder(); + $rs = $finder->findByNameAndActive('Marketing',true,true); + $this->assertNotNull($rs); + } + + function test_dynamic_delete_by() + { + $finder = DepartmentRecord::finder(); + //$finder->RecordManager->OnDelete[] = array($this, 'assertDeleteSql'); + $this->assertEqual($finder->deleteByName('tasds'), 0); + } + + function assertDeleteSql($sender, $param) + { + var_dump($param); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php index 597f8a6b..e962046b 100644 --- a/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php +++ b/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php @@ -1,45 +1,45 @@ setDbConnection($conn); - } - - function testFindBySQL_returns_one_record() - { - $department = DepartmentRecord::finder()->find('department_id < ?', 5); - $this->assertNotNull($department); - } - - function testFindBySQL_returns_zero_records() - { - $department = DepartmentRecord::finder()->find('department_id > ?', 15); - $this->assertNull($department); - } - - function test_find_by_sql_returns_iterator() - { - $deps = DepartmentRecord::finder()->findAll('department_id < :id', array('id'=>5)); - $this->assertEqual(count($deps),4); - } - - function test_find_by_multiple_parameters() - { - $department = DepartmentRecord::finder()->find('department_id < ? AND "order" > ?', 5,2); - $this->assertNotNull($department); - } - - function test_find_by_array_parameter() - { - $department = DepartmentRecord::finder()->find('department_id < ? AND "order" > ?', array(5,2)); - $this->assertNotNull($department); - } - -} +Prado::using('System.Data.ActiveRecord.TActiveRecord'); +require_once(dirname(__FILE__).'/records/DepartmentRecord.php'); + +class ActiveRecordFinderTestCase extends UnitTestCase +{ + function setup() + { + $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + TActiveRecordManager::getInstance()->setDbConnection($conn); + } + + function testFindBySQL_returns_one_record() + { + $department = DepartmentRecord::finder()->find('department_id < ?', 5); + $this->assertNotNull($department); + } + + function testFindBySQL_returns_zero_records() + { + $department = DepartmentRecord::finder()->find('department_id > ?', 15); + $this->assertNull($department); + } + + function test_find_by_sql_returns_iterator() + { + $deps = DepartmentRecord::finder()->findAll('department_id < :id', array('id'=>5)); + $this->assertEqual(count($deps),4); + } + + function test_find_by_multiple_parameters() + { + $department = DepartmentRecord::finder()->find('department_id < ? AND "order" > ?', 5,2); + $this->assertNotNull($department); + } + + function test_find_by_array_parameter() + { + $department = DepartmentRecord::finder()->find('department_id < ? AND "order" > ?', array(5,2)); + $this->assertNotNull($department); + } + +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php index b0d7ccf4..d173f005 100644 --- a/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php +++ b/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php @@ -1,46 +1,46 @@ -setDbConnection($conn); - } - - function test_find_first_blog() - { - $blog = Blogs::finder()->findByPk(1); - $this->assertNotNull($blog); - } - - function test_insert_new_blog() - { - $blog = new Blogs(); - $blog->blog_name = 'test1'; - $blog->blog_author = 'wei'; - - $this->assertTrue($blog->save()); - - $blog->blog_name = 'test2'; - - $this->assertTrue($blog->save()); - - $check = Blogs::finder()->findByPk($blog->blog_id); - - $this->assertSameBlog($check,$blog); - - $this->assertTrue($blog->delete()); - } - - function assertSameBlog($check, $blog) - { - $props = array('blog_id', 'blog_name', 'blog_author'); - foreach($props as $prop) - $this->assertEqual($check->{$prop}, $blog->{$prop}); - } - +setDbConnection($conn); + } + + function test_find_first_blog() + { + $blog = Blogs::finder()->findByPk(1); + $this->assertNotNull($blog); + } + + function test_insert_new_blog() + { + $blog = new Blogs(); + $blog->blog_name = 'test1'; + $blog->blog_author = 'wei'; + + $this->assertTrue($blog->save()); + + $blog->blog_name = 'test2'; + + $this->assertTrue($blog->save()); + + $check = Blogs::finder()->findByPk($blog->blog_id); + + $this->assertSameBlog($check,$blog); + + $this->assertTrue($blog->delete()); + } + + function assertSameBlog($check, $blog) + { + $props = array('blog_id', 'blog_name', 'blog_author'); + foreach($props as $prop) + $this->assertEqual($check->{$prop}, $blog->{$prop}); + } + } ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php index fbae5a4b..fe1507cd 100644 --- a/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php +++ b/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php @@ -1,167 +1,167 @@ -assertTrue($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - } - - function test_clean_object_registers_without_error() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - $registry->registerClean($obj); - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertTrue($registry->isCleanObject($obj)); - } - - function test_clean_object_becomes_dirty_when_changed() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - - $registry->registerClean($obj); - - $obj->propB='b'; - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertTrue($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - } - - function test_removed_object_must_register_as_clean_first() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - - try - { - $registry->registerRemoved($obj); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - } - - function test_removed_object_registers_without_error() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - $registry->registerClean($obj); - - $registry->registerRemoved($obj); - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertTrue($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - } - - - function test_removed_object_can_not_become_clean() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - $registry->registerClean($obj); - - $registry->registerRemoved($obj); - - try - { - $registry->registerClean($obj); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertTrue($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - } - - function test_remove_dirty_object() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - - $registry->registerClean($obj); - - $obj->propB='b'; - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertTrue($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - - $registry->registerRemoved($obj); - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertTrue($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - - try - { - $registry->registerClean($obj); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - } - - function test_clean_dirty_clean_object() - { - $obj = new StateTestObject(); - $registry = new TActiveRecordStateRegistry(); - - $registry->registerClean($obj); - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertTrue($registry->isCleanObject($obj)); - - $obj->propB='b'; - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertTrue($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertFalse($registry->isCleanObject($obj)); - - $registry->registerClean($obj); - - $this->assertFalse($registry->isNewObject($obj)); - $this->assertFalse($registry->isDirtyObject($obj)); - $this->assertFalse($registry->isRemovedObject($obj)); - $this->assertTrue($registry->isCleanObject($obj)); - } - -} +assertTrue($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + } + + function test_clean_object_registers_without_error() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + $registry->registerClean($obj); + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertTrue($registry->isCleanObject($obj)); + } + + function test_clean_object_becomes_dirty_when_changed() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + + $registry->registerClean($obj); + + $obj->propB='b'; + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertTrue($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + } + + function test_removed_object_must_register_as_clean_first() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + + try + { + $registry->registerRemoved($obj); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + } + + function test_removed_object_registers_without_error() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + $registry->registerClean($obj); + + $registry->registerRemoved($obj); + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertTrue($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + } + + + function test_removed_object_can_not_become_clean() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + $registry->registerClean($obj); + + $registry->registerRemoved($obj); + + try + { + $registry->registerClean($obj); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertTrue($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + } + + function test_remove_dirty_object() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + + $registry->registerClean($obj); + + $obj->propB='b'; + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertTrue($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + + $registry->registerRemoved($obj); + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertTrue($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + + try + { + $registry->registerClean($obj); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + } + + function test_clean_dirty_clean_object() + { + $obj = new StateTestObject(); + $registry = new TActiveRecordStateRegistry(); + + $registry->registerClean($obj); + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertTrue($registry->isCleanObject($obj)); + + $obj->propB='b'; + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertTrue($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertFalse($registry->isCleanObject($obj)); + + $registry->registerClean($obj); + + $this->assertFalse($registry->isNewObject($obj)); + $this->assertFalse($registry->isDirtyObject($obj)); + $this->assertFalse($registry->isRemovedObject($obj)); + $this->assertTrue($registry->isCleanObject($obj)); + } + +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php b/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php index fbb1c927..c356216b 100644 --- a/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php +++ b/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php @@ -1,33 +1,33 @@ -assertIdentical($obj1,$obj2); - } - - function test_finder_throw_exception_when_save() - { - $obj = TActiveRecord::finder('BaseRecordTest'); - try - { - $obj->save(); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - } -} +assertIdentical($obj1,$obj2); + } + + function test_finder_throw_exception_when_save() + { + $obj = TActiveRecord::finder('BaseRecordTest'); + try + { + $obj->save(); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php b/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php index 4d1cf51d..4c489d49 100644 --- a/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php +++ b/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php @@ -1,35 +1,35 @@ setDbConnection($conn); - } - - function test_count() - { - $finder = DepartmentRecord::finder(); - $count = $finder->count('"order" > ?', 2); - $this->assertTrue($count > 0); - } - - function test_count_zero() - { - $finder = DepartmentRecord::finder(); - $count = $finder->count('"order" > ?', 11); - $this->assertEqual($count,0); - } - - function test_count_without_parameter() - { - $finder = DepartmentRecord::finder(); - $this->assertEqual($finder->count(), 8); - } -} + +Prado::using('System.Data.ActiveRecord.TActiveRecord'); +require_once(dirname(__FILE__).'/records/DepartmentRecord.php'); + +class CountRecordsTestCase extends UnitTestCase +{ + function setup() + { + $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + TActiveRecordManager::getInstance()->setDbConnection($conn); + } + + function test_count() + { + $finder = DepartmentRecord::finder(); + $count = $finder->count('"order" > ?', 2); + $this->assertTrue($count > 0); + } + + function test_count_zero() + { + $finder = DepartmentRecord::finder(); + $count = $finder->count('"order" > ?', 11); + $this->assertEqual($count,0); + } + + function test_count_without_parameter() + { + $finder = DepartmentRecord::finder(); + $this->assertEqual($finder->count(), 8); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/CriteriaTestCase.php b/tests/simple_unit/ActiveRecord/CriteriaTestCase.php index 17f691d7..de5b3b71 100644 --- a/tests/simple_unit/ActiveRecord/CriteriaTestCase.php +++ b/tests/simple_unit/ActiveRecord/CriteriaTestCase.php @@ -1,50 +1,50 @@ -setDbConnection($conn); - } - - function test_orderby_only() - { - $criteria = new TActiveRecordCriteria; - $criteria->OrdersBy['name'] = 'asc'; - $records = DepartmentRecord::finder()->findAll($criteria); - $this->assertEqual(count($records), 8); - $this->assertEqual($records[0]->name, '+GX Service'); - $this->assertEqual($records[7]->name, 'Marketing'); - } - - function test_orderby_only_desc() - { - $criteria = new TActiveRecordCriteria; - $criteria->OrdersBy['name'] = 'desc'; - $records = DepartmentRecord::finder()->findAll($criteria); - $this->assertEqual(count($records), 8); - $this->assertEqual($records[7]->name, '+GX Service'); - $this->assertEqual($records[0]->name, 'Marketing'); - } - - function test_criteria_parameters() - { - $criteria = new TActiveRecordCriteria('sql', "One", "two", 3); - $expect = array("One", "two", 3); - $this->assertEqual($criteria->getParameters()->toArray(), $expect); - } - - function test_criteria_parameters_array() - { - $expect = array("One", "two", 3); - $criteria = new TActiveRecordCriteria('sql', $expect); - $this->assertEqual($criteria->getParameters()->toArray(), $expect); - } -} - +setDbConnection($conn); + } + + function test_orderby_only() + { + $criteria = new TActiveRecordCriteria; + $criteria->OrdersBy['name'] = 'asc'; + $records = DepartmentRecord::finder()->findAll($criteria); + $this->assertEqual(count($records), 8); + $this->assertEqual($records[0]->name, '+GX Service'); + $this->assertEqual($records[7]->name, 'Marketing'); + } + + function test_orderby_only_desc() + { + $criteria = new TActiveRecordCriteria; + $criteria->OrdersBy['name'] = 'desc'; + $records = DepartmentRecord::finder()->findAll($criteria); + $this->assertEqual(count($records), 8); + $this->assertEqual($records[7]->name, '+GX Service'); + $this->assertEqual($records[0]->name, 'Marketing'); + } + + function test_criteria_parameters() + { + $criteria = new TActiveRecordCriteria('sql', "One", "two", 3); + $expect = array("One", "two", 3); + $this->assertEqual($criteria->getParameters()->toArray(), $expect); + } + + function test_criteria_parameters_array() + { + $expect = array("One", "two", 3); + $criteria = new TActiveRecordCriteria('sql', $expect); + $this->assertEqual($criteria->getParameters()->toArray(), $expect); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php b/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php index 45415b90..f848033c 100644 --- a/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php +++ b/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php @@ -1,31 +1,31 @@ setDbConnection($conn); - } - - function test_delete_by_pks() - { - $finder = DepartmentRecord::finder(); - $this->assertEqual($finder->deleteByPk(100),0); - $this->assertEqual($finder->deleteByPk(100, 101),0); - $this->assertEqual($finder->deleteByPk(array(100, 101)),0); - } - - function test_delete_by_composite_pks() - { - $finder = DepSections::finder(); - $this->assertEqual($finder->deleteByPk(array(100,101)),0); - $this->assertEqual($finder->deleteByPk(array(100, 101), array(102, 103)),0); - $this->assertEqual($finder->deleteByPk(array(array(100, 101), array(102, 103))),0); - } + +Prado::using('System.Data.ActiveRecord.TActiveRecord'); +require_once(dirname(__FILE__).'/records/DepartmentRecord.php'); +require_once(dirname(__FILE__).'/records/DepSections.php'); + +class DeleteByPkTestCase extends UnitTestCase +{ + function setup() + { + $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + TActiveRecordManager::getInstance()->setDbConnection($conn); + } + + function test_delete_by_pks() + { + $finder = DepartmentRecord::finder(); + $this->assertEqual($finder->deleteByPk(100),0); + $this->assertEqual($finder->deleteByPk(100, 101),0); + $this->assertEqual($finder->deleteByPk(array(100, 101)),0); + } + + function test_delete_by_composite_pks() + { + $finder = DepSections::finder(); + $this->assertEqual($finder->deleteByPk(array(100,101)),0); + $this->assertEqual($finder->deleteByPk(array(100, 101), array(102, 103)),0); + $this->assertEqual($finder->deleteByPk(array(array(100, 101), array(102, 103))),0); + } } ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php b/tests/simple_unit/ActiveRecord/FindByPksTestCase.php index e3ba0358..4ccbddd5 100644 --- a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php +++ b/tests/simple_unit/ActiveRecord/FindByPksTestCase.php @@ -1,64 +1,64 @@ -setDbConnection($conn); - } - - function test_find_by_1pk() - { - $dep = DepartmentRecord::finder()->findByPk(1); - $this->assertNotNull($dep); - $this->assertEqual($dep->department_id, 1); - } - - function test_find_by_1pk_array() - { - $dep = DepartmentRecord::finder()->findByPk(array(1)); - $this->assertNotNull($dep); - $this->assertEqual($dep->department_id, 1); - } - - function test_find_by_pks() - { - $deps = DepartmentRecord::finder()->findAllByPks(1,2,4); - $this->assertEqual(count($deps), 3); - - $this->assertEqual($deps[0]->department_id, 1); - $this->assertEqual($deps[1]->department_id, 2); - $this->assertEqual($deps[2]->department_id, 4); - } - - function test_find_by_pks_with_invalid() - { - $deps = DepartmentRecord::finder()->findAllByPks(4,2,14); - $this->assertEqual(count($deps), 2); - - $this->assertEqual($deps[0]->department_id, 2); - $this->assertEqual($deps[1]->department_id, 4); - } - - function test_find_by_composite_pks() - { - $ds = DepSections::finder()->findAllByPks(array(1,1), array(2,5)); - $this->assertEqual(count($ds), 2); - - $this->assertIsDepSection($ds[0], 1, 1); - $this->assertIsDepSection($ds[1], 2, 5); - } - - function assertIsDepSection($dep, $dep_id, $sec_id) - { - $this->assertTrue($dep instanceof DepSections); - $this->assertEqual($dep->department_id, $dep_id); - $this->assertEqual($dep->section_id, $sec_id); - } -} +setDbConnection($conn); + } + + function test_find_by_1pk() + { + $dep = DepartmentRecord::finder()->findByPk(1); + $this->assertNotNull($dep); + $this->assertEqual($dep->department_id, 1); + } + + function test_find_by_1pk_array() + { + $dep = DepartmentRecord::finder()->findByPk(array(1)); + $this->assertNotNull($dep); + $this->assertEqual($dep->department_id, 1); + } + + function test_find_by_pks() + { + $deps = DepartmentRecord::finder()->findAllByPks(1,2,4); + $this->assertEqual(count($deps), 3); + + $this->assertEqual($deps[0]->department_id, 1); + $this->assertEqual($deps[1]->department_id, 2); + $this->assertEqual($deps[2]->department_id, 4); + } + + function test_find_by_pks_with_invalid() + { + $deps = DepartmentRecord::finder()->findAllByPks(4,2,14); + $this->assertEqual(count($deps), 2); + + $this->assertEqual($deps[0]->department_id, 2); + $this->assertEqual($deps[1]->department_id, 4); + } + + function test_find_by_composite_pks() + { + $ds = DepSections::finder()->findAllByPks(array(1,1), array(2,5)); + $this->assertEqual(count($ds), 2); + + $this->assertIsDepSection($ds[0], 1, 1); + $this->assertIsDepSection($ds[1], 2, 5); + } + + function assertIsDepSection($dep, $dep_id, $sec_id) + { + $this->assertTrue($dep instanceof DepSections); + $this->assertEqual($dep->department_id, $dep_id); + $this->assertEqual($dep->section_id, $sec_id); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php b/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php index 7f22afc5..e613cc30 100644 --- a/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php +++ b/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php @@ -1,46 +1,46 @@ -setDbConnection($conn); - } - - function test_find_by_sql() - { - $deps = DepartmentRecord::finder()->findBySql('SELECT * FROM departments'); - $this->assertTrue(count($deps) > 0); - } - - function test_find_by_sql_arb() - { - $sql = 'SELECT c.name as category, i.name as item - FROM items i, categories c - WHERE i.category_id = c.category_id LIMIT 2'; - $items = TActiveRecord::finder('SqlTest')->findBySql($sql); - - $sql = "SELECT users.*, 'hello' as another_value FROM users LIMIT 2"; - $users = TActiveRecord::finder('UserRecord2')->findBySql($sql); - var_dump($users); - } -} +setDbConnection($conn); + } + + function test_find_by_sql() + { + $deps = DepartmentRecord::finder()->findBySql('SELECT * FROM departments'); + $this->assertTrue(count($deps) > 0); + } + + function test_find_by_sql_arb() + { + $sql = 'SELECT c.name as category, i.name as item + FROM items i, categories c + WHERE i.category_id = c.category_id LIMIT 2'; + $items = TActiveRecord::finder('SqlTest')->findBySql($sql); + + $sql = "SELECT users.*, 'hello' as another_value FROM users LIMIT 2"; + $users = TActiveRecord::finder('UserRecord2')->findBySql($sql); + var_dump($users); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php index d8017aeb..b960760e 100644 --- a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php +++ b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php @@ -1,175 +1,175 @@ - array(self::HAS_MANY, 'Track'), - 'Artists' => array(self::MANY_TO_MANY, 'Artist', 'album_artists'), - 'cover' => array(self::HAS_ONE, 'Cover') - ); - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - -class Artist extends SqliteRecord -{ - public $name; - - public $Albums = array(); - - public static $RELATIONS=array - ( - 'Albums' => array(self::MANY_TO_MANY, 'Album', 'album_artists') - ); - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - -class Track extends SqliteRecord -{ - public $id; - public $song_name; - public $album_id; //FK -> Album.id - - public $Album; - - public static $RELATIONS = array( - 'Album' => array(self::BELONGS_TO, 'Album'), - ); - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - -class Cover extends SqliteRecord -{ - public $album; - public $content; -} - -class ForeignKeyTestCase extends UnitTestCase -{ - function test_has_many() - { - $albums = Album::finder()->withTracks()->findAll(); - $this->assertEqual(count($albums), 2); - - $this->assertEqual($albums[0]->title, 'Album 1'); - $this->assertEqual($albums[1]->title, 'Album 2'); - - $this->assertEqual(count($albums[0]->Artists), 0); - $this->assertEqual(count($albums[1]->Artists), 0); - - $this->assertEqual(count($albums[0]->Tracks), 3); - $this->assertEqual(count($albums[1]->Tracks), 2); - - $this->assertEqual($albums[0]->Tracks[0]->song_name, 'Track 1'); - $this->assertEqual($albums[0]->Tracks[1]->song_name, 'Song 2'); - $this->assertEqual($albums[0]->Tracks[2]->song_name, 'Song 3'); - - $this->assertEqual($albums[1]->Tracks[0]->song_name, 'Track A'); - $this->assertEqual($albums[1]->Tracks[1]->song_name, 'Track B'); - } - - function test_has_one() - { - $albums = Album::finder()->with_cover()->findAll(); - $this->assertEqual(count($albums), 2); - - $this->assertEqual($albums[0]->title, 'Album 1'); - $this->assertEqual($albums[1]->title, 'Album 2'); - - $this->assertEqual($albums[0]->cover->content, 'lalala'); - $this->assertEqual($albums[1]->cover->content, 'conver content'); - - $this->assertEqual(count($albums[0]->Artists), 0); - $this->assertEqual(count($albums[1]->Artists), 0); - - $this->assertEqual(count($albums[0]->Tracks), 0); - $this->assertEqual(count($albums[1]->Tracks), 0); - } - - function test_belongs_to() - { - $track = Track::finder()->withAlbum()->find('id = ?', 1); - - $this->assertEqual($track->id, "1"); - $this->assertEqual($track->song_name, "Track 1"); - $this->assertEqual($track->Album->title, "Album 1"); - } - - function test_has_many_associate() - { - $album = Album::finder()->withArtists()->find('title = ?', 'Album 2'); - $this->assertEqual($album->title, 'Album 2'); - $this->assertEqual(count($album->Artists), 3); - - $this->assertEqual($album->Artists[0]->name, 'Dan'); - $this->assertEqual($album->Artists[1]->name, 'Karl'); - $this->assertEqual($album->Artists[2]->name, 'Tom'); - } - - function test_multiple_fk() - { - $album = Album::finder()->withArtists()->withTracks()->with_cover()->find('title = ?', 'Album 1'); - - $this->assertEqual($album->title, 'Album 1'); - $this->assertEqual(count($album->Artists), 2); - - $this->assertEqual($album->Artists[0]->name, 'Dan'); - $this->assertEqual($album->Artists[1]->name, 'Jenny'); - - $this->assertEqual($album->Tracks[0]->song_name, 'Track 1'); - $this->assertEqual($album->Tracks[1]->song_name, 'Song 2'); - $this->assertEqual($album->Tracks[2]->song_name, 'Song 3'); - - $this->assertEqual($album->cover->content, 'lalala'); - } - - function test_self_reference_fk() - { - $item = ItemRecord::finder()->withRelated_Items()->findByPk(1); - $this->assertNotNull($item); - $this->assertEqual($item->name, "Professional Work Attire"); - - $this->assertEqual(count($item->related_items),2); - $this->assertEqual($item->related_items[0]->name, "Nametags"); - $this->assertEqual($item->related_items[0]->item_id, 2); - - $this->assertEqual($item->related_items[1]->name, "Grooming and Hygiene"); - $this->assertEqual($item->related_items[1]->item_id, 3); - } - -} - + array(self::HAS_MANY, 'Track'), + 'Artists' => array(self::MANY_TO_MANY, 'Artist', 'album_artists'), + 'cover' => array(self::HAS_ONE, 'Cover') + ); + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + +class Artist extends SqliteRecord +{ + public $name; + + public $Albums = array(); + + public static $RELATIONS=array + ( + 'Albums' => array(self::MANY_TO_MANY, 'Album', 'album_artists') + ); + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + +class Track extends SqliteRecord +{ + public $id; + public $song_name; + public $album_id; //FK -> Album.id + + public $Album; + + public static $RELATIONS = array( + 'Album' => array(self::BELONGS_TO, 'Album'), + ); + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + +class Cover extends SqliteRecord +{ + public $album; + public $content; +} + +class ForeignKeyTestCase extends UnitTestCase +{ + function test_has_many() + { + $albums = Album::finder()->withTracks()->findAll(); + $this->assertEqual(count($albums), 2); + + $this->assertEqual($albums[0]->title, 'Album 1'); + $this->assertEqual($albums[1]->title, 'Album 2'); + + $this->assertEqual(count($albums[0]->Artists), 0); + $this->assertEqual(count($albums[1]->Artists), 0); + + $this->assertEqual(count($albums[0]->Tracks), 3); + $this->assertEqual(count($albums[1]->Tracks), 2); + + $this->assertEqual($albums[0]->Tracks[0]->song_name, 'Track 1'); + $this->assertEqual($albums[0]->Tracks[1]->song_name, 'Song 2'); + $this->assertEqual($albums[0]->Tracks[2]->song_name, 'Song 3'); + + $this->assertEqual($albums[1]->Tracks[0]->song_name, 'Track A'); + $this->assertEqual($albums[1]->Tracks[1]->song_name, 'Track B'); + } + + function test_has_one() + { + $albums = Album::finder()->with_cover()->findAll(); + $this->assertEqual(count($albums), 2); + + $this->assertEqual($albums[0]->title, 'Album 1'); + $this->assertEqual($albums[1]->title, 'Album 2'); + + $this->assertEqual($albums[0]->cover->content, 'lalala'); + $this->assertEqual($albums[1]->cover->content, 'conver content'); + + $this->assertEqual(count($albums[0]->Artists), 0); + $this->assertEqual(count($albums[1]->Artists), 0); + + $this->assertEqual(count($albums[0]->Tracks), 0); + $this->assertEqual(count($albums[1]->Tracks), 0); + } + + function test_belongs_to() + { + $track = Track::finder()->withAlbum()->find('id = ?', 1); + + $this->assertEqual($track->id, "1"); + $this->assertEqual($track->song_name, "Track 1"); + $this->assertEqual($track->Album->title, "Album 1"); + } + + function test_has_many_associate() + { + $album = Album::finder()->withArtists()->find('title = ?', 'Album 2'); + $this->assertEqual($album->title, 'Album 2'); + $this->assertEqual(count($album->Artists), 3); + + $this->assertEqual($album->Artists[0]->name, 'Dan'); + $this->assertEqual($album->Artists[1]->name, 'Karl'); + $this->assertEqual($album->Artists[2]->name, 'Tom'); + } + + function test_multiple_fk() + { + $album = Album::finder()->withArtists()->withTracks()->with_cover()->find('title = ?', 'Album 1'); + + $this->assertEqual($album->title, 'Album 1'); + $this->assertEqual(count($album->Artists), 2); + + $this->assertEqual($album->Artists[0]->name, 'Dan'); + $this->assertEqual($album->Artists[1]->name, 'Jenny'); + + $this->assertEqual($album->Tracks[0]->song_name, 'Track 1'); + $this->assertEqual($album->Tracks[1]->song_name, 'Song 2'); + $this->assertEqual($album->Tracks[2]->song_name, 'Song 3'); + + $this->assertEqual($album->cover->content, 'lalala'); + } + + function test_self_reference_fk() + { + $item = ItemRecord::finder()->withRelated_Items()->findByPk(1); + $this->assertNotNull($item); + $this->assertEqual($item->name, "Professional Work Attire"); + + $this->assertEqual(count($item->related_items),2); + $this->assertEqual($item->related_items[0]->name, "Nametags"); + $this->assertEqual($item->related_items[0]->item_id, 2); + + $this->assertEqual($item->related_items[1]->name, "Grooming and Hygiene"); + $this->assertEqual($item->related_items[1]->item_id, 3); + } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php b/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php index 026efb4d..672c2d0f 100644 --- a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php +++ b/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php @@ -1,242 +1,242 @@ -OnExecuteCommand[] = array($this,'logger'); - } - return $conn; - } - - function logger($sender,$param) - { - } -} - -class TeamRecord extends BaseFkRecord -{ - const TABLE='teams'; - public $name; - public $location; - - public $players=array(); - - //define the $player member having has many relationship with PlayerRecord - public static $RELATIONS=array - ( - 'players' => array(self::HAS_MANY, 'PlayerRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} - -class PlayerRecord extends BaseFkRecord -{ - const TABLE='players'; - public $player_id; - public $age; - public $team_name; - - public $team; - private $_skills; - public $profile; - - public static $RELATIONS=array - ( - 'skills' => array(self::MANY_TO_MANY, 'SkillRecord', 'player_skills'), - 'team' => array(self::BELONGS_TO, 'TeamRecord'), - 'profile' => array(self::HAS_ONE, 'ProfileRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } - - public function getSkills() - { - if($this->_skills===null && $this->player_id !==null) - { - //lazy load the skill records - $this->setSkills($this->withSkills()->findByPk($this->player_id)->skills); - } - else if($this->_skills===null) - { - //create new TList; - $this->setSkills(new TList()); - } - return $this->_skills; - } - - public function setSkills($value) - { - $this->_skills = $value instanceof TList ? $value : new TList($value); - } -} - -class ProfileRecord extends BaseFkRecord -{ - const TABLE='profiles'; - public $fk_player_id; - public $salary; - - public $player; - - public static $RELATIONS=array - ( - 'player' => array(self::BELONGS_TO, 'PlayerRecord'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} - -class SkillRecord extends BaseFkRecord -{ - const TABLE='skills'; - public $skill_id; - public $name; - - public $players=array(); - - public static $RELATIONS=array - ( - 'players' => array(self::MANY_TO_MANY, 'PlayerRecord', 'player_skills'), - ); - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } - - -} - -class ForeignObjectUpdateTest extends UnitTestCase -{ - function test_add_has_one() - { - ProfileRecord::finder()->deleteByPk(3); - - $player = PlayerRecord::finder()->findByPk(3); - $player->profile = new ProfileRecord(array('salary'=>50000)); - $player->save(); - - //test insert - $player2 = PlayerRecord::finder()->withProfile()->findByPk(3); - $this->assertEqual($player2->profile->salary,50000); - - $player2->profile->salary = 45000; - $player2->save(); - $this->assertEqual($player2->profile->salary,45000); - - //test update - $player3 = PlayerRecord::finder()->withProfile()->findByPk(3); - $this->assertEqual($player3->profile->salary,45000); - } - - function test_add_many() - { - PlayerRecord::finder()->deleteAll("player_id > ?", 3); - - $team = TeamRecord::finder()->findByPk('Team b'); - $team->players[] = new PlayerRecord(array('age'=>20)); - $team->players[] = new PlayerRecord(array('age'=>25)); - $team->save(); - - //test insert - $team1 = TeamRecord::finder()->withPlayers()->findByPk('Team b'); - $this->assertEqual(count($team1->players),3); - $this->assertEqual($team1->players[0]->age, 18); - $this->assertEqual($team1->players[1]->age, 20); - $this->assertEqual($team1->players[2]->age, 25); - - //test update - $team1->players[1]->age = 55; - $team1->save(); - - $this->assertEqual($team1->players[0]->age, 18); - $this->assertEqual($team1->players[1]->age, 55); - $this->assertEqual($team1->players[2]->age, 25); - - $criteria = new TActiveRecordCriteria(); - $criteria->OrdersBy['age'] = 'desc'; - $team2 = TeamRecord::finder()->withPlayers($criteria)->findByPk('Team b'); - $this->assertEqual(count($team2->players),3); - //ordered by age - $this->assertEqual($team2->players[0]->age, 55); - $this->assertEqual($team2->players[1]->age, 25); - $this->assertEqual($team2->players[2]->age, 18); - } - - function test_add_belongs_to() - { - TeamRecord::finder()->deleteByPk('Team c'); - PlayerRecord::finder()->deleteAll("player_id > ?", 3); - - $player = new PlayerRecord(array('age'=>27)); - $player->team = new TeamRecord(array('name'=>'Team c', 'location'=>'Sydney')); - $player->save(); - - //test insert - $player1 = PlayerRecord::finder()->withTeam()->findByAge(27); - $this->assertNotNull($player1); - $this->assertNotNull($player1->team); - $this->assertEqual($player1->team->name, 'Team c'); - $this->assertEqual($player1->team->location, 'Sydney'); - } - - function test_add_many_via_association() - { - PlayerRecord::finder()->deleteAll("player_id > ?", 3); - SkillRecord::finder()->deleteAll("skill_id > ?", 3); - - $player = new PlayerRecord(array('age'=>37)); - $player->skills[] = new SkillRecord(array('name'=>'Bash')); - $player->skills[] = new SkillRecord(array('name'=>'Jump')); - $player->save(); - - //test insert - $player2 = PlayerRecord::finder()->withSkills()->findByAge(37); - $this->assertNotNull($player2); - $this->assertEqual(count($player2->skills), 2); - $this->assertEqual($player2->skills[0]->name, 'Bash'); - $this->assertEqual($player2->skills[1]->name, 'Jump'); - - //test update - $player2->skills[1]->name = "Skip"; - $player2->skills[] = new SkillRecord(array('name'=>'Push')); - $player2->save(); - - $criteria = new TActiveRecordCriteria(); - $criteria->OrdersBy['name'] = 'asc'; - $player3 = PlayerRecord::finder()->withSkills($criteria)->findByAge(37); - $this->assertNotNull($player3); - $this->assertEqual(count($player3->skills), 3); - $this->assertEqual($player3->skills[0]->name, 'Bash'); - $this->assertEqual($player3->skills[1]->name, 'Push'); - $this->assertEqual($player3->skills[2]->name, 'Skip'); - - //test lazy load - $player4 = PlayerRecord::finder()->findByAge(37); - $this->assertEqual(count($player4->skills), 3); - - $this->assertEqual($player4->skills[0]->name, 'Bash'); - $this->assertEqual($player4->skills[1]->name, 'Skip'); - $this->assertEqual($player4->skills[2]->name, 'Push'); - } -//*/ -} - +OnExecuteCommand[] = array($this,'logger'); + } + return $conn; + } + + function logger($sender,$param) + { + } +} + +class TeamRecord extends BaseFkRecord +{ + const TABLE='teams'; + public $name; + public $location; + + public $players=array(); + + //define the $player member having has many relationship with PlayerRecord + public static $RELATIONS=array + ( + 'players' => array(self::HAS_MANY, 'PlayerRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + +class PlayerRecord extends BaseFkRecord +{ + const TABLE='players'; + public $player_id; + public $age; + public $team_name; + + public $team; + private $_skills; + public $profile; + + public static $RELATIONS=array + ( + 'skills' => array(self::MANY_TO_MANY, 'SkillRecord', 'player_skills'), + 'team' => array(self::BELONGS_TO, 'TeamRecord'), + 'profile' => array(self::HAS_ONE, 'ProfileRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } + + public function getSkills() + { + if($this->_skills===null && $this->player_id !==null) + { + //lazy load the skill records + $this->setSkills($this->withSkills()->findByPk($this->player_id)->skills); + } + else if($this->_skills===null) + { + //create new TList; + $this->setSkills(new TList()); + } + return $this->_skills; + } + + public function setSkills($value) + { + $this->_skills = $value instanceof TList ? $value : new TList($value); + } +} + +class ProfileRecord extends BaseFkRecord +{ + const TABLE='profiles'; + public $fk_player_id; + public $salary; + + public $player; + + public static $RELATIONS=array + ( + 'player' => array(self::BELONGS_TO, 'PlayerRecord'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + +class SkillRecord extends BaseFkRecord +{ + const TABLE='skills'; + public $skill_id; + public $name; + + public $players=array(); + + public static $RELATIONS=array + ( + 'players' => array(self::MANY_TO_MANY, 'PlayerRecord', 'player_skills'), + ); + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } + + +} + +class ForeignObjectUpdateTest extends UnitTestCase +{ + function test_add_has_one() + { + ProfileRecord::finder()->deleteByPk(3); + + $player = PlayerRecord::finder()->findByPk(3); + $player->profile = new ProfileRecord(array('salary'=>50000)); + $player->save(); + + //test insert + $player2 = PlayerRecord::finder()->withProfile()->findByPk(3); + $this->assertEqual($player2->profile->salary,50000); + + $player2->profile->salary = 45000; + $player2->save(); + $this->assertEqual($player2->profile->salary,45000); + + //test update + $player3 = PlayerRecord::finder()->withProfile()->findByPk(3); + $this->assertEqual($player3->profile->salary,45000); + } + + function test_add_many() + { + PlayerRecord::finder()->deleteAll("player_id > ?", 3); + + $team = TeamRecord::finder()->findByPk('Team b'); + $team->players[] = new PlayerRecord(array('age'=>20)); + $team->players[] = new PlayerRecord(array('age'=>25)); + $team->save(); + + //test insert + $team1 = TeamRecord::finder()->withPlayers()->findByPk('Team b'); + $this->assertEqual(count($team1->players),3); + $this->assertEqual($team1->players[0]->age, 18); + $this->assertEqual($team1->players[1]->age, 20); + $this->assertEqual($team1->players[2]->age, 25); + + //test update + $team1->players[1]->age = 55; + $team1->save(); + + $this->assertEqual($team1->players[0]->age, 18); + $this->assertEqual($team1->players[1]->age, 55); + $this->assertEqual($team1->players[2]->age, 25); + + $criteria = new TActiveRecordCriteria(); + $criteria->OrdersBy['age'] = 'desc'; + $team2 = TeamRecord::finder()->withPlayers($criteria)->findByPk('Team b'); + $this->assertEqual(count($team2->players),3); + //ordered by age + $this->assertEqual($team2->players[0]->age, 55); + $this->assertEqual($team2->players[1]->age, 25); + $this->assertEqual($team2->players[2]->age, 18); + } + + function test_add_belongs_to() + { + TeamRecord::finder()->deleteByPk('Team c'); + PlayerRecord::finder()->deleteAll("player_id > ?", 3); + + $player = new PlayerRecord(array('age'=>27)); + $player->team = new TeamRecord(array('name'=>'Team c', 'location'=>'Sydney')); + $player->save(); + + //test insert + $player1 = PlayerRecord::finder()->withTeam()->findByAge(27); + $this->assertNotNull($player1); + $this->assertNotNull($player1->team); + $this->assertEqual($player1->team->name, 'Team c'); + $this->assertEqual($player1->team->location, 'Sydney'); + } + + function test_add_many_via_association() + { + PlayerRecord::finder()->deleteAll("player_id > ?", 3); + SkillRecord::finder()->deleteAll("skill_id > ?", 3); + + $player = new PlayerRecord(array('age'=>37)); + $player->skills[] = new SkillRecord(array('name'=>'Bash')); + $player->skills[] = new SkillRecord(array('name'=>'Jump')); + $player->save(); + + //test insert + $player2 = PlayerRecord::finder()->withSkills()->findByAge(37); + $this->assertNotNull($player2); + $this->assertEqual(count($player2->skills), 2); + $this->assertEqual($player2->skills[0]->name, 'Bash'); + $this->assertEqual($player2->skills[1]->name, 'Jump'); + + //test update + $player2->skills[1]->name = "Skip"; + $player2->skills[] = new SkillRecord(array('name'=>'Push')); + $player2->save(); + + $criteria = new TActiveRecordCriteria(); + $criteria->OrdersBy['name'] = 'asc'; + $player3 = PlayerRecord::finder()->withSkills($criteria)->findByAge(37); + $this->assertNotNull($player3); + $this->assertEqual(count($player3->skills), 3); + $this->assertEqual($player3->skills[0]->name, 'Bash'); + $this->assertEqual($player3->skills[1]->name, 'Push'); + $this->assertEqual($player3->skills[2]->name, 'Skip'); + + //test lazy load + $player4 = PlayerRecord::finder()->findByAge(37); + $this->assertEqual(count($player4->skills), 3); + + $this->assertEqual($player4->skills[0]->name, 'Bash'); + $this->assertEqual($player4->skills[1]->name, 'Skip'); + $this->assertEqual($player4->skills[2]->name, 'Push'); + } +//*/ +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php index 77408631..c43db032 100644 --- a/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php +++ b/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php @@ -1,192 +1,192 @@ - array(self::BELONGS_TO, 'Table2', 'fk1'), - 'object2' => array(self::BELONGS_TO, 'Table2', 'fk2'), - 'object3' => array(self::BELONGS_TO, 'Table2', 'fk3'), - ); - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - -/** - * CREATE TABLE table2 (id integer PRIMARY KEY AUTOINCREMENT,field1 varchar) - */ -class Table2 extends MultipleFKSqliteRecord -{ - public $id; - public $field1; - - private $_state1; - //public $state2; //commented out for testing __get/__set - public $state3; - - public static $RELATIONS = array - ( - 'state1' => array(self::HAS_MANY, 'Table1', 'fk1'), - 'state2' => array(self::HAS_MANY, 'Table1', 'fk2'), - 'state3' => array(self::HAS_ONE, 'Table1', 'fk3'), - ); - - public function setState1($obj) - { - $this->_state1 = $obj; - } - - public function getState1() - { - if(is_null($this->_state1)) - $this->fetchResultsFor('state1'); - return $this->_state1; - } - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - - -class Category extends MultipleFKSqliteRecord -{ - public $cat_id; - public $category_name; - public $parent_cat; - - public $parent_category; - public $child_categories=array(); - - public static $RELATIONS=array - ( - 'parent_category' => array(self::BELONGS_TO, 'Category'), - 'child_categories' => array(self::HAS_MANY, 'Category'), - ); - - public static function finder($class=__CLASS__) - { - return parent::finder($class); - } -} - -class MultipleForeignKeyTestCase extends UnitTestCase -{ - function testBelongsTo() - { - $obj = Table1::finder()->withObject1()->findAll(); - $this->assertEqual(count($obj), 3); - $this->assertEqual($obj[0]->id, '1'); - $this->assertEqual($obj[1]->id, '2'); - $this->assertEqual($obj[2]->id, '3'); - - $this->assertEqual($obj[0]->object1->id, '1'); - $this->assertEqual($obj[1]->object1->id, '2'); - $this->assertEqual($obj[2]->object1->id, '2'); - } - - function testHasMany() - { - $obj = Table2::finder()->withState1()->findAll(); - $this->assertEqual(count($obj), 5); - - $this->assertEqual(count($obj[0]->state1), 1); - $this->assertEqual($obj[0]->state1[0]->id, '1'); - - $this->assertEqual(count($obj[1]->state1), 2); - $this->assertEqual($obj[1]->state1[0]->id, '2'); - $this->assertEqual($obj[1]->state1[1]->id, '3'); - - $this->assertEqual(count($obj[2]->state1), 0); - $this->assertEqual($obj[2]->id, '3'); - - $this->assertEqual(count($obj[3]->state1), 0); - $this->assertEqual($obj[3]->id, '4'); - } - - function testHasOne() - { - $obj = Table2::finder()->withState3('id = 3')->findAll(); - - $this->assertEqual(count($obj), 5); - - $this->assertEqual($obj[0]->id, '1'); - $this->assertNull($obj[0]->state3); - - $this->assertEqual($obj[1]->id, '2'); - $this->assertNull($obj[1]->state3); - - $this->assertEqual($obj[2]->id, '3'); - $this->assertNotNull($obj[2]->state3); - $this->assertEqual($obj[2]->state3->id, '3'); - - $this->assertEqual($obj[3]->id, '4'); - $this->assertNull($obj[3]->state3); - } - - function testParentChild() - { - $obj = Category::finder()->withChild_Categories()->withParent_Category()->findByPk(2); - - $this->assertEqual($obj->cat_id, '2'); - $this->assertEqual(count($obj->child_categories), 2); - $this->assertNotNull($obj->parent_category); - - $this->assertEqual($obj->child_categories[0]->cat_id, 3); - $this->assertEqual($obj->child_categories[1]->cat_id, 4); - - $this->assertEqual($obj->parent_category->cat_id, 1); - } - - function testLazyLoadingGetterSetter_hasMany() - { - $arr = Table2::finder()->findByPk(2); - - $this->assertNotNull($arr->state2); //lazy load - $this->assertEqual(count($arr->state2), 1); - $this->assertEqual($arr->state2[0]->id, "1"); - $this->assertNotNull($arr->state2[0]->object2); - $this->assertEqual($arr->state2[0]->object2->id, "2"); - - $this->assertNotIdentical($arr, $arr->state2[0]->object2); - } -} - + array(self::BELONGS_TO, 'Table2', 'fk1'), + 'object2' => array(self::BELONGS_TO, 'Table2', 'fk2'), + 'object3' => array(self::BELONGS_TO, 'Table2', 'fk3'), + ); + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + +/** + * CREATE TABLE table2 (id integer PRIMARY KEY AUTOINCREMENT,field1 varchar) + */ +class Table2 extends MultipleFKSqliteRecord +{ + public $id; + public $field1; + + private $_state1; + //public $state2; //commented out for testing __get/__set + public $state3; + + public static $RELATIONS = array + ( + 'state1' => array(self::HAS_MANY, 'Table1', 'fk1'), + 'state2' => array(self::HAS_MANY, 'Table1', 'fk2'), + 'state3' => array(self::HAS_ONE, 'Table1', 'fk3'), + ); + + public function setState1($obj) + { + $this->_state1 = $obj; + } + + public function getState1() + { + if(is_null($this->_state1)) + $this->fetchResultsFor('state1'); + return $this->_state1; + } + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + + +class Category extends MultipleFKSqliteRecord +{ + public $cat_id; + public $category_name; + public $parent_cat; + + public $parent_category; + public $child_categories=array(); + + public static $RELATIONS=array + ( + 'parent_category' => array(self::BELONGS_TO, 'Category'), + 'child_categories' => array(self::HAS_MANY, 'Category'), + ); + + public static function finder($class=__CLASS__) + { + return parent::finder($class); + } +} + +class MultipleForeignKeyTestCase extends UnitTestCase +{ + function testBelongsTo() + { + $obj = Table1::finder()->withObject1()->findAll(); + $this->assertEqual(count($obj), 3); + $this->assertEqual($obj[0]->id, '1'); + $this->assertEqual($obj[1]->id, '2'); + $this->assertEqual($obj[2]->id, '3'); + + $this->assertEqual($obj[0]->object1->id, '1'); + $this->assertEqual($obj[1]->object1->id, '2'); + $this->assertEqual($obj[2]->object1->id, '2'); + } + + function testHasMany() + { + $obj = Table2::finder()->withState1()->findAll(); + $this->assertEqual(count($obj), 5); + + $this->assertEqual(count($obj[0]->state1), 1); + $this->assertEqual($obj[0]->state1[0]->id, '1'); + + $this->assertEqual(count($obj[1]->state1), 2); + $this->assertEqual($obj[1]->state1[0]->id, '2'); + $this->assertEqual($obj[1]->state1[1]->id, '3'); + + $this->assertEqual(count($obj[2]->state1), 0); + $this->assertEqual($obj[2]->id, '3'); + + $this->assertEqual(count($obj[3]->state1), 0); + $this->assertEqual($obj[3]->id, '4'); + } + + function testHasOne() + { + $obj = Table2::finder()->withState3('id = 3')->findAll(); + + $this->assertEqual(count($obj), 5); + + $this->assertEqual($obj[0]->id, '1'); + $this->assertNull($obj[0]->state3); + + $this->assertEqual($obj[1]->id, '2'); + $this->assertNull($obj[1]->state3); + + $this->assertEqual($obj[2]->id, '3'); + $this->assertNotNull($obj[2]->state3); + $this->assertEqual($obj[2]->state3->id, '3'); + + $this->assertEqual($obj[3]->id, '4'); + $this->assertNull($obj[3]->state3); + } + + function testParentChild() + { + $obj = Category::finder()->withChild_Categories()->withParent_Category()->findByPk(2); + + $this->assertEqual($obj->cat_id, '2'); + $this->assertEqual(count($obj->child_categories), 2); + $this->assertNotNull($obj->parent_category); + + $this->assertEqual($obj->child_categories[0]->cat_id, 3); + $this->assertEqual($obj->child_categories[1]->cat_id, 4); + + $this->assertEqual($obj->parent_category->cat_id, 1); + } + + function testLazyLoadingGetterSetter_hasMany() + { + $arr = Table2::finder()->findByPk(2); + + $this->assertNotNull($arr->state2); //lazy load + $this->assertEqual(count($arr->state2), 1); + $this->assertEqual($arr->state2[0]->id, "1"); + $this->assertNotNull($arr->state2[0]->object2); + $this->assertEqual($arr->state2[0]->object2->id, "2"); + + $this->assertNotIdentical($arr, $arr->state2[0]->object2); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/RecordEventTestCase.php b/tests/simple_unit/ActiveRecord/RecordEventTestCase.php index f6009608..3e98d46b 100644 --- a/tests/simple_unit/ActiveRecord/RecordEventTestCase.php +++ b/tests/simple_unit/ActiveRecord/RecordEventTestCase.php @@ -1,37 +1,37 @@ -setDbConnection($conn); - } - - function testFindByPk() - { - $user1 = UserRecord::finder()->findByPk('admin'); - $this->assertNotNull($user1); - } - - function test_same_data_returns_same_object() - { - $criteria = new TActiveRecordCriteria('username = ?', 'admin'); - $finder = new UserRecord(); - $finder->OnCreateCommand[] = array($this, 'logger'); - $finder->OnExecuteCommand[] = array($this, 'logger'); - $user1 = $finder->find($criteria); - //var_dump($user1); - - //var_dump(UserRecord::finder()->find($criteria)); - } - - function logger($sender, $param) - { - //var_dump($param); - } -} - +setDbConnection($conn); + } + + function testFindByPk() + { + $user1 = UserRecord::finder()->findByPk('admin'); + $this->assertNotNull($user1); + } + + function test_same_data_returns_same_object() + { + $criteria = new TActiveRecordCriteria('username = ?', 'admin'); + $finder = new UserRecord(); + $finder->OnCreateCommand[] = array($this, 'logger'); + $finder->OnExecuteCommand[] = array($this, 'logger'); + $user1 = $finder->find($criteria); + //var_dump($user1); + + //var_dump(UserRecord::finder()->find($criteria)); + } + + function logger($sender, $param) + { + //var_dump($param); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/SqliteTestCase.php b/tests/simple_unit/ActiveRecord/SqliteTestCase.php index 94af6200..7d860b9a 100644 --- a/tests/simple_unit/ActiveRecord/SqliteTestCase.php +++ b/tests/simple_unit/ActiveRecord/SqliteTestCase.php @@ -1,21 +1,21 @@ -setDbConnection($conn); - } - - function test_finder() - { - $finder = SqliteUsers::finder(); - $user = $finder->findByPk('test'); - $this->assertNotNull($user); - } -} +setDbConnection($conn); + } + + function test_finder() + { + $finder = SqliteUsers::finder(); + $user = $finder->findByPk('test'); + $this->assertNotNull($user); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/UserRecordTestCase.php b/tests/simple_unit/ActiveRecord/UserRecordTestCase.php index 057455f7..34e45ca8 100644 --- a/tests/simple_unit/ActiveRecord/UserRecordTestCase.php +++ b/tests/simple_unit/ActiveRecord/UserRecordTestCase.php @@ -1,66 +1,66 @@ -setDbConnection($conn); - } - - function testFindByPk() - { - $user1 = UserRecord::finder()->findByPk('admin'); - $this->assertNotNull($user1); - } - - function test_same_data_returns_different_instance() - { - $user1 = UserRecord::finder()->findByPk('admin'); - $this->assertNotNull($user1); - - $user2 = UserRecord::finder()->findByPk('admin'); - $this->assertFalse($user1===$user2); - } - - function testFindByPk_returns_null() - { - $user = UserRecord::finder()->findByPk('me'); - $this->assertNull($user); - } - - function test_Create_new_user_returns_true() - { - $user = new UserRecord; - $user->username = 'hello'; - $user->password = md5('asd'); - $user->email = 'asdasd'; - $user->first_name = 'wei'; - $user->last_name = 'zhuo'; - - $this->assertTrue($user->save()); - - $user->password = md5('more'); - - $this->assertTrue($user->save()); - - $check = UserRecord::finder()->findByPk('hello'); - - $this->assertSameUser($user, $check); - - $this->assertTrue($user->delete()); - } - - function assertSameUser($user,$check) - { - $props = array('username', 'password', 'email', 'first_name', 'last_name', 'job_title', - 'work_phone', 'work_fax', 'active', 'department_id', 'salutation', - 'hint_question', 'hint_answer'); - foreach($props as $prop) - $this->assertEqual($user->$prop,$check->$prop); - } -} - +setDbConnection($conn); + } + + function testFindByPk() + { + $user1 = UserRecord::finder()->findByPk('admin'); + $this->assertNotNull($user1); + } + + function test_same_data_returns_different_instance() + { + $user1 = UserRecord::finder()->findByPk('admin'); + $this->assertNotNull($user1); + + $user2 = UserRecord::finder()->findByPk('admin'); + $this->assertFalse($user1===$user2); + } + + function testFindByPk_returns_null() + { + $user = UserRecord::finder()->findByPk('me'); + $this->assertNull($user); + } + + function test_Create_new_user_returns_true() + { + $user = new UserRecord; + $user->username = 'hello'; + $user->password = md5('asd'); + $user->email = 'asdasd'; + $user->first_name = 'wei'; + $user->last_name = 'zhuo'; + + $this->assertTrue($user->save()); + + $user->password = md5('more'); + + $this->assertTrue($user->save()); + + $check = UserRecord::finder()->findByPk('hello'); + + $this->assertSameUser($user, $check); + + $this->assertTrue($user->delete()); + } + + function assertSameUser($user,$check) + { + $props = array('username', 'password', 'email', 'first_name', 'last_name', 'job_title', + 'work_phone', 'work_fax', 'active', 'department_id', 'salutation', + 'hint_question', 'hint_answer'); + foreach($props as $prop) + $this->assertEqual($user->$prop,$check->$prop); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php b/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php index db23f01a..adf0beed 100644 --- a/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php +++ b/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php @@ -1,76 +1,76 @@ setDbConnection($conn); - } - - function test_view_record() - { - $users = SimpleUser::finder()->findAll(); - $this->assertTrue(count($users) > 0); - } - - function test_save_view_record_throws_exception() - { - $user = new SimpleUser(); - try - { - $user->save(); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - } - - function test_update_view_record_throws_exception() - { - $user = SimpleUser::finder()->findByUsername('admin'); - $user->username = 'ads'; - try - { - $user->save(); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } - } - - function test_find_by_pk_throws_exception() - { - try - { - $user = SimpleUser::finder()->findByPk('admin'); - $this->fail(); - } - catch(TDbException $e) - { - $this->pass(); - } - } - - function test_delete_by_pk_throws_exception() - { - try - { - SimpleUser::finder()->deleteByPk('admin'); - $this->fail(); - } - catch(TDbException $e) - { - $this->pass(); - } - } + + +Prado::using('System.Data.ActiveRecord.TActiveRecord'); +require_once(dirname(__FILE__).'/records/SimpleUser.php'); + +class ViewRecordTestCase extends UnitTestCase +{ + function setup() + { + $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + TActiveRecordManager::getInstance()->setDbConnection($conn); + } + + function test_view_record() + { + $users = SimpleUser::finder()->findAll(); + $this->assertTrue(count($users) > 0); + } + + function test_save_view_record_throws_exception() + { + $user = new SimpleUser(); + try + { + $user->save(); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + } + + function test_update_view_record_throws_exception() + { + $user = SimpleUser::finder()->findByUsername('admin'); + $user->username = 'ads'; + try + { + $user->save(); + $this->fail(); + } + catch(TActiveRecordException $e) + { + $this->pass(); + } + } + + function test_find_by_pk_throws_exception() + { + try + { + $user = SimpleUser::finder()->findByPk('admin'); + $this->fail(); + } + catch(TDbException $e) + { + $this->pass(); + } + } + + function test_delete_by_pk_throws_exception() + { + try + { + SimpleUser::finder()->deleteByPk('admin'); + $this->fail(); + } + catch(TDbException $e) + { + $this->pass(); + } + } } ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/Blogs.php b/tests/simple_unit/ActiveRecord/records/Blogs.php index c32ca6b6..680b3141 100644 --- a/tests/simple_unit/ActiveRecord/records/Blogs.php +++ b/tests/simple_unit/ActiveRecord/records/Blogs.php @@ -1,14 +1,14 @@ - \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/DepSections.php b/tests/simple_unit/ActiveRecord/records/DepSections.php index 7b213c33..6f37ae3e 100644 --- a/tests/simple_unit/ActiveRecord/records/DepSections.php +++ b/tests/simple_unit/ActiveRecord/records/DepSections.php @@ -1,16 +1,16 @@ - \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php b/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php index 61307826..732610ae 100644 --- a/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php +++ b/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php @@ -1,18 +1,18 @@ - \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/ItemRecord.php b/tests/simple_unit/ActiveRecord/records/ItemRecord.php index 52a1a658..8585ebaf 100644 --- a/tests/simple_unit/ActiveRecord/records/ItemRecord.php +++ b/tests/simple_unit/ActiveRecord/records/ItemRecord.php @@ -1,49 +1,49 @@ - array(self::MANY_TO_MANY, 'ItemRecord', 'related_items.related_item_id'), - ); - - public function getDbConnection() - { - static $conn; - if($conn===null) - { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); - $this->OnExecuteCommand[] = array($this,'logger'); - } - return $conn; - } - - public function logger($sender,$param) - { - //var_dump($param->Command->Text); - } - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} - + array(self::MANY_TO_MANY, 'ItemRecord', 'related_items.related_item_id'), + ); + + public function getDbConnection() + { + static $conn; + if($conn===null) + { + $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $this->OnExecuteCommand[] = array($this,'logger'); + } + return $conn; + } + + public function logger($sender,$param) + { + //var_dump($param->Command->Text); + } + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/SimpleUser.php b/tests/simple_unit/ActiveRecord/records/SimpleUser.php index 4ff0b982..cfba272e 100644 --- a/tests/simple_unit/ActiveRecord/records/SimpleUser.php +++ b/tests/simple_unit/ActiveRecord/records/SimpleUser.php @@ -1,14 +1,14 @@ - \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/SqliteUsers.php b/tests/simple_unit/ActiveRecord/records/SqliteUsers.php index ffa47c72..8e5b9fde 100644 --- a/tests/simple_unit/ActiveRecord/records/SqliteUsers.php +++ b/tests/simple_unit/ActiveRecord/records/SqliteUsers.php @@ -1,16 +1,16 @@ - \ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/UserRecord.php b/tests/simple_unit/ActiveRecord/records/UserRecord.php index c3cb78b2..c4e8ce60 100644 --- a/tests/simple_unit/ActiveRecord/records/UserRecord.php +++ b/tests/simple_unit/ActiveRecord/records/UserRecord.php @@ -1,38 +1,38 @@ -_level; - } - - public function setLevel($level) - { - $this->_level=TPropertyValue::ensureInteger($level); - } - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} +_level; + } + + public function setLevel($level) + { + $this->_level=TPropertyValue::ensureInteger($level); + } + + public static function finder($className=__CLASS__) + { + return parent::finder($className); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/DbCommon/CommandBuilderMssqlTest.php b/tests/simple_unit/DbCommon/CommandBuilderMssqlTest.php index cc7b8b45..f8a4257c 100644 --- a/tests/simple_unit/DbCommon/CommandBuilderMssqlTest.php +++ b/tests/simple_unit/DbCommon/CommandBuilderMssqlTest.php @@ -1,46 +1,46 @@ 'SELECT username, age FROM accounts', - 'multiple' => 'select a.username, b.name from accounts a, table1 b where a.age = b.id1', - 'ordering' => 'select a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 order by age DESC, name', - 'index' => 'select a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 ORDER BY 1 DESC, 2 ASC', - //'compute' => 'SELECT username, age FROM accounts order by age compute avg(age)', - ); - - function test_limit() - { - $builder = new TMssqlCommandBuilder(); - - $sql = $builder->applyLimitOffset(self::$sql['simple'], 3); - $expect = 'SELECT TOP 3 username, age FROM accounts'; - $this->assertEqual($expect, $sql); - - - $sql = $builder->applyLimitOffset(self::$sql['simple'], 3, 2); - $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 username, age FROM accounts) as [__inner top table__] ) as [__outer top table__] '; - $this->assertEqual($expect, $sql); - - $sql = $builder->applyLimitOffset(self::$sql['multiple'], 3, 2); - $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name from accounts a, table1 b where a.age = b.id1) as [__inner top table__] ) as [__outer top table__] '; - $this->assertEqual($sql, $expect); - - $sql = $builder->applyLimitOffset(self::$sql['ordering'], 3, 2); - $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 order by age DESC, name) as [__inner top table__] ORDER BY age ASC, name DESC) as [__outer top table__] ORDER BY age DESC, name ASC'; - $this->assertEqual($sql, $expect); - - $sql = $builder->applyLimitOffset(self::$sql['index'], 3, 2); - $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 ORDER BY 1 DESC, 2 ASC) as [__inner top table__] ORDER BY 1 ASC, 2 DESC) as [__outer top table__] ORDER BY 1 DESC, 2 ASC'; - $this->assertEqual($expect, $sql); - - // $sql = $builder->applyLimitOffset(self::$sql['compute'], 3, 2); - // var_dump($sql); - } -} + +Prado::using('System.Data.*'); +Prado::using('System.Data.Common.Mssql.TMssqlCommandBuilder'); + +class CommandBuilderMssqlTest extends UnitTestCase +{ + protected static $sql = array( + 'simple' => 'SELECT username, age FROM accounts', + 'multiple' => 'select a.username, b.name from accounts a, table1 b where a.age = b.id1', + 'ordering' => 'select a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 order by age DESC, name', + 'index' => 'select a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 ORDER BY 1 DESC, 2 ASC', + //'compute' => 'SELECT username, age FROM accounts order by age compute avg(age)', + ); + + function test_limit() + { + $builder = new TMssqlCommandBuilder(); + + $sql = $builder->applyLimitOffset(self::$sql['simple'], 3); + $expect = 'SELECT TOP 3 username, age FROM accounts'; + $this->assertEqual($expect, $sql); + + + $sql = $builder->applyLimitOffset(self::$sql['simple'], 3, 2); + $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 username, age FROM accounts) as [__inner top table__] ) as [__outer top table__] '; + $this->assertEqual($expect, $sql); + + $sql = $builder->applyLimitOffset(self::$sql['multiple'], 3, 2); + $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name from accounts a, table1 b where a.age = b.id1) as [__inner top table__] ) as [__outer top table__] '; + $this->assertEqual($sql, $expect); + + $sql = $builder->applyLimitOffset(self::$sql['ordering'], 3, 2); + $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 order by age DESC, name) as [__inner top table__] ORDER BY age ASC, name DESC) as [__outer top table__] ORDER BY age DESC, name ASC'; + $this->assertEqual($sql, $expect); + + $sql = $builder->applyLimitOffset(self::$sql['index'], 3, 2); + $expect = 'SELECT * FROM (SELECT TOP 3 * FROM (SELECT TOP 5 a.username, b.name, a.age from accounts a, table1 b where a.age = b.id1 ORDER BY 1 DESC, 2 ASC) as [__inner top table__] ORDER BY 1 ASC, 2 DESC) as [__outer top table__] ORDER BY 1 DESC, 2 ASC'; + $this->assertEqual($expect, $sql); + + // $sql = $builder->applyLimitOffset(self::$sql['compute'], 3, 2); + // var_dump($sql); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php b/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php index 6b744a4b..e248defd 100644 --- a/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php +++ b/tests/simple_unit/DbCommon/CommandBuilderMysqlTest.php @@ -1,19 +1,19 @@ mysql_meta_data()->getTableInfo("tests.table1"); - } -} +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;port=3307', 'test5','test5'); + 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 index 9ee9c411..63660aee 100644 --- a/tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php +++ b/tests/simple_unit/DbCommon/CommandBuilderPgsqlTest.php @@ -1,76 +1,76 @@ -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); - } -} +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); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/DbCommon/MssqlColumnTest.php b/tests/simple_unit/DbCommon/MssqlColumnTest.php index db2df03b..16d73bc4 100644 --- a/tests/simple_unit/DbCommon/MssqlColumnTest.php +++ b/tests/simple_unit/DbCommon/MssqlColumnTest.php @@ -1,48 +1,48 @@ get_conn()); - } - - function test_insert() - { - $table = new TTableGateway('table1', $this->get_conn()); - $this->assertTrue(is_int($table->insert(array('name'=>'cool')))); - } - -/* function test_meta() - { - $result = $this->meta_data()->getTableInfo("bar"); - var_dump($result); - } -*/ - /*function test_insert() - { - $table = new TTableGateway('table1', $this->get_conn()); - //var_dump($table->insert(array('name'=>'cool'))); - //var_dump($table->getLastInsertId()); - $criteria = new TSqlCriteria(); - $criteria->Limit = 5; - $criteria->Offset = 2; - - $result = $table->findAll($criteria)->readAll(); - var_dump($result); - }*/ -} + +Prado::using('System.Data.*'); +Prado::using('System.Data.Common.Mssql.TMssqlMetaData'); +Prado::using('System.Data.DataGateway.TTableGateway'); + +class MssqlColumnTest extends UnitTestCase +{ + function get_conn() + { + return new TDbConnection('mssql:host=localhost\\sqlexpress', 'test', 'test01'); + } + + /** + * @return TMssqlMetaData + */ + function meta_data() + { + return new TMssqlMetaData($this->get_conn()); + } + + function test_insert() + { + $table = new TTableGateway('table1', $this->get_conn()); + $this->assertTrue(is_int($table->insert(array('name'=>'cool')))); + } + +/* function test_meta() + { + $result = $this->meta_data()->getTableInfo("bar"); + var_dump($result); + } +*/ + /*function test_insert() + { + $table = new TTableGateway('table1', $this->get_conn()); + //var_dump($table->insert(array('name'=>'cool'))); + //var_dump($table->getLastInsertId()); + $criteria = new TSqlCriteria(); + $criteria->Limit = 5; + $criteria->Offset = 2; + + $result = $table->findAll($criteria)->readAll(); + var_dump($result); + }*/ +} ?> \ No newline at end of file diff --git a/tests/simple_unit/DbCommon/Mysql4ColumnTest.php b/tests/simple_unit/DbCommon/Mysql4ColumnTest.php index d69f3093..234a212f 100644 --- a/tests/simple_unit/DbCommon/Mysql4ColumnTest.php +++ b/tests/simple_unit/DbCommon/Mysql4ColumnTest.php @@ -1,254 +1,254 @@ -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, - '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, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field1'] = array( - 'ColumnName' => '`field1`', - 'ColumnSize' => 4, - 'ColumnIndex' => 2, - 'DbType' => 'tinyint', - 'AllowNull' => false, - 'DefaultValue' => '0', - 'NumericPrecision' => null, - 'NumericScale' => null, - 'IsPrimaryKey' => false, - 'IsForeignKey' => 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, - '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, - '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, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field5_float'] = array( - 'ColumnName' => '`field5_float`', - 'ColumnSize' => null, - 'ColumnIndex' => 6, - 'DbType' => 'float', - 'AllowNull' => false, - 'DefaultValue' => '0.0000', - 'NumericPrecision' => 5, - 'NumericScale' => 4, - 'IsPrimaryKey' => false, - 'IsForeignKey' => false, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field6_double'] = array( - 'ColumnName' => '`field6_double`', - 'ColumnSize' => null, - 'ColumnIndex' => 7, - 'DbType' => 'double', - 'AllowNull' => false, - 'DefaultValue' => '0', - 'NumericPrecision' => null, - 'NumericScale' => null, - 'IsPrimaryKey' => false, - 'IsForeignKey' => false, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field7_datetime'] = array( - 'ColumnName' => '`field7_datetime`', - 'ColumnSize' => null, - 'ColumnIndex' => 8, - 'DbType' => 'datetime', - 'AllowNull' => false, - 'DefaultValue' => '0000-00-00 00:00:00', - 'NumericPrecision' => null, - 'NumericScale' => null, - 'IsPrimaryKey' => false, - 'IsForeignKey' => 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, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field9_time'] = array( - 'ColumnName' => '`field9_time`', - 'ColumnSize' => null, - 'ColumnIndex' => 10, - 'DbType' => 'time', - 'AllowNull' => false, - 'DefaultValue' => '00:00:00', - 'NumericPrecision' => null, - 'NumericScale' => null, - 'IsPrimaryKey' => false, - 'IsForeignKey' => false, - 'SequenceName' => null, - 'AutoIncrement' => false, - ); - - $columns['field10_year'] = array( - 'ColumnName' => '`field10_year`', - 'ColumnSize' => 4, - 'ColumnIndex' => 11, - 'DbType' => 'year', - 'AllowNull' => false, - 'DefaultValue' => '0000', - 'NumericPrecision' => null, - 'NumericScale' => null, - 'IsPrimaryKey' => false, - 'IsForeignKey' => 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, - '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, - '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()); - } - - 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}"); - } - } - } -} +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, + '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, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field1'] = array( + 'ColumnName' => '`field1`', + 'ColumnSize' => 4, + 'ColumnIndex' => 2, + 'DbType' => 'tinyint', + 'AllowNull' => false, + 'DefaultValue' => '0', + 'NumericPrecision' => null, + 'NumericScale' => null, + 'IsPrimaryKey' => false, + 'IsForeignKey' => 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, + '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, + '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, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field5_float'] = array( + 'ColumnName' => '`field5_float`', + 'ColumnSize' => null, + 'ColumnIndex' => 6, + 'DbType' => 'float', + 'AllowNull' => false, + 'DefaultValue' => '0.0000', + 'NumericPrecision' => 5, + 'NumericScale' => 4, + 'IsPrimaryKey' => false, + 'IsForeignKey' => false, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field6_double'] = array( + 'ColumnName' => '`field6_double`', + 'ColumnSize' => null, + 'ColumnIndex' => 7, + 'DbType' => 'double', + 'AllowNull' => false, + 'DefaultValue' => '0', + 'NumericPrecision' => null, + 'NumericScale' => null, + 'IsPrimaryKey' => false, + 'IsForeignKey' => false, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field7_datetime'] = array( + 'ColumnName' => '`field7_datetime`', + 'ColumnSize' => null, + 'ColumnIndex' => 8, + 'DbType' => 'datetime', + 'AllowNull' => false, + 'DefaultValue' => '0000-00-00 00:00:00', + 'NumericPrecision' => null, + 'NumericScale' => null, + 'IsPrimaryKey' => false, + 'IsForeignKey' => 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, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field9_time'] = array( + 'ColumnName' => '`field9_time`', + 'ColumnSize' => null, + 'ColumnIndex' => 10, + 'DbType' => 'time', + 'AllowNull' => false, + 'DefaultValue' => '00:00:00', + 'NumericPrecision' => null, + 'NumericScale' => null, + 'IsPrimaryKey' => false, + 'IsForeignKey' => false, + 'SequenceName' => null, + 'AutoIncrement' => false, + ); + + $columns['field10_year'] = array( + 'ColumnName' => '`field10_year`', + 'ColumnSize' => 4, + 'ColumnIndex' => 11, + 'DbType' => 'year', + 'AllowNull' => false, + 'DefaultValue' => '0000', + 'NumericPrecision' => null, + 'NumericScale' => null, + 'IsPrimaryKey' => false, + 'IsForeignKey' => 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, + '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, + '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()); + } + + 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/MysqlColumnTest.php b/tests/simple_unit/DbCommon/MysqlColumnTest.php index 1508f2c6..08fdb545 100644 --- a/tests/simple_unit/DbCommon/MysqlColumnTest.php +++ b/tests/simple_unit/DbCommon/MysqlColumnTest.php @@ -1,254 +1,254 @@ -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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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, - '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()); - } - - 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}"); - } - } - } -} +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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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, + '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()); + } + + 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 index de12083e..a16de964 100644 --- a/tests/simple_unit/DbCommon/PgsqlColumnTest.php +++ b/tests/simple_unit/DbCommon/PgsqlColumnTest.php @@ -1,139 +1,139 @@ 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, - '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, - '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, - '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, - '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, - '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, - '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, - 'SequenceName' => null, - ); - $this->assertColumn($columns, $table); - - $this->assertEqual('public', $table->getSchemaName()); - $this->assertEqual('address', $table->getTableName()); - $this->assertEqual(array('id'), $table->getPrimaryKeys()); - } - - 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}"); - } - } - } -} + +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, + '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, + '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, + '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, + '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, + '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, + '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, + 'SequenceName' => null, + ); + $this->assertColumn($columns, $table); + + $this->assertEqual('public', $table->getSchemaName()); + $this->assertEqual('address', $table->getTableName()); + $this->assertEqual(array('id'), $table->getPrimaryKeys()); + } + + 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/SqliteColumnTest.php b/tests/simple_unit/DbCommon/SqliteColumnTest.php index 36a4baab..246c4a27 100644 --- a/tests/simple_unit/DbCommon/SqliteColumnTest.php +++ b/tests/simple_unit/DbCommon/SqliteColumnTest.php @@ -1,29 +1,29 @@ -meta_data()->getTableInfo('foo'); - //var_dump($table); - } - - function test_table() - { - $conn = new TDbConnection('sqlite:c:/test.db'); - //$table = new TTableGateway('Accounts', $conn); -// var_dump($table->findAll()->readAll()); - } +meta_data()->getTableInfo('foo'); + //var_dump($table); + } + + function test_table() + { + $conn = new TDbConnection('sqlite:c:/test.db'); + //$table = new TTableGateway('Accounts', $conn); +// var_dump($table->findAll()->readAll()); + } } ?> \ No newline at end of file diff --git a/tests/simple_unit/I18N/ChoiceFormatTest.php b/tests/simple_unit/I18N/ChoiceFormatTest.php index 3a95b5a8..809d46b4 100644 --- a/tests/simple_unit/I18N/ChoiceFormatTest.php +++ b/tests/simple_unit/I18N/ChoiceFormatTest.php @@ -1,98 +1,98 @@ -assertEqual($want, $choice->format($string, 0)); - - $want = 'is one file'; - $this->assertEqual($want, $choice->format($string, 1)); - - $want = 'are {number} files'; - $this->assertEqual($want, $choice->format($string, 5)); - - $this->assertFalse($choice->format($string, -1)); - - $string = '{1,2} one two |{3,4} three four |[2,5] two to five inclusive'; - $this->assertEqual($choice->format($string,1),'one two'); - $this->assertEqual($choice->format($string,2.1),'two to five inclusive'); - $this->assertEqual($choice->format($string,3),'three four'); - } - - function test_set_notation() - { - $choice = new ChoiceFormat(); - $string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5'; - - $want = 'are even numbers'; - $this->assertEqual($want, $choice->format($string, 0)); - $this->assertEqual($want, $choice->format($string, 2)); - $this->assertEqual($want, $choice->format($string, 4)); - $this->assertNotEqual($want, $choice->format($string, 1)); - - $want = 'are not even and greater than or equal to 5'; - $this->assertEqual($want, $choice->format($string, 5)); - } - - function test_polish() - { - $choice = new ChoiceFormat(); - $string = '[1] plik |{2,3,4} pliki - |[5,21] pliko\'w |{n: n % 10 > 1 && n %10 < 5} pliki |{n: n%10 >= 5 || n%10 <=1} pliko\'w'; - - $wants = array( 'plik' => array(1), - 'pliki' => array(2,3,4,22,23,24), - 'pliko\'w' => array(5,6,7,11,12,15,17,20,21,25,26,30)); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } - - function test_russian() - { - $choice = new ChoiceFormat(); - $string = ' - {n: n % 10 == 1 && n % 100 != 11} test1 - |{n: n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 )} test2 - |{n: 2} test3'; - - $wants = array('test1' => array(1,21,31,41), - 'test2' => array(2,4, 22, 24, 32, 34), - 'test3' => array(0, 5,6,7,8,9,10,11,12,13,14, 20,25,26,30) - ); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } - - function test_english() - { - $choice = new ChoiceFormat(); - $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th'; - - $wants = array('none' => array(0), - '1st' => array(1,11,21), - '2nd' => array(2,12,22), - '3rd' => array(3,13,23), - 'th' => array(4,5,6,7,14,15) - ); - foreach($wants as $want => $numbers) - { - foreach($numbers as $n) - $this->assertEqual($want, $choice->format($string, $n)); - } - } -} - +assertEqual($want, $choice->format($string, 0)); + + $want = 'is one file'; + $this->assertEqual($want, $choice->format($string, 1)); + + $want = 'are {number} files'; + $this->assertEqual($want, $choice->format($string, 5)); + + $this->assertFalse($choice->format($string, -1)); + + $string = '{1,2} one two |{3,4} three four |[2,5] two to five inclusive'; + $this->assertEqual($choice->format($string,1),'one two'); + $this->assertEqual($choice->format($string,2.1),'two to five inclusive'); + $this->assertEqual($choice->format($string,3),'three four'); + } + + function test_set_notation() + { + $choice = new ChoiceFormat(); + $string = '{n: n%2 == 0} are even numbers |{n: n >= 5} are not even and greater than or equal to 5'; + + $want = 'are even numbers'; + $this->assertEqual($want, $choice->format($string, 0)); + $this->assertEqual($want, $choice->format($string, 2)); + $this->assertEqual($want, $choice->format($string, 4)); + $this->assertNotEqual($want, $choice->format($string, 1)); + + $want = 'are not even and greater than or equal to 5'; + $this->assertEqual($want, $choice->format($string, 5)); + } + + function test_polish() + { + $choice = new ChoiceFormat(); + $string = '[1] plik |{2,3,4} pliki + |[5,21] pliko\'w |{n: n % 10 > 1 && n %10 < 5} pliki |{n: n%10 >= 5 || n%10 <=1} pliko\'w'; + + $wants = array( 'plik' => array(1), + 'pliki' => array(2,3,4,22,23,24), + 'pliko\'w' => array(5,6,7,11,12,15,17,20,21,25,26,30)); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEqual($want, $choice->format($string, $n)); + } + } + + function test_russian() + { + $choice = new ChoiceFormat(); + $string = ' + {n: n % 10 == 1 && n % 100 != 11} test1 + |{n: n % 10 >= 2 && n % 10 <= 4 && ( n % 100 < 10 || n % 100 >= 20 )} test2 + |{n: 2} test3'; + + $wants = array('test1' => array(1,21,31,41), + 'test2' => array(2,4, 22, 24, 32, 34), + 'test3' => array(0, 5,6,7,8,9,10,11,12,13,14, 20,25,26,30) + ); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEqual($want, $choice->format($string, $n)); + } + } + + function test_english() + { + $choice = new ChoiceFormat(); + $string = '[0] none |{n: n % 10 == 1} 1st |{n: n % 10 == 2} 2nd |{n: n % 10 == 3} 3rd |{n:n} th'; + + $wants = array('none' => array(0), + '1st' => array(1,11,21), + '2nd' => array(2,12,22), + '3rd' => array(3,13,23), + 'th' => array(4,5,6,7,14,15) + ); + foreach($wants as $want => $numbers) + { + foreach($numbers as $n) + $this->assertEqual($want, $choice->format($string, $n)); + } + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/I18N/CultureInfoTest.php b/tests/simple_unit/I18N/CultureInfoTest.php index 840d8f17..7df7deeb 100644 --- a/tests/simple_unit/I18N/CultureInfoTest.php +++ b/tests/simple_unit/I18N/CultureInfoTest.php @@ -1,13 +1,13 @@ -assertEqual($culture->getEnglishName(), 'iw'); - } -} - +assertEqual($culture->getEnglishName(), 'iw'); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php b/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php index 2fc96163..80e9c1fd 100644 --- a/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php +++ b/tests/simple_unit/I18N/MysqlMessageSourceTestCase.php @@ -1,45 +1,45 @@ -_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'); - } -*/ -} - +_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/Soap/ContactManager.php b/tests/simple_unit/Soap/ContactManager.php index 8bf3d756..290063b3 100644 --- a/tests/simple_unit/Soap/ContactManager.php +++ b/tests/simple_unit/Soap/ContactManager.php @@ -1,157 +1,157 @@ -address = new Address(); - $Contact->address->city ="sesamcity"; - $Contact->address->street ="sesamstreet"; - $Contact->email = "me@you.com"; - $Contact->id = 1; - $Contact->name ="me"; - - $ret[] = $Contact; - //debugObject("Contacten: ",$ret); - return $ret; - } - - /** - * Gets the Contact with the given id. - * @param int $id The id - * @return Contact - * @soapmethod - */ - public function getContact($id) { - //get Contact from db - //might wanna throw an exception when it does not exists - throw new Exception("Contact '$id' not found"); - } - /** - * Generates an new, empty Contact template - * @return Contact - * @soapmethod - */ - public function newContact() { - return new Contact(); - } - - /** - * Saves a given Contact - * @param Contact $Contact - * @return boolean - * @soapmethod - */ - public function saveContact(Contact $Contact) { - //error_log(var_export($Contact,true)); - //$Contact->save(); - return true; - } - - /** - * @return mixed - * @soapmethod - */ - public function getList() - { - return array(array(1,2), array("12", 1.2)); - } - - /** - * @return array - * @soapmethod - */ - public function getEmptyArray() - { - return array(); - } - -} - - -/** - * The Contact details for a person - * - * Stores the person's name, address and e-mail - * This class is for example purposes only, just to - * show how to create a webservice - * - */ -class Contact{ - - /** - * @var int $id - * @soapproperty - */ - public $id; - - /** - * @var string $name - * @soapproperty - */ - public $name; - - /** @var Address $address - * @soapproperty - */ - public $address; - - /** @var string $email - * @soapproperty - */ - public $email; - - /** - * saves a Contact - * - * @return void - */ - public function save() { - //save Contact 2 db - } -} - -/** - * Stores an address - * - * An address consists of a street, number, zipcode and city. - * This class is for example purposes only, just to - * show how to create a webservice - * - */ -class Address{ - /** @var string $street - * @soapproperty - */ - public $street; - - /** @var string $nr - * @soapproperty - */ - public $nr; - - /** @var string $zipcode - * @soapproperty - */ - public $zipcode; - - /** @var string $city - * @soapproperty - */ - public $city; -} - +address = new Address(); + $Contact->address->city ="sesamcity"; + $Contact->address->street ="sesamstreet"; + $Contact->email = "me@you.com"; + $Contact->id = 1; + $Contact->name ="me"; + + $ret[] = $Contact; + //debugObject("Contacten: ",$ret); + return $ret; + } + + /** + * Gets the Contact with the given id. + * @param int $id The id + * @return Contact + * @soapmethod + */ + public function getContact($id) { + //get Contact from db + //might wanna throw an exception when it does not exists + throw new Exception("Contact '$id' not found"); + } + /** + * Generates an new, empty Contact template + * @return Contact + * @soapmethod + */ + public function newContact() { + return new Contact(); + } + + /** + * Saves a given Contact + * @param Contact $Contact + * @return boolean + * @soapmethod + */ + public function saveContact(Contact $Contact) { + //error_log(var_export($Contact,true)); + //$Contact->save(); + return true; + } + + /** + * @return mixed + * @soapmethod + */ + public function getList() + { + return array(array(1,2), array("12", 1.2)); + } + + /** + * @return array + * @soapmethod + */ + public function getEmptyArray() + { + return array(); + } + +} + + +/** + * The Contact details for a person + * + * Stores the person's name, address and e-mail + * This class is for example purposes only, just to + * show how to create a webservice + * + */ +class Contact{ + + /** + * @var int $id + * @soapproperty + */ + public $id; + + /** + * @var string $name + * @soapproperty + */ + public $name; + + /** @var Address $address + * @soapproperty + */ + public $address; + + /** @var string $email + * @soapproperty + */ + public $email; + + /** + * saves a Contact + * + * @return void + */ + public function save() { + //save Contact 2 db + } +} + +/** + * Stores an address + * + * An address consists of a street, number, zipcode and city. + * This class is for example purposes only, just to + * show how to create a webservice + * + */ +class Address{ + /** @var string $street + * @soapproperty + */ + public $street; + + /** @var string $nr + * @soapproperty + */ + public $nr; + + /** @var string $zipcode + * @soapproperty + */ + public $zipcode; + + /** @var string $city + * @soapproperty + */ + public $city; +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/Soap/SoapTestCase.php b/tests/simple_unit/Soap/SoapTestCase.php index d297ce41..fe151b04 100644 --- a/tests/simple_unit/Soap/SoapTestCase.php +++ b/tests/simple_unit/Soap/SoapTestCase.php @@ -1,91 +1,91 @@ -getWsdlUri()); - } - - function testContactArray() - { - $result = $this->getClient()->getContacts(); - $this->assertEqual(count($result), 1); - $obj = $result->Contact; - $this->assertEqual($obj->name, "me"); - $this->assertEqual($obj->id, 1); - $this->assertEqual($obj->address->street, "sesamstreet"); - $this->assertNull($obj->address->nr); - $this->assertNull($obj->address->zipcode); - $this->assertEqual($obj->address->city, "sesamcity"); - $this->assertEqual($obj->email, "me@you.com"); - } - - function testGetContactThrowsException() - { - try - { - $result = $this->getClient()->getContact(1); - $this->fail(); - } - catch (SoapFault $f) - { - $this->pass(); - } - } - - function testGetNewContact() - { - $obj = $this->getClient()->newContact(); - $this->assertNull($obj->name); - $this->assertNull($obj->id); - $this->assertNull($obj->address); - $this->assertNull($obj->email); - } - - function testSaveContactReturnsTrue() - { - $c = new Contact; - $result = $this->getClient()->saveContact($c); - $this->assertTrue($result); - } - - function getMixedArray() - { - $result = $this->getClient()>getList(); - $expected = array(array(1,2), array("12", 1.2)); - $this->assertEqual($result, $expected); - } - - function testEmptyArray() - { - $result = $this->getClient()->getEmptyArray(); - $this->assertTrue(is_array($result)); - $this->assertEqual(count($result), 0); - } - - function testUnknownFunctionThrowsException() - { - try - { - $this->getClient()->test(); - $this->fail(); - } - catch (SoapFault $f) - { - $this->pass(); - } - } -} - -?> +getWsdlUri()); + } + + function testContactArray() + { + $result = $this->getClient()->getContacts(); + $this->assertEqual(count($result), 1); + $obj = $result->Contact; + $this->assertEqual($obj->name, "me"); + $this->assertEqual($obj->id, 1); + $this->assertEqual($obj->address->street, "sesamstreet"); + $this->assertNull($obj->address->nr); + $this->assertNull($obj->address->zipcode); + $this->assertEqual($obj->address->city, "sesamcity"); + $this->assertEqual($obj->email, "me@you.com"); + } + + function testGetContactThrowsException() + { + try + { + $result = $this->getClient()->getContact(1); + $this->fail(); + } + catch (SoapFault $f) + { + $this->pass(); + } + } + + function testGetNewContact() + { + $obj = $this->getClient()->newContact(); + $this->assertNull($obj->name); + $this->assertNull($obj->id); + $this->assertNull($obj->address); + $this->assertNull($obj->email); + } + + function testSaveContactReturnsTrue() + { + $c = new Contact; + $result = $this->getClient()->saveContact($c); + $this->assertTrue($result); + } + + function getMixedArray() + { + $result = $this->getClient()>getList(); + $expected = array(array(1,2), array("12", 1.2)); + $this->assertEqual($result, $expected); + } + + function testEmptyArray() + { + $result = $this->getClient()->getEmptyArray(); + $this->assertTrue(is_array($result)); + $this->assertEqual(count($result), 0); + } + + function testUnknownFunctionThrowsException() + { + try + { + $this->getClient()->test(); + $this->fail(); + } + catch (SoapFault $f) + { + $this->pass(); + } + } +} + +?> diff --git a/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php b/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php index cc276a25..b3cde511 100644 --- a/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php +++ b/tests/simple_unit/SqlMap/ActiveRecordSqlMapTest.php @@ -1,87 +1,87 @@ -initSqlMap(); - TActiveRecordManager::getInstance()->setDbConnection($this->getConnection()); - - //$this->initScript('account-init.sql'); - } - - function testLoadWithSqlMap() - { - $records = $this->sqlmap->queryForList('GetActiveRecordAccounts'); - $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); - foreach($records as $record) - { - $this->assertEqual(get_class($record), 'ActiveAccount'); - $this->assertTrue($registry->isCleanObject($record)); - } - } - - function testLoadWithActiveRecord() - { - $records = ActiveAccount::finder()->findAll(); - $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); - foreach($records as $record) - { - $this->assertEqual(get_class($record), 'ActiveAccount'); - //$this->assertTrue($registry->isCleanObject($record)); //? not clean anymore? - } - } - - function testLoadWithSqlMap_SaveWithActiveRecord() - { - $record = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); - $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); - $record->Account_FirstName = "Testing 123"; - $this->assertTrue($registry->isDirtyObject($record)); - - $this->assertTrue($record->save()); - - $check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); - $finder = ActiveAccount::finder(); - $check2 = $finder->findByAccount_FirstName($record->Account_FirstName); - - - $this->assertSameAccount($record,$check1); - $this->assertSameAccount($record,$check2); - - $this->initScript('account-init.sql'); - } - - function assertSameAccount($account1,$account2) - { - $props = array('Account_Id', 'Account_FirstName', 'Account_LastName', - 'Account_Email', 'Account_Banner_Option', 'Account_Cart_Option'); - foreach($props as $prop) - $this->assertEqual($account1->{$prop}, $account2->{$prop}); - } -} - +initSqlMap(); + TActiveRecordManager::getInstance()->setDbConnection($this->getConnection()); + + //$this->initScript('account-init.sql'); + } + + function testLoadWithSqlMap() + { + $records = $this->sqlmap->queryForList('GetActiveRecordAccounts'); + $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); + foreach($records as $record) + { + $this->assertEqual(get_class($record), 'ActiveAccount'); + $this->assertTrue($registry->isCleanObject($record)); + } + } + + function testLoadWithActiveRecord() + { + $records = ActiveAccount::finder()->findAll(); + $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); + foreach($records as $record) + { + $this->assertEqual(get_class($record), 'ActiveAccount'); + //$this->assertTrue($registry->isCleanObject($record)); //? not clean anymore? + } + } + + function testLoadWithSqlMap_SaveWithActiveRecord() + { + $record = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); + $registry=TActiveRecordManager::getInstance()->getObjectStateRegistry(); + $record->Account_FirstName = "Testing 123"; + $this->assertTrue($registry->isDirtyObject($record)); + + $this->assertTrue($record->save()); + + $check1 = $this->sqlmap->queryForObject('GetActiveRecordAccounts'); + $finder = ActiveAccount::finder(); + $check2 = $finder->findByAccount_FirstName($record->Account_FirstName); + + + $this->assertSameAccount($record,$check1); + $this->assertSameAccount($record,$check2); + + $this->initScript('account-init.sql'); + } + + function assertSameAccount($account1,$account2) + { + $props = array('Account_Id', 'Account_FirstName', 'Account_LastName', + 'Account_Email', 'Account_Banner_Option', 'Account_Cart_Option'); + foreach($props as $prop) + $this->assertEqual($account1->{$prop}, $account2->{$prop}); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/BaseCase.php b/tests/simple_unit/SqlMap/BaseCase.php index e311302d..b0961b5b 100644 --- a/tests/simple_unit/SqlMap/BaseCase.php +++ b/tests/simple_unit/SqlMap/BaseCase.php @@ -1,262 +1,262 @@ -assertTrue(true); - } - - public function testCase2() - { - $this->assertTrue(true); - } - - public function __construct() - { - parent::__construct(); - $this->config = BaseTestConfig::createConfigInstance(); - $this->ScriptDirectory = $this->config->getScriptDir(); - } - - public function hasSupportFor($feature) - { - return $this->config->hasFeature($feature); - } - - public function __destruct() - { - if(!is_null($this->mapper)) - $this->mapper->cacheConfiguration(); - } - - function getConnection() - { - if(is_null($this->connection)) - $this->connection = $this->config->getConnection(); - $this->connection->setActive(true); - return $this->connection; - } - - /** - * Initialize an sqlMap - */ - protected function initSqlMap() - { - $manager = new TSqlMapManager($this->config->getConnection()); - $manager->configureXml($this->config->getSqlMapConfigFile()); - $this->sqlmap = $manager->getSqlMapGateway(); - $manager->TypeHandlers->registerTypeHandler(new TDateTimeHandler); - } - - /** - * Run a sql batch for the datasource. - */ - protected function initScript($script) - { - $runner = $this->config->getScriptRunner(); - $runner->runScript($this->getConnection(), $this->ScriptDirectory.$script); - } - - /** - * Create a new account with id = 6 - */ - protected function NewAccount6() - { - $account = new Account(); - $account->setID(6); - $account->setFirstName('Calamity'); - $account->setLastName('Jane'); - $account->setEmailAddress('no_email@provided.com'); - return $account; - } - - /** - * Verify that the input account is equal to the account(id=1). - */ - protected function assertAccount1(Account $account) - { - $this->assertIdentical($account->getID(), 1); - $this->assertIdentical($account->getFirstName(), 'Joe'); - $this->assertIdentical($account->getEmailAddress(), 'Joe.Dalton@somewhere.com'); - } - - /** - * Verify that the input account is equal to the account(id=6). - */ - protected function assertAccount6(Account $account) - { - $this->assertIdentical($account->getID(), 6); - $this->assertIdentical($account->getFirstName(), 'Calamity'); - $this->assertIdentical($account->getLastName(), 'Jane'); - $this->assertNull($account->getEmailAddress()); - } - - /** - * Verify that the input order is equal to the order(id=1). - */ - protected function assertOrder1(Order $order) - { - $date = @mktime(8,15,0,2,15,2003); - - $this->assertIdentical((int)$order->getID(), 1); - if($order->getDate() instanceof TDateTime) - $this->assertIdentical($order->getDate()->getTimestamp(), $date); - else - $this->fail(); - $this->assertIdentical($order->getCardType(), 'VISA'); - $this->assertIdentical($order->getCardNumber(), '999999999999'); - $this->assertIdentical($order->getCardExpiry(), '05/03'); - $this->assertIdentical($order->getStreet(), '11 This Street'); - $this->assertIdentical($order->getProvince(), 'BC'); - $this->assertIdentical($order->getPostalCode(), 'C4B 4F4'); - } - - function assertAccount1AsHashArray($account) - { - $this->assertIdentical(1, (int)$account["Id"]); - $this->assertIdentical("Joe", $account["FirstName"]); - $this->assertIdentical("Dalton", $account["LastName"]); - $this->assertIdentical("Joe.Dalton@somewhere.com", $account["EmailAddress"]); - } - - function AssertOrder1AsHashArray($order) - { - $date = @mktime(8,15,0,2,15,2003); - - $this->assertIdentical(1, $order["Id"]); - if($order['Date'] instanceof TDateTime) - $this->assertIdentical($date, $order["Date"]->getTimestamp()); - else - $this->fail(); - $this->assertIdentical("VISA", $order["CardType"]); - $this->assertIdentical("999999999999", $order["CardNumber"]); - $this->assertIdentical("05/03", $order["CardExpiry"]); - $this->assertIdentical("11 This Street", $order["Street"]); - $this->assertIdentical("Victoria", $order["City"]); - $this->assertIdentical("BC", $order["Province"]); - $this->assertIdentical("C4B 4F4", $order["PostalCode"]); - } - -} - -class HundredsBool extends TSqlMapTypeHandler -{ - public function getResult($string) - { - $value = intval($string); - if($value == 100) - return true; - if($value == 200) - return false; - //throw new Exception('unexpected value '.$value); - } - - public function getParameter($parameter) - { - if($parameter) - return 100; - else - return 200; - } - - public function createNewInstance($data=null) - { - throw new TDataMapperException('can not create'); - } -} - -class OuiNonBool extends TSqlMapTypeHandler -{ - const YES = "Oui"; - const NO = "Non"; - - public function getResult($string) - { - if($string === self::YES) - return true; - if($string === self::NO) - return false; - //throw new Exception('unexpected value '.$string); - } - - public function getParameter($parameter) - { - if($parameter) - return self::YES; - else - return self::NO; - } - - public function createNewInstance($data=null) - { - throw new TDataMapperException('can not create'); - } -} - -class TDateTimeHandler extends TSqlMapTypeHandler -{ - public function getType() - { - return 'date'; - } - - public function getResult($string) - { - $time = new TDateTime($string); - return $time; - } - - public function getParameter($parameter) - { - if($parameter instanceof TDateTime) - return $parameter->getTimestamp(); - else - return $parameter; - } - - public function createNewInstance($data=null) - { - return new TDateTime; - } -} - -class TDateTime -{ - private $_datetime; - - public function __construct($datetime=null) - { - if(!is_null($datetime)) - $this->setDatetime($datetime); - } - - public function getTimestamp() - { - return strtotime($this->getDatetime()); - } - - public function getDateTime() - { - return $this->_datetime; - } - - public function setDateTime($value) - { - $this->_datetime = $value; - } -} - +assertTrue(true); + } + + public function testCase2() + { + $this->assertTrue(true); + } + + public function __construct() + { + parent::__construct(); + $this->config = BaseTestConfig::createConfigInstance(); + $this->ScriptDirectory = $this->config->getScriptDir(); + } + + public function hasSupportFor($feature) + { + return $this->config->hasFeature($feature); + } + + public function __destruct() + { + if(!is_null($this->mapper)) + $this->mapper->cacheConfiguration(); + } + + function getConnection() + { + if(is_null($this->connection)) + $this->connection = $this->config->getConnection(); + $this->connection->setActive(true); + return $this->connection; + } + + /** + * Initialize an sqlMap + */ + protected function initSqlMap() + { + $manager = new TSqlMapManager($this->config->getConnection()); + $manager->configureXml($this->config->getSqlMapConfigFile()); + $this->sqlmap = $manager->getSqlMapGateway(); + $manager->TypeHandlers->registerTypeHandler(new TDateTimeHandler); + } + + /** + * Run a sql batch for the datasource. + */ + protected function initScript($script) + { + $runner = $this->config->getScriptRunner(); + $runner->runScript($this->getConnection(), $this->ScriptDirectory.$script); + } + + /** + * Create a new account with id = 6 + */ + protected function NewAccount6() + { + $account = new Account(); + $account->setID(6); + $account->setFirstName('Calamity'); + $account->setLastName('Jane'); + $account->setEmailAddress('no_email@provided.com'); + return $account; + } + + /** + * Verify that the input account is equal to the account(id=1). + */ + protected function assertAccount1(Account $account) + { + $this->assertIdentical($account->getID(), 1); + $this->assertIdentical($account->getFirstName(), 'Joe'); + $this->assertIdentical($account->getEmailAddress(), 'Joe.Dalton@somewhere.com'); + } + + /** + * Verify that the input account is equal to the account(id=6). + */ + protected function assertAccount6(Account $account) + { + $this->assertIdentical($account->getID(), 6); + $this->assertIdentical($account->getFirstName(), 'Calamity'); + $this->assertIdentical($account->getLastName(), 'Jane'); + $this->assertNull($account->getEmailAddress()); + } + + /** + * Verify that the input order is equal to the order(id=1). + */ + protected function assertOrder1(Order $order) + { + $date = @mktime(8,15,0,2,15,2003); + + $this->assertIdentical((int)$order->getID(), 1); + if($order->getDate() instanceof TDateTime) + $this->assertIdentical($order->getDate()->getTimestamp(), $date); + else + $this->fail(); + $this->assertIdentical($order->getCardType(), 'VISA'); + $this->assertIdentical($order->getCardNumber(), '999999999999'); + $this->assertIdentical($order->getCardExpiry(), '05/03'); + $this->assertIdentical($order->getStreet(), '11 This Street'); + $this->assertIdentical($order->getProvince(), 'BC'); + $this->assertIdentical($order->getPostalCode(), 'C4B 4F4'); + } + + function assertAccount1AsHashArray($account) + { + $this->assertIdentical(1, (int)$account["Id"]); + $this->assertIdentical("Joe", $account["FirstName"]); + $this->assertIdentical("Dalton", $account["LastName"]); + $this->assertIdentical("Joe.Dalton@somewhere.com", $account["EmailAddress"]); + } + + function AssertOrder1AsHashArray($order) + { + $date = @mktime(8,15,0,2,15,2003); + + $this->assertIdentical(1, $order["Id"]); + if($order['Date'] instanceof TDateTime) + $this->assertIdentical($date, $order["Date"]->getTimestamp()); + else + $this->fail(); + $this->assertIdentical("VISA", $order["CardType"]); + $this->assertIdentical("999999999999", $order["CardNumber"]); + $this->assertIdentical("05/03", $order["CardExpiry"]); + $this->assertIdentical("11 This Street", $order["Street"]); + $this->assertIdentical("Victoria", $order["City"]); + $this->assertIdentical("BC", $order["Province"]); + $this->assertIdentical("C4B 4F4", $order["PostalCode"]); + } + +} + +class HundredsBool extends TSqlMapTypeHandler +{ + public function getResult($string) + { + $value = intval($string); + if($value == 100) + return true; + if($value == 200) + return false; + //throw new Exception('unexpected value '.$value); + } + + public function getParameter($parameter) + { + if($parameter) + return 100; + else + return 200; + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} + +class OuiNonBool extends TSqlMapTypeHandler +{ + const YES = "Oui"; + const NO = "Non"; + + public function getResult($string) + { + if($string === self::YES) + return true; + if($string === self::NO) + return false; + //throw new Exception('unexpected value '.$string); + } + + public function getParameter($parameter) + { + if($parameter) + return self::YES; + else + return self::NO; + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} + +class TDateTimeHandler extends TSqlMapTypeHandler +{ + public function getType() + { + return 'date'; + } + + public function getResult($string) + { + $time = new TDateTime($string); + return $time; + } + + public function getParameter($parameter) + { + if($parameter instanceof TDateTime) + return $parameter->getTimestamp(); + else + return $parameter; + } + + public function createNewInstance($data=null) + { + return new TDateTime; + } +} + +class TDateTime +{ + private $_datetime; + + public function __construct($datetime=null) + { + if(!is_null($datetime)) + $this->setDatetime($datetime); + } + + public function getTimestamp() + { + return strtotime($this->getDatetime()); + } + + public function getDateTime() + { + return $this->_datetime; + } + + public function setDateTime($value) + { + $this->_datetime = $value; + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/CacheTest.php b/tests/simple_unit/SqlMap/CacheTest.php index 04475cdb..131ddfbb 100644 --- a/tests/simple_unit/SqlMap/CacheTest.php +++ b/tests/simple_unit/SqlMap/CacheTest.php @@ -1,164 +1,164 @@ -initSqlMap(); - - //force autoload - new Account; - } - - function resetDatabase() - { - $this->initScript('account-init.sql'); - } - - /** - * Test for JIRA 29 - */ - function testJIRA28() - { - $account = $this->sqlmap->queryForObject("GetNoAccountWithCache",-99); - $this->assertNull($account); - } - - /** - * Test Cache query - */ - function testQueryWithCache() - { - $this->resetDatabase(); - - $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 === $list2); - - $account = $list1[1]; - $account->setEmailAddress("somebody@cache.com"); - - //this will cause the cache to flush - $this->sqlmap->update("UpdateAccountViaInlineParameters", $account); - - $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 !== $list3); - - $this->resetDatabase(); - } - - - /** - * Test flush Cache - */ - function testFlushDataCache() - { - $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 === $list2); - $this->sqlmap->flushCaches(); - - $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 !== $list3); - } - - /** - * - */ - function testFlushDataCacheOnExecute() - { - $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 === $list2); - $this->sqlmap->update("UpdateAccountViaInlineParameters", $list1[0]); - - $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); - - $this->assertTrue($list1 !== $list3); - } - - /** - */ - protected function getCacheModel() - { - $cache = new TSqlMapCacheModel(); - // $cache->setFlushInterval(5*60); - $cache->setImplementation('LRU'); - $cache->initialize(); - return $cache; - } - - /** - * Test CacheHit - */ - function testCacheHit() - { - $cache = $this->getCacheModel(); - $key = new TSqlMapCacheKey('testkey'); - $cache->set($key, 'a'); - - $returnedObject = $cache->get($key); - - $this->assertIdentical('a', $returnedObject); - - $this->assertIdentical(1, $cache->getHitRatio()); - } - - - - /** - * Test CacheMiss - */ - function testCacheMiss() - { - $cache = $this->getCacheModel(); - $key = new TSqlMapCacheKey('testKey'); - $value = 'testValue'; - $cache->set($key, $value); - - $wrongKey = new TSqlMapCacheKey('wrongKey'); - - $returnedObject = $cache->get($wrongKey); - $this->assertNotEqual($value, $returnedObject); - $this->assertNull($returnedObject) ; - $this->assertIdentical(0, $cache->getHitRatio()); - } - - /** - * Test CacheHitMiss - */ - function testCacheHitMiss() - { - $cache = $this->getCacheModel(); - $key = new TSqlMapCacheKey('testKey'); - - $value = "testValue"; - $cache->set($key, $value); - - $returnedObject = $cache->get($key); - $this->assertIdentical($value, $returnedObject); - - $wrongKey = new TSqlMapCacheKey('wrongKey'); - - $returnedObject = $cache->get($wrongKey); - $this->assertNotEqual($value, $returnedObject); - $this->assertNull($returnedObject) ; - $this->assertIdentical(0.5, $cache->getHitRatio()); - } -} - +initSqlMap(); + + //force autoload + new Account; + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + } + + /** + * Test for JIRA 29 + */ + function testJIRA28() + { + $account = $this->sqlmap->queryForObject("GetNoAccountWithCache",-99); + $this->assertNull($account); + } + + /** + * Test Cache query + */ + function testQueryWithCache() + { + $this->resetDatabase(); + + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + + $account = $list1[1]; + $account->setEmailAddress("somebody@cache.com"); + + //this will cause the cache to flush + $this->sqlmap->update("UpdateAccountViaInlineParameters", $account); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + + $this->resetDatabase(); + } + + + /** + * Test flush Cache + */ + function testFlushDataCache() + { + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + $this->sqlmap->flushCaches(); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + } + + /** + * + */ + function testFlushDataCacheOnExecute() + { + $list1 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $list2 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 === $list2); + $this->sqlmap->update("UpdateAccountViaInlineParameters", $list1[0]); + + $list3 = $this->sqlmap->queryForList("GetCachedAccountsViaResultMap"); + + $this->assertTrue($list1 !== $list3); + } + + /** + */ + protected function getCacheModel() + { + $cache = new TSqlMapCacheModel(); + // $cache->setFlushInterval(5*60); + $cache->setImplementation('LRU'); + $cache->initialize(); + return $cache; + } + + /** + * Test CacheHit + */ + function testCacheHit() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testkey'); + $cache->set($key, 'a'); + + $returnedObject = $cache->get($key); + + $this->assertIdentical('a', $returnedObject); + + $this->assertIdentical(1, $cache->getHitRatio()); + } + + + + /** + * Test CacheMiss + */ + function testCacheMiss() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testKey'); + $value = 'testValue'; + $cache->set($key, $value); + + $wrongKey = new TSqlMapCacheKey('wrongKey'); + + $returnedObject = $cache->get($wrongKey); + $this->assertNotEqual($value, $returnedObject); + $this->assertNull($returnedObject) ; + $this->assertIdentical(0, $cache->getHitRatio()); + } + + /** + * Test CacheHitMiss + */ + function testCacheHitMiss() + { + $cache = $this->getCacheModel(); + $key = new TSqlMapCacheKey('testKey'); + + $value = "testValue"; + $cache->set($key, $value); + + $returnedObject = $cache->get($key); + $this->assertIdentical($value, $returnedObject); + + $wrongKey = new TSqlMapCacheKey('wrongKey'); + + $returnedObject = $cache->get($wrongKey); + $this->assertNotEqual($value, $returnedObject); + $this->assertNull($returnedObject) ; + $this->assertIdentical(0.5, $cache->getHitRatio()); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/DelegateTest.php b/tests/simple_unit/SqlMap/DelegateTest.php index 32c47fd1..800e4240 100644 --- a/tests/simple_unit/SqlMap/DelegateTest.php +++ b/tests/simple_unit/SqlMap/DelegateTest.php @@ -1,64 +1,64 @@ -initSqlMap(); - } - - function testListDelegate() - { - $list = $this->sqlmap->queryWithRowDelegate( - "GetAllAccountsViaResultMap", array($this, 'listHandler')); - - $this->assertIdentical(5, count($list)); - $this->assertAccount1($list[0]); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - $this->assertIdentical(3, $list[2]->getID()); - $this->assertIdentical(4, $list[3]->getID()); - $this->assertIdentical(5, $list[4]->getID()); - } - - /** - * Test ExecuteQueryForMap : Hashtable. - */ - function testExecuteQueryForMap() - { - $map = $this->sqlmap->QueryForMapWithRowDelegate( - "GetAllAccountsViaResultClass", array($this, 'mapHandler'), null, "FirstName"); - - $this->assertIdentical(5, count($map)); - $this->assertAccount1($map["Joe"]); - - $this->assertIdentical(1, $map["Joe"]->getID()); - $this->assertIdentical(2, $map["Averel"]->getID()); - $this->assertIdentical(3, $map["William"]->getID()); - $this->assertIdentical(4, $map["Jack"]->getID()); - $this->assertIdentical(5, $map["Gilles"]->getID()); - } - - public function listHandler($sender, $param) - { - $list = &$param->getList(); - $list[] = $param->result; - $this->assertTrue($param->result instanceof Account); - } - - public function mapHandler($sender, $param) - { - $map = &$param->getMap(); - $map[$param->getKey()] = $param->getValue(); - $this->assertTrue($param->getValue() instanceof Account); - } -} - - - +initSqlMap(); + } + + function testListDelegate() + { + $list = $this->sqlmap->queryWithRowDelegate( + "GetAllAccountsViaResultMap", array($this, 'listHandler')); + + $this->assertIdentical(5, count($list)); + $this->assertAccount1($list[0]); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMapWithRowDelegate( + "GetAllAccountsViaResultClass", array($this, 'mapHandler'), null, "FirstName"); + + $this->assertIdentical(5, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertIdentical(1, $map["Joe"]->getID()); + $this->assertIdentical(2, $map["Averel"]->getID()); + $this->assertIdentical(3, $map["William"]->getID()); + $this->assertIdentical(4, $map["Jack"]->getID()); + $this->assertIdentical(5, $map["Gilles"]->getID()); + } + + public function listHandler($sender, $param) + { + $list = &$param->getList(); + $list[] = $param->result; + $this->assertTrue($param->result instanceof Account); + } + + public function mapHandler($sender, $param) + { + $map = &$param->getMap(); + $map[$param->getKey()] = $param->getValue(); + $this->assertTrue($param->getValue() instanceof Account); + } +} + + + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/Dynamic/DynamicTest.php b/tests/simple_unit/SqlMap/Dynamic/DynamicTest.php index ce58327b..436cd49e 100644 --- a/tests/simple_unit/SqlMap/Dynamic/DynamicTest.php +++ b/tests/simple_unit/SqlMap/Dynamic/DynamicTest.php @@ -1,11 +1,11 @@ - \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/GroupByTest.php b/tests/simple_unit/SqlMap/GroupByTest.php index 5f6782e5..11bd86bb 100644 --- a/tests/simple_unit/SqlMap/GroupByTest.php +++ b/tests/simple_unit/SqlMap/GroupByTest.php @@ -1,43 +1,43 @@ -_orders = $orders; - } - - public function getOrders() - { - return $this->_orders; - } -} - - -/** - * @package System.DataAccess.SQLMap - */ -class GroupByTest extends BaseCase -{ - function __construct() - { - parent::__construct(); - $this->initSqlMap(); - } - - function testAccountWithOrders() - { - $this->initScript('account-init.sql'); - $accounts = $this->sqlmap->queryForList("getAccountWithOrders"); - $this->assertIdentical(5, count($accounts)); - foreach($accounts as $account) - $this->assertIdentical(2, count($account->getOrders())); - } - -/**/ -} - +_orders = $orders; + } + + public function getOrders() + { + return $this->_orders; + } +} + + +/** + * @package System.DataAccess.SQLMap + */ +class GroupByTest extends BaseCase +{ + function __construct() + { + parent::__construct(); + $this->initSqlMap(); + } + + function testAccountWithOrders() + { + $this->initScript('account-init.sql'); + $accounts = $this->sqlmap->queryForList("getAccountWithOrders"); + $this->assertIdentical(5, count($accounts)); + foreach($accounts as $account) + $this->assertIdentical(2, count($account->getOrders())); + } + +/**/ +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/InheritanceTest.php b/tests/simple_unit/SqlMap/InheritanceTest.php index b0dd2dc9..82f86af3 100644 --- a/tests/simple_unit/SqlMap/InheritanceTest.php +++ b/tests/simple_unit/SqlMap/InheritanceTest.php @@ -1,145 +1,145 @@ -initSqlMap(); - $this->initScript('documents-init.sql'); - } - - /// Test All document with no formula - function testGetAllDocument() - { - $list = $this->sqlmap->queryForList("GetAllDocument"); - - $this->assertEqual(6, count($list)); - $book = $list[0]; - $this->assertBook($book, 1, "The World of Null-A", 55); - - $book = $list[1]; - $this->assertBook($book, 3, "Lord of the Rings", 3587); - - $document = $list[2]; - $this->assertDocument($document, 5, "Le Monde"); - - $document = $list[3]; - $this->assertDocument($document, 6, "Foundation"); - - $news = $list[4]; - $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); - - $document = $list[5]; - $this->assertDocument($document, 4, "Le Canard enchaine"); - } - - /// Test All document in a typed collection - function testGetTypedCollection() - { - $list = $this->sqlmap->queryForList("GetTypedCollection"); - - $this->assertEqual(6, $list->getCount()); - - $book = $list[0]; - $this->assertBook($book, 1, "The World of Null-A", 55); - - $book = $list[1]; - $this->assertBook($book, 3, "Lord of the Rings", 3587); - - $document = $list[2]; - $this->assertDocument($document, 5, "Le Monde"); - - $document = $list[3]; - $this->assertDocument($document, 6, "Foundation"); - - $news = $list[4]; - $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); - - $document = $list[5]; - $this->assertDocument($document, 4, "Le Canard enchaine"); - } - - /// Test All document with Custom Type Handler - function testGetAllDocumentWithCustomTypeHandler() - { - - //register the custom inheritance type handler - $this->sqlmap->registerTypeHandler(new CustomInheritance); - - $list = $this->sqlmap->queryForList("GetAllDocumentWithCustomTypeHandler"); - - $this->assertEqual(6, count($list)); - $book = $list[0]; - $this->assertBook($book, 1, "The World of Null-A", 55); - - $book = $list[1]; - $this->assertBook($book, 3, "Lord of the Rings", 3587); - - $news = $list[2]; - $this->assertNewspaper($news, 5, "Le Monde", "Paris"); - - $book = $list[3]; - $this->assertBook($book, 6, "Foundation", 557); - - $news = $list[4]; - $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); - - $news = $list[5]; - $this->assertNewspaper($news, 4, "Le Canard enchaine", "Paris"); - } - - function AssertDocument(Document $document, $id, $title) - { - $this->assertEqual($id, $document->getID()); - $this->assertEqual($title, $document->getTitle()); - } - - function AssertBook(Book $book, $id, $title, $pageNumber) - { - $this->assertEqual($id, $book->getId()); - $this->assertEqual($title, $book->getTitle()); - $this->assertEqual($pageNumber, (int)$book->getPageNumber()); - } - - function AssertNewspaper(Newspaper $news, $id, $title, $city) - { - $this->assertEqual($id, $news->getId()); - $this->assertEqual($title, $news->getTitle()); - $this->assertEqual($city, $news->getCity()); - } -} - - -class CustomInheritance extends TSqlMapTypeHandler -{ - public function getResult($type) - { - switch ($type) - { - case 'Monograph': case 'Book': - return 'Book'; - case 'Tabloid': case 'Broadsheet': case 'Newspaper': - return 'Newspaper'; - default: - return 'Document'; - } - } - - public function getParameter($parameter) - { - throw new TDataMapperException('not implemented'); - } - - public function createNewInstance($data=null) - { - throw new TDataMapperException('can not create'); - } -} +initSqlMap(); + $this->initScript('documents-init.sql'); + } + + /// Test All document with no formula + function testGetAllDocument() + { + $list = $this->sqlmap->queryForList("GetAllDocument"); + + $this->assertEqual(6, count($list)); + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $document = $list[2]; + $this->assertDocument($document, 5, "Le Monde"); + + $document = $list[3]; + $this->assertDocument($document, 6, "Foundation"); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $document = $list[5]; + $this->assertDocument($document, 4, "Le Canard enchaine"); + } + + /// Test All document in a typed collection + function testGetTypedCollection() + { + $list = $this->sqlmap->queryForList("GetTypedCollection"); + + $this->assertEqual(6, $list->getCount()); + + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $document = $list[2]; + $this->assertDocument($document, 5, "Le Monde"); + + $document = $list[3]; + $this->assertDocument($document, 6, "Foundation"); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $document = $list[5]; + $this->assertDocument($document, 4, "Le Canard enchaine"); + } + + /// Test All document with Custom Type Handler + function testGetAllDocumentWithCustomTypeHandler() + { + + //register the custom inheritance type handler + $this->sqlmap->registerTypeHandler(new CustomInheritance); + + $list = $this->sqlmap->queryForList("GetAllDocumentWithCustomTypeHandler"); + + $this->assertEqual(6, count($list)); + $book = $list[0]; + $this->assertBook($book, 1, "The World of Null-A", 55); + + $book = $list[1]; + $this->assertBook($book, 3, "Lord of the Rings", 3587); + + $news = $list[2]; + $this->assertNewspaper($news, 5, "Le Monde", "Paris"); + + $book = $list[3]; + $this->assertBook($book, 6, "Foundation", 557); + + $news = $list[4]; + $this->assertNewspaper($news, 2, "Le Progres de Lyon", "Lyon"); + + $news = $list[5]; + $this->assertNewspaper($news, 4, "Le Canard enchaine", "Paris"); + } + + function AssertDocument(Document $document, $id, $title) + { + $this->assertEqual($id, $document->getID()); + $this->assertEqual($title, $document->getTitle()); + } + + function AssertBook(Book $book, $id, $title, $pageNumber) + { + $this->assertEqual($id, $book->getId()); + $this->assertEqual($title, $book->getTitle()); + $this->assertEqual($pageNumber, (int)$book->getPageNumber()); + } + + function AssertNewspaper(Newspaper $news, $id, $title, $city) + { + $this->assertEqual($id, $news->getId()); + $this->assertEqual($title, $news->getTitle()); + $this->assertEqual($city, $news->getCity()); + } +} + + +class CustomInheritance extends TSqlMapTypeHandler +{ + public function getResult($type) + { + switch ($type) + { + case 'Monograph': case 'Book': + return 'Book'; + case 'Tabloid': case 'Broadsheet': case 'Newspaper': + return 'Newspaper'; + default: + return 'Document'; + } + } + + public function getParameter($parameter) + { + throw new TDataMapperException('not implemented'); + } + + public function createNewInstance($data=null) + { + throw new TDataMapperException('can not create'); + } +} ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/ParameterMapTest.php b/tests/simple_unit/SqlMap/ParameterMapTest.php index 7ace082f..fb29c162 100644 --- a/tests/simple_unit/SqlMap/ParameterMapTest.php +++ b/tests/simple_unit/SqlMap/ParameterMapTest.php @@ -1,249 +1,249 @@ -initSqlMap(); - } - - function setup() - { - $this->initScript('account-init.sql'); -// $this->initScript('account-procedure.sql'); - $this->initScript('order-init.sql'); -// $this->initScript('line-item-init.sql'); - $this->initScript('category-init.sql'); - } - - /// Test null replacement in ParameterMap property - function testNullValueReplacement() - { - $account = $this->newAccount6(); - - $this->sqlmap->insert("InsertAccountViaParameterMap", $account); - $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); - - $this->assertNull($account->getEmailAddress(), 'no_email@provided.com'); - - $this->assertAccount6($account); - } - - /// Test Test Null Value Replacement Inline - function testNullValueReplacementInline() - { - $account = $this->newAccount6(); - - $this->sqlmap->insert("InsertAccountViaInlineParameters", $account); - $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); - $this->assertNull($account->getEmailAddress()); - - $this->assertAccount6($account); - } - - /// Test Test Null Value Replacement Inline - function testSpecifiedType() - { - $account = $this->newAccount6(); - $account->setEmailAddress(null); - $this->sqlmap->insert("InsertAccountNullableEmail", $account); - $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); - $this->assertAccount6($account); - } - - - /// Test Test Null Value Replacement Inline - function testUnknownParameterClass() - { - $account = $this->newAccount6(); - $account->setEmailAddress(null); - $this->sqlmap->insert("InsertAccountUknownParameterClass", $account); - $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); - $this->assertAccount6($account); - } - - - /// Test null replacement in ParameterMap property - /// for System.DateTime.MinValue - function testNullValueReplacementForDateTimeMinValue() - { - $account = $this->newAccount6(); - $this->sqlmap->insert("InsertAccountViaParameterMap", $account); - $order = new Order(); - $order->setId(99); - $order->setCardExpiry("09/11"); - $order->setAccount($account); - $order->setCardNumber("154564656"); - $order->setCardType("Visa"); - $order->setCity("Lyon"); - $order->setDate(null); - $order->setPostalCode("69004"); - $order->setProvince("Rhone"); - $order->setStreet("rue Durand"); - - $this->sqlmap->insert("InsertOrderViaParameterMap", $order); - - $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); - - $this->assertIdentical($order->getCity(), $orderTest->getCity()); - } - - /// Test null replacement in ParameterMap/Hahstable property - /// for System.DateTime.MinValue - function testNullValueReplacementForDateTimeWithHashtable() - { - $account = $this->newAccount6(); - - $this->sqlmap->insert("InsertAccountViaParameterMap", $account); - - $order = new Order(); - $order->setId(99); - $order->setCardExpiry("09/11"); - $order->setAccount($account); - $order->setCardNumber("154564656"); - $order->setCardType("Visa"); - $order->setCity("Lyon"); - $order->setDate('0001-01-01 00:00:00'); //<-- null replacement - $order->setPostalCode("69004"); - $order->setProvince("Rhone"); - $order->setStreet("rue Durand"); - - $this->sqlmap->insert("InsertOrderViaParameterMap", $order); - - $orderTest = $this->sqlmap->queryForObject("GetOrderByHashTable", 99); - - $this->assertIdentical($orderTest["Date"], '0001-01-01 00:00:00'); - } - - /// Test null replacement in ParameterMap property - /// for Guid - function testNullValueReplacementForGuidValue() - { - if($this->hasSupportFor('last_insert_id')) - { - $category = new Category(); - $category->setName("Totoasdasd"); - $category->setGuidString('00000000-0000-0000-0000-000000000000'); - - $key = $this->sqlmap->insert("InsertCategoryNull", $category); - - $categoryRead = $this->sqlmap->queryForObject("GetCategory", $key); - - $this->assertIdentical($category->getName(), $categoryRead->getName()); - $this->assertIdentical('', $categoryRead->getGuidString()); - } - } - - - -/// Test complex mapping Via hasTable - /// - /// - /// map.Add("Item", Item); - /// map.Add("Order", Order); - /// - /// - /// ... #Item.prop1#...#Order.prop2# - /// - /// - /// - function testComplexMappingViaHasTable() - { - $a = new Account(); - $a->setFirstName("Joe"); - - $param["Account"] = $a; - - $o = new Order(); - $o->setCity("Dalton"); - $param["Order"] = $o; - - $accountTest = $this->sqlmap->queryForObject("GetAccountComplexMapping", $param); - - $this->assertAccount1($accountTest); - } - -/* - /// Test ByteArrayTypeHandler via Picture Property - function testByteArrayTypeHandler() - { - $account = $this->newAccount6(); - - $this->sqlmap->insert("InsertAccountViaParameterMap", $account); - - $order = new Order(); - $order->setId(99); - $order->setCardExpiry("09/11"); - $order->setAccount($account); - $order->setCardNumber("154564656"); - $order->setCardType("Visa"); - $order->setCity("Lyon"); - $order->setDate(0); - $order->setPostalCode("69004"); - $order->setProvince("Rhone"); - $order->setStreet("rue Durand"); - - $this->sqlmap->insert("InsertOrderViaParameterMap", $order); - - $item = new LineItem(); - $item->setId(99); - $item->setCode("test"); - $item->setPrice(-99.99); - $item->setQuantity(99); - $item->setOrder($order); - $item->setPicture(null); - - // Check insert - $this->sqlmap->insert("InsertLineItemWithPicture", $item); - - // select - $item = null; - - $param["LineItem_ID"] = 99; - $param["Order_ID"] = 99; - - $item = $this->sqlmap->queryForObject("GetSpecificLineItemWithPicture", $param); - - $this->assertNotNull($item->getId()); -// $this->assertNotNull($item->getPicture()); -// $this->assertIdentical( GetSize(item.Picture), this.GetSize( this.GetPicture() )); - } -*/ - - /// Test extend parameter map capacity - /// (Support Requests 1043181) - function testInsertOrderViaExtendParameterMap() - { - $this->sqlmap->getSqlMapManager()->getTypeHandlers()->registerTypeHandler(new HundredsBool()); - - $account = $this->newAccount6(); - $this->sqlmap->insert("InsertAccountViaParameterMap", $account); - - $order = new Order(); - $order->setId(99); - $order->setCardExpiry("09/11"); - $order->setAccount($account); - $order->setCardNumber("154564656"); - $order->setCardType("Visa"); - $order->setCity("Lyon"); - $order->setDate(null); //<-- null replacement - $order->setPostalCode("69004"); - $order->setProvince("Rhone"); - $order->setStreet("rue Durand"); - - $this->sqlmap->insert("InsertOrderViaExtendParameterMap", $order); - - $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); - - $this->assertIdentical($order->getCity(), $orderTest->getCity()); - } -/**/ -} - +initSqlMap(); + } + + function setup() + { + $this->initScript('account-init.sql'); +// $this->initScript('account-procedure.sql'); + $this->initScript('order-init.sql'); +// $this->initScript('line-item-init.sql'); + $this->initScript('category-init.sql'); + } + + /// Test null replacement in ParameterMap property + function testNullValueReplacement() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + + $this->assertNull($account->getEmailAddress(), 'no_email@provided.com'); + + $this->assertAccount6($account); + } + + /// Test Test Null Value Replacement Inline + function testNullValueReplacementInline() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaInlineParameters", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertNull($account->getEmailAddress()); + + $this->assertAccount6($account); + } + + /// Test Test Null Value Replacement Inline + function testSpecifiedType() + { + $account = $this->newAccount6(); + $account->setEmailAddress(null); + $this->sqlmap->insert("InsertAccountNullableEmail", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertAccount6($account); + } + + + /// Test Test Null Value Replacement Inline + function testUnknownParameterClass() + { + $account = $this->newAccount6(); + $account->setEmailAddress(null); + $this->sqlmap->insert("InsertAccountUknownParameterClass", $account); + $account = $this->sqlmap->queryForObject("GetAccountNullableEmail", 6); + $this->assertAccount6($account); + } + + + /// Test null replacement in ParameterMap property + /// for System.DateTime.MinValue + function testNullValueReplacementForDateTimeMinValue() + { + $account = $this->newAccount6(); + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(null); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); + + $this->assertIdentical($order->getCity(), $orderTest->getCity()); + } + + /// Test null replacement in ParameterMap/Hahstable property + /// for System.DateTime.MinValue + function testNullValueReplacementForDateTimeWithHashtable() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate('0001-01-01 00:00:00'); //<-- null replacement + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderByHashTable", 99); + + $this->assertIdentical($orderTest["Date"], '0001-01-01 00:00:00'); + } + + /// Test null replacement in ParameterMap property + /// for Guid + function testNullValueReplacementForGuidValue() + { + if($this->hasSupportFor('last_insert_id')) + { + $category = new Category(); + $category->setName("Totoasdasd"); + $category->setGuidString('00000000-0000-0000-0000-000000000000'); + + $key = $this->sqlmap->insert("InsertCategoryNull", $category); + + $categoryRead = $this->sqlmap->queryForObject("GetCategory", $key); + + $this->assertIdentical($category->getName(), $categoryRead->getName()); + $this->assertIdentical('', $categoryRead->getGuidString()); + } + } + + + +/// Test complex mapping Via hasTable + /// + /// + /// map.Add("Item", Item); + /// map.Add("Order", Order); + /// + /// + /// ... #Item.prop1#...#Order.prop2# + /// + /// + /// + function testComplexMappingViaHasTable() + { + $a = new Account(); + $a->setFirstName("Joe"); + + $param["Account"] = $a; + + $o = new Order(); + $o->setCity("Dalton"); + $param["Order"] = $o; + + $accountTest = $this->sqlmap->queryForObject("GetAccountComplexMapping", $param); + + $this->assertAccount1($accountTest); + } + +/* + /// Test ByteArrayTypeHandler via Picture Property + function testByteArrayTypeHandler() + { + $account = $this->newAccount6(); + + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(0); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaParameterMap", $order); + + $item = new LineItem(); + $item->setId(99); + $item->setCode("test"); + $item->setPrice(-99.99); + $item->setQuantity(99); + $item->setOrder($order); + $item->setPicture(null); + + // Check insert + $this->sqlmap->insert("InsertLineItemWithPicture", $item); + + // select + $item = null; + + $param["LineItem_ID"] = 99; + $param["Order_ID"] = 99; + + $item = $this->sqlmap->queryForObject("GetSpecificLineItemWithPicture", $param); + + $this->assertNotNull($item->getId()); +// $this->assertNotNull($item->getPicture()); +// $this->assertIdentical( GetSize(item.Picture), this.GetSize( this.GetPicture() )); + } +*/ + + /// Test extend parameter map capacity + /// (Support Requests 1043181) + function testInsertOrderViaExtendParameterMap() + { + $this->sqlmap->getSqlMapManager()->getTypeHandlers()->registerTypeHandler(new HundredsBool()); + + $account = $this->newAccount6(); + $this->sqlmap->insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate(null); //<-- null replacement + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->insert("InsertOrderViaExtendParameterMap", $order); + + $orderTest = $this->sqlmap->queryForObject("GetOrderLiteByColumnName", 99); + + $this->assertIdentical($order->getCity(), $orderTest->getCity()); + } +/**/ +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/PropertyAccessTest.php b/tests/simple_unit/SqlMap/PropertyAccessTest.php index 38573f4e..d580f965 100644 --- a/tests/simple_unit/SqlMap/PropertyAccessTest.php +++ b/tests/simple_unit/SqlMap/PropertyAccessTest.php @@ -1,77 +1,77 @@ -Id = 10; - $account->FirstName = "Luky"; - $account->LastName = "Luke"; - $account->EmailAddress = "luly.luke@somewhere.com"; - - $two = new AccountBis(); - $two->Id = 12; - $two->FirstName = "Mini Me!"; - $account->More = $two; - - $account6 = $this->NewAccount6(); - $two->More = $account6; - - $this->assertIdentical(10, TPropertyAccess::get($account, 'Id')); - $this->assertIdentical(12, TPropertyAccess::get($account, 'More.Id')); - $this->assertIdentical(6, TPropertyAccess::get($account, 'More.More.Id')); - } - - function testSetPublicProperty() - { - $account = new AccountBis(); - - $account->Id = 10; - $account->FirstName = "Luky"; - $account->LastName = "Luke"; - $account->EmailAddress = "luly.luke@somewhere.com"; - - $two = new AccountBis(); - $two->Id = 12; - $two->FirstName = "Mini Me!"; - TPropertyAccess::set($account, 'More', $two); - - $account6 = $this->NewAccount6(); - TPropertyAccess::set($account, 'More.More', $account6); - - TPropertyAccess::set($account, 'More.More.EmailAddress', 'hahaha'); - - $this->assertIdentical(10, TPropertyAccess::get($account, 'Id')); - $this->assertIdentical(12, TPropertyAccess::get($account, 'More.Id')); - $this->assertIdentical(6, TPropertyAccess::get($account, 'More.More.Id')); - - $this->assertIdentical('hahaha', - TPropertyAccess::get($account, 'More.More.EmailAddress')); - } - - function testArrayAccessProperty() - { - $account = new AccountBis(); - $things['more'] = 1; - $things['accounts'] = $this->NewAccount6(); - $account->More = $things; - - $this->assertIdentical(6, TPropertyAccess::get($account, 'More.accounts.ID')); - - TPropertyAccess::set($account, 'More.accounts.EmailAddress', 'adssd'); - $this->assertIdentical('adssd', TPropertyAccess::get($account, 'More.accounts.EmailAddress')); - - $this->assertIdentical(1, TPropertyAccess::get($things, 'more')); - } - -} - - +Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $two = new AccountBis(); + $two->Id = 12; + $two->FirstName = "Mini Me!"; + $account->More = $two; + + $account6 = $this->NewAccount6(); + $two->More = $account6; + + $this->assertIdentical(10, TPropertyAccess::get($account, 'Id')); + $this->assertIdentical(12, TPropertyAccess::get($account, 'More.Id')); + $this->assertIdentical(6, TPropertyAccess::get($account, 'More.More.Id')); + } + + function testSetPublicProperty() + { + $account = new AccountBis(); + + $account->Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $two = new AccountBis(); + $two->Id = 12; + $two->FirstName = "Mini Me!"; + TPropertyAccess::set($account, 'More', $two); + + $account6 = $this->NewAccount6(); + TPropertyAccess::set($account, 'More.More', $account6); + + TPropertyAccess::set($account, 'More.More.EmailAddress', 'hahaha'); + + $this->assertIdentical(10, TPropertyAccess::get($account, 'Id')); + $this->assertIdentical(12, TPropertyAccess::get($account, 'More.Id')); + $this->assertIdentical(6, TPropertyAccess::get($account, 'More.More.Id')); + + $this->assertIdentical('hahaha', + TPropertyAccess::get($account, 'More.More.EmailAddress')); + } + + function testArrayAccessProperty() + { + $account = new AccountBis(); + $things['more'] = 1; + $things['accounts'] = $this->NewAccount6(); + $account->More = $things; + + $this->assertIdentical(6, TPropertyAccess::get($account, 'More.accounts.ID')); + + TPropertyAccess::set($account, 'More.accounts.EmailAddress', 'adssd'); + $this->assertIdentical('adssd', TPropertyAccess::get($account, 'More.accounts.EmailAddress')); + + $this->assertIdentical(1, TPropertyAccess::get($things, 'more')); + } + +} + + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/ResultClassTest.php b/tests/simple_unit/SqlMap/ResultClassTest.php index a2b81925..041c124e 100644 --- a/tests/simple_unit/SqlMap/ResultClassTest.php +++ b/tests/simple_unit/SqlMap/ResultClassTest.php @@ -1,249 +1,249 @@ -initSqlMap(); - } - - /** - * Test a boolean resultClass - */ - function testBoolean() - { - $bit = $this->sqlmap->queryForObject("GetBoolean", 1); - $this->assertIdentical(true, $bit); - } - - /** - * Test a boolean implicit resultClass - */ - function testBooleanWithoutResultClass() - { - $bit = (boolean)$this->sqlmap->queryForObject("GetBooleanWithoutResultClass", 1); - $this->assertIdentical(true, $bit); - } - - /** - * Test a byte resultClass - */ - function testByte() - { - $letter = $this->sqlmap->queryForObject("GetByte", 1); - $this->assertIdentical(155, (int)$letter); - } - - /** - * Test a byte implicit resultClass - */ - function testByteWithoutResultClass() - { - $letter = $this->sqlmap->queryForObject("GetByteWithoutResultClass", 1); - $this->assertIdentical(155, (int)$letter); - } - - /** - * Test a char resultClass - */ - function testChar() - { - $letter = $this->sqlmap->queryForObject("GetChar", 1); - $this->assertIdentical('a', trim($letter)); - } - - /** - * Test a char implicit resultClass - */ - function testCharWithoutResultClass() - { - $letter = $this->sqlmap->queryForObject("GetCharWithoutResultClass", 1); - $this->assertIdentical('a', trim($letter)); - } - - /** - * Test a DateTime resultClass - */ - function testDateTime() - { - $orderDate = $this->sqlmap->queryForObject("GetDate", 1); - $date = @mktime(8, 15, 00, 2, 15, 2003); - $this->assertIdentical($date, $orderDate->getTimeStamp()); - } - - /** - * Test a DateTime implicit resultClass - */ - function testDateTimeWithoutResultClass() - { - $date = $this->sqlmap->queryForObject("GetDateWithoutResultClass", 1); - $orderDate = new TDateTime; - $orderDate->setDateTime($date); - $date = @mktime(8, 15, 00, 2, 15, 2003); - - $this->assertIdentical($date, $orderDate->getTimeStamp()); - } - - /** - * Test a decimal resultClass - */ - function testDecimal() - { - $price = $this->sqlmap->queryForObject("GetDecimal", 1); - $this->assertIdentical(1.56, $price); - } - - /** - * Test a decimal implicit resultClass - */ - function testDecimalWithoutResultClass() - { - $price = $this->sqlmap->queryForObject("GetDecimalWithoutResultClass", 1); - $this->assertIdentical(1.56, (float)$price); - } - - /** - * Test a double resultClass - */ - function testDouble() - { - $price = $this->sqlmap->queryForObject("GetDouble", 1); - $this->assertIdentical(99.5, $price); - } - - /** - * Test a double implicit resultClass - */ - function testDoubleWithoutResultClass() - { - $price = $this->sqlmap->queryForObject("GetDoubleWithoutResultClass", 1); - $this->assertIdentical(99.5, (float)$price); - } - - /** - * IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass - */ -/* function testGuid() - { - Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); - - Guid guid = (Guid) $this->sqlmap->queryForObject("GetGuid", 1); - - $this->assertIdentical(newGuid, guid); - } -*/ - - /** - * Test a Guid implicit resultClass - */ -/* function testGuidWithoutResultClass() - { - Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); - - string guidString = Convert.ToString($this->sqlmap->queryForObject("GetGuidWithoutResultClass", 1)); - - Guid guid = new Guid(guidString); - - $this->assertIdentical(newGuid, guid); - } -*/ - /** - * Test a int16 resultClass (integer in PHP) - */ - function testInt16() - { - $integer = $this->sqlmap->queryForObject("GetInt16", 1); - - $this->assertIdentical(32111, $integer); - } - - /** - * Test a int16 implicit resultClass (integer in PHP) - */ - function testInt16WithoutResultClass() - { - $integer = $this->sqlmap->queryForObject("GetInt16WithoutResultClass", 1); - $this->assertIdentical(32111, (int)$integer); - } - - /** - * Test a int 32 resultClass (integer in PHP) - */ - function testInt32() - { - $integer = $this->sqlmap->queryForObject("GetInt32", 1); - $this->assertIdentical(999999, $integer); - } - - /** - * Test a int 32 implicit resultClass (integer in PHP) - */ - function testInt32WithoutResultClass() - { - $integer = $this->sqlmap->queryForObject("GetInt32WithoutResultClass", 1); - $this->assertIdentical(999999, (int)$integer); - } - - /** - * Test a int64 resultClass (float in PHP) - */ - function testInt64() - { - $bigInt = $this->sqlmap->queryForObject("GetInt64", 1); - $this->assertIdentical(9223372036854775800, $bigInt); - } - - /** - * Test a int64 implicit resultClass (float in PHP) - */ - function testInt64WithoutResultClass() - { - $bigInt = $this->sqlmap->queryForObject("GetInt64WithoutResultClass", 1); - $this->assertIdentical(9223372036854775800, (double)$bigInt); - } - - /** - * Test a single/float resultClass - */ - function testSingle() - { - $price = (float)$this->sqlmap->queryForObject("GetSingle", 1); - $this->assertIdentical(92233.5, $price); - } - - /** - * Test a single/float implicit resultClass - */ - function testSingleWithoutResultClass() - { - $price = $this->sqlmap->queryForObject("GetSingleWithoutResultClass", 1); - $this->assertIdentical(92233.5, (float)$price); - } - - /** - * Test a string resultClass - */ - function testString() - { - $cardType = $this->sqlmap->queryForObject("GetString", 1); - $this->assertIdentical("VISA", $cardType); - } - - /** - * Test a string implicit resultClass - */ - function testStringWithoutResultClass() - { - $cardType = $this->sqlmap->queryForObject("GetStringWithoutResultClass", 1); - $this->assertIdentical("VISA", $cardType); - } -/**/ - -} - +initSqlMap(); + } + + /** + * Test a boolean resultClass + */ + function testBoolean() + { + $bit = $this->sqlmap->queryForObject("GetBoolean", 1); + $this->assertIdentical(true, $bit); + } + + /** + * Test a boolean implicit resultClass + */ + function testBooleanWithoutResultClass() + { + $bit = (boolean)$this->sqlmap->queryForObject("GetBooleanWithoutResultClass", 1); + $this->assertIdentical(true, $bit); + } + + /** + * Test a byte resultClass + */ + function testByte() + { + $letter = $this->sqlmap->queryForObject("GetByte", 1); + $this->assertIdentical(155, (int)$letter); + } + + /** + * Test a byte implicit resultClass + */ + function testByteWithoutResultClass() + { + $letter = $this->sqlmap->queryForObject("GetByteWithoutResultClass", 1); + $this->assertIdentical(155, (int)$letter); + } + + /** + * Test a char resultClass + */ + function testChar() + { + $letter = $this->sqlmap->queryForObject("GetChar", 1); + $this->assertIdentical('a', trim($letter)); + } + + /** + * Test a char implicit resultClass + */ + function testCharWithoutResultClass() + { + $letter = $this->sqlmap->queryForObject("GetCharWithoutResultClass", 1); + $this->assertIdentical('a', trim($letter)); + } + + /** + * Test a DateTime resultClass + */ + function testDateTime() + { + $orderDate = $this->sqlmap->queryForObject("GetDate", 1); + $date = @mktime(8, 15, 00, 2, 15, 2003); + $this->assertIdentical($date, $orderDate->getTimeStamp()); + } + + /** + * Test a DateTime implicit resultClass + */ + function testDateTimeWithoutResultClass() + { + $date = $this->sqlmap->queryForObject("GetDateWithoutResultClass", 1); + $orderDate = new TDateTime; + $orderDate->setDateTime($date); + $date = @mktime(8, 15, 00, 2, 15, 2003); + + $this->assertIdentical($date, $orderDate->getTimeStamp()); + } + + /** + * Test a decimal resultClass + */ + function testDecimal() + { + $price = $this->sqlmap->queryForObject("GetDecimal", 1); + $this->assertIdentical(1.56, $price); + } + + /** + * Test a decimal implicit resultClass + */ + function testDecimalWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetDecimalWithoutResultClass", 1); + $this->assertIdentical(1.56, (float)$price); + } + + /** + * Test a double resultClass + */ + function testDouble() + { + $price = $this->sqlmap->queryForObject("GetDouble", 1); + $this->assertIdentical(99.5, $price); + } + + /** + * Test a double implicit resultClass + */ + function testDoubleWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetDoubleWithoutResultClass", 1); + $this->assertIdentical(99.5, (float)$price); + } + + /** + * IBATISNET-25 Error applying ResultMap when using 'Guid' in resultClass + */ +/* function testGuid() + { + Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); + + Guid guid = (Guid) $this->sqlmap->queryForObject("GetGuid", 1); + + $this->assertIdentical(newGuid, guid); + } +*/ + + /** + * Test a Guid implicit resultClass + */ +/* function testGuidWithoutResultClass() + { + Guid newGuid = new Guid("CD5ABF17-4BBC-4C86-92F1-257735414CF4"); + + string guidString = Convert.ToString($this->sqlmap->queryForObject("GetGuidWithoutResultClass", 1)); + + Guid guid = new Guid(guidString); + + $this->assertIdentical(newGuid, guid); + } +*/ + /** + * Test a int16 resultClass (integer in PHP) + */ + function testInt16() + { + $integer = $this->sqlmap->queryForObject("GetInt16", 1); + + $this->assertIdentical(32111, $integer); + } + + /** + * Test a int16 implicit resultClass (integer in PHP) + */ + function testInt16WithoutResultClass() + { + $integer = $this->sqlmap->queryForObject("GetInt16WithoutResultClass", 1); + $this->assertIdentical(32111, (int)$integer); + } + + /** + * Test a int 32 resultClass (integer in PHP) + */ + function testInt32() + { + $integer = $this->sqlmap->queryForObject("GetInt32", 1); + $this->assertIdentical(999999, $integer); + } + + /** + * Test a int 32 implicit resultClass (integer in PHP) + */ + function testInt32WithoutResultClass() + { + $integer = $this->sqlmap->queryForObject("GetInt32WithoutResultClass", 1); + $this->assertIdentical(999999, (int)$integer); + } + + /** + * Test a int64 resultClass (float in PHP) + */ + function testInt64() + { + $bigInt = $this->sqlmap->queryForObject("GetInt64", 1); + $this->assertIdentical(9223372036854775800, $bigInt); + } + + /** + * Test a int64 implicit resultClass (float in PHP) + */ + function testInt64WithoutResultClass() + { + $bigInt = $this->sqlmap->queryForObject("GetInt64WithoutResultClass", 1); + $this->assertIdentical(9223372036854775800, (double)$bigInt); + } + + /** + * Test a single/float resultClass + */ + function testSingle() + { + $price = (float)$this->sqlmap->queryForObject("GetSingle", 1); + $this->assertIdentical(92233.5, $price); + } + + /** + * Test a single/float implicit resultClass + */ + function testSingleWithoutResultClass() + { + $price = $this->sqlmap->queryForObject("GetSingleWithoutResultClass", 1); + $this->assertIdentical(92233.5, (float)$price); + } + + /** + * Test a string resultClass + */ + function testString() + { + $cardType = $this->sqlmap->queryForObject("GetString", 1); + $this->assertIdentical("VISA", $cardType); + } + + /** + * Test a string implicit resultClass + */ + function testStringWithoutResultClass() + { + $cardType = $this->sqlmap->queryForObject("GetStringWithoutResultClass", 1); + $this->assertIdentical("VISA", $cardType); + } +/**/ + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/ResultMapTest.php b/tests/simple_unit/SqlMap/ResultMapTest.php index 41fb5931..d545b65e 100644 --- a/tests/simple_unit/SqlMap/ResultMapTest.php +++ b/tests/simple_unit/SqlMap/ResultMapTest.php @@ -1,273 +1,273 @@ -initSqlMap(); - new Order; - new LineItemCollection; - new Account; - } - - function resetDatabase() - { - $this->initScript('account-init.sql'); - $this->initScript('order-init.sql'); - $this->initScript('line-item-init.sql'); -// $this->initScript('enumeration-init.sql'); - } - - function testColumnsByName() - { - $order = $this->sqlmap->QueryForObject('GetOrderLiteByColumnName', 1); - $this->assertOrder1($order); - } - - function testColumnsByIndex() - { - $order = $this->sqlmap->QueryForObject("GetOrderLiteByColumnIndex", 1); - $this->assertOrder1($order); - } - - function testExtendedResultMap() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsNoLazyLoad", 1); - $this->assertOrder1($order); - $this->assertTrue($order->getLineItemsList() instanceof TList); - $this->assertIdentical(2, $order->getLineItemsList()->getCount()); - } - - - function testLazyLoad() - { - $order = $this->sqlmap->QueryForObject("GetOrderWithLineItems", 1); - $this->assertOrder1($order); - $this->assertNotNull($order->getLineItemsList()); - $this->assertFalse($order->getLineItemsList() instanceof TList); - $this->assertIdentical(2, $order->getLineItemsList()->getCount()); - - // After a call to a method from a proxy object, - // the proxy object is replaced by the real object. - $this->assertTrue($order->getLineItemsList() instanceof TList); - $this->assertIdentical(2, $order->getLineItemsList()->getCount()); - } - - function testLazyWithTypedCollectionMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollection", 1); - $this->assertOrder1($order); - $this->assertNotNull($order->getLineItems()); - $this->assertFalse($order->getLineItemsList() instanceof LineItemCollection); - - $this->assertIdentical(2, $order->getLineItems()->getCount()); - - // After a call to a method from a proxy object, - // the proxy object is replaced by the real object. - $this->assertTrue($order->getLineItems() instanceof LineItemCollection); - foreach($order->getLineItems() as $item) - { - $this->assertNotNull($item); - $this->assertTrue($item instanceof LineItem); - } - } - - function testNullValueReplacementOnString() - { - $account = $this->sqlmap->queryForObject("GetAccountViaColumnName", 5); - $this->assertIdentical("no_email@provided.com", $account->getEmailAddress()); - } - - function testTypeSpecified() - { - $order = $this->sqlmap->queryForObject("GetOrderWithTypes", 1); - $this->assertOrder1($order); - } - - function testComplexObjectMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderWithAccount", 1); - $this->assertOrder1($order); - $this->assertAccount1($order->getAccount()); - } - - function testCollectionMappingAndExtends() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsCollection", 1); - $this->assertOrder1($order); - - // Check strongly typed collection - $this->assertNotNull($order->getLineItems()); - $this->assertIdentical(2, $order->getLineItems()->getCount()); - } - - function testListMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItems", 1); - $this->assertOrder1($order); - - // Check TList collection - $this->assertNotNull($order->getLineItemsList()); - $this->assertIdentical(2, $order->getLineItemsList()->getCount()); - } - - function testArrayMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItemArray", 1); - $this->assertOrder1($order); - $this->assertNotNull($order->getLineItemsArray()); - $this->assertTrue(is_array($order->getLineItemsArray())); - $this->assertIdentical(2, count($order->getLineItemsArray())); - } - - function testTypedCollectionMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollectionNoLazy", 1); - $this->assertOrder1($order); - $this->assertNotNull($order->getLineItems()); - $this->assertTrue($order->getLineItems() instanceof LineItemCollection); - $this->assertIdentical(2, $order->getLineItems()->getCount()); - foreach($order->getLineItems() as $item) - { - $this->assertNotNull($item); - $this->assertTrue($item instanceof LineItem); - } - } - - function testHashArrayMapping() - { - $order = $this->sqlmap->queryForObject("GetOrderAsHastable", 1); - $this->assertOrder1AsHashArray($order); - } - - function testNestedObjects() - { - $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite", 1); - - $this->assertOrder1($order); - $this->assertNotNull($order->getFavouriteLineItem()); - $this->assertIdentical(2, (int)$order->getFavouriteLineItem()->getID()); - $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); - - } - - - function testNestedObjects2() - { - $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite2", 1); - $this->assertOrder1($order); - - $this->assertNotNull($order->getFavouriteLineItem()); - $this->assertIdentical(2, (int)$order->getFavouriteLineItem()->getID()); - $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); - } - - function testImplicitResultMaps() - { - $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite3", 1); - - // *** force date to timestamp since data type can't be - // *** explicity known without mapping - $order->setDate(new TDateTime($order->getDate())); - - $this->assertOrder1($order); - - $this->assertNotNull($order->getFavouriteLineItem()); - $this->assertIdentical(2, $order->getFavouriteLineItem()->getID()); - $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); - } - - function testCompositeKeyMapping() - { - $this->resetDatabase(); - - $order1 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 1); - $order2 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 2); - - $this->assertNotNull($order1); - $this->assertNotNull($order1->getFavouriteLineItem()); - $this->assertIdentical(2, $order1->getFavouriteLineItem()->getID()); - - $this->assertNotNull($order2); - $this->assertNotNull($order2->getFavouriteLineItem()); - $this->assertIdentical(1, $order2->getFavouriteLineItem()->getID()); - } - - - function testSimpleTypeMapping() - { - $this->resetDatabase(); - - $list = $this->sqlmap->QueryForList("GetAllCreditCardNumbersFromOrders", null); - - $this->assertIdentical(5, count($list)); - $this->assertIdentical("555555555555", $list[0]); - } - - function testDecimalTypeMapping() - { - $this->resetDatabase(); - - $param["LineItem_ID"] = 1; - $param["Order_ID"] = 10; - $price = $this->sqlmap->queryForObject("GetLineItemPrice", $param); - $this->assertIdentical(gettype($price), 'double'); - $this->assertIdentical(45.43, $price); - } - -//todo -/* - function testNullValueReplacementOnEnum() - { - $enum['Id'] = 99; - $enum['Day'] = 'Days.Thu'; - $enum['Color'] = 'Colors.Blue'; - $enum['Month'] = 'Months.All'; - - $this->sqlmap->insert("InsertEnumViaParameterMap", $enum); - - $enumClass = $this->sqlmap->queryForObject("GetEnumerationNullValue", 99); - - $this->assertIdentical($enumClass['Day'], 'Days.Thu'); - $this->asserEquals($enumClass['Color'], 'Colors.Blue'); - $this->assertIdentical($enumClass['Month'], 'Months.All'); - } - - - function testByteArrayMapping() - { - } - - function testNullValueReplacementOnDecimal() - { - } - - function testNullValueReplacementOnDateTime() - { - } -*/ - -//future work - -/* - //requires dynamic SQL - function testDynamiqueCompositeKeyMapping() - { - $order1 = $this->sqlmap->queryForObject("GetOrderWithDynFavouriteLineItem", 1); - - $this->assertNotNull($order1); - $this->assertNotNull($order1->getFavouriteLineItem()); - var_dump($order1); - $this->assertIdentical(2, $order1->getFavouriteLineItem()->getID()); - } -*/ - -} - +initSqlMap(); + new Order; + new LineItemCollection; + new Account; + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $this->initScript('line-item-init.sql'); +// $this->initScript('enumeration-init.sql'); + } + + function testColumnsByName() + { + $order = $this->sqlmap->QueryForObject('GetOrderLiteByColumnName', 1); + $this->assertOrder1($order); + } + + function testColumnsByIndex() + { + $order = $this->sqlmap->QueryForObject("GetOrderLiteByColumnIndex", 1); + $this->assertOrder1($order); + } + + function testExtendedResultMap() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsNoLazyLoad", 1); + $this->assertOrder1($order); + $this->assertTrue($order->getLineItemsList() instanceof TList); + $this->assertIdentical(2, $order->getLineItemsList()->getCount()); + } + + + function testLazyLoad() + { + $order = $this->sqlmap->QueryForObject("GetOrderWithLineItems", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItemsList()); + $this->assertFalse($order->getLineItemsList() instanceof TList); + $this->assertIdentical(2, $order->getLineItemsList()->getCount()); + + // After a call to a method from a proxy object, + // the proxy object is replaced by the real object. + $this->assertTrue($order->getLineItemsList() instanceof TList); + $this->assertIdentical(2, $order->getLineItemsList()->getCount()); + } + + function testLazyWithTypedCollectionMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollection", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItems()); + $this->assertFalse($order->getLineItemsList() instanceof LineItemCollection); + + $this->assertIdentical(2, $order->getLineItems()->getCount()); + + // After a call to a method from a proxy object, + // the proxy object is replaced by the real object. + $this->assertTrue($order->getLineItems() instanceof LineItemCollection); + foreach($order->getLineItems() as $item) + { + $this->assertNotNull($item); + $this->assertTrue($item instanceof LineItem); + } + } + + function testNullValueReplacementOnString() + { + $account = $this->sqlmap->queryForObject("GetAccountViaColumnName", 5); + $this->assertIdentical("no_email@provided.com", $account->getEmailAddress()); + } + + function testTypeSpecified() + { + $order = $this->sqlmap->queryForObject("GetOrderWithTypes", 1); + $this->assertOrder1($order); + } + + function testComplexObjectMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithAccount", 1); + $this->assertOrder1($order); + $this->assertAccount1($order->getAccount()); + } + + function testCollectionMappingAndExtends() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemsCollection", 1); + $this->assertOrder1($order); + + // Check strongly typed collection + $this->assertNotNull($order->getLineItems()); + $this->assertIdentical(2, $order->getLineItems()->getCount()); + } + + function testListMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItems", 1); + $this->assertOrder1($order); + + // Check TList collection + $this->assertNotNull($order->getLineItemsList()); + $this->assertIdentical(2, $order->getLineItemsList()->getCount()); + } + + function testArrayMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemArray", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItemsArray()); + $this->assertTrue(is_array($order->getLineItemsArray())); + $this->assertIdentical(2, count($order->getLineItemsArray())); + } + + function testTypedCollectionMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderWithLineItemCollectionNoLazy", 1); + $this->assertOrder1($order); + $this->assertNotNull($order->getLineItems()); + $this->assertTrue($order->getLineItems() instanceof LineItemCollection); + $this->assertIdentical(2, $order->getLineItems()->getCount()); + foreach($order->getLineItems() as $item) + { + $this->assertNotNull($item); + $this->assertTrue($item instanceof LineItem); + } + } + + function testHashArrayMapping() + { + $order = $this->sqlmap->queryForObject("GetOrderAsHastable", 1); + $this->assertOrder1AsHashArray($order); + } + + function testNestedObjects() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite", 1); + + $this->assertOrder1($order); + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertIdentical(2, (int)$order->getFavouriteLineItem()->getID()); + $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); + + } + + + function testNestedObjects2() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite2", 1); + $this->assertOrder1($order); + + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertIdentical(2, (int)$order->getFavouriteLineItem()->getID()); + $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); + } + + function testImplicitResultMaps() + { + $order = $this->sqlmap->queryForObject("GetOrderJoinedFavourite3", 1); + + // *** force date to timestamp since data type can't be + // *** explicity known without mapping + $order->setDate(new TDateTime($order->getDate())); + + $this->assertOrder1($order); + + $this->assertNotNull($order->getFavouriteLineItem()); + $this->assertIdentical(2, $order->getFavouriteLineItem()->getID()); + $this->assertIdentical("ESM-23", $order->getFavouriteLineItem()->getCode()); + } + + function testCompositeKeyMapping() + { + $this->resetDatabase(); + + $order1 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 1); + $order2 = $this->sqlmap->queryForObject("GetOrderWithFavouriteLineItem", 2); + + $this->assertNotNull($order1); + $this->assertNotNull($order1->getFavouriteLineItem()); + $this->assertIdentical(2, $order1->getFavouriteLineItem()->getID()); + + $this->assertNotNull($order2); + $this->assertNotNull($order2->getFavouriteLineItem()); + $this->assertIdentical(1, $order2->getFavouriteLineItem()->getID()); + } + + + function testSimpleTypeMapping() + { + $this->resetDatabase(); + + $list = $this->sqlmap->QueryForList("GetAllCreditCardNumbersFromOrders", null); + + $this->assertIdentical(5, count($list)); + $this->assertIdentical("555555555555", $list[0]); + } + + function testDecimalTypeMapping() + { + $this->resetDatabase(); + + $param["LineItem_ID"] = 1; + $param["Order_ID"] = 10; + $price = $this->sqlmap->queryForObject("GetLineItemPrice", $param); + $this->assertIdentical(gettype($price), 'double'); + $this->assertIdentical(45.43, $price); + } + +//todo +/* + function testNullValueReplacementOnEnum() + { + $enum['Id'] = 99; + $enum['Day'] = 'Days.Thu'; + $enum['Color'] = 'Colors.Blue'; + $enum['Month'] = 'Months.All'; + + $this->sqlmap->insert("InsertEnumViaParameterMap", $enum); + + $enumClass = $this->sqlmap->queryForObject("GetEnumerationNullValue", 99); + + $this->assertIdentical($enumClass['Day'], 'Days.Thu'); + $this->asserEquals($enumClass['Color'], 'Colors.Blue'); + $this->assertIdentical($enumClass['Month'], 'Months.All'); + } + + + function testByteArrayMapping() + { + } + + function testNullValueReplacementOnDecimal() + { + } + + function testNullValueReplacementOnDateTime() + { + } +*/ + +//future work + +/* + //requires dynamic SQL + function testDynamiqueCompositeKeyMapping() + { + $order1 = $this->sqlmap->queryForObject("GetOrderWithDynFavouriteLineItem", 1); + + $this->assertNotNull($order1); + $this->assertNotNull($order1->getFavouriteLineItem()); + var_dump($order1); + $this->assertIdentical(2, $order1->getFavouriteLineItem()->getID()); + } +*/ + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/SelectKeyTest.php b/tests/simple_unit/SqlMap/SelectKeyTest.php index dd1d58df..a1efa640 100644 --- a/tests/simple_unit/SqlMap/SelectKeyTest.php +++ b/tests/simple_unit/SqlMap/SelectKeyTest.php @@ -1,120 +1,120 @@ -initSqlMap(); - - //force autoload - new Account; - new Order; - new LineItem; - new LineItemCollection; - new A; new B; new C; new D; new E; new F; - } - - /** - * Test Insert with post GeneratedKey - */ - function testInsertPostKey() - { - $this->initScript('line-item-init.sql'); - - $item = new LineItem(); - - $item->setId(10); - $item->setCode("blah"); - $item->setOrder(new Order()); - $item->getOrder()->setId(9); - $item->setPrice(44.00); - $item->setQuantity(1); - - $key = $this->sqlmap->Insert("InsertLineItemPostKey", $item); - - $this->assertIdentical(99, $key); - $this->assertIdentical(99, $item->getId()); - - $param["Order_ID"] = 9; - $param["LineItem_ID"] =10; - $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); - - $this->assertNotNull($testItem); - $this->assertIdentical(10, $testItem->getId()); - - $this->initScript('line-item-init.sql'); - } - - /** - * Test Insert pre GeneratedKey - */ - function testInsertPreKey() - { - $this->initScript('line-item-init.sql'); - - $item = new LineItem(); - - $item->setId(10); - $item->setCode("blah"); - $item->setOrder(new Order()); - $item->getOrder()->setId(9); - $item->setPrice(44.00); - $item->setQuantity(1); - - $key = $this->sqlmap->Insert("InsertLineItemPreKey", $item); - - $this->assertIdentical(99, $key); - $this->assertIdentical(99, $item->getId()); - - $param["Order_ID"] = 9; - $param["LineItem_ID"] = 99; - - $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); - - $this->assertNotNull($testItem); - $this->assertIdentical(99, $testItem->getId()); - - $this->initScript('line-item-init.sql'); - } - - /** - * Test Test Insert No Key - */ - function testInsertNoKey() - { - $this->initScript('line-item-init.sql'); - - $item = new LineItem(); - - $item->setId(100); - $item->setCode("blah"); - $item->setOrder(new Order()); - $item->getOrder()->setId(9); - $item->setPrice(44.00); - $item->setQuantity(1); - - - $key = $this->sqlmap->Insert("InsertLineItemNoKey", $item); - - $this->assertNull($key); - $this->assertIdentical(100, $item->getId()); - - $param["Order_ID"] = 9; - $param["LineItem_ID"] = 100; - - $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); - - $this->assertNotNull($testItem); - $this->assertIdentical(100, $testItem->getId()); - - $this->initScript('line-item-init.sql'); - } -} - +initSqlMap(); + + //force autoload + new Account; + new Order; + new LineItem; + new LineItemCollection; + new A; new B; new C; new D; new E; new F; + } + + /** + * Test Insert with post GeneratedKey + */ + function testInsertPostKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(10); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + $key = $this->sqlmap->Insert("InsertLineItemPostKey", $item); + + $this->assertIdentical(99, $key); + $this->assertIdentical(99, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] =10; + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertIdentical(10, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } + + /** + * Test Insert pre GeneratedKey + */ + function testInsertPreKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(10); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + $key = $this->sqlmap->Insert("InsertLineItemPreKey", $item); + + $this->assertIdentical(99, $key); + $this->assertIdentical(99, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] = 99; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertIdentical(99, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } + + /** + * Test Test Insert No Key + */ + function testInsertNoKey() + { + $this->initScript('line-item-init.sql'); + + $item = new LineItem(); + + $item->setId(100); + $item->setCode("blah"); + $item->setOrder(new Order()); + $item->getOrder()->setId(9); + $item->setPrice(44.00); + $item->setQuantity(1); + + + $key = $this->sqlmap->Insert("InsertLineItemNoKey", $item); + + $this->assertNull($key); + $this->assertIdentical(100, $item->getId()); + + $param["Order_ID"] = 9; + $param["LineItem_ID"] = 100; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertIdentical(100, $testItem->getId()); + + $this->initScript('line-item-init.sql'); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/SqlMapCacheTest.php b/tests/simple_unit/SqlMap/SqlMapCacheTest.php index af392fb3..1bb9b8d4 100644 --- a/tests/simple_unit/SqlMap/SqlMapCacheTest.php +++ b/tests/simple_unit/SqlMap/SqlMapCacheTest.php @@ -1,77 +1,77 @@ -set($key1, $object1); - $fifo->set($key2, $object2); - - $this->assertTrue($object1 === $fifo->get($key1)); - $this->assertTrue($object2 === $fifo->get($key2)); - - //object 1 should be removed - $fifo->set($key3, $object3); - - $this->assertNull($fifo->get($key1)); - $this->assertTrue($object2 === $fifo->get($key2)); - $this->assertTrue($object3 === $fifo->get($key3)); - - //object 2 should be removed - $fifo->set($key1, $object1); - - $this->assertNull($fifo->get($key2)); - $this->assertTrue($object3 === $fifo->get($key3)); - $this->assertTrue($object1 === $fifo->get($key1)); - } - - function testLruCache() - { - $lru = new TSqlMapLruCache(2); - - $object1 = new TSqlMapManager; - $object2 = new TComponent; - $object3 = new TSqlMapGateway(null); - - $key1 = 'key1'; - $key2 = 'key2'; - $key3 = 'key3'; - - $lru->set($key1, $object1); - $lru->set($key2, $object2); - - $this->assertTrue($object2 === $lru->get($key2)); - $this->assertTrue($object1 === $lru->get($key1)); - - //object 2 should be removed, i.e. least recently used - $lru->set($key3, $object3); - - $this->assertNull($lru->get($key2)); - $this->assertTrue($object1 === $lru->get($key1)); - $this->assertTrue($object3 === $lru->get($key3)); - - //object 1 will be removed - $lru->set($key2, $object2); - - $this->assertNull($lru->get($key1)); - $this->assertTrue($object2 === $lru->get($key2)); - $this->assertTrue($object3 === $lru->get($key3)); - } -} - - +set($key1, $object1); + $fifo->set($key2, $object2); + + $this->assertTrue($object1 === $fifo->get($key1)); + $this->assertTrue($object2 === $fifo->get($key2)); + + //object 1 should be removed + $fifo->set($key3, $object3); + + $this->assertNull($fifo->get($key1)); + $this->assertTrue($object2 === $fifo->get($key2)); + $this->assertTrue($object3 === $fifo->get($key3)); + + //object 2 should be removed + $fifo->set($key1, $object1); + + $this->assertNull($fifo->get($key2)); + $this->assertTrue($object3 === $fifo->get($key3)); + $this->assertTrue($object1 === $fifo->get($key1)); + } + + function testLruCache() + { + $lru = new TSqlMapLruCache(2); + + $object1 = new TSqlMapManager; + $object2 = new TComponent; + $object3 = new TSqlMapGateway(null); + + $key1 = 'key1'; + $key2 = 'key2'; + $key3 = 'key3'; + + $lru->set($key1, $object1); + $lru->set($key2, $object2); + + $this->assertTrue($object2 === $lru->get($key2)); + $this->assertTrue($object1 === $lru->get($key1)); + + //object 2 should be removed, i.e. least recently used + $lru->set($key3, $object3); + + $this->assertNull($lru->get($key2)); + $this->assertTrue($object1 === $lru->get($key1)); + $this->assertTrue($object3 === $lru->get($key3)); + + //object 1 will be removed + $lru->set($key2, $object2); + + $this->assertNull($lru->get($key1)); + $this->assertTrue($object2 === $lru->get($key2)); + $this->assertTrue($object3 === $lru->get($key3)); + } +} + + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/StatementExtendsTest.php b/tests/simple_unit/SqlMap/StatementExtendsTest.php index 4d87ca58..f496f154 100644 --- a/tests/simple_unit/SqlMap/StatementExtendsTest.php +++ b/tests/simple_unit/SqlMap/StatementExtendsTest.php @@ -1,29 +1,29 @@ -ConfigFile = dirname(__FILE__).'/maps/tests.xml'; - $this->sqlmap = $config->getClient(); - } - - function test_extends1() - { - $manager = $this->sqlmap->SqlMapManager; - $sql = $manager->getMappedStatement('test')->getSqlString(); - - $this->assertPattern('/img_request/', $sql); - $this->assertNoPattern('/img_progress/', $sql); - - $sql2 = $manager->getMappedStatement('GetAllProgress')->getSqlString(); - $this->assertPattern('/img_request/', $sql2); - $this->assertPattern('/img_progress/', $sql2); - } -} - +ConfigFile = dirname(__FILE__).'/maps/tests.xml'; + $this->sqlmap = $config->getClient(); + } + + function test_extends1() + { + $manager = $this->sqlmap->SqlMapManager; + $sql = $manager->getMappedStatement('test')->getSqlString(); + + $this->assertPattern('/img_request/', $sql); + $this->assertNoPattern('/img_progress/', $sql); + + $sql2 = $manager->getMappedStatement('GetAllProgress')->getSqlString(); + $this->assertPattern('/img_request/', $sql2); + $this->assertPattern('/img_progress/', $sql2); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/StatementTest.php b/tests/simple_unit/SqlMap/StatementTest.php index 3ac0a3ab..f9c3fb13 100644 --- a/tests/simple_unit/SqlMap/StatementTest.php +++ b/tests/simple_unit/SqlMap/StatementTest.php @@ -1,1135 +1,1135 @@ -initSqlMap(); - - //force autoload - new Account; - new Order; - new LineItem; - new LineItemCollection; - new A; new B; new C; new D; new E; new F; - } - - public function setup() - { - - } - - function resetDatabase() - { - $this->initScript('account-init.sql'); - $this->initScript('order-init.sql'); - $this->initScript('line-item-init.sql'); -// $this->initScript('enumeration-init.sql'); - $this->initScript('other-init.sql'); - } - - - #region Object Query tests - - /** - * Test Open connection with a connection string - */ - function testOpenConnection() - { - $conn = $this->sqlmap->getDbConnection(); - $conn->setActive(true); - $account= $this->sqlmap->QueryForObject("SelectWithProperty"); - $conn->setActive(false); - $this->assertAccount1($account); - } - - /** - * Test use a statement with property subtitution - * (JIRA 22) - */ - function testSelectWithProperty() - { - $account= $this->sqlmap->QueryForObject("SelectWithProperty"); - $this->assertAccount1($account); - } - - /** - * Test ExecuteQueryForObject Via ColumnName - */ - function testExecuteQueryForObjectViaColumnName() - { - $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - $this->assertAccount1($account); - } - - /** - * Test ExecuteQueryForObject Via ColumnIndex - */ - function testExecuteQueryForObjectViaColumnIndex() - { - $account= $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 1); - $this->assertAccount1($account); - } - - /** - * Test ExecuteQueryForObject Via ResultClass - */ - function testExecuteQueryForObjectViaResultClass() - { - $account= $this->sqlmap->QueryForObject("GetAccountViaResultClass", 1); - $this->assertAccount1($account); - } - - /** - * Test ExecuteQueryForObject With simple ResultClass : string - */ - function testExecuteQueryForObjectWithSimpleResultClass() - { - $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultClass", 1); - $this->assertIdentical("Joe.Dalton@somewhere.com", $email); - } - - /** - * Test ExecuteQueryForObject With simple ResultMap : string - */ - function testExecuteQueryForObjectWithSimpleResultMap() - { - $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultMap", 1); - $this->assertIdentical("Joe.Dalton@somewhere.com", $email); - } - - /** - * Test Primitive ReturnValue : TDateTime - */ - function testPrimitiveReturnValue() - { - $CardExpiry = $this->sqlmap->QueryForObject("GetOrderCardExpiryViaResultClass", 1); - $date = @mktime(8, 15, 00, 2, 15, 2003); - $this->assertIdentical($date, $CardExpiry->getTimeStamp()); - } - - /** - * Test ExecuteQueryForObject with result object : Account - */ - function testExecuteQueryForObjectWithResultObject() - { - $account= new Account(); - $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1, $account); - $this->assertAccount1($account); - $this->assertTrue($account == $testAccount); - } - - /** - * Test ExecuteQueryForObject as array - */ - function testExecuteQueryForObjectAsHashArray() - { - $account = $this->sqlmap->QueryForObject("GetAccountAsHashtable", 1); - $this->assertAccount1AsHashArray($account); - } - - /** - * Test ExecuteQueryForObject as Hashtable ResultClass - */ - function testExecuteQueryForObjectAsHashtableResultClass() - { - $account = $this->sqlmap->QueryForObject("GetAccountAsHashtableResultClass", 1); - $this->assertAccount1AsHashArray($account); - } - - /** - * Test ExecuteQueryForObject via Hashtable - */ - function testExecuteQueryForObjectViaHashtable() - { - $param["LineItem_ID"] = 2; - $param["Order_ID"] = 9; - - $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); - - $this->assertNotNull($testItem); - $this->assertIdentical("TSM-12", $testItem->getCode()); - } - /**/ - - //TODO: Test Query Dynamic Sql Element - function testQueryDynamicSqlElement() - { - //$list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID"); - - //$this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); - - //list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName"); - - //$this->assertIdentical("Averel.Dalton@somewhere.com", $list[0]); - - } - - // TODO: Test Execute QueryForList With ResultMap With Dynamic Element - function testExecuteQueryForListWithResultMapWithDynamicElement() - { - //$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE"); - - //$this->assertAccount1$list[0]); - //$this->assertIdentical(3, $list->getCount()); - //$this->assertIdentical(1, $list[0]->getID()); - //$this->assertIdentical(2, $list[1]->getID()); - //$this->assertIdentical(4, $list[2]->getID()); - - //list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "="); - - //$this->assertIdentical(0, $list->getCount()); - } - - - - /** - * Test Get Account Via Inline Parameters - */ - function testExecuteQueryForObjectViaInlineParameters() - { - $account= new Account(); - $account->setID(1); - - $testAccount = $this->sqlmap->QueryForObject("GetAccountViaInlineParameters", $account); - - $this->assertAccount1($testAccount); - } - /**/ - - // TODO: Test ExecuteQuery For Object With Enum property - - function testExecuteQueryForObjectWithEnum() - { - //$enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 1); - - //$this->assertIdentical(enumClass.Day, Days.Sat); - //$this->assertIdentical(enumClass.Color, Colors.Red); - //$this->assertIdentical(enumClass.Month, Months.August); - - //enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 3) as Enumeration; - - //$this->assertIdentical(enumClass.Day, Days.Mon); - //$this->assertIdentical(enumClass.Color, Colors.Blue); - //$this->assertIdentical(enumClass.Month, Months.September);*/ - } - - #endregion - - #region List Query tests - - /** - * Test QueryForList with Hashtable ResultMap - */ - function testQueryForListWithHashtableResultMap() - { - $this->initScript('account-init.sql'); - $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashMapViaResultMap"); - - $this->assertAccount1AsHashArray($list[0]); - $this->assertIdentical(5, count($list)); - - $this->assertIdentical(1, (int)$list[0]["Id"]); - $this->assertIdentical(2, (int)$list[1]["Id"]); - $this->assertIdentical(3, (int)$list[2]["Id"]); - $this->assertIdentical(4, (int)$list[3]["Id"]); - $this->assertIdentical(5, (int)$list[4]["Id"]); - } - - /** - * Test QueryForList with Hashtable ResultClass - */ - function testQueryForListWithHashtableResultClass() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashtableViaResultClass"); - - $this->assertAccount1AsHashArray($list[0]); - $this->assertIdentical(5, count($list)); - - $this->assertIdentical(1, (int)$list[0]["Id"]); - $this->assertIdentical(2, (int)$list[1]["Id"]); - $this->assertIdentical(3, (int)$list[2]["Id"]); - $this->assertIdentical(4, (int)$list[3]["Id"]); - $this->assertIdentical(5, (int)$list[4]["Id"]); - } - - /** - * Test QueryForList with IList ResultClass - */ - function testQueryForListWithIListResultClass() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsAsArrayListViaResultClass"); - - $listAccount = $list[0]; - - $this->assertIdentical(1,(int)$listAccount[0]); - $this->assertIdentical("Joe",$listAccount[1]); - $this->assertIdentical("Dalton",$listAccount[2]); - $this->assertIdentical("Joe.Dalton@somewhere.com",$listAccount[3]); - - $this->assertIdentical(5, count($list)); - - $listAccount = $list[0]; - $this->assertIdentical(1, (int)$listAccount[0]); - $listAccount = $list[1]; - $this->assertIdentical(2, (int)$listAccount[0]); - $listAccount = $list[2]; - $this->assertIdentical(3, (int)$listAccount[0]); - $listAccount = $list[3]; - $this->assertIdentical(4, (int)$listAccount[0]); - $listAccount = $list[4]; - $this->assertIdentical(5, (int)$listAccount[0]); - } - - /** - * Test QueryForList With ResultMap, result collection as ArrayList - */ - function testQueryForListWithResultMap() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap"); - - $this->assertAccount1($list[0]); - $this->assertIdentical(5, count($list)); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - $this->assertIdentical(3, $list[2]->getID()); - $this->assertIdentical(4, $list[3]->getID()); - $this->assertIdentical(5, $list[4]->getID()); - } - - /** - * Test ExecuteQueryForPaginatedList - */ - function testExecuteQueryForPaginatedList() - { - // Get List of all 5 - $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 2); - - // Test initial state (page 0) - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertAccount1($list[0]); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - - // Test illegal previous page (no effect, state should be same) - $list->PreviousPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertAccount1($list[0]); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - - // Test next (page 1) - $list->NextPage(); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(3, $list[0]->getID()); - $this->assertIdentical(4, $list[1]->getID()); - - // Test next (page 2 -last) - $list->NextPage(); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - $this->assertIdentical(5, $list[0]->getID()); - - // Test previous (page 1) - $list->PreviousPage(); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(3, $list[0]->getID()); - $this->assertIdentical(4, $list[1]->getID()); - - // Test previous (page 0 -first) - $list->PreviousPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertAccount1($list[0]); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - - // Test goto (page 0) - $list->GotoPage(0); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - - // Test goto (page 1) - $list->GotoPage(1); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertTrue($list->getIsNextPageAvailable()); - $this->assertIdentical(2, $list->getCount()); - $this->assertIdentical(3, $list[0]->getID()); - $this->assertIdentical(4, $list[1]->getID()); - - // Test goto (page 2) - $list->GotoPage(2); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - $this->assertIdentical(5, $list[0]->getID()); - - // Test illegal goto (page 0) - $list->GotoPage(3); - $this->assertTrue($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(0, $list->getCount()); - - $list = $this->sqlmap->QueryForPagedList("GetNoAccountsViaResultMap", null, 2); - - // Test empty list - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(0, $list->getCount()); - - // Test next - $list->NextPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(0, $list->getCount()); - - // Test previous - $list->PreviousPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(0, $list->getCount()); - - // Test previous - $list->GotoPage(0); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(0, $list->getCount()); - $list = $this->sqlmap->QueryForPagedList("GetFewAccountsViaResultMap", null, 2); - - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - - // Test next - $list->NextPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - // Test previous - $list->PreviousPage(); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - - // Test previous - $list->GotoPage(0); - $this->assertFalse($list->getIsPreviousPageAvailable()); - $this->assertFalse($list->getIsNextPageAvailable()); - $this->assertIdentical(1, $list->getCount()); - - - $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 5); - - $this->assertIdentical(5, $list->getCount()); - - $list->NextPage(); - $this->assertIdentical(5, $list->getCount()); - - $b = $list->getIsPreviousPageAvailable(); - $list->PreviousPage(); - $this->assertIdentical(5, $list->getCount()); - } - - /** - * Test QueryForList with ResultObject : - * AccountCollection strongly typed collection - */ - function testQueryForListWithResultObject() - { - $accounts = new AccountCollection(); - - $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, $accounts); - $this->assertAccount1($accounts[0]); - $this->assertIdentical(5, $accounts->getCount()); - $this->assertIdentical(1, $accounts[0]->getID()); - $this->assertIdentical(2, $accounts[1]->getID()); - $this->assertIdentical(3, $accounts[2]->getID()); - $this->assertIdentical(4, $accounts[3]->getID()); - $this->assertIdentical(5, $accounts[4]->GetId()); - } - - /** - * Test QueryForList with ListClass : LineItemCollection - */ - function testQueryForListWithListClass() - { - $linesItem = $this->sqlmap->QueryForList("GetLineItemsForOrderWithListClass", 10); - - $this->assertNotNull($linesItem); - $this->assertIdentical(2, $linesItem->getCount()); - $this->assertIdentical("ESM-34", $linesItem[0]->getCode()); - $this->assertIdentical("QSM-98", $linesItem[1]->getCode()); - } - - /** - * Test QueryForList with no result. - */ - function testQueryForListWithNoResult() - { - $list = $this->sqlmap->QueryForList("GetNoAccountsViaResultMap"); - - $this->assertIdentical(0, count($list)); - } - - /** - * Test QueryForList with ResultClass : Account. - */ - function testQueryForListResultClass() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultClass"); - - $this->assertAccount1($list[0]); - $this->assertIdentical(5, count($list)); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - $this->assertIdentical(3, $list[2]->getID()); - $this->assertIdentical(4, $list[3]->getID()); - $this->assertIdentical(5, $list[4]->getID()); - } - - /** - * Test QueryForList with simple resultClass : string - */ - function testQueryForListWithSimpleResultClass() - { - $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultClass"); - - $this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); - $this->assertIdentical("Averel.Dalton@somewhere.com", $list[1]); - $this->assertIdentical('', $list[2]); - $this->assertIdentical("Jack.Dalton@somewhere.com", $list[3]); - $this->assertIdentical('', $list[4]); - } - - /** - * Test QueryForList with simple ResultMap : string - */ - function testQueryForListWithSimpleResultMap() - { - $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultMap"); - - $this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); - $this->assertIdentical("Averel.Dalton@somewhere.com", $list[1]); - $this->assertIdentical('', $list[2]); - $this->assertIdentical("Jack.Dalton@somewhere.com", $list[3]); - $this->assertIdentical('', $list[4]); - } - - /** - * Test QueryForListWithSkipAndMax - */ - function testQueryForListWithSkipAndMax() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, null, 2, 2); - - $this->assertIdentical(2, count($list)); - $this->assertIdentical(3, $list[0]->getID()); - $this->assertIdentical(4, $list[1]->getID()); - } - - - /** - * Test row delegate - */ - function testQueryWithRowDelegate() - { - //$handler = new SqlMapper.RowDelegate(this.RowHandler); - - //$list = $this->sqlmap->QueryWithRowDelegate("GetAllAccountsViaResultMap", null, handler); - - //$this->assertIdentical(5, _index); - //$this->assertIdentical(5, $list->getCount()); - //$this->assertAccount1$list[0]); - //$this->assertIdentical(1, $list[0]->getID()); - //$this->assertIdentical(2, $list[1]->getID()); - //$this->assertIdentical(3, $list[2]->getID()); - //$this->assertIdentical(4, $list[3]->getID()); - //$this->assertIdentical(5, $list[4]->getID()); - } - - #endregion - - #region Map Tests - - /** - * Test ExecuteQueryForMap : Hashtable. - */ - function testExecuteQueryForMap() - { - $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName"); - - $this->assertIdentical(5, count($map)); - $this->assertAccount1($map["Joe"]); - - $this->assertIdentical(1, $map["Joe"]->getID()); - $this->assertIdentical(2, $map["Averel"]->getID()); - $this->assertIdentical(3, $map["William"]->getID()); - $this->assertIdentical(4, $map["Jack"]->getID()); - $this->assertIdentical(5, $map["Gilles"]->getID()); - } - - /** - * Test ExecuteQueryForMap : Hashtable. - * - * If the keyProperty is an integer, you must acces the map - * by map[integer] and not by map["integer"] - */ - function testExecuteQueryForMap2() - { - $map = $this->sqlmap->QueryForMap("GetAllOrderWithLineItems", null, "PostalCode"); - - $this->assertIdentical(11, count($map)); - $order = $map["T4H 9G4"]; - - $this->assertIdentical(2, $order->getLineItemsList()->getCount()); - } - - /** - * Test ExecuteQueryForMap with value property : - * "FirstName" as key, "EmailAddress" as value - */ - function testExecuteQueryForMapWithValueProperty() - { - $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, - "FirstName", "EmailAddress"); - - $this->assertIdentical(5, count($map)); - - $this->assertIdentical("Joe.Dalton@somewhere.com", $map["Joe"]); - $this->assertIdentical("Averel.Dalton@somewhere.com", $map["Averel"]); - $this->assertNull($map["William"]); - $this->assertIdentical("Jack.Dalton@somewhere.com", $map["Jack"]); - $this->assertNull($map["Gilles"]); - } - - /** - * Test ExecuteQueryForWithJoined - */ - function testExecuteQueryForWithJoined() - { - $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",10); - - $this->assertNotNull($order->getAccount()); - - $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",11); - - $this->assertNull($order->getAccount()); - } - - /** - * Test ExecuteQueryFor With Complex Joined - * - * A->B->C - * ->E - * ->F - */ - function testExecuteQueryForWithComplexJoined() - { - $a = $this->sqlmap->QueryForObject("SelectComplexJoined"); - $this->assertNotNull($a); - $this->assertNotNull($a->getB()); - $this->assertNotNull($a->getB()->getC()); - $this->assertNull($a->getB()->getD()); - $this->assertNotNull($a->getE()); - $this->assertNull($a->getF()); - } - #endregion - - #region Extends statement - - /** - * Test base Extends statement - */ - function testExtendsGetAllAccounts() - { - $list = $this->sqlmap->QueryForList("GetAllAccounts"); - - $this->assertAccount1($list[0]); - $this->assertIdentical(5, count($list)); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - $this->assertIdentical(3, $list[2]->getID()); - $this->assertIdentical(4, $list[3]->getID()); - $this->assertIdentical(5, $list[4]->getID()); - } - - /** - * Test Extends statement GetAllAccountsOrderByName extends GetAllAccounts - */ - function testExtendsGetAllAccountsOrderByName() - { - $list = $this->sqlmap->QueryForList("GetAllAccountsOrderByName"); - - $this->assertAccount1($list[3]); - $this->assertIdentical(5, count($list)); - - $this->assertIdentical(2, $list[0]->getID()); - $this->assertIdentical(5, $list[1]->getID()); - $this->assertIdentical(4, $list[2]->getID()); - $this->assertIdentical(1, $list[3]->getID()); - $this->assertIdentical(3, $list[4]->getID()); - } - - /** - * Test Extends statement GetOneAccount extends GetAllAccounts - */ - function testExtendsGetOneAccount() - { - $account= $this->sqlmap->QueryForObject("GetOneAccount", 1); - $this->assertAccount1($account); - } - - /** - * Test Extends statement GetSomeAccount extends GetAllAccounts - */ - function testExtendsGetSomeAccount() - { - $param["lowID"] = 2; - $param["hightID"] = 4; - - $list = $this->sqlmap->QueryForList("GetSomeAccount", $param); - - $this->assertIdentical(3, count($list)); - - $this->assertIdentical(2, $list[0]->getID()); - $this->assertIdentical(3, $list[1]->getID()); - $this->assertIdentical(4, $list[2]->getID()); - } - - #endregion - - #region Update tests - - - /** - * Test Insert account via public fields - */ - function testInsertAccountViaPublicFields() - { - $this->initScript('account-init.sql'); - - $account = new AccountBis(); - - $account->Id = 10; - $account->FirstName = "Luky"; - $account->LastName = "Luke"; - $account->EmailAddress = "luly.luke@somewhere.com"; - - $this->sqlmap->Insert("InsertAccountViaPublicFields", $account); - - $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 10); - - $this->assertNotNull($testAccount); - - $this->assertIdentical(10, $testAccount->getID()); - - $this->initScript('account-init.sql'); - } - - /** - * - */ - function testInsertOrderViaProperties() - { - $this->initScript('account-init.sql'); - $this->initScript('order-init.sql'); - $account= $this->NewAccount6(); - - $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); - - $order = new Order(); - $order->setId(99); - $order->setCardExpiry("09/11"); - $order->setAccount($account); - $order->setCardNumber("154564656"); - $order->setCardType("Visa"); - $order->setCity("Lyon"); - $order->setDate('2005-05-20'); - $order->setPostalCode("69004"); - $order->setProvince("Rhone"); - $order->setStreet("rue Durand"); - - $this->sqlmap->Insert("InsertOrderViaPublicFields", $order); - - $this->initScript('account-init.sql'); - $this->initScript('order-init.sql'); - } - - - /** - * Test Insert account via inline parameters - */ - function testInsertAccountViaInlineParameters() - { - $this->initScript('account-init.sql'); - $account= new Account(); - - $account->setId(10); - $account->setFirstName("Luky"); - $account->setLastName("Luke"); - $account->setEmailAddress("luly.luke@somewhere.com"); - - $this->sqlmap->Insert("InsertAccountViaInlineParameters", $account); - - $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 10); - - $this->assertNotNull($testAccount); - $this->assertIdentical(10, $testAccount->getId()); - $this->initScript('account-init.sql'); - } - - /** - * Test Insert account via parameterMap - */ - function testInsertAccountViaParameterMap() - { - $this->initScript('account-init.sql'); - $account= $this->NewAccount6(); - $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); - - $account = $this->sqlmap->QueryForObject("GetAccountNullableEmail", 6); - $this->AssertAccount6($account); - - $this->initScript('account-init.sql'); - } - - /** - * Test Update via parameterMap - */ - function testUpdateViaParameterMap() - { - $this->initScript('account-init.sql'); - $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $account->setEmailAddress("new@somewhere.com"); - $this->sqlmap->Update("UpdateAccountViaParameterMap", $account); - - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); - $this->initScript('account-init.sql'); - } - - /** - * Test Update via parameterMap V2 - */ - function testUpdateViaParameterMap2() - { - $this->initScript('account-init.sql'); - $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $account->setEmailAddress("new@somewhere.com"); - $this->sqlmap->Update("UpdateAccountViaParameterMap2", $account); - - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); - $this->initScript('account-init.sql'); - } - - /** - * Test Update with inline parameters - */ - function testUpdateWithInlineParameters() - { - $this->initScript('account-init.sql'); - $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $account->setEmailAddress("new@somewhere.com"); - $this->sqlmap->Update("UpdateAccountViaInlineParameters", $account); - - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); - - $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); - $this->initScript('account-init.sql'); - } - - /** - * Test Execute Update With Parameter Class - */ - function testExecuteUpdateWithParameterClass() - { - $this->initScript('account-init.sql'); - $account= $this->NewAccount6(); - - $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); - - $noRowsDeleted = $this->sqlmap->Update("DeleteAccount", null); - - $this->sqlmap->Update("DeleteAccount", $account); - - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); - - $this->assertNull($account); - $this->assertIdentical(0, $noRowsDeleted); - $this->initScript('account-init.sql'); - } - - /** - * Test Execute Delete - */ - function testExecuteDelete() - { - $this->initScript('account-init.sql'); - $account= $this->NewAccount6(); - - $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); - - $account = null; - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); - - $this->assertTrue($account->getId() == 6); - - $rowNumber = $this->sqlmap->Delete("DeleteAccount", $account); - $this->assertTrue($rowNumber == 1); - - $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); - - $this->assertNull($account); - $this->initScript('account-init.sql'); - } - - /** - * Test Execute Delete - */ - function testDeleteWithComments() - { - $this->initScript('line-item-init.sql'); - $rowNumber = $this->sqlmap->Delete("DeleteWithComments"); - - $this->assertIdentical($rowNumber, 2); - $this->initScript('line-item-init.sql'); - } - - - - #endregion - - #region Row delegate - - private $_index = 0; - - function RowHandler($sender, $paramterObject, $list) - { - //_index++; - //$this->assertIdentical(_index, (($account) obj).Id); - //$list->Add(obj); - } - - #endregion - - #region JIRA Tests - - /** - * Test JIRA 30 (repeating property) - */ - function testJIRA30() - { - $account= new Account(); - $account->setId(1); - $account->setFirstName("Joe"); - $account->setLastName("Dalton"); - $account->setEmailAddress("Joe.Dalton@somewhere.com"); - - $result = $this->sqlmap->QueryForObject("GetAccountWithRepeatingProperty", $account); - - $this->assertAccount1($result); - } - - /** - * Test Bit column - */ - function testJIRA42() - { - $other = new Other(); - - $other->setInt(100); - $other->setBool(true); - $other->setLong(789456321); - - $this->sqlmap->Insert("InsertBool", $other); - } - - /** - * Test for access a result map in a different namespace - */ - function testJIRA45() - { - $account= $this->sqlmap->QueryForObject("GetAccountJIRA45", 1); - $this->assertAccount1($account); - } - - /** - * Test : Whitespace is not maintained properly when CDATA tags are used - */ - function testJIRA110() - { - $account= $this->sqlmap->QueryForObject("Get1Account"); - $this->assertAccount1($account); - } - - /** - * Test : Whitespace is not maintained properly when CDATA tags are used - */ - function testJIRA110Bis() - { - $list = $this->sqlmap->QueryForList("GetAccounts"); - - $this->assertAccount1($list[0]); - $this->assertIdentical(5, count($list)); - } - - /** - * Test for cache stats only being calculated on CachingStatments - */ - function testJIRA113() - { - // $this->sqlmap->FlushCaches(); - - // taken from TestFlushDataCache() - // first query is not cached, second query is: 50% cache hit - /*$list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); - $firstId = HashCodeProvider.GetIdentityHashCode(list); - list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); - int secondId = HashCodeProvider.GetIdentityHashCode(list); - $this->assertIdentical(firstId, secondId); - - string cacheStats = $this->sqlmap->GetDataCacheStats(); - - $this->assertNotNull(cacheStats);*/ - } - - #endregion - - #region CustomTypeHandler tests - - /** - * Test CustomTypeHandler - */ - function testExecuteQueryWithCustomTypeHandler() - { - $this->sqlmap->registerTypeHandler(new HundredsBool()); - $this->sqlmap->registerTypeHandler(new OuiNonBool()); - - $list = $this->sqlmap->QueryForList("GetAllAccountsViaCustomTypeHandler"); - - $this->assertAccount1($list[0]); - $this->assertIdentical(5, count($list)); - $this->assertIdentical(1, $list[0]->getID()); - $this->assertIdentical(2, $list[1]->getID()); - $this->assertIdentical(3, $list[2]->getID()); - $this->assertIdentical(4, $list[3]->getID()); - $this->assertIdentical(5, $list[4]->getID()); - - $this->assertFalse($list[0]->getCartOptions()); - $this->assertFalse($list[1]->getCartOptions()); - $this->assertTrue($list[2]->getCartOptions()); - $this->assertTrue($list[3]->getCartOptions()); - $this->assertTrue($list[4]->getCartOptions()); - - $this->assertTrue($list[0]->getBannerOptions()); - $this->assertTrue($list[1]->getBannerOptions()); - $this->assertFalse($list[2]->getBannerOptions()); - $this->assertFalse($list[3]->getBannerOptions()); - $this->assertTrue($list[4]->getBannerOptions()); - } - - /** - * Test CustomTypeHandler Oui/Non - */ - function testCustomTypeHandler() - { - $this->initScript('other-init.sql'); - $this->initScript('account-init.sql'); - - $this->sqlmap->registerTypeHandler(new OuiNonBool()); - - $other = new Other(); - $other->setInt(99); - $other->setLong(1966); - $other->setBool(true); - $other->setBool2(false); - $this->sqlmap->Insert("InsertCustomTypeHandler", $other); - - $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); - $this->assertNotNull( $anOther ); - $this->assertIdentical(99, (int)$anOther->getInt()); - $this->assertIdentical(1966, (int)$anOther->getLong()); - $this->assertIdentical(true, (boolean)$anOther->getBool()); - $this->assertIdentical(false, (boolean)$anOther->getBool2()); - - } - - /** - * Test CustomTypeHandler Oui/Non - */ - function testInsertInlineCustomTypeHandlerV1() - { - $this->initScript('other-init.sql'); - $this->initScript('account-init.sql'); - - $other = new Other(); - $other->setInt(99); - $other->setLong(1966); - $other->setBool(true); - $other->setBool2(false); - - $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV1", $other); - - $anOther = $this->sqlmap->QueryForObject("SelectByIntV1", 99); - - $this->assertNotNull( $anOther ); - $this->assertIdentical(99, (int)$anOther->getInt()); - $this->assertIdentical(1966, (int)$anOther->getLong()); - $this->assertIdentical(true, (boolean)$anOther->getBool()); - $this->assertIdentical(false, (boolean)$anOther->getBool2()); - - } - - /** - * Test CustomTypeHandler Oui/Non - */ - function testInsertInlineCustomTypeHandlerV2() - { - $this->initScript('other-init.sql'); - $this->initScript('account-init.sql'); - - $other = new Other(); - $other->setInt(99); - $other->setLong(1966); - $other->setBool(true); - $other->setBool2(false); - - $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV2", $other); - - $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); - - $this->assertNotNull( $anOther ); - $this->assertIdentical(99, (int)$anOther->getInt()); - $this->assertIdentical(1966, (int)$anOther->getLong()); - $this->assertIdentical(true, (boolean)$anOther->getBool()); - $this->assertIdentical(false, (boolean)$anOther->getBool2()); - } - #endregion - /**/ -} - +initSqlMap(); + + //force autoload + new Account; + new Order; + new LineItem; + new LineItemCollection; + new A; new B; new C; new D; new E; new F; + } + + public function setup() + { + + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $this->initScript('line-item-init.sql'); +// $this->initScript('enumeration-init.sql'); + $this->initScript('other-init.sql'); + } + + + #region Object Query tests + + /** + * Test Open connection with a connection string + */ + function testOpenConnection() + { + $conn = $this->sqlmap->getDbConnection(); + $conn->setActive(true); + $account= $this->sqlmap->QueryForObject("SelectWithProperty"); + $conn->setActive(false); + $this->assertAccount1($account); + } + + /** + * Test use a statement with property subtitution + * (JIRA 22) + */ + function testSelectWithProperty() + { + $account= $this->sqlmap->QueryForObject("SelectWithProperty"); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ColumnName + */ + function testExecuteQueryForObjectViaColumnName() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ColumnIndex + */ + function testExecuteQueryForObjectViaColumnIndex() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject Via ResultClass + */ + function testExecuteQueryForObjectViaResultClass() + { + $account= $this->sqlmap->QueryForObject("GetAccountViaResultClass", 1); + $this->assertAccount1($account); + } + + /** + * Test ExecuteQueryForObject With simple ResultClass : string + */ + function testExecuteQueryForObjectWithSimpleResultClass() + { + $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultClass", 1); + $this->assertIdentical("Joe.Dalton@somewhere.com", $email); + } + + /** + * Test ExecuteQueryForObject With simple ResultMap : string + */ + function testExecuteQueryForObjectWithSimpleResultMap() + { + $email = $this->sqlmap->QueryForObject("GetEmailAddressViaResultMap", 1); + $this->assertIdentical("Joe.Dalton@somewhere.com", $email); + } + + /** + * Test Primitive ReturnValue : TDateTime + */ + function testPrimitiveReturnValue() + { + $CardExpiry = $this->sqlmap->QueryForObject("GetOrderCardExpiryViaResultClass", 1); + $date = @mktime(8, 15, 00, 2, 15, 2003); + $this->assertIdentical($date, $CardExpiry->getTimeStamp()); + } + + /** + * Test ExecuteQueryForObject with result object : Account + */ + function testExecuteQueryForObjectWithResultObject() + { + $account= new Account(); + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1, $account); + $this->assertAccount1($account); + $this->assertTrue($account == $testAccount); + } + + /** + * Test ExecuteQueryForObject as array + */ + function testExecuteQueryForObjectAsHashArray() + { + $account = $this->sqlmap->QueryForObject("GetAccountAsHashtable", 1); + $this->assertAccount1AsHashArray($account); + } + + /** + * Test ExecuteQueryForObject as Hashtable ResultClass + */ + function testExecuteQueryForObjectAsHashtableResultClass() + { + $account = $this->sqlmap->QueryForObject("GetAccountAsHashtableResultClass", 1); + $this->assertAccount1AsHashArray($account); + } + + /** + * Test ExecuteQueryForObject via Hashtable + */ + function testExecuteQueryForObjectViaHashtable() + { + $param["LineItem_ID"] = 2; + $param["Order_ID"] = 9; + + $testItem = $this->sqlmap->QueryForObject("GetSpecificLineItem", $param); + + $this->assertNotNull($testItem); + $this->assertIdentical("TSM-12", $testItem->getCode()); + } + /**/ + + //TODO: Test Query Dynamic Sql Element + function testQueryDynamicSqlElement() + { + //$list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_ID"); + + //$this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); + + //list = $this->sqlmap->QueryForList("GetDynamicOrderedEmailAddressesViaResultMap", "Account_FirstName"); + + //$this->assertIdentical("Averel.Dalton@somewhere.com", $list[0]); + + } + + // TODO: Test Execute QueryForList With ResultMap With Dynamic Element + function testExecuteQueryForListWithResultMapWithDynamicElement() + { + //$list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "LIKE"); + + //$this->assertAccount1$list[0]); + //$this->assertIdentical(3, $list->getCount()); + //$this->assertIdentical(1, $list[0]->getID()); + //$this->assertIdentical(2, $list[1]->getID()); + //$this->assertIdentical(4, $list[2]->getID()); + + //list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMapWithDynamicElement", "="); + + //$this->assertIdentical(0, $list->getCount()); + } + + + + /** + * Test Get Account Via Inline Parameters + */ + function testExecuteQueryForObjectViaInlineParameters() + { + $account= new Account(); + $account->setID(1); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaInlineParameters", $account); + + $this->assertAccount1($testAccount); + } + /**/ + + // TODO: Test ExecuteQuery For Object With Enum property + + function testExecuteQueryForObjectWithEnum() + { + //$enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 1); + + //$this->assertIdentical(enumClass.Day, Days.Sat); + //$this->assertIdentical(enumClass.Color, Colors.Red); + //$this->assertIdentical(enumClass.Month, Months.August); + + //enumClass = $this->sqlmap->QueryForObject("GetEnumeration", 3) as Enumeration; + + //$this->assertIdentical(enumClass.Day, Days.Mon); + //$this->assertIdentical(enumClass.Color, Colors.Blue); + //$this->assertIdentical(enumClass.Month, Months.September);*/ + } + + #endregion + + #region List Query tests + + /** + * Test QueryForList with Hashtable ResultMap + */ + function testQueryForListWithHashtableResultMap() + { + $this->initScript('account-init.sql'); + $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashMapViaResultMap"); + + $this->assertAccount1AsHashArray($list[0]); + $this->assertIdentical(5, count($list)); + + $this->assertIdentical(1, (int)$list[0]["Id"]); + $this->assertIdentical(2, (int)$list[1]["Id"]); + $this->assertIdentical(3, (int)$list[2]["Id"]); + $this->assertIdentical(4, (int)$list[3]["Id"]); + $this->assertIdentical(5, (int)$list[4]["Id"]); + } + + /** + * Test QueryForList with Hashtable ResultClass + */ + function testQueryForListWithHashtableResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsAsHashtableViaResultClass"); + + $this->assertAccount1AsHashArray($list[0]); + $this->assertIdentical(5, count($list)); + + $this->assertIdentical(1, (int)$list[0]["Id"]); + $this->assertIdentical(2, (int)$list[1]["Id"]); + $this->assertIdentical(3, (int)$list[2]["Id"]); + $this->assertIdentical(4, (int)$list[3]["Id"]); + $this->assertIdentical(5, (int)$list[4]["Id"]); + } + + /** + * Test QueryForList with IList ResultClass + */ + function testQueryForListWithIListResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsAsArrayListViaResultClass"); + + $listAccount = $list[0]; + + $this->assertIdentical(1,(int)$listAccount[0]); + $this->assertIdentical("Joe",$listAccount[1]); + $this->assertIdentical("Dalton",$listAccount[2]); + $this->assertIdentical("Joe.Dalton@somewhere.com",$listAccount[3]); + + $this->assertIdentical(5, count($list)); + + $listAccount = $list[0]; + $this->assertIdentical(1, (int)$listAccount[0]); + $listAccount = $list[1]; + $this->assertIdentical(2, (int)$listAccount[0]); + $listAccount = $list[2]; + $this->assertIdentical(3, (int)$listAccount[0]); + $listAccount = $list[3]; + $this->assertIdentical(4, (int)$listAccount[0]); + $listAccount = $list[4]; + $this->assertIdentical(5, (int)$listAccount[0]); + } + + /** + * Test QueryForList With ResultMap, result collection as ArrayList + */ + function testQueryForListWithResultMap() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap"); + + $this->assertAccount1($list[0]); + $this->assertIdentical(5, count($list)); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + } + + /** + * Test ExecuteQueryForPaginatedList + */ + function testExecuteQueryForPaginatedList() + { + // Get List of all 5 + $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 2); + + // Test initial state (page 0) + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + + // Test illegal previous page (no effect, state should be same) + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + + // Test next (page 1) + $list->NextPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(3, $list[0]->getID()); + $this->assertIdentical(4, $list[1]->getID()); + + // Test next (page 2 -last) + $list->NextPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + $this->assertIdentical(5, $list[0]->getID()); + + // Test previous (page 1) + $list->PreviousPage(); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(3, $list[0]->getID()); + $this->assertIdentical(4, $list[1]->getID()); + + // Test previous (page 0 -first) + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertAccount1($list[0]); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + + // Test goto (page 0) + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + + // Test goto (page 1) + $list->GotoPage(1); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertTrue($list->getIsNextPageAvailable()); + $this->assertIdentical(2, $list->getCount()); + $this->assertIdentical(3, $list[0]->getID()); + $this->assertIdentical(4, $list[1]->getID()); + + // Test goto (page 2) + $list->GotoPage(2); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + $this->assertIdentical(5, $list[0]->getID()); + + // Test illegal goto (page 0) + $list->GotoPage(3); + $this->assertTrue($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(0, $list->getCount()); + + $list = $this->sqlmap->QueryForPagedList("GetNoAccountsViaResultMap", null, 2); + + // Test empty list + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(0, $list->getCount()); + + // Test next + $list->NextPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(0, $list->getCount()); + + // Test previous + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(0, $list->getCount()); + + // Test previous + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(0, $list->getCount()); + $list = $this->sqlmap->QueryForPagedList("GetFewAccountsViaResultMap", null, 2); + + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + + // Test next + $list->NextPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + // Test previous + $list->PreviousPage(); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + + // Test previous + $list->GotoPage(0); + $this->assertFalse($list->getIsPreviousPageAvailable()); + $this->assertFalse($list->getIsNextPageAvailable()); + $this->assertIdentical(1, $list->getCount()); + + + $list = $this->sqlmap->QueryForPagedList("GetAllAccountsViaResultMap", null, 5); + + $this->assertIdentical(5, $list->getCount()); + + $list->NextPage(); + $this->assertIdentical(5, $list->getCount()); + + $b = $list->getIsPreviousPageAvailable(); + $list->PreviousPage(); + $this->assertIdentical(5, $list->getCount()); + } + + /** + * Test QueryForList with ResultObject : + * AccountCollection strongly typed collection + */ + function testQueryForListWithResultObject() + { + $accounts = new AccountCollection(); + + $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, $accounts); + $this->assertAccount1($accounts[0]); + $this->assertIdentical(5, $accounts->getCount()); + $this->assertIdentical(1, $accounts[0]->getID()); + $this->assertIdentical(2, $accounts[1]->getID()); + $this->assertIdentical(3, $accounts[2]->getID()); + $this->assertIdentical(4, $accounts[3]->getID()); + $this->assertIdentical(5, $accounts[4]->GetId()); + } + + /** + * Test QueryForList with ListClass : LineItemCollection + */ + function testQueryForListWithListClass() + { + $linesItem = $this->sqlmap->QueryForList("GetLineItemsForOrderWithListClass", 10); + + $this->assertNotNull($linesItem); + $this->assertIdentical(2, $linesItem->getCount()); + $this->assertIdentical("ESM-34", $linesItem[0]->getCode()); + $this->assertIdentical("QSM-98", $linesItem[1]->getCode()); + } + + /** + * Test QueryForList with no result. + */ + function testQueryForListWithNoResult() + { + $list = $this->sqlmap->QueryForList("GetNoAccountsViaResultMap"); + + $this->assertIdentical(0, count($list)); + } + + /** + * Test QueryForList with ResultClass : Account. + */ + function testQueryForListResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultClass"); + + $this->assertAccount1($list[0]); + $this->assertIdentical(5, count($list)); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + } + + /** + * Test QueryForList with simple resultClass : string + */ + function testQueryForListWithSimpleResultClass() + { + $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultClass"); + + $this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); + $this->assertIdentical("Averel.Dalton@somewhere.com", $list[1]); + $this->assertIdentical('', $list[2]); + $this->assertIdentical("Jack.Dalton@somewhere.com", $list[3]); + $this->assertIdentical('', $list[4]); + } + + /** + * Test QueryForList with simple ResultMap : string + */ + function testQueryForListWithSimpleResultMap() + { + $list = $this->sqlmap->QueryForList("GetAllEmailAddressesViaResultMap"); + + $this->assertIdentical("Joe.Dalton@somewhere.com", $list[0]); + $this->assertIdentical("Averel.Dalton@somewhere.com", $list[1]); + $this->assertIdentical('', $list[2]); + $this->assertIdentical("Jack.Dalton@somewhere.com", $list[3]); + $this->assertIdentical('', $list[4]); + } + + /** + * Test QueryForListWithSkipAndMax + */ + function testQueryForListWithSkipAndMax() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsViaResultMap", null, null, 2, 2); + + $this->assertIdentical(2, count($list)); + $this->assertIdentical(3, $list[0]->getID()); + $this->assertIdentical(4, $list[1]->getID()); + } + + + /** + * Test row delegate + */ + function testQueryWithRowDelegate() + { + //$handler = new SqlMapper.RowDelegate(this.RowHandler); + + //$list = $this->sqlmap->QueryWithRowDelegate("GetAllAccountsViaResultMap", null, handler); + + //$this->assertIdentical(5, _index); + //$this->assertIdentical(5, $list->getCount()); + //$this->assertAccount1$list[0]); + //$this->assertIdentical(1, $list[0]->getID()); + //$this->assertIdentical(2, $list[1]->getID()); + //$this->assertIdentical(3, $list[2]->getID()); + //$this->assertIdentical(4, $list[3]->getID()); + //$this->assertIdentical(5, $list[4]->getID()); + } + + #endregion + + #region Map Tests + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName"); + + $this->assertIdentical(5, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertIdentical(1, $map["Joe"]->getID()); + $this->assertIdentical(2, $map["Averel"]->getID()); + $this->assertIdentical(3, $map["William"]->getID()); + $this->assertIdentical(4, $map["Jack"]->getID()); + $this->assertIdentical(5, $map["Gilles"]->getID()); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + * + * If the keyProperty is an integer, you must acces the map + * by map[integer] and not by map["integer"] + */ + function testExecuteQueryForMap2() + { + $map = $this->sqlmap->QueryForMap("GetAllOrderWithLineItems", null, "PostalCode"); + + $this->assertIdentical(11, count($map)); + $order = $map["T4H 9G4"]; + + $this->assertIdentical(2, $order->getLineItemsList()->getCount()); + } + + /** + * Test ExecuteQueryForMap with value property : + * "FirstName" as key, "EmailAddress" as value + */ + function testExecuteQueryForMapWithValueProperty() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, + "FirstName", "EmailAddress"); + + $this->assertIdentical(5, count($map)); + + $this->assertIdentical("Joe.Dalton@somewhere.com", $map["Joe"]); + $this->assertIdentical("Averel.Dalton@somewhere.com", $map["Averel"]); + $this->assertNull($map["William"]); + $this->assertIdentical("Jack.Dalton@somewhere.com", $map["Jack"]); + $this->assertNull($map["Gilles"]); + } + + /** + * Test ExecuteQueryForWithJoined + */ + function testExecuteQueryForWithJoined() + { + $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",10); + + $this->assertNotNull($order->getAccount()); + + $order = $this->sqlmap->QueryForObject("GetOrderJoinWithAccount",11); + + $this->assertNull($order->getAccount()); + } + + /** + * Test ExecuteQueryFor With Complex Joined + * + * A->B->C + * ->E + * ->F + */ + function testExecuteQueryForWithComplexJoined() + { + $a = $this->sqlmap->QueryForObject("SelectComplexJoined"); + $this->assertNotNull($a); + $this->assertNotNull($a->getB()); + $this->assertNotNull($a->getB()->getC()); + $this->assertNull($a->getB()->getD()); + $this->assertNotNull($a->getE()); + $this->assertNull($a->getF()); + } + #endregion + + #region Extends statement + + /** + * Test base Extends statement + */ + function testExtendsGetAllAccounts() + { + $list = $this->sqlmap->QueryForList("GetAllAccounts"); + + $this->assertAccount1($list[0]); + $this->assertIdentical(5, count($list)); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + } + + /** + * Test Extends statement GetAllAccountsOrderByName extends GetAllAccounts + */ + function testExtendsGetAllAccountsOrderByName() + { + $list = $this->sqlmap->QueryForList("GetAllAccountsOrderByName"); + + $this->assertAccount1($list[3]); + $this->assertIdentical(5, count($list)); + + $this->assertIdentical(2, $list[0]->getID()); + $this->assertIdentical(5, $list[1]->getID()); + $this->assertIdentical(4, $list[2]->getID()); + $this->assertIdentical(1, $list[3]->getID()); + $this->assertIdentical(3, $list[4]->getID()); + } + + /** + * Test Extends statement GetOneAccount extends GetAllAccounts + */ + function testExtendsGetOneAccount() + { + $account= $this->sqlmap->QueryForObject("GetOneAccount", 1); + $this->assertAccount1($account); + } + + /** + * Test Extends statement GetSomeAccount extends GetAllAccounts + */ + function testExtendsGetSomeAccount() + { + $param["lowID"] = 2; + $param["hightID"] = 4; + + $list = $this->sqlmap->QueryForList("GetSomeAccount", $param); + + $this->assertIdentical(3, count($list)); + + $this->assertIdentical(2, $list[0]->getID()); + $this->assertIdentical(3, $list[1]->getID()); + $this->assertIdentical(4, $list[2]->getID()); + } + + #endregion + + #region Update tests + + + /** + * Test Insert account via public fields + */ + function testInsertAccountViaPublicFields() + { + $this->initScript('account-init.sql'); + + $account = new AccountBis(); + + $account->Id = 10; + $account->FirstName = "Luky"; + $account->LastName = "Luke"; + $account->EmailAddress = "luly.luke@somewhere.com"; + + $this->sqlmap->Insert("InsertAccountViaPublicFields", $account); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 10); + + $this->assertNotNull($testAccount); + + $this->assertIdentical(10, $testAccount->getID()); + + $this->initScript('account-init.sql'); + } + + /** + * + */ + function testInsertOrderViaProperties() + { + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $order = new Order(); + $order->setId(99); + $order->setCardExpiry("09/11"); + $order->setAccount($account); + $order->setCardNumber("154564656"); + $order->setCardType("Visa"); + $order->setCity("Lyon"); + $order->setDate('2005-05-20'); + $order->setPostalCode("69004"); + $order->setProvince("Rhone"); + $order->setStreet("rue Durand"); + + $this->sqlmap->Insert("InsertOrderViaPublicFields", $order); + + $this->initScript('account-init.sql'); + $this->initScript('order-init.sql'); + } + + + /** + * Test Insert account via inline parameters + */ + function testInsertAccountViaInlineParameters() + { + $this->initScript('account-init.sql'); + $account= new Account(); + + $account->setId(10); + $account->setFirstName("Luky"); + $account->setLastName("Luke"); + $account->setEmailAddress("luly.luke@somewhere.com"); + + $this->sqlmap->Insert("InsertAccountViaInlineParameters", $account); + + $testAccount = $this->sqlmap->QueryForObject("GetAccountViaColumnIndex", 10); + + $this->assertNotNull($testAccount); + $this->assertIdentical(10, $testAccount->getId()); + $this->initScript('account-init.sql'); + } + + /** + * Test Insert account via parameterMap + */ + function testInsertAccountViaParameterMap() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountNullableEmail", 6); + $this->AssertAccount6($account); + + $this->initScript('account-init.sql'); + } + + /** + * Test Update via parameterMap + */ + function testUpdateViaParameterMap() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaParameterMap", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Update via parameterMap V2 + */ + function testUpdateViaParameterMap2() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaParameterMap2", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Update with inline parameters + */ + function testUpdateWithInlineParameters() + { + $this->initScript('account-init.sql'); + $account= $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $account->setEmailAddress("new@somewhere.com"); + $this->sqlmap->Update("UpdateAccountViaInlineParameters", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 1); + + $this->assertIdentical("new@somewhere.com", $account->getEmailAddress()); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Update With Parameter Class + */ + function testExecuteUpdateWithParameterClass() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $noRowsDeleted = $this->sqlmap->Update("DeleteAccount", null); + + $this->sqlmap->Update("DeleteAccount", $account); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertNull($account); + $this->assertIdentical(0, $noRowsDeleted); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Delete + */ + function testExecuteDelete() + { + $this->initScript('account-init.sql'); + $account= $this->NewAccount6(); + + $this->sqlmap->Insert("InsertAccountViaParameterMap", $account); + + $account = null; + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertTrue($account->getId() == 6); + + $rowNumber = $this->sqlmap->Delete("DeleteAccount", $account); + $this->assertTrue($rowNumber == 1); + + $account = $this->sqlmap->QueryForObject("GetAccountViaColumnName", 6); + + $this->assertNull($account); + $this->initScript('account-init.sql'); + } + + /** + * Test Execute Delete + */ + function testDeleteWithComments() + { + $this->initScript('line-item-init.sql'); + $rowNumber = $this->sqlmap->Delete("DeleteWithComments"); + + $this->assertIdentical($rowNumber, 2); + $this->initScript('line-item-init.sql'); + } + + + + #endregion + + #region Row delegate + + private $_index = 0; + + function RowHandler($sender, $paramterObject, $list) + { + //_index++; + //$this->assertIdentical(_index, (($account) obj).Id); + //$list->Add(obj); + } + + #endregion + + #region JIRA Tests + + /** + * Test JIRA 30 (repeating property) + */ + function testJIRA30() + { + $account= new Account(); + $account->setId(1); + $account->setFirstName("Joe"); + $account->setLastName("Dalton"); + $account->setEmailAddress("Joe.Dalton@somewhere.com"); + + $result = $this->sqlmap->QueryForObject("GetAccountWithRepeatingProperty", $account); + + $this->assertAccount1($result); + } + + /** + * Test Bit column + */ + function testJIRA42() + { + $other = new Other(); + + $other->setInt(100); + $other->setBool(true); + $other->setLong(789456321); + + $this->sqlmap->Insert("InsertBool", $other); + } + + /** + * Test for access a result map in a different namespace + */ + function testJIRA45() + { + $account= $this->sqlmap->QueryForObject("GetAccountJIRA45", 1); + $this->assertAccount1($account); + } + + /** + * Test : Whitespace is not maintained properly when CDATA tags are used + */ + function testJIRA110() + { + $account= $this->sqlmap->QueryForObject("Get1Account"); + $this->assertAccount1($account); + } + + /** + * Test : Whitespace is not maintained properly when CDATA tags are used + */ + function testJIRA110Bis() + { + $list = $this->sqlmap->QueryForList("GetAccounts"); + + $this->assertAccount1($list[0]); + $this->assertIdentical(5, count($list)); + } + + /** + * Test for cache stats only being calculated on CachingStatments + */ + function testJIRA113() + { + // $this->sqlmap->FlushCaches(); + + // taken from TestFlushDataCache() + // first query is not cached, second query is: 50% cache hit + /*$list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); + $firstId = HashCodeProvider.GetIdentityHashCode(list); + list = $this->sqlmap->QueryForList("GetCachedAccountsViaResultMap"); + int secondId = HashCodeProvider.GetIdentityHashCode(list); + $this->assertIdentical(firstId, secondId); + + string cacheStats = $this->sqlmap->GetDataCacheStats(); + + $this->assertNotNull(cacheStats);*/ + } + + #endregion + + #region CustomTypeHandler tests + + /** + * Test CustomTypeHandler + */ + function testExecuteQueryWithCustomTypeHandler() + { + $this->sqlmap->registerTypeHandler(new HundredsBool()); + $this->sqlmap->registerTypeHandler(new OuiNonBool()); + + $list = $this->sqlmap->QueryForList("GetAllAccountsViaCustomTypeHandler"); + + $this->assertAccount1($list[0]); + $this->assertIdentical(5, count($list)); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + + $this->assertFalse($list[0]->getCartOptions()); + $this->assertFalse($list[1]->getCartOptions()); + $this->assertTrue($list[2]->getCartOptions()); + $this->assertTrue($list[3]->getCartOptions()); + $this->assertTrue($list[4]->getCartOptions()); + + $this->assertTrue($list[0]->getBannerOptions()); + $this->assertTrue($list[1]->getBannerOptions()); + $this->assertFalse($list[2]->getBannerOptions()); + $this->assertFalse($list[3]->getBannerOptions()); + $this->assertTrue($list[4]->getBannerOptions()); + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testCustomTypeHandler() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $this->sqlmap->registerTypeHandler(new OuiNonBool()); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + $this->sqlmap->Insert("InsertCustomTypeHandler", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); + $this->assertNotNull( $anOther ); + $this->assertIdentical(99, (int)$anOther->getInt()); + $this->assertIdentical(1966, (int)$anOther->getLong()); + $this->assertIdentical(true, (boolean)$anOther->getBool()); + $this->assertIdentical(false, (boolean)$anOther->getBool2()); + + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testInsertInlineCustomTypeHandlerV1() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + + $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV1", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByIntV1", 99); + + $this->assertNotNull( $anOther ); + $this->assertIdentical(99, (int)$anOther->getInt()); + $this->assertIdentical(1966, (int)$anOther->getLong()); + $this->assertIdentical(true, (boolean)$anOther->getBool()); + $this->assertIdentical(false, (boolean)$anOther->getBool2()); + + } + + /** + * Test CustomTypeHandler Oui/Non + */ + function testInsertInlineCustomTypeHandlerV2() + { + $this->initScript('other-init.sql'); + $this->initScript('account-init.sql'); + + $other = new Other(); + $other->setInt(99); + $other->setLong(1966); + $other->setBool(true); + $other->setBool2(false); + + $this->sqlmap->Insert("InsertInlineCustomTypeHandlerV2", $other); + + $anOther = $this->sqlmap->QueryForObject("SelectByInt", 99); + + $this->assertNotNull( $anOther ); + $this->assertIdentical(99, (int)$anOther->getInt()); + $this->assertIdentical(1966, (int)$anOther->getLong()); + $this->assertIdentical(true, (boolean)$anOther->getBool()); + $this->assertIdentical(false, (boolean)$anOther->getBool2()); + } + #endregion + /**/ +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/TestQueryForMap.php b/tests/simple_unit/SqlMap/TestQueryForMap.php index 25ef2f4d..89676469 100644 --- a/tests/simple_unit/SqlMap/TestQueryForMap.php +++ b/tests/simple_unit/SqlMap/TestQueryForMap.php @@ -1,43 +1,43 @@ -initSqlMap(); - } - - /** - * Test ExecuteQueryForMap : Hashtable. - */ - function testExecuteQueryForMap() - { - $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName",null,0,2); - $this->assertIdentical(2, count($map)); - $this->assertAccount1($map["Joe"]); - - $this->assertIdentical(1, $map["Joe"]->getID()); - $this->assertIdentical(2, $map["Averel"]->getID()); - } - - /** - * Test ExecuteQueryForMap with value property : - * "FirstName" as key, "EmailAddress" as value - */ - function testExecuteQueryForMapWithValueProperty() - { - $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, - "FirstName", "EmailAddress",1,3); - - $this->assertIdentical(3, count($map)); - - $this->assertIdentical("Averel.Dalton@somewhere.com", $map["Averel"]); - $this->assertNull($map["William"]); - $this->assertIdentical("Jack.Dalton@somewhere.com", $map["Jack"]); - } - -} - +initSqlMap(); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, "FirstName",null,0,2); + $this->assertIdentical(2, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertIdentical(1, $map["Joe"]->getID()); + $this->assertIdentical(2, $map["Averel"]->getID()); + } + + /** + * Test ExecuteQueryForMap with value property : + * "FirstName" as key, "EmailAddress" as value + */ + function testExecuteQueryForMapWithValueProperty() + { + $map = $this->sqlmap->QueryForMap("GetAllAccountsViaResultClass", null, + "FirstName", "EmailAddress",1,3); + + $this->assertIdentical(3, count($map)); + + $this->assertIdentical("Averel.Dalton@somewhere.com", $map["Averel"]); + $this->assertNull($map["William"]); + $this->assertIdentical("Jack.Dalton@somewhere.com", $map["Jack"]); + } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/common.php b/tests/simple_unit/SqlMap/common.php index aaba8c80..5146d123 100644 --- a/tests/simple_unit/SqlMap/common.php +++ b/tests/simple_unit/SqlMap/common.php @@ -1,155 +1,155 @@ - 0) - $connection->createCommand($line)->execute(); - } - } -} - -class CopyFileScriptRunner -{ - protected $baseFile; - protected $targetFile; - - public function __construct($base, $target) - { - $this->baseFile = $base; - $this->targetFile = $target; - } - - function runScript($connection, $script) - { - copy($this->baseFile, $this->targetFile); - } -} - -class SQLiteBaseTestConfig extends BaseTestConfig -{ - protected $baseFile; - protected $targetFile; - - public function __construct() - { - $this->_sqlmapConfigFile = SQLMAP_TESTS.'/sqlite.xml'; - $this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/'; - - $this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db'); - $this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db'); - $file = realpath($this->targetFile); - $this->_connection = new TDbConnection("sqlite:{$file}"); - } - - public function getScriptRunner() - { - return new CopyFileScriptRunner($this->baseFile, $this->targetFile); - } -} - -class MySQLBaseTestConfig extends BaseTestConfig -{ - public function __construct() - { - $this->_sqlmapConfigFile = SQLMAP_TESTS.'/mysql.xml'; - $this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/'; - $this->_features = array('insert_id'); - $dsn = 'mysql:host=localhost;dbname=sqlmap_test;port=3307'; - $this->_connection = new TDbConnection($dsn, 'test5', 'test5'); - } -} - -class MSSQLBaseTestConfig extends BaseTestConfig -{ - public function __construct() - { - $this->_sqlmap = SQLMAP_TESTS.'/mssql.xml'; - $this->_connectionString = 'odbc_mssql://sqlmap_tests'; - $this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/'; - $this->_features = array('insert_id'); - } -} - -class BaseTestConfig -{ - protected $_scriptDir; - protected $_connection; - protected $_sqlmapConfigFile; - - public function hasFeature($type) - { - return false; - } - - public function getScriptDir() - { - return $this->_scriptDir; - } - - public function getConnection() - { - return $this->_connection; - } - - public function getSqlMapConfigFile() - { - return $this->_sqlmapConfigFile; - } - - public function getScriptRunner() - { - return new DefaultScriptRunner(); - } - - public static function createConfigInstance() - { - //change this to connection to a different database - - //return new MySQLBaseTestConfig(); - - return new SQLiteBaseTestConfig(); - - //return new MSSQLBaseTestConfig(); - } -} - - + 0) + $connection->createCommand($line)->execute(); + } + } +} + +class CopyFileScriptRunner +{ + protected $baseFile; + protected $targetFile; + + public function __construct($base, $target) + { + $this->baseFile = $base; + $this->targetFile = $target; + } + + function runScript($connection, $script) + { + copy($this->baseFile, $this->targetFile); + } +} + +class SQLiteBaseTestConfig extends BaseTestConfig +{ + protected $baseFile; + protected $targetFile; + + public function __construct() + { + $this->_sqlmapConfigFile = SQLMAP_TESTS.'/sqlite.xml'; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/sqlite/'; + + $this->targetFile = realpath(SQLMAP_TESTS.'/sqlite/tests.db'); + $this->baseFile = realpath(SQLMAP_TESTS.'/sqlite/backup.db'); + $file = realpath($this->targetFile); + $this->_connection = new TDbConnection("sqlite:{$file}"); + } + + public function getScriptRunner() + { + return new CopyFileScriptRunner($this->baseFile, $this->targetFile); + } +} + +class MySQLBaseTestConfig extends BaseTestConfig +{ + public function __construct() + { + $this->_sqlmapConfigFile = SQLMAP_TESTS.'/mysql.xml'; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/mysql/'; + $this->_features = array('insert_id'); + $dsn = 'mysql:host=localhost;dbname=sqlmap_test;port=3307'; + $this->_connection = new TDbConnection($dsn, 'test5', 'test5'); + } +} + +class MSSQLBaseTestConfig extends BaseTestConfig +{ + public function __construct() + { + $this->_sqlmap = SQLMAP_TESTS.'/mssql.xml'; + $this->_connectionString = 'odbc_mssql://sqlmap_tests'; + $this->_scriptDir = SQLMAP_TESTS.'/scripts/mssql/'; + $this->_features = array('insert_id'); + } +} + +class BaseTestConfig +{ + protected $_scriptDir; + protected $_connection; + protected $_sqlmapConfigFile; + + public function hasFeature($type) + { + return false; + } + + public function getScriptDir() + { + return $this->_scriptDir; + } + + public function getConnection() + { + return $this->_connection; + } + + public function getSqlMapConfigFile() + { + return $this->_sqlmapConfigFile; + } + + public function getScriptRunner() + { + return new DefaultScriptRunner(); + } + + public static function createConfigInstance() + { + //change this to connection to a different database + + //return new MySQLBaseTestConfig(); + + return new SQLiteBaseTestConfig(); + + //return new MSSQLBaseTestConfig(); + } +} + + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/A.php b/tests/simple_unit/SqlMap/domain/A.php index 6830ea4d..af1f925d 100644 --- a/tests/simple_unit/SqlMap/domain/A.php +++ b/tests/simple_unit/SqlMap/domain/A.php @@ -1,27 +1,27 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } - - public function getB(){ return $this->_B; } - public function setB($value){ $this->_B = $value; } - - public function getE(){ return $this->_E; } - public function setE($value){ $this->_E = $value; } - - public function getF(){ return $this->_F; } - public function setF($value){ $this->_F = $value; } -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + + public function getB(){ return $this->_B; } + public function setB($value){ $this->_B = $value; } + + public function getE(){ return $this->_E; } + public function setE($value){ $this->_E = $value; } + + public function getF(){ return $this->_F; } + public function setF($value){ $this->_F = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Account.php b/tests/simple_unit/SqlMap/domain/Account.php index f01726ba..9502eb85 100644 --- a/tests/simple_unit/SqlMap/domain/Account.php +++ b/tests/simple_unit/SqlMap/domain/Account.php @@ -1,36 +1,36 @@ -_ID; } - public function setID($value){ $this->_ID = intval($value); } - - public function getFirstName(){ return $this->_FirstName; } - public function setFirstName($value){ $this->_FirstName = $value; } - - public function getLastName(){ return $this->_LastName; } - public function setLastName($value){ $this->_LastName = $value; } - - public function getEmailAddress(){ return $this->_EmailAddress; } - public function setEmailAddress($value){ $this->_EmailAddress = $value; } - - public function getIDS(){ return $this->_IDS; } - public function setIDS($value){ $this->_IDS = $value; } - - public function getBannerOptions(){ return $this->_BannerOptions; } - public function setBannerOptions($value){ $this->_BannerOptions = $value; } - - public function getCartOptions(){ return $this->_CartOptions; } - public function setCartOptions($value){ $this->_CartOptions = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = intval($value); } + + public function getFirstName(){ return $this->_FirstName; } + public function setFirstName($value){ $this->_FirstName = $value; } + + public function getLastName(){ return $this->_LastName; } + public function setLastName($value){ $this->_LastName = $value; } + + public function getEmailAddress(){ return $this->_EmailAddress; } + public function setEmailAddress($value){ $this->_EmailAddress = $value; } + + public function getIDS(){ return $this->_IDS; } + public function setIDS($value){ $this->_IDS = $value; } + + public function getBannerOptions(){ return $this->_BannerOptions; } + public function setBannerOptions($value){ $this->_BannerOptions = $value; } + + public function getCartOptions(){ return $this->_CartOptions; } + public function setCartOptions($value){ $this->_CartOptions = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/AccountBis.php b/tests/simple_unit/SqlMap/domain/AccountBis.php index 8c96d8e4..d454f2a8 100644 --- a/tests/simple_unit/SqlMap/domain/AccountBis.php +++ b/tests/simple_unit/SqlMap/domain/AccountBis.php @@ -1,13 +1,13 @@ - \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/AccountCollection.php b/tests/simple_unit/SqlMap/domain/AccountCollection.php index 9fc8edb7..b14ece5e 100644 --- a/tests/simple_unit/SqlMap/domain/AccountCollection.php +++ b/tests/simple_unit/SqlMap/domain/AccountCollection.php @@ -1,17 +1,17 @@ -add($account); - } - - public function copyTo(TList $array) - { - $array->copyFrom($this); - } -} - +add($account); + } + + public function copyTo(TList $array) + { + $array->copyFrom($this); + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/B.php b/tests/simple_unit/SqlMap/domain/B.php index a05e21d4..788b804e 100644 --- a/tests/simple_unit/SqlMap/domain/B.php +++ b/tests/simple_unit/SqlMap/domain/B.php @@ -1,23 +1,23 @@ -_C; } - public function setC($value){ $this->_C = $value; } - - public function getD(){ return $this->_D; } - public function setD($value){ $this->_D = $value; } - - public function getID(){ return $this->_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } -} - +_C; } + public function setC($value){ $this->_C = $value; } + + public function getD(){ return $this->_D; } + public function setD($value){ $this->_D = $value; } + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Book.php b/tests/simple_unit/SqlMap/domain/Book.php index cc12c30e..80877112 100644 --- a/tests/simple_unit/SqlMap/domain/Book.php +++ b/tests/simple_unit/SqlMap/domain/Book.php @@ -1,11 +1,11 @@ -_PageNumber; } - public function setPageNumber($value){ $this->_PageNumber = $value; } -} - +_PageNumber; } + public function setPageNumber($value){ $this->_PageNumber = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/C.php b/tests/simple_unit/SqlMap/domain/C.php index 09fb456a..47118d44 100644 --- a/tests/simple_unit/SqlMap/domain/C.php +++ b/tests/simple_unit/SqlMap/domain/C.php @@ -1,15 +1,15 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Category.php b/tests/simple_unit/SqlMap/domain/Category.php index 83fecc7e..db76edb4 100644 --- a/tests/simple_unit/SqlMap/domain/Category.php +++ b/tests/simple_unit/SqlMap/domain/Category.php @@ -1,19 +1,19 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getName(){ return $this->_Name; } - public function setName($value){ $this->_Name = $value; } - - public function getGuidString(){ return $this->_Guid; } - public function setGuidString($value){ $this->_Guid = $value; } -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getName(){ return $this->_Name; } + public function setName($value){ $this->_Name = $value; } + + public function getGuidString(){ return $this->_Guid; } + public function setGuidString($value){ $this->_Guid = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Complex.php b/tests/simple_unit/SqlMap/domain/Complex.php index 92b500f4..99cb04b8 100644 --- a/tests/simple_unit/SqlMap/domain/Complex.php +++ b/tests/simple_unit/SqlMap/domain/Complex.php @@ -1,11 +1,11 @@ -_map; } - public function setMap(TMap $map){ $this->_map = $map; } -} - +_map; } + public function setMap(TMap $map){ $this->_map = $map; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/D.php b/tests/simple_unit/SqlMap/domain/D.php index 5d1baabd..2cbd2883 100644 --- a/tests/simple_unit/SqlMap/domain/D.php +++ b/tests/simple_unit/SqlMap/domain/D.php @@ -1,16 +1,16 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Document.php b/tests/simple_unit/SqlMap/domain/Document.php index 63bcfd33..682f8eb3 100644 --- a/tests/simple_unit/SqlMap/domain/Document.php +++ b/tests/simple_unit/SqlMap/domain/Document.php @@ -1,16 +1,16 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getTitle(){ return $this->_Title; } - public function setTitle($value){ $this->_Title = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getTitle(){ return $this->_Title; } + public function setTitle($value){ $this->_Title = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/DocumentCollection.php b/tests/simple_unit/SqlMap/domain/DocumentCollection.php index c15b6f7d..c130db56 100644 --- a/tests/simple_unit/SqlMap/domain/DocumentCollection.php +++ b/tests/simple_unit/SqlMap/domain/DocumentCollection.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/E.php b/tests/simple_unit/SqlMap/domain/E.php index 2c80bb46..8473c156 100644 --- a/tests/simple_unit/SqlMap/domain/E.php +++ b/tests/simple_unit/SqlMap/domain/E.php @@ -1,16 +1,16 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/F.php b/tests/simple_unit/SqlMap/domain/F.php index b1090cc6..2bbbb2fb 100644 --- a/tests/simple_unit/SqlMap/domain/F.php +++ b/tests/simple_unit/SqlMap/domain/F.php @@ -1,16 +1,16 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getLibelle(){ return $this->_Libelle; } - public function setLibelle($value){ $this->_Libelle = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getLibelle(){ return $this->_Libelle; } + public function setLibelle($value){ $this->_Libelle = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/LineItem.php b/tests/simple_unit/SqlMap/domain/LineItem.php index d851da6c..f6908bbd 100644 --- a/tests/simple_unit/SqlMap/domain/LineItem.php +++ b/tests/simple_unit/SqlMap/domain/LineItem.php @@ -1,32 +1,32 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getOrder(){ return $this->_Order; } - public function setOrder($value){ $this->_Order = $value; } - - public function getCode(){ return $this->_Code; } - public function setCode($value){ $this->_Code = $value; } - - public function getQuantity(){ return $this->_Quantity; } - public function setQuantity($value){ $this->_Quantity = $value; } - - public function getPrice(){ return $this->_Price; } - public function setPrice($value){ $this->_Price = $value; } - - public function getPictureData(){ return $this->_PictureData; } - public function setPictureData($value){ $this->_PictureData = $value; } - -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getOrder(){ return $this->_Order; } + public function setOrder($value){ $this->_Order = $value; } + + public function getCode(){ return $this->_Code; } + public function setCode($value){ $this->_Code = $value; } + + public function getQuantity(){ return $this->_Quantity; } + public function setQuantity($value){ $this->_Quantity = $value; } + + public function getPrice(){ return $this->_Price; } + public function setPrice($value){ $this->_Price = $value; } + + public function getPictureData(){ return $this->_PictureData; } + public function setPictureData($value){ $this->_PictureData = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/LineItemCollection.php b/tests/simple_unit/SqlMap/domain/LineItemCollection.php index f177487c..8bc95622 100644 --- a/tests/simple_unit/SqlMap/domain/LineItemCollection.php +++ b/tests/simple_unit/SqlMap/domain/LineItemCollection.php @@ -1,8 +1,8 @@ - \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Newspaper.php b/tests/simple_unit/SqlMap/domain/Newspaper.php index 4eb56aa2..08716c6d 100644 --- a/tests/simple_unit/SqlMap/domain/Newspaper.php +++ b/tests/simple_unit/SqlMap/domain/Newspaper.php @@ -1,12 +1,12 @@ -_City; } - public function setCity($value){ $this->_City = $value; } - -} - +_City; } + public function setCity($value){ $this->_City = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Order.php b/tests/simple_unit/SqlMap/domain/Order.php index 65d18b13..312626fe 100644 --- a/tests/simple_unit/SqlMap/domain/Order.php +++ b/tests/simple_unit/SqlMap/domain/Order.php @@ -1,71 +1,71 @@ -_LineItemsList = new TList; - $this->_LineItems = new TList; - $this->_FavouriteLineItem = new LineItem; - } - - public function getID(){ return $this->_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getAccount(){ return $this->_Account; } - public function setAccount($value){ $this->_Account = $value; } - - public function getDate(){ return $this->_Date; } - public function setDate($value){ $this->_Date = $value; } - - public function getCardType(){ return $this->_CardType; } - public function setCardType($value){ $this->_CardType = $value; } - - public function getCardExpiry(){ return $this->_CardExpiry; } - public function setCardExpiry($value){ $this->_CardExpiry = $value; } - - public function getCardNumber(){ return $this->_CardNumber; } - public function setCardNumber($value){ $this->_CardNumber = $value; } - - public function getStreet(){ return $this->_Street; } - public function setStreet($value){ $this->_Street = $value; } - - public function getCity(){ return $this->_City; } - public function setCity($value){ $this->_City = $value; } - - public function getProvince(){ return $this->_Province; } - public function setProvince($value){ $this->_Province = $value; } - - public function getPostalCode(){ return $this->_PostalCode; } - public function setPostalCode($value){ $this->_PostalCode = $value; } - - public function getLineItemsList(){ return $this->_LineItemsList; } - public function setLineItemsList($value){ $this->_LineItemsList = $value; } - - public function getLineItems(){ return $this->_LineItems; } - public function setLineItems($value){ $this->_LineItems = $value; } - - public function getLineItemsArray(){ return $this->_LineItemsArray; } - public function setLineItemsArray($value){ $this->_LineItemsArray = $value; } - - public function getFavouriteLineItem(){ return $this->_FavouriteLineItem; } - public function setFavouriteLineItem($value){ $this->_FavouriteLineItem = $value; } - -} - +_LineItemsList = new TList; + $this->_LineItems = new TList; + $this->_FavouriteLineItem = new LineItem; + } + + public function getID(){ return $this->_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getAccount(){ return $this->_Account; } + public function setAccount($value){ $this->_Account = $value; } + + public function getDate(){ return $this->_Date; } + public function setDate($value){ $this->_Date = $value; } + + public function getCardType(){ return $this->_CardType; } + public function setCardType($value){ $this->_CardType = $value; } + + public function getCardExpiry(){ return $this->_CardExpiry; } + public function setCardExpiry($value){ $this->_CardExpiry = $value; } + + public function getCardNumber(){ return $this->_CardNumber; } + public function setCardNumber($value){ $this->_CardNumber = $value; } + + public function getStreet(){ return $this->_Street; } + public function setStreet($value){ $this->_Street = $value; } + + public function getCity(){ return $this->_City; } + public function setCity($value){ $this->_City = $value; } + + public function getProvince(){ return $this->_Province; } + public function setProvince($value){ $this->_Province = $value; } + + public function getPostalCode(){ return $this->_PostalCode; } + public function setPostalCode($value){ $this->_PostalCode = $value; } + + public function getLineItemsList(){ return $this->_LineItemsList; } + public function setLineItemsList($value){ $this->_LineItemsList = $value; } + + public function getLineItems(){ return $this->_LineItems; } + public function setLineItems($value){ $this->_LineItems = $value; } + + public function getLineItemsArray(){ return $this->_LineItemsArray; } + public function setLineItemsArray($value){ $this->_LineItemsArray = $value; } + + public function getFavouriteLineItem(){ return $this->_FavouriteLineItem; } + public function setFavouriteLineItem($value){ $this->_FavouriteLineItem = $value; } + +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Other.php b/tests/simple_unit/SqlMap/domain/Other.php index 32d85e90..9e78ab97 100644 --- a/tests/simple_unit/SqlMap/domain/Other.php +++ b/tests/simple_unit/SqlMap/domain/Other.php @@ -1,23 +1,23 @@ -_Bool2; } - public function setBool2($value){ $this->_Bool2 = $value; } - - public function getBool(){ return $this->_Bool; } - public function setBool($value){ $this->_Bool = $value; } - - public function getInt(){ return $this->_Int; } - public function setInt($value){ $this->_Int = $value; } - - public function getLong(){ return $this->_Long; } - public function setLong($value){ $this->_Long = $value; } -} - +_Bool2; } + public function setBool2($value){ $this->_Bool2 = $value; } + + public function getBool(){ return $this->_Bool; } + public function setBool($value){ $this->_Bool = $value; } + + public function getInt(){ return $this->_Int; } + public function setInt($value){ $this->_Int = $value; } + + public function getLong(){ return $this->_Long; } + public function setLong($value){ $this->_Long = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Sample.php b/tests/simple_unit/SqlMap/domain/Sample.php index c9a34601..e03be2df 100644 --- a/tests/simple_unit/SqlMap/domain/Sample.php +++ b/tests/simple_unit/SqlMap/domain/Sample.php @@ -1,55 +1,55 @@ -_FirstID; } - public function setFirstID($value){ $this->_FirstID = $value; } - - public function getSecondID(){ return $this->_SecondID; } - public function setSecondID($value){ $this->_SecondID = $value; } - - public function getThirdID(){ return $this->_ThirdID; } - public function setThirdID($value){ $this->_ThirdID = $value; } - - public function getFourthID(){ return $this->_FourthID; } - public function setFourthID($value){ $this->_FourthID = $value; } - - public function getFifthID(){ return $this->_FifthID; } - public function setFifthID($value){ $this->_FifthID = $value; } - - public function getSequenceID(){ return $this->_SequenceID; } - public function setSequenceID($value){ $this->_SequenceID = $value; } - - public function getDistributedID(){ return $this->_DistributedID; } - public function setDistributedID($value){ $this->_DistributedID = $value; } - - public function getSampleChar(){ return $this->_SampleChar; } - public function setSampleChar($value){ $this->_SampleChar = $value; } - - public function getSampleDecimal(){ return $this->_SampleDecimal; } - public function setSampleDecimal($value){ $this->_SampleDecimal = $value; } - - public function getSampleMoney(){ return $this->_SampleMoney; } - public function setSampleMoney($value){ $this->_SampleMoney = $value; } - - public function getSampleDate(){ return $this->_SampleDate; } - public function setSampleDate($value){ $this->_SampleDate = $value; } - - public function getSequenceDate(){ return $this->_SequenceDate; } - public function setSequenceDate($value){ $this->_SequenceDate = $value; } -} - +_FirstID; } + public function setFirstID($value){ $this->_FirstID = $value; } + + public function getSecondID(){ return $this->_SecondID; } + public function setSecondID($value){ $this->_SecondID = $value; } + + public function getThirdID(){ return $this->_ThirdID; } + public function setThirdID($value){ $this->_ThirdID = $value; } + + public function getFourthID(){ return $this->_FourthID; } + public function setFourthID($value){ $this->_FourthID = $value; } + + public function getFifthID(){ return $this->_FifthID; } + public function setFifthID($value){ $this->_FifthID = $value; } + + public function getSequenceID(){ return $this->_SequenceID; } + public function setSequenceID($value){ $this->_SequenceID = $value; } + + public function getDistributedID(){ return $this->_DistributedID; } + public function setDistributedID($value){ $this->_DistributedID = $value; } + + public function getSampleChar(){ return $this->_SampleChar; } + public function setSampleChar($value){ $this->_SampleChar = $value; } + + public function getSampleDecimal(){ return $this->_SampleDecimal; } + public function setSampleDecimal($value){ $this->_SampleDecimal = $value; } + + public function getSampleMoney(){ return $this->_SampleMoney; } + public function setSampleMoney($value){ $this->_SampleMoney = $value; } + + public function getSampleDate(){ return $this->_SampleDate; } + public function setSampleDate($value){ $this->_SampleDate = $value; } + + public function getSequenceDate(){ return $this->_SequenceDate; } + public function setSequenceDate($value){ $this->_SequenceDate = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/Search.php b/tests/simple_unit/SqlMap/domain/Search.php index a09ca6e6..c01891a9 100644 --- a/tests/simple_unit/SqlMap/domain/Search.php +++ b/tests/simple_unit/SqlMap/domain/Search.php @@ -1,23 +1,23 @@ -_NumberSearch; } - public function setNumberSearch($value){ $this->_NumberSearch = $value; } - - public function getStartDate(){ return $this->_StartDate; } - public function setStartDate($value){ $this->_StartDate = $value; } - - public function getOperande(){ return $this->_Operande; } - public function setOperande($value){ $this->_Operande = $value; } - - public function getStartDateAnd(){ return $this->_StartDateAnd; } - public function setStartDateAnd($value){ $this->_StartDateAnd = $value; } -} - +_NumberSearch; } + public function setNumberSearch($value){ $this->_NumberSearch = $value; } + + public function getStartDate(){ return $this->_StartDate; } + public function setStartDate($value){ $this->_StartDate = $value; } + + public function getOperande(){ return $this->_Operande; } + public function setOperande($value){ $this->_Operande = $value; } + + public function getStartDateAnd(){ return $this->_StartDateAnd; } + public function setStartDateAnd($value){ $this->_StartDateAnd = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/domain/User.php b/tests/simple_unit/SqlMap/domain/User.php index 0c3a547f..b21712a3 100644 --- a/tests/simple_unit/SqlMap/domain/User.php +++ b/tests/simple_unit/SqlMap/domain/User.php @@ -1,27 +1,27 @@ -_ID; } - public function setID($value){ $this->_ID = $value; } - - public function getUserName(){ return $this->_UserName; } - public function setUserName($value){ $this->_UserName = $value; } - - public function getPassword(){ return $this->_Password; } - public function setPassword($value){ $this->_Password = $value; } - - public function getEmailAddress(){ return $this->_EmailAddress; } - public function setEmailAddress($value){ $this->_EmailAddress = $value; } - - public function getLastLogon(){ return $this->_LastLogon; } - public function setLastLogon($value){ $this->_LastLogon = $value; } -} - +_ID; } + public function setID($value){ $this->_ID = $value; } + + public function getUserName(){ return $this->_UserName; } + public function setUserName($value){ $this->_UserName = $value; } + + public function getPassword(){ return $this->_Password; } + public function setPassword($value){ $this->_Password = $value; } + + public function getEmailAddress(){ return $this->_EmailAddress; } + public function setEmailAddress($value){ $this->_EmailAddress = $value; } + + public function getLastLogon(){ return $this->_LastLogon; } + public function setLastLogon($value){ $this->_LastLogon = $value; } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/gen.php b/tests/simple_unit/SqlMap/gen.php index b7c42271..855172ba 100644 --- a/tests/simple_unit/SqlMap/gen.php +++ b/tests/simple_unit/SqlMap/gen.php @@ -1,33 +1,33 @@ -{$prop}; }\n"; - $setter = "\tpublic function set{$name}(\$value){ \$this->{$prop} = \$value; }\n"; - echo $getter.$setter."\n"; - } -} - +{$prop}; }\n"; + $setter = "\tpublic function set{$name}(\$value){ \$this->{$prop} = \$value; }\n"; + echo $getter.$setter."\n"; + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/SqlMap/queryForListLimitTest.php b/tests/simple_unit/SqlMap/queryForListLimitTest.php index 3937474a..349314a5 100644 --- a/tests/simple_unit/SqlMap/queryForListLimitTest.php +++ b/tests/simple_unit/SqlMap/queryForListLimitTest.php @@ -1,40 +1,40 @@ -initSqlMap(); - - //force autoload - new Account; - } - - function resetDatabase() - { - $this->initScript('account-init.sql'); - } - - function test_accounts_limit_2() - { - $list1 = $this->sqlmap->queryForList('GetAllAccountsAsArrayListViaResultClass',null,null,1,2); - $this->assertEqual(count($list1),2); - - $this->assertEqual($list1[0][0],'2'); - $this->assertEqual($list1[0][1],'Averel'); - $this->assertEqual($list1[0][2],'Dalton'); - - $this->assertEqual($list1[1][0],'3'); - $this->assertEqual($list1[1][1],'William'); - $this->assertEqual($list1[1][2],'Dalton'); - } -} - +initSqlMap(); + + //force autoload + new Account; + } + + function resetDatabase() + { + $this->initScript('account-init.sql'); + } + + function test_accounts_limit_2() + { + $list1 = $this->sqlmap->queryForList('GetAllAccountsAsArrayListViaResultClass',null,null,1,2); + $this->assertEqual(count($list1),2); + + $this->assertEqual($list1[0][0],'2'); + $this->assertEqual($list1[0][1],'Averel'); + $this->assertEqual($list1[0][2],'Dalton'); + + $this->assertEqual($list1[1][0],'3'); + $this->assertEqual($list1[1][1],'William'); + $this->assertEqual($list1[1][2],'Dalton'); + } +} + ?> \ No newline at end of file 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 diff --git a/tests/simple_unit/Tickets/Ticket589Test.php b/tests/simple_unit/Tickets/Ticket589Test.php index 26f4f7ed..2fedda6f 100644 --- a/tests/simple_unit/Tickets/Ticket589Test.php +++ b/tests/simple_unit/Tickets/Ticket589Test.php @@ -1,22 +1,22 @@ -configureXml(dirname(__FILE__).'/sqlmap.xml'); - $this->fail(); - }catch(TSqlMapConfigurationException $e) - { - $expect = 'Invalid property \'parametrClass\' for class \'TSqlMapStatement\' for tag \'assertEqual(strpos($e->getMessage(),$expect),0); - } - } -} - +configureXml(dirname(__FILE__).'/sqlmap.xml'); + $this->fail(); + }catch(TSqlMapConfigurationException $e) + { + $expect = 'Invalid property \'parametrClass\' for class \'TSqlMapStatement\' for tag \'assertEqual(strpos($e->getMessage(),$expect),0); + } + } +} + ?> \ No newline at end of file diff --git a/tests/simple_unit/unit.php b/tests/simple_unit/unit.php index 7e86e925..63910f68 100644 --- a/tests/simple_unit/unit.php +++ b/tests/simple_unit/unit.php @@ -1,9 +1,9 @@ -run(new HtmlReporter()); - +run(new HtmlReporter()); + ?> \ No newline at end of file diff --git a/tests/simple_unit/ws.php b/tests/simple_unit/ws.php index 97e21cad..703235d1 100644 --- a/tests/simple_unit/ws.php +++ b/tests/simple_unit/ws.php @@ -1,9 +1,9 @@ -run(); - +run(); + ?> \ No newline at end of file -- cgit v1.2.3