From 8423421973ecfd63bd8f40b49ff0b8bb189ccdd6 Mon Sep 17 00:00:00 2001 From: jackbravo Date: Mon, 3 Sep 2007 21:13:31 +0000 Subject: [PATCH] Added ticket 428 test case using Album model Not using User model since users gets its table cleared before each test method call ($this->objTable()->clear()), and that affects the result --- tests/Ticket/428TestCase.php | 52 ++++++++++++++++++++++++++++++++++++ tests/run.php | 1 + 2 files changed, 53 insertions(+) create mode 100644 tests/Ticket/428TestCase.php diff --git a/tests/Ticket/428TestCase.php b/tests/Ticket/428TestCase.php new file mode 100644 index 000000000..1a560a0fa --- /dev/null +++ b/tests/Ticket/428TestCase.php @@ -0,0 +1,52 @@ + + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.com + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Ticket_428_TestCase extends Doctrine_UnitTestCase +{ + public function prepareData() + { + } + + public function testInitData() + { + // Since the tests do a $this->objTable()->clear() before each method call + // using the User model is not recommended for this test + $albums = new Doctrine_Collection('Album'); + + $albums[0]->name = 'Revolution'; + $albums[0]->Song[0]->title = 'Revolution'; + $albums[0]->Song[1]->title = 'Hey Jude'; + $albums[0]->Song[2]->title = 'Across the Universe'; + $albums[0]->Song[3]->title = 'Michelle'; + $albums->save(); + $this->assertEqual(count($albums[0]->Song), 4); + } + + public function testAggregateValueMappingSupportsLeftJoins() + { + $q = new Doctrine_Query(); + + $q->select('a.name, COUNT(s.id) count')->from('Album a')->leftJoin('a.Song s')->groupby('a.id'); + $albums = $q->execute(); + + // Should not reuse the existing collection in this case + $this->assertEqual(count($albums[0]->Song), 1); + + try { + // Collection[0] should refer to the object with aggregate value + $this->assertEqual($albums[0]['Song'][0]['count'], 4); + } catch (Exception $e) { + $this->fail('count aggregate value should be available'); + } + } +} diff --git a/tests/run.php b/tests/run.php index e94a1b8e8..711152530 100644 --- a/tests/run.php +++ b/tests/run.php @@ -94,6 +94,7 @@ $test = new GroupTest('Doctrine Framework Unit Tests'); //TICKET test cases $tickets = new GroupTest('Tickets tests'); $tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_428_TestCase()); //If you write a ticket testcase add it here like shown above! $test->addTestCase($tickets);