From 70e305a918fcf193009831d4e89aa8c386df3dc4 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Tue, 29 Mar 2016 09:24:08 +0200 Subject: Ported / fixed most old tests --- .../ActiveRecord/ActiveRecordDynamicCallTest.php | 19 +++-- .../Data/ActiveRecord/ActiveRecordFinderTest.php | 8 +- .../Data/ActiveRecord/ActiveRecordMySql5Test.php | 4 +- .../Data/ActiveRecord/BaseActiveRecordTest.php | 22 +---- tests/unit/Data/ActiveRecord/CountRecordsTest.php | 10 +-- tests/unit/Data/ActiveRecord/CriteriaTest.php | 18 ++-- tests/unit/Data/ActiveRecord/DeleteByPkTest.php | 14 ++-- tests/unit/Data/ActiveRecord/FindByPksTest.php | 26 +++--- tests/unit/Data/ActiveRecord/FindBySqlTest.php | 20 +---- tests/unit/Data/ActiveRecord/ForeignKeyTest.php | 95 +++++++++------------- .../Data/ActiveRecord/ForeignObjectUpdateTest.php | 64 +++++++-------- .../Data/ActiveRecord/MultipleForeignKeyTest.php | 71 ++++++++-------- tests/unit/Data/ActiveRecord/RecordEventTest.php | 14 +--- tests/unit/Data/ActiveRecord/SqliteTest.php | 22 ----- tests/unit/Data/ActiveRecord/UserRecordTest.php | 4 +- tests/unit/Data/ActiveRecord/ViewRecordTest.php | 78 ------------------ .../unit/Data/ActiveRecord/records/ItemRecord.php | 2 +- 17 files changed, 173 insertions(+), 318 deletions(-) delete mode 100644 tests/unit/Data/ActiveRecord/SqliteTest.php delete mode 100644 tests/unit/Data/ActiveRecord/ViewRecordTest.php (limited to 'tests/unit/Data/ActiveRecord') diff --git a/tests/unit/Data/ActiveRecord/ActiveRecordDynamicCallTest.php b/tests/unit/Data/ActiveRecord/ActiveRecordDynamicCallTest.php index 1bf98415..8c6b9789 100644 --- a/tests/unit/Data/ActiveRecord/ActiveRecordDynamicCallTest.php +++ b/tests/unit/Data/ActiveRecord/ActiveRecordDynamicCallTest.php @@ -10,7 +10,7 @@ class ActiveRecordDynamicCallTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -45,22 +45,31 @@ class ActiveRecordDynamicCallTest extends PHPUnit_Framework_TestCase } catch(TDbException $e) { - $this->pass(); + return; } + $this->fail(); } function test_dynamic_call_extras_parameters_ok() { $finder = DepartmentRecord::finder(); - $rs = $finder->findByNameAndActive('Marketing',true,true); - $this->assertNotNull($rs); + try + { + $rs = $finder->findByNameAndActive('Marketing',true,true); + $this->fail(); + } + catch(TDbException $e) + { + return; + } + $this->fail(); } function test_dynamic_delete_by() { $finder = DepartmentRecord::finder(); //$finder->RecordManager->OnDelete[] = array($this, 'assertDeleteSql'); - $this->assertEqual($finder->deleteByName('tasds'), 0); + $this->assertEquals($finder->deleteByName('tasds'), 0); } function assertDeleteSql($sender, $param) diff --git a/tests/unit/Data/ActiveRecord/ActiveRecordFinderTest.php b/tests/unit/Data/ActiveRecord/ActiveRecordFinderTest.php index 2209fc6a..f0aae0b8 100644 --- a/tests/unit/Data/ActiveRecord/ActiveRecordFinderTest.php +++ b/tests/unit/Data/ActiveRecord/ActiveRecordFinderTest.php @@ -9,7 +9,7 @@ class ActiveRecordFinderTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -28,18 +28,18 @@ class ActiveRecordFinderTest extends PHPUnit_Framework_TestCase function test_find_by_sql_returns_iterator() { $deps = DepartmentRecord::finder()->findAll('department_id < :id', array('id'=>5)); - $this->assertEqual(count($deps),4); + $this->assertEquals(count($deps),4); } function test_find_by_multiple_parameters() { - $department = DepartmentRecord::finder()->find('department_id < ? AND "order" > ?', 5,2); + $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)); + $department = DepartmentRecord::finder()->find('department_id < ? AND `order` > ?', array(5,2)); $this->assertNotNull($department); } diff --git a/tests/unit/Data/ActiveRecord/ActiveRecordMySql5Test.php b/tests/unit/Data/ActiveRecord/ActiveRecordMySql5Test.php index 31cbed5c..622e5977 100644 --- a/tests/unit/Data/ActiveRecord/ActiveRecordMySql5Test.php +++ b/tests/unit/Data/ActiveRecord/ActiveRecordMySql5Test.php @@ -9,7 +9,7 @@ class ActiveRecordMySql5Test extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('mysql:host=localhost;dbname=ar_test;port=3307', 'test5','test5'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -42,7 +42,7 @@ class ActiveRecordMySql5Test extends PHPUnit_Framework_TestCase { $props = array('blog_id', 'blog_name', 'blog_author'); foreach($props as $prop) - $this->assertEqual($check->{$prop}, $blog->{$prop}); + $this->assertEquals($check->{$prop}, $blog->{$prop}); } } \ No newline at end of file diff --git a/tests/unit/Data/ActiveRecord/BaseActiveRecordTest.php b/tests/unit/Data/ActiveRecord/BaseActiveRecordTest.php index 258fe70c..e39bdc87 100644 --- a/tests/unit/Data/ActiveRecord/BaseActiveRecordTest.php +++ b/tests/unit/Data/ActiveRecord/BaseActiveRecordTest.php @@ -1,34 +1,20 @@ assertIdentical($obj1,$obj2); - } - - function test_finder_throw_exception_when_save() - { - $obj = TActiveRecord::finder('BaseRecordTest'); - try - { - $obj->save(); - $this->fail(); - } - catch(TActiveRecordException $e) - { - $this->pass(); - } + $this->assertSame($obj1,$obj2); } } diff --git a/tests/unit/Data/ActiveRecord/CountRecordsTest.php b/tests/unit/Data/ActiveRecord/CountRecordsTest.php index b97f83ed..bd68393e 100644 --- a/tests/unit/Data/ActiveRecord/CountRecordsTest.php +++ b/tests/unit/Data/ActiveRecord/CountRecordsTest.php @@ -10,27 +10,27 @@ class CountRecordsTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } function test_count() { $finder = DepartmentRecord::finder(); - $count = $finder->count('"order" > ?', 2); + $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); + $count = $finder->count('`order` > ?', 11); + $this->assertEquals($count,0); } function test_count_without_parameter() { $finder = DepartmentRecord::finder(); - $this->assertEqual($finder->count(), 8); + $this->assertEquals($finder->count(), 8); } } diff --git a/tests/unit/Data/ActiveRecord/CriteriaTest.php b/tests/unit/Data/ActiveRecord/CriteriaTest.php index 3c4c15d7..778d2ea7 100644 --- a/tests/unit/Data/ActiveRecord/CriteriaTest.php +++ b/tests/unit/Data/ActiveRecord/CriteriaTest.php @@ -11,7 +11,7 @@ class CriteriaTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -20,9 +20,9 @@ class CriteriaTest extends PHPUnit_Framework_TestCase $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'); + $this->assertEquals(count($records), 8); + $this->assertEquals($records[0]->name, '+GX Service'); + $this->assertEquals($records[7]->name, 'Services'); } function test_orderby_only_desc() @@ -30,22 +30,22 @@ class CriteriaTest extends PHPUnit_Framework_TestCase $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'); + $this->assertEquals(count($records), 8); + $this->assertEquals($records[7]->name, '+GX Service'); + $this->assertEquals($records[0]->name, 'Services'); } function test_criteria_parameters() { $criteria = new TActiveRecordCriteria('sql', "One", "two", 3); $expect = array("One", "two", 3); - $this->assertEqual($criteria->getParameters()->toArray(), $expect); + $this->assertEquals($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); + $this->assertEquals($criteria->getParameters()->toArray(), $expect); } } diff --git a/tests/unit/Data/ActiveRecord/DeleteByPkTest.php b/tests/unit/Data/ActiveRecord/DeleteByPkTest.php index 2f2c09c9..10be32a6 100644 --- a/tests/unit/Data/ActiveRecord/DeleteByPkTest.php +++ b/tests/unit/Data/ActiveRecord/DeleteByPkTest.php @@ -11,23 +11,23 @@ class DeleteByPkTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); 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); + $this->assertEquals($finder->deleteByPk(100),0); + $this->assertEquals($finder->deleteByPk(100, 101),0); + $this->assertEquals($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); + $this->assertEquals($finder->deleteByPk(array(100,101)),0); + $this->assertEquals($finder->deleteByPk(array(100, 101), array(102, 103)),0); + $this->assertEquals($finder->deleteByPk(array(array(100, 101), array(102, 103))),0); } } \ No newline at end of file diff --git a/tests/unit/Data/ActiveRecord/FindByPksTest.php b/tests/unit/Data/ActiveRecord/FindByPksTest.php index 8235352c..b0e9cf93 100644 --- a/tests/unit/Data/ActiveRecord/FindByPksTest.php +++ b/tests/unit/Data/ActiveRecord/FindByPksTest.php @@ -10,7 +10,7 @@ class FindByPksTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -18,39 +18,39 @@ class FindByPksTest extends PHPUnit_Framework_TestCase { $dep = DepartmentRecord::finder()->findByPk(1); $this->assertNotNull($dep); - $this->assertEqual($dep->department_id, 1); + $this->assertEquals($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); + $this->assertEquals($dep->department_id, 1); } function test_find_by_pks() { $deps = DepartmentRecord::finder()->findAllByPks(1,2,4); - $this->assertEqual(count($deps), 3); + $this->assertEquals(count($deps), 3); - $this->assertEqual($deps[0]->department_id, 1); - $this->assertEqual($deps[1]->department_id, 2); - $this->assertEqual($deps[2]->department_id, 4); + $this->assertEquals($deps[0]->department_id, 1); + $this->assertEquals($deps[1]->department_id, 2); + $this->assertEquals($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->assertEquals(count($deps), 2); - $this->assertEqual($deps[0]->department_id, 2); - $this->assertEqual($deps[1]->department_id, 4); + $this->assertEquals($deps[0]->department_id, 2); + $this->assertEquals($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->assertEquals(count($ds), 2); $this->assertIsDepSection($ds[0], 1, 1); $this->assertIsDepSection($ds[1], 2, 5); @@ -59,7 +59,7 @@ class FindByPksTest extends PHPUnit_Framework_TestCase 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); + $this->assertEquals($dep->department_id, $dep_id); + $this->assertEquals($dep->section_id, $sec_id); } } diff --git a/tests/unit/Data/ActiveRecord/FindBySqlTest.php b/tests/unit/Data/ActiveRecord/FindBySqlTest.php index 98113b06..b8020d7e 100644 --- a/tests/unit/Data/ActiveRecord/FindBySqlTest.php +++ b/tests/unit/Data/ActiveRecord/FindBySqlTest.php @@ -3,9 +3,6 @@ Prado::using('System.Data.ActiveRecord.TActiveRecord'); require_once(dirname(__FILE__).'/records/DepartmentRecord.php'); require_once(dirname(__FILE__).'/records/UserRecord.php'); -/** - * @package System.Data.ActiveRecord - */ class UserRecord2 extends UserRecord { public $another_value; @@ -19,11 +16,14 @@ class SqlTest extends TActiveRecord const TABLE='items'; } +/** + * @package System.Data.ActiveRecord + */ class FindBySqlTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -32,16 +32,4 @@ class FindBySqlTest extends PHPUnit_Framework_TestCase $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/unit/Data/ActiveRecord/ForeignKeyTest.php b/tests/unit/Data/ActiveRecord/ForeignKeyTest.php index 99c8b527..58a6e468 100644 --- a/tests/unit/Data/ActiveRecord/ForeignKeyTest.php +++ b/tests/unit/Data/ActiveRecord/ForeignKeyTest.php @@ -3,9 +3,6 @@ Prado::using('System.Data.ActiveRecord.TActiveRecord'); require_once(dirname(__FILE__).'/records/ItemRecord.php'); -/** - * @package System.Data.ActiveRecord - */ abstract class SqliteRecord extends TActiveRecord { protected static $conn; @@ -80,97 +77,85 @@ class Cover extends SqliteRecord public $content; } +/** + * @package System.Data.ActiveRecord + */ class ForeignKeyTest extends PHPUnit_Framework_TestCase { function test_has_many() { $albums = Album::finder()->withTracks()->findAll(); - $this->assertEqual(count($albums), 2); + $this->assertEquals(count($albums), 2); - $this->assertEqual($albums[0]->title, 'Album 1'); - $this->assertEqual($albums[1]->title, 'Album 2'); + $this->assertEquals($albums[0]->title, 'Album 1'); + $this->assertEquals($albums[1]->title, 'Album 2'); - $this->assertEqual(count($albums[0]->Artists), 0); - $this->assertEqual(count($albums[1]->Artists), 0); + $this->assertEquals(count($albums[0]->Artists), 0); + $this->assertEquals(count($albums[1]->Artists), 0); - $this->assertEqual(count($albums[0]->Tracks), 3); - $this->assertEqual(count($albums[1]->Tracks), 2); + $this->assertEquals(count($albums[0]->Tracks), 3); + $this->assertEquals(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->assertEquals($albums[0]->Tracks[0]->song_name, 'Track 1'); + $this->assertEquals($albums[0]->Tracks[1]->song_name, 'Song 2'); + $this->assertEquals($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'); + $this->assertEquals($albums[1]->Tracks[0]->song_name, 'Track A'); + $this->assertEquals($albums[1]->Tracks[1]->song_name, 'Track B'); } function test_has_one() { $albums = Album::finder()->with_cover()->findAll(); - $this->assertEqual(count($albums), 2); + $this->assertEquals(count($albums), 2); - $this->assertEqual($albums[0]->title, 'Album 1'); - $this->assertEqual($albums[1]->title, 'Album 2'); + $this->assertEquals($albums[0]->title, 'Album 1'); + $this->assertEquals($albums[1]->title, 'Album 2'); - $this->assertEqual($albums[0]->cover->content, 'lalala'); - $this->assertEqual($albums[1]->cover->content, 'conver content'); + $this->assertEquals($albums[0]->cover->content, 'lalala'); + $this->assertEquals($albums[1]->cover->content, 'conver content'); - $this->assertEqual(count($albums[0]->Artists), 0); - $this->assertEqual(count($albums[1]->Artists), 0); + $this->assertEquals(count($albums[0]->Artists), 0); + $this->assertEquals(count($albums[1]->Artists), 0); - $this->assertEqual(count($albums[0]->Tracks), 0); - $this->assertEqual(count($albums[1]->Tracks), 0); + $this->assertEquals(count($albums[0]->Tracks), 0); + $this->assertEquals(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"); + $this->assertEquals($track->id, "1"); + $this->assertEquals($track->song_name, "Track 1"); + $this->assertEquals($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->assertEquals($album->title, 'Album 2'); + $this->assertEquals(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'); + $this->assertEquals($album->Artists[0]->name, 'Dan'); + $this->assertEquals($album->Artists[1]->name, 'Karl'); + $this->assertEquals($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->assertEquals($album->title, 'Album 1'); + $this->assertEquals(count($album->Artists), 2); - $this->assertEqual($album->Artists[0]->name, 'Dan'); - $this->assertEqual($album->Artists[1]->name, 'Jenny'); + $this->assertEquals($album->Artists[0]->name, 'Dan'); + $this->assertEquals($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->assertEquals($album->Tracks[0]->song_name, 'Track 1'); + $this->assertEquals($album->Tracks[1]->song_name, 'Song 2'); + $this->assertEquals($album->Tracks[2]->song_name, 'Song 3'); - $this->assertEqual($album->cover->content, 'lalala'); + $this->assertEquals($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/unit/Data/ActiveRecord/ForeignObjectUpdateTest.php b/tests/unit/Data/ActiveRecord/ForeignObjectUpdateTest.php index 8b9d0673..a4790d69 100644 --- a/tests/unit/Data/ActiveRecord/ForeignObjectUpdateTest.php +++ b/tests/unit/Data/ActiveRecord/ForeignObjectUpdateTest.php @@ -1,9 +1,6 @@ OnExecuteCommand[] = array($this,'logger'); } return $conn; @@ -122,10 +119,11 @@ class SkillRecord extends BaseFkRecord { return parent::finder($className); } - - } +/** + * @package System.Data.ActiveRecord + */ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase { function test_add_has_one() @@ -138,15 +136,15 @@ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase //test insert $player2 = PlayerRecord::finder()->withProfile()->findByPk(3); - $this->assertEqual($player2->profile->salary,50000); + $this->assertEquals($player2->profile->salary,50000); $player2->profile->salary = 45000; $player2->save(); - $this->assertEqual($player2->profile->salary,45000); + $this->assertEquals($player2->profile->salary,45000); //test update $player3 = PlayerRecord::finder()->withProfile()->findByPk(3); - $this->assertEqual($player3->profile->salary,45000); + $this->assertEquals($player3->profile->salary,45000); } function test_add_many() @@ -160,27 +158,27 @@ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase //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); + $this->assertEquals(count($team1->players),3); + $this->assertEquals($team1->players[0]->age, 18); + $this->assertEquals($team1->players[1]->age, 20); + $this->assertEquals($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); + $this->assertEquals($team1->players[0]->age, 18); + $this->assertEquals($team1->players[1]->age, 55); + $this->assertEquals($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); + $this->assertEquals(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); + $this->assertEquals($team2->players[0]->age, 55); + $this->assertEquals($team2->players[1]->age, 25); + $this->assertEquals($team2->players[2]->age, 18); } function test_add_belongs_to() @@ -196,8 +194,8 @@ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase $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'); + $this->assertEquals($player1->team->name, 'Team c'); + $this->assertEquals($player1->team->location, 'Sydney'); } function test_add_many_via_association() @@ -213,9 +211,9 @@ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase //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'); + $this->assertEquals(count($player2->skills), 2); + $this->assertEquals($player2->skills[0]->name, 'Bash'); + $this->assertEquals($player2->skills[1]->name, 'Jump'); //test update $player2->skills[1]->name = "Skip"; @@ -226,18 +224,18 @@ class ForeignObjectUpdateTest extends PHPUnit_Framework_TestCase $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'); + $this->assertEquals(count($player3->skills), 3); + $this->assertEquals($player3->skills[0]->name, 'Bash'); + $this->assertEquals($player3->skills[1]->name, 'Push'); + $this->assertEquals($player3->skills[2]->name, 'Skip'); //test lazy load $player4 = PlayerRecord::finder()->findByAge(37); - $this->assertEqual(count($player4->skills), 3); + $this->assertEquals(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'); + $this->assertEquals($player4->skills[0]->name, 'Bash'); + $this->assertEquals($player4->skills[1]->name, 'Skip'); + $this->assertEquals($player4->skills[2]->name, 'Push'); } //*/ } diff --git a/tests/unit/Data/ActiveRecord/MultipleForeignKeyTest.php b/tests/unit/Data/ActiveRecord/MultipleForeignKeyTest.php index d8c54b03..b37559df 100644 --- a/tests/unit/Data/ActiveRecord/MultipleForeignKeyTest.php +++ b/tests/unit/Data/ActiveRecord/MultipleForeignKeyTest.php @@ -2,9 +2,6 @@ Prado::using('System.Data.ActiveRecord.TActiveRecord'); -/** - * @package System.Data.ActiveRecord - */ abstract class MultipleFKSqliteRecord extends TActiveRecord { protected static $conn; @@ -26,6 +23,7 @@ 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; @@ -110,57 +108,60 @@ class CategoryX extends MultipleFKSqliteRecord } } +/** + * @package System.Data.ActiveRecord + */ class MultipleForeignKeyTest extends PHPUnit_Framework_TestCase { 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'); + $this->assertEquals(count($obj), 3); + $this->assertEquals($obj[0]->id, '1'); + $this->assertEquals($obj[1]->id, '2'); + $this->assertEquals($obj[2]->id, '3'); + + $this->assertEquals($obj[0]->object1->id, '1'); + $this->assertEquals($obj[1]->object1->id, '2'); + $this->assertEquals($obj[2]->object1->id, '2'); } function testHasMany() { $obj = Table2::finder()->withState1()->findAll(); - $this->assertEqual(count($obj), 5); + $this->assertEquals(count($obj), 5); - $this->assertEqual(count($obj[0]->state1), 1); - $this->assertEqual($obj[0]->state1[0]->id, '1'); + $this->assertEquals(count($obj[0]->state1), 1); + $this->assertEquals($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->assertEquals(count($obj[1]->state1), 2); + $this->assertEquals($obj[1]->state1[0]->id, '2'); + $this->assertEquals($obj[1]->state1[1]->id, '3'); - $this->assertEqual(count($obj[2]->state1), 0); - $this->assertEqual($obj[2]->id, '3'); + $this->assertEquals(count($obj[2]->state1), 0); + $this->assertEquals($obj[2]->id, '3'); - $this->assertEqual(count($obj[3]->state1), 0); - $this->assertEqual($obj[3]->id, '4'); + $this->assertEquals(count($obj[3]->state1), 0); + $this->assertEquals($obj[3]->id, '4'); } function testHasOne() { $obj = Table2::finder()->withState3('id = 3')->findAll(); - $this->assertEqual(count($obj), 5); + $this->assertEquals(count($obj), 5); - $this->assertEqual($obj[0]->id, '1'); + $this->assertEquals($obj[0]->id, '1'); $this->assertNull($obj[0]->state3); - $this->assertEqual($obj[1]->id, '2'); + $this->assertEquals($obj[1]->id, '2'); $this->assertNull($obj[1]->state3); - $this->assertEqual($obj[2]->id, '3'); + $this->assertEquals($obj[2]->id, '3'); $this->assertNotNull($obj[2]->state3); - $this->assertEqual($obj[2]->state3->id, '3'); + $this->assertEquals($obj[2]->state3->id, '3'); - $this->assertEqual($obj[3]->id, '4'); + $this->assertEquals($obj[3]->id, '4'); $this->assertNull($obj[3]->state3); } @@ -168,14 +169,14 @@ class MultipleForeignKeyTest extends PHPUnit_Framework_TestCase { $obj = CategoryX::finder()->withChild_Categories()->withParent_Category()->findByPk(2); - $this->assertEqual($obj->cat_id, '2'); - $this->assertEqual(count($obj->child_categories), 2); + $this->assertEquals($obj->cat_id, '2'); + $this->assertEquals(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->assertEquals($obj->child_categories[0]->cat_id, 3); + $this->assertEquals($obj->child_categories[1]->cat_id, 4); - $this->assertEqual($obj->parent_category->cat_id, 1); + $this->assertEquals($obj->parent_category->cat_id, 1); } function testLazyLoadingGetterSetter_hasMany() @@ -183,10 +184,10 @@ class MultipleForeignKeyTest extends PHPUnit_Framework_TestCase $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->assertEquals(count($arr->state2), 1); + $this->assertEquals($arr->state2[0]->id, "1"); $this->assertNotNull($arr->state2[0]->object2); - $this->assertEqual($arr->state2[0]->object2->id, "2"); + $this->assertEquals($arr->state2[0]->object2->id, "2"); $this->assertNotIdentical($arr, $arr->state2[0]->object2); } diff --git a/tests/unit/Data/ActiveRecord/RecordEventTest.php b/tests/unit/Data/ActiveRecord/RecordEventTest.php index 0114e0a4..9112bc82 100644 --- a/tests/unit/Data/ActiveRecord/RecordEventTest.php +++ b/tests/unit/Data/ActiveRecord/RecordEventTest.php @@ -9,7 +9,7 @@ class RecordEventTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -19,18 +19,6 @@ class RecordEventTest extends PHPUnit_Framework_TestCase $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/unit/Data/ActiveRecord/SqliteTest.php b/tests/unit/Data/ActiveRecord/SqliteTest.php deleted file mode 100644 index c7f8f515..00000000 --- a/tests/unit/Data/ActiveRecord/SqliteTest.php +++ /dev/null @@ -1,22 +0,0 @@ -setDbConnection($conn); - } - - function test_finder() - { - $finder = SqliteUsers::finder(); - $user = $finder->findByPk('test'); - $this->assertNotNull($user); - } -} diff --git a/tests/unit/Data/ActiveRecord/UserRecordTest.php b/tests/unit/Data/ActiveRecord/UserRecordTest.php index c582e95b..b3992cb4 100644 --- a/tests/unit/Data/ActiveRecord/UserRecordTest.php +++ b/tests/unit/Data/ActiveRecord/UserRecordTest.php @@ -9,7 +9,7 @@ class UserRecordTest extends PHPUnit_Framework_TestCase { function setup() { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); TActiveRecordManager::getInstance()->setDbConnection($conn); } @@ -62,6 +62,6 @@ class UserRecordTest extends PHPUnit_Framework_TestCase 'work_phone', 'work_fax', 'active', 'department_id', 'salutation', 'hint_question', 'hint_answer'); foreach($props as $prop) - $this->assertEqual($user->$prop,$check->$prop); + $this->assertEquals($user->$prop,$check->$prop); } } diff --git a/tests/unit/Data/ActiveRecord/ViewRecordTest.php b/tests/unit/Data/ActiveRecord/ViewRecordTest.php deleted file mode 100644 index f319e45f..00000000 --- a/tests/unit/Data/ActiveRecord/ViewRecordTest.php +++ /dev/null @@ -1,78 +0,0 @@ -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/unit/Data/ActiveRecord/records/ItemRecord.php b/tests/unit/Data/ActiveRecord/records/ItemRecord.php index e6707cde..398b0b69 100644 --- a/tests/unit/Data/ActiveRecord/records/ItemRecord.php +++ b/tests/unit/Data/ActiveRecord/records/ItemRecord.php @@ -29,7 +29,7 @@ class ItemRecord extends TActiveRecord static $conn; if($conn===null) { - $conn = new TDbConnection('pgsql:host=localhost;dbname=test', 'test','test'); + $conn = new TDbConnection('mysql:host=localhost;dbname=prado_unitest', 'prado_unitest','prado_unitest'); $this->OnExecuteCommand[] = array($this,'logger'); } return $conn; -- cgit v1.2.3