diff options
author | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
---|---|---|
committer | Fabio Bas <ctrlaltca@gmail.com> | 2016-03-25 17:55:51 +0100 |
commit | a3388622287e218beddfa14a47ed677d4307b36b (patch) | |
tree | 1b4c7ac8597b1cc798b6683d4a81c90d38de12f6 /tests/simple_unit/ActiveRecord | |
parent | c7fd3e1167b6f2fa7746edbd0fb8f8c1694c61f9 (diff) |
Removed simpletest and moved all tests in the unit tree
Tests are executed now, but a lot of them need fixing.
Diffstat (limited to 'tests/simple_unit/ActiveRecord')
30 files changed, 0 insertions, 1613 deletions
diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php deleted file mode 100644 index 58c9977a..00000000 --- a/tests/simple_unit/ActiveRecord/ActiveRecordDynamicCallTestCase.php +++ /dev/null @@ -1,67 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php deleted file mode 100644 index d9bd7420..00000000 --- a/tests/simple_unit/ActiveRecord/ActiveRecordFinderTestCase.php +++ /dev/null @@ -1,43 +0,0 @@ -<?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); - } - -} diff --git a/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php b/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php deleted file mode 100644 index 09981f43..00000000 --- a/tests/simple_unit/ActiveRecord/ActiveRecordMySql5TestCase.php +++ /dev/null @@ -1,45 +0,0 @@ -<?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 deleted file mode 100644 index 12b0796c..00000000 --- a/tests/simple_unit/ActiveRecord/ActiveRecordRegistryTestCase.php +++ /dev/null @@ -1,165 +0,0 @@ -<?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)); - } - -} diff --git a/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php b/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php deleted file mode 100644 index 676a0dd0..00000000 --- a/tests/simple_unit/ActiveRecord/BaseActiveRecordTestCase.php +++ /dev/null @@ -1,31 +0,0 @@ -<?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(); - } - } -} diff --git a/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php b/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php deleted file mode 100644 index 36a96ab6..00000000 --- a/tests/simple_unit/ActiveRecord/CountRecordsTestCase.php +++ /dev/null @@ -1,33 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/CriteriaTestCase.php b/tests/simple_unit/ActiveRecord/CriteriaTestCase.php deleted file mode 100644 index a320f38c..00000000 --- a/tests/simple_unit/ActiveRecord/CriteriaTestCase.php +++ /dev/null @@ -1,48 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php b/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php deleted file mode 100644 index 0c09a9b0..00000000 --- a/tests/simple_unit/ActiveRecord/DeleteByPkTestCase.php +++ /dev/null @@ -1,30 +0,0 @@ -<?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); - } -}
\ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php b/tests/simple_unit/ActiveRecord/FindByPksTestCase.php deleted file mode 100644 index 32a79cea..00000000 --- a/tests/simple_unit/ActiveRecord/FindByPksTestCase.php +++ /dev/null @@ -1,62 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php b/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php deleted file mode 100644 index 14da0833..00000000 --- a/tests/simple_unit/ActiveRecord/FindBySqlTestCase.php +++ /dev/null @@ -1,44 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php deleted file mode 100644 index 86462ca6..00000000 --- a/tests/simple_unit/ActiveRecord/ForeignKeyTestCase.php +++ /dev/null @@ -1,173 +0,0 @@ -<?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); - } - -} diff --git a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php b/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php deleted file mode 100644 index 29fbff42..00000000 --- a/tests/simple_unit/ActiveRecord/ForeignObjectUpdateTest.php +++ /dev/null @@ -1,240 +0,0 @@ -<?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'); - } -//*/ -} diff --git a/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php b/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php deleted file mode 100644 index 4b149503..00000000 --- a/tests/simple_unit/ActiveRecord/MultipleForeignKeyTestCase.php +++ /dev/null @@ -1,190 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/RecordEventTestCase.php b/tests/simple_unit/ActiveRecord/RecordEventTestCase.php deleted file mode 100644 index 12c57421..00000000 --- a/tests/simple_unit/ActiveRecord/RecordEventTestCase.php +++ /dev/null @@ -1,35 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/SqliteTestCase.php b/tests/simple_unit/ActiveRecord/SqliteTestCase.php deleted file mode 100644 index ed0ea496..00000000 --- a/tests/simple_unit/ActiveRecord/SqliteTestCase.php +++ /dev/null @@ -1,19 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/UserRecordTestCase.php b/tests/simple_unit/ActiveRecord/UserRecordTestCase.php deleted file mode 100644 index 85b12594..00000000 --- a/tests/simple_unit/ActiveRecord/UserRecordTestCase.php +++ /dev/null @@ -1,64 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php b/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php deleted file mode 100644 index bb13a96f..00000000 --- a/tests/simple_unit/ActiveRecord/ViewRecordTestCase.php +++ /dev/null @@ -1,75 +0,0 @@ -<?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(); - } - } -}
\ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/ar_test.db b/tests/simple_unit/ActiveRecord/ar_test.db Binary files differdeleted file mode 100644 index 7549bb66..00000000 --- a/tests/simple_unit/ActiveRecord/ar_test.db +++ /dev/null diff --git a/tests/simple_unit/ActiveRecord/blog.db b/tests/simple_unit/ActiveRecord/blog.db Binary files differdeleted file mode 100644 index 30a9cb7a..00000000 --- a/tests/simple_unit/ActiveRecord/blog.db +++ /dev/null diff --git a/tests/simple_unit/ActiveRecord/fk_tests.db b/tests/simple_unit/ActiveRecord/fk_tests.db Binary files differdeleted file mode 100644 index 87835c84..00000000 --- a/tests/simple_unit/ActiveRecord/fk_tests.db +++ /dev/null diff --git a/tests/simple_unit/ActiveRecord/mysql4text.sql b/tests/simple_unit/ActiveRecord/mysql4text.sql deleted file mode 100644 index 4d61bc81..00000000 --- a/tests/simple_unit/ActiveRecord/mysql4text.sql +++ /dev/null @@ -1,52 +0,0 @@ -CREATE TABLE album (
- title varchar(100) NOT NULL default '',
- PRIMARY KEY (title)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE artist (
- name varchar(25) NOT NULL default '',
- PRIMARY KEY (name)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE album_artists (
- album_title varchar(100) NOT NULL default '',
- artist_name varchar(25) NOT NULL default '',
- PRIMARY KEY (album_title,artist_name),
- KEY FK_album_artists_2 (artist_name)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-CREATE TABLE track (
- id int(11) NOT NULL auto_increment,
- song_name varchar(200) NOT NULL default '',
- album_id varchar(100) NOT NULL default '',
- PRIMARY KEY (id),
- KEY album_id (album_id)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-
-ALTER TABLE album_artists
- ADD CONSTRAINT FK_album_artists_2 FOREIGN KEY (artist_name) REFERENCES artist (name),
- ADD CONSTRAINT FK_album_artists_1 FOREIGN KEY (album_title) REFERENCES album (title);
-
-ALTER TABLE track
- ADD CONSTRAINT track_ibfk_1 FOREIGN KEY (album_id) REFERENCES album (title);
-
-
-INSERT INTO album (title) VALUES ('Album 1');
-INSERT INTO album (title) VALUES ('Album 2');
-
-INSERT INTO artist (name) VALUES ('Dan');
-INSERT INTO artist (name) VALUES ('Jenny');
-INSERT INTO artist (name) VALUES ('Karl');
-INSERT INTO artist (name) VALUES ('Tom');
-
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 1', 'Dan');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Dan');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 1', 'Jenny');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Karl');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Tom');
-
-INSERT INTO track (id, song_name, album_id) VALUES (1, 'Track 1', 'Album 1');
-INSERT INTO track (id, song_name, album_id) VALUES (2, 'Song 2', 'Album 1');
-INSERT INTO track (id, song_name, album_id) VALUES (3, 'Track A', 'Album 2');
-INSERT INTO track (id, song_name, album_id) VALUES (4, 'Track B', 'Album 2');
-INSERT INTO track (id, song_name, album_id) VALUES (5, 'Song 3', 'Album 1');
\ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/records/Blogs.php b/tests/simple_unit/ActiveRecord/records/Blogs.php deleted file mode 100644 index 6523f029..00000000 --- a/tests/simple_unit/ActiveRecord/records/Blogs.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -class Blogs extends TActiveRecord -{ - public $blog_id; - public $blog_name; - public $blog_author; - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/DepSections.php b/tests/simple_unit/ActiveRecord/records/DepSections.php deleted file mode 100644 index bf01ed12..00000000 --- a/tests/simple_unit/ActiveRecord/records/DepSections.php +++ /dev/null @@ -1,14 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php b/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php deleted file mode 100644 index b60c7930..00000000 --- a/tests/simple_unit/ActiveRecord/records/DepartmentRecord.php +++ /dev/null @@ -1,16 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/ItemRecord.php b/tests/simple_unit/ActiveRecord/records/ItemRecord.php deleted file mode 100644 index e6707cde..00000000 --- a/tests/simple_unit/ActiveRecord/records/ItemRecord.php +++ /dev/null @@ -1,47 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/SimpleUser.php b/tests/simple_unit/ActiveRecord/records/SimpleUser.php deleted file mode 100644 index b6748857..00000000 --- a/tests/simple_unit/ActiveRecord/records/SimpleUser.php +++ /dev/null @@ -1,12 +0,0 @@ -<?php -class SimpleUser extends TActiveRecord -{ - public $username; - - const TABLE='simple_users'; - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/SqliteUsers.php b/tests/simple_unit/ActiveRecord/records/SqliteUsers.php deleted file mode 100644 index f8fa12c5..00000000 --- a/tests/simple_unit/ActiveRecord/records/SqliteUsers.php +++ /dev/null @@ -1,14 +0,0 @@ -<?php -class SqliteUsers extends TActiveRecord -{ - public $username; - public $password; - public $email; - - const TABLE='users'; - - public static function finder($className=__CLASS__) - { - return parent::finder($className); - } -} diff --git a/tests/simple_unit/ActiveRecord/records/UserRecord.php b/tests/simple_unit/ActiveRecord/records/UserRecord.php deleted file mode 100644 index 4ef98baf..00000000 --- a/tests/simple_unit/ActiveRecord/records/UserRecord.php +++ /dev/null @@ -1,36 +0,0 @@ -<?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); - } -} diff --git a/tests/simple_unit/ActiveRecord/sqlite.sql b/tests/simple_unit/ActiveRecord/sqlite.sql deleted file mode 100644 index 03e4a1ab..00000000 --- a/tests/simple_unit/ActiveRecord/sqlite.sql +++ /dev/null @@ -1,46 +0,0 @@ -CREATE TABLE album (
- title varchar(100) NOT NULL PRIMARY KEY
-);
-
-CREATE TABLE artist (
- name varchar(25) NOT NULL PRIMARY KEY
-);
-
-CREATE TABLE album_artists (
- album_title varchar(100) NOT NULL CONSTRAINT fk_album REFERENCES album(title) ON DELETE CASCADE,
- artist_name varchar(25) NOT NULL CONSTRAINT fk_artist REFERENCES artist(name) ON DELETE CASCADE
-);
-
-CREATE TABLE track (
- id INTEGER NOT NULL PRIMARY KEY,
- song_name varchar(200) NOT NULL default '',
- album_id varchar(100) NOT NULL CONSTRAINT fk_album_1 REFERENCES album(title) ON DELETE CASCADE
-);
-
-CREATE TABLE cover(
- album varchar(200) NOT NULL CONSTRAINT fk_album_2 REFERENCES album(title) ON DELETE CASCADE,
- content text
-);
-
-INSERT INTO album (title) VALUES ('Album 1');
-INSERT INTO album (title) VALUES ('Album 2');
-
-INSERT INTO cover(album,content) VALUES ('Album 1', 'lalala');
-INSERT INTO cover(album,content) VALUES ('Album 2', 'conver content');
-
-INSERT INTO artist (name) VALUES ('Dan');
-INSERT INTO artist (name) VALUES ('Jenny');
-INSERT INTO artist (name) VALUES ('Karl');
-INSERT INTO artist (name) VALUES ('Tom');
-
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 1', 'Dan');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Dan');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 1', 'Jenny');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Karl');
-INSERT INTO album_artists (album_title, artist_name) VALUES ('Album 2', 'Tom');
-
-INSERT INTO track (id, song_name, album_id) VALUES (1, 'Track 1', 'Album 1');
-INSERT INTO track (id, song_name, album_id) VALUES (2, 'Song 2', 'Album 1');
-INSERT INTO track (id, song_name, album_id) VALUES (3, 'Track A', 'Album 2');
-INSERT INTO track (id, song_name, album_id) VALUES (4, 'Track B', 'Album 2');
-INSERT INTO track (id, song_name, album_id) VALUES (5, 'Song 3', 'Album 1');
\ No newline at end of file diff --git a/tests/simple_unit/ActiveRecord/test1.sqlite b/tests/simple_unit/ActiveRecord/test1.sqlite Binary files differdeleted file mode 100644 index 1e056b52..00000000 --- a/tests/simple_unit/ActiveRecord/test1.sqlite +++ /dev/null |