summaryrefslogtreecommitdiff
path: root/tests/simple_unit/ActiveRecord
diff options
context:
space:
mode:
authorctrlaltca <>2012-07-12 11:21:01 +0000
committerctrlaltca <>2012-07-12 11:21:01 +0000
commit903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 (patch)
treee08bf04f0823650a231227ac3499121270172a23 /tests/simple_unit/ActiveRecord
parent3e4e6e66aeb3f8fea4e1eb4237498ef9d2358f63 (diff)
standardize the use of unix eol; use svn properties to enforce native eol
Diffstat (limited to 'tests/simple_unit/ActiveRecord')
-rw-r--r--tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php134
-rw-r--r--tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php84
-rw-r--r--tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php88
-rw-r--r--tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php330
-rw-r--r--tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php62
-rw-r--r--tests/simple_unit/ActiveRecord/CountRecordsTestCase.php64
-rw-r--r--tests/simple_unit/ActiveRecord/CriteriaTestCase.php98
-rw-r--r--tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php56
-rw-r--r--tests/simple_unit/ActiveRecord/FindByPksTestCase.php124
-rw-r--r--tests/simple_unit/ActiveRecord/FindBySqlTestCase.php88
-rw-r--r--tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php348
-rw-r--r--tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php482
-rw-r--r--tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php382
-rw-r--r--tests/simple_unit/ActiveRecord/RecordEventTestCase.php72
-rw-r--r--tests/simple_unit/ActiveRecord/SqliteTestCase.php38
-rw-r--r--tests/simple_unit/ActiveRecord/UserRecordTestCase.php130
-rw-r--r--tests/simple_unit/ActiveRecord/ViewRecordTestCase.php146
-rw-r--r--tests/simple_unit/ActiveRecord/records/Blogs.php24
-rw-r--r--tests/simple_unit/ActiveRecord/records/DepSections.php28
-rw-r--r--tests/simple_unit/ActiveRecord/records/DepartmentRecord.php32
-rw-r--r--tests/simple_unit/ActiveRecord/records/ItemRecord.php96
-rw-r--r--tests/simple_unit/ActiveRecord/records/SimpleUser.php24
-rw-r--r--tests/simple_unit/ActiveRecord/records/SqliteUsers.php28
-rw-r--r--tests/simple_unit/ActiveRecord/records/UserRecord.php72
24 files changed, 1515 insertions, 1515 deletions
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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
-require_once(dirname(__FILE__).'/records/DepSections.php');
-
-class ActiveRecordDynamicCallTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->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);
- }
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
+require_once(dirname(__FILE__).'/records/DepSections.php');
+
+class ActiveRecordDynamicCallTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->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 @@
<?php
-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);
- }
-
-}
+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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/Blogs.php');
-
-class ActiveRecordMySql5TestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('mysql:host=localhost;dbname=ar_test;port=3307', 'test5','test5');
- TActiveRecordManager::getInstance()->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});
- }
-
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/Blogs.php');
+
+class ActiveRecordMySql5TestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('mysql:host=localhost;dbname=ar_test;port=3307', 'test5','test5');
+ TActiveRecordManager::getInstance()->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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecordStateRegistry');
-Prado::using('System.Data.ActiveRecord.Exceptions.*');
-
-class StateTestObject
-{
- public $propA = 'a';
- public $propB;
-}
-
-class ActiveRecordRegistryTestCase extends UnitTestCase
-{
- function test_new_object()
- {
- $obj = new StateTestObject();
- $registry = new TActiveRecordStateRegistry();
-
- $this->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));
- }
-
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecordStateRegistry');
+Prado::using('System.Data.ActiveRecord.Exceptions.*');
+
+class StateTestObject
+{
+ public $propA = 'a';
+ public $propB;
+}
+
+class ActiveRecordRegistryTestCase extends UnitTestCase
+{
+ function test_new_object()
+ {
+ $obj = new StateTestObject();
+ $registry = new TActiveRecordStateRegistry();
+
+ $this->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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-
-class BaseRecordTest extends TActiveRecord
-{
-
-}
-
-class BaseActiveRecordTestCase extends UnitTestCase
-{
- function test_finder_returns_same_instance()
- {
- $obj1 = TActiveRecord::finder('BaseRecordTest');
- $obj2 = TActiveRecord::finder('BaseRecordTest');
- $this->assertIdentical($obj1,$obj2);
- }
-
- function test_finder_throw_exception_when_save()
- {
- $obj = TActiveRecord::finder('BaseRecordTest');
- try
- {
- $obj->save();
- $this->fail();
- }
- catch(TActiveRecordException $e)
- {
- $this->pass();
- }
- }
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+class BaseRecordTest extends TActiveRecord
+{
+
+}
+
+class BaseActiveRecordTestCase extends UnitTestCase
+{
+ function test_finder_returns_same_instance()
+ {
+ $obj1 = TActiveRecord::finder('BaseRecordTest');
+ $obj2 = TActiveRecord::finder('BaseRecordTest');
+ $this->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 @@
<?php
-
-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);
- }
-}
+
+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 @@
-<?php
-
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
-require_once(dirname(__FILE__).'/records/DepSections.php');
-
-class CriteriaTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->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);
- }
-}
-
+<?php
+
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
+require_once(dirname(__FILE__).'/records/DepSections.php');
+
+class CriteriaTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->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 @@
<?php
-
-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);
- }
+
+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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
-require_once(dirname(__FILE__).'/records/DepSections.php');
-
-class FindByPksTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->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);
- }
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
+require_once(dirname(__FILE__).'/records/DepSections.php');
+
+class FindByPksTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
-require_once(dirname(__FILE__).'/records/UserRecord.php');
-
-class UserRecord2 extends UserRecord
-{
- public $another_value;
-}
-
-class SqlTest extends TActiveRecord
-{
- public $category;
- public $item;
-
- const TABLE='items';
-}
-
-class FindBySqlTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->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);
- }
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/DepartmentRecord.php');
+require_once(dirname(__FILE__).'/records/UserRecord.php');
+
+class UserRecord2 extends UserRecord
+{
+ public $another_value;
+}
+
+class SqlTest extends TActiveRecord
+{
+ public $category;
+ public $item;
+
+ const TABLE='items';
+}
+
+class FindBySqlTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->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 @@
-<?php
-
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/ItemRecord.php');
-
-abstract class SqliteRecord extends TActiveRecord
-{
- protected static $conn;
-
- public function getDbConnection()
- {
- if(self::$conn===null)
- self::$conn = new TDbConnection('sqlite:'.dirname(__FILE__).'/fk_tests.db');
- return self::$conn;
- }
-}
-
-class Album extends SqliteRecord
-{
- public $title;
-
- public $Tracks = array();
- public $Artists = array();
-
- public $cover;
-
- public static $RELATIONS = array(
- 'Tracks' => 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);
- }
-
-}
-
+<?php
+
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/ItemRecord.php');
+
+abstract class SqliteRecord extends TActiveRecord
+{
+ protected static $conn;
+
+ public function getDbConnection()
+ {
+ if(self::$conn===null)
+ self::$conn = new TDbConnection('sqlite:'.dirname(__FILE__).'/fk_tests.db');
+ return self::$conn;
+ }
+}
+
+class Album extends SqliteRecord
+{
+ public $title;
+
+ public $Tracks = array();
+ public $Artists = array();
+
+ public $cover;
+
+ public static $RELATIONS = array(
+ 'Tracks' => 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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-
-class BaseFkRecord extends TActiveRecord
-{
- 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;
- }
-
- 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');
- }
-//*/
-}
-
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+class BaseFkRecord extends TActiveRecord
+{
+ 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;
+ }
+
+ 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 @@
-<?php
-
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-
-abstract class MultipleFKSqliteRecord extends TActiveRecord
-{
- protected static $conn;
-
- public function getDbConnection()
- {
- if(self::$conn===null)
- self::$conn = new TDbConnection('sqlite:'.dirname(__FILE__).'/test1.sqlite');
- return self::$conn;
- }
-}
-
-/**
- *
-CREATE TABLE table1 (
-id integer PRIMARY KEY AUTOINCREMENT,
-field1 varchar,
-fk1 integer CONSTRAINT fk_id1 REFERENCES table2(id) ON DELETE CASCADE,
-fk2 integer CONSTRAINT fk_id2 REFERENCES table2(id) ON DELETE CASCADE,
-fk3 integer CONSTRAINT fk_id3 REFERENCES table2(id) ON DELETE CASCADE)
- */
-class Table1 extends MultipleFKSqliteRecord
-{
- public $id;
- public $field1;
- public $fk1;
- public $fk2;
- public $fk3;
-
- public $object1;
- //public $object2; //commented out for testing __get/__set
- public $object3;
-
- public static $RELATIONS = array
- (
- 'object1' => 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);
- }
-}
-
+<?php
+
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+
+abstract class MultipleFKSqliteRecord extends TActiveRecord
+{
+ protected static $conn;
+
+ public function getDbConnection()
+ {
+ if(self::$conn===null)
+ self::$conn = new TDbConnection('sqlite:'.dirname(__FILE__).'/test1.sqlite');
+ return self::$conn;
+ }
+}
+
+/**
+ *
+CREATE TABLE table1 (
+id integer PRIMARY KEY AUTOINCREMENT,
+field1 varchar,
+fk1 integer CONSTRAINT fk_id1 REFERENCES table2(id) ON DELETE CASCADE,
+fk2 integer CONSTRAINT fk_id2 REFERENCES table2(id) ON DELETE CASCADE,
+fk3 integer CONSTRAINT fk_id3 REFERENCES table2(id) ON DELETE CASCADE)
+ */
+class Table1 extends MultipleFKSqliteRecord
+{
+ public $id;
+ public $field1;
+ public $fk1;
+ public $fk2;
+ public $fk3;
+
+ public $object1;
+ //public $object2; //commented out for testing __get/__set
+ public $object3;
+
+ public static $RELATIONS = array
+ (
+ 'object1' => 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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/UserRecord.php');
-
-class RecordEventTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->setDbConnection($conn);
- }
-
- function testFindByPk()
- {
- $user1 = UserRecord::finder()->findByPk('admin');
- $this->assertNotNull($user1);
- }
-
- function test_same_data_returns_same_object()
- {
- $criteria = new TActiveRecordCriteria('username = ?', 'admin');
- $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);
- }
-}
-
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/UserRecord.php');
+
+class RecordEventTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->setDbConnection($conn);
+ }
+
+ function testFindByPk()
+ {
+ $user1 = UserRecord::finder()->findByPk('admin');
+ $this->assertNotNull($user1);
+ }
+
+ function test_same_data_returns_same_object()
+ {
+ $criteria = new TActiveRecordCriteria('username = ?', 'admin');
+ $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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/SqliteUsers.php');
-
-class SqliteTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('sqlite2:'.dirname(__FILE__).'/ar_test.db');
- TActiveRecordManager::getInstance()->setDbConnection($conn);
- }
-
- function test_finder()
- {
- $finder = SqliteUsers::finder();
- $user = $finder->findByPk('test');
- $this->assertNotNull($user);
- }
-}
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/SqliteUsers.php');
+
+class SqliteTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('sqlite2:'.dirname(__FILE__).'/ar_test.db');
+ TActiveRecordManager::getInstance()->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 @@
-<?php
-Prado::using('System.Data.ActiveRecord.TActiveRecord');
-require_once(dirname(__FILE__).'/records/UserRecord.php');
-
-class UserRecordTestCase extends UnitTestCase
-{
- function setup()
- {
- $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
- TActiveRecordManager::getInstance()->setDbConnection($conn);
- }
-
- function testFindByPk()
- {
- $user1 = UserRecord::finder()->findByPk('admin');
- $this->assertNotNull($user1);
- }
-
- function test_same_data_returns_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);
- }
-}
-
+<?php
+Prado::using('System.Data.ActiveRecord.TActiveRecord');
+require_once(dirname(__FILE__).'/records/UserRecord.php');
+
+class UserRecordTestCase extends UnitTestCase
+{
+ function setup()
+ {
+ $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test');
+ TActiveRecordManager::getInstance()->setDbConnection($conn);
+ }
+
+ function testFindByPk()
+ {
+ $user1 = UserRecord::finder()->findByPk('admin');
+ $this->assertNotNull($user1);
+ }
+
+ function test_same_data_returns_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 @@
<?php
-
-
-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();
- }
- }
+
+
+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 @@
-<?php
-class Blogs extends TActiveRecord
-{
- public $blog_id;
- public $blog_name;
- public $blog_author;
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class Blogs extends TActiveRecord
+{
+ public $blog_id;
+ public $blog_name;
+ public $blog_author;
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
?> \ 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 @@
-<?php
-class DepSections extends TActiveRecord
-{
- public $department_id;
- public $section_id;
- public $order;
-
- const TABLE='department_sections';
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class DepSections extends TActiveRecord
+{
+ public $department_id;
+ public $section_id;
+ public $order;
+
+ const TABLE='department_sections';
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
?> \ 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 @@
-<?php
-class DepartmentRecord extends TActiveRecord
-{
- public $department_id;
- public $name;
- public $description;
- public $active;
- public $order;
-
- const TABLE = 'departments';
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class DepartmentRecord extends TActiveRecord
+{
+ public $department_id;
+ public $name;
+ public $description;
+ public $active;
+ public $order;
+
+ const TABLE = 'departments';
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
?> \ 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 @@
-<?php
-
-class ItemRecord extends TActiveRecord
-{
- const TABLE='items';
- public $item_id;
- public $name;
- public $brand_specific;
- public $description;
- public $meta;
- public $active;
- public $need_review;
- public $category_id;
- public $type_id;
- public $content;
- public $standard_id;
- public $timestamp;
-
- public $related_items = array();
- public $related_item_id;
-
- public static $RELATIONS=array
- (
- 'related_items' => 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);
- }
-}
-
+<?php
+
+class ItemRecord extends TActiveRecord
+{
+ const TABLE='items';
+ public $item_id;
+ public $name;
+ public $brand_specific;
+ public $description;
+ public $meta;
+ public $active;
+ public $need_review;
+ public $category_id;
+ public $type_id;
+ public $content;
+ public $standard_id;
+ public $timestamp;
+
+ public $related_items = array();
+ public $related_item_id;
+
+ public static $RELATIONS=array
+ (
+ 'related_items' => 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 @@
-<?php
-class SimpleUser extends TActiveRecord
-{
- public $username;
-
- const TABLE='simple_users';
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class SimpleUser extends TActiveRecord
+{
+ public $username;
+
+ const TABLE='simple_users';
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
?> \ 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 @@
-<?php
-class SqliteUsers extends TActiveRecord
-{
- public $username;
- public $password;
- public $email;
-
- const TABLE='users';
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class SqliteUsers extends TActiveRecord
+{
+ public $username;
+ public $password;
+ public $email;
+
+ const TABLE='users';
+
+ public static function finder($className=__CLASS__)
+ {
+ return parent::finder($className);
+ }
+}
?> \ 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 @@
-<?php
-class UserRecord extends TActiveRecord
-{
- public $username;
- public $password;
- public $email;
- public $first_name;
- public $last_name;
- public $job_title;
- public $work_phone;
- public $work_fax;
- public $active=true;
- public $department_id;
- public $salutation;
- public $hint_question;
- public $hint_answer;
-
- private $_level=-1;
-
- const TABLE='users';
-
- public function getLevel()
- {
- return $this->_level;
- }
-
- public function setLevel($level)
- {
- $this->_level=TPropertyValue::ensureInteger($level);
- }
-
- public static function finder($className=__CLASS__)
- {
- return parent::finder($className);
- }
-}
+<?php
+class UserRecord extends TActiveRecord
+{
+ public $username;
+ public $password;
+ public $email;
+ public $first_name;
+ public $last_name;
+ public $job_title;
+ public $work_phone;
+ public $work_fax;
+ public $active=true;
+ public $department_id;
+ public $salutation;
+ public $hint_question;
+ public $hint_answer;
+
+ private $_level=-1;
+
+ const TABLE='users';
+
+ public function getLevel()
+ {
+ return $this->_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