From 562979c4a8fe47952edf7986d4144624e41630f7 Mon Sep 17 00:00:00 2001 From: wei <> Date: Mon, 4 Dec 2006 02:42:57 +0000 Subject: add unit tests for active record and sqlmap --- tests/simple_unit/SqlMap/DelegateTest.php | 64 +++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 tests/simple_unit/SqlMap/DelegateTest.php (limited to 'tests/simple_unit/SqlMap/DelegateTest.php') diff --git a/tests/simple_unit/SqlMap/DelegateTest.php b/tests/simple_unit/SqlMap/DelegateTest.php new file mode 100644 index 00000000..32c47fd1 --- /dev/null +++ b/tests/simple_unit/SqlMap/DelegateTest.php @@ -0,0 +1,64 @@ +initSqlMap(); + } + + function testListDelegate() + { + $list = $this->sqlmap->queryWithRowDelegate( + "GetAllAccountsViaResultMap", array($this, 'listHandler')); + + $this->assertIdentical(5, count($list)); + $this->assertAccount1($list[0]); + $this->assertIdentical(1, $list[0]->getID()); + $this->assertIdentical(2, $list[1]->getID()); + $this->assertIdentical(3, $list[2]->getID()); + $this->assertIdentical(4, $list[3]->getID()); + $this->assertIdentical(5, $list[4]->getID()); + } + + /** + * Test ExecuteQueryForMap : Hashtable. + */ + function testExecuteQueryForMap() + { + $map = $this->sqlmap->QueryForMapWithRowDelegate( + "GetAllAccountsViaResultClass", array($this, 'mapHandler'), null, "FirstName"); + + $this->assertIdentical(5, count($map)); + $this->assertAccount1($map["Joe"]); + + $this->assertIdentical(1, $map["Joe"]->getID()); + $this->assertIdentical(2, $map["Averel"]->getID()); + $this->assertIdentical(3, $map["William"]->getID()); + $this->assertIdentical(4, $map["Jack"]->getID()); + $this->assertIdentical(5, $map["Gilles"]->getID()); + } + + public function listHandler($sender, $param) + { + $list = &$param->getList(); + $list[] = $param->result; + $this->assertTrue($param->result instanceof Account); + } + + public function mapHandler($sender, $param) + { + $map = &$param->getMap(); + $map[$param->getKey()] = $param->getValue(); + $this->assertTrue($param->getValue() instanceof Account); + } +} + + + +?> \ No newline at end of file -- cgit v1.2.3