Author: jwage Date: 2008-09-25 22:05:15 +0100 (Thu, 25 Sep 2008) New Revision: 4975
Added: branches/1.0/tests/Ticket/1395TestCase.php Modified: branches/1.0/tests/run.php Log: [1.0] Adding coverage for #1395 Added: branches/1.0/tests/Ticket/1395TestCase.php =================================================================== --- branches/1.0/tests/Ticket/1395TestCase.php (rev 0) +++ branches/1.0/tests/Ticket/1395TestCase.php 2008-09-25 21:05:15 UTC (rev 4975) @@ -0,0 +1,97 @@ +<?php +/* + * $Id$ + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * This software consists of voluntary contributions made by many individuals + * and is licensed under the LGPL. For more information, see + * <http://www.phpdoctrine.org>. + */ + +/** + * Doctrine_Ticket_1395_TestCase + * + * @package Doctrine + * @author Konsta Vesterinen <[EMAIL PROTECTED]> + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @category Object Relational Mapping + * @link www.phpdoctrine.org + * @since 1.0 + * @version $Revision$ + */ +class Doctrine_Ticket_1395_TestCase extends Doctrine_UnitTestCase +{ + public function prepareTables() + { + $this->tables = array(); + $this->tables[] = 'T1395_MyModel'; + parent::prepareTables(); + } + + public function prepareData() + { + $myModel = new T1395_MyModel(); + $myModel->dt_created = '2005-10-01'; + $myModel->id = 0; + $myModel->save(); + } + + public function testTicket() + { + try { + $myModel = $this->conn->getTable('T1395_MyModel')->find(0); + $this->assertTrue(isset($myModel->dt_created)); + $this->assertTrue(isset($myModel->days_old)); // This is a calculated field from within the T1395_Listener::preHydrate + $this->assertTrue(isset($myModel->dt_created_tx)); // This is a calculated field from within the T1395_Listener::preHydrate + } catch (Doctrine_Exception $e) { + $this->fail($e->getMessage()); + } + } +} + +class T1395_MyModel extends Doctrine_Record +{ + public function setTableDefinition() + { + $this->hasColumn('id', 'integer', 4, array('primary' => true, 'notnull' => true)); + $this->hasColumn('dt_created', 'date', null, array('alltypes' => array( 0 => 'date', ), 'ntype' => 'date', 'values' => array(), 'primary' => false, 'notnull' => false, 'autoincrement' => false)); + } + + public function setUp() + { + $this->addListener(new T1395_Listener()); + } + +} + +class T1395_Listener extends Doctrine_Record_Listener +{ + public function preHydrate(Doctrine_Event $event) + { + $data = $event->data; + + // Calculate days since creation + $days = (strtotime('now') - strtotime($data['dt_created'])) / (24 * 60 * 60); + $data['days_old'] = number_format($days, 2); + + self::addSomeData($data); + + $event->data = $data; + } + + public static function addSomeData(&$data) + { + $data['dt_created_tx'] = date('M d, Y', strtotime($data['dt_created'])); + } +} \ No newline at end of file Modified: branches/1.0/tests/run.php =================================================================== --- branches/1.0/tests/run.php 2008-09-25 20:09:12 UTC (rev 4974) +++ branches/1.0/tests/run.php 2008-09-25 21:05:15 UTC (rev 4975) @@ -26,6 +26,7 @@ // If you write a ticket testcase add it to the bottom of the list, with the ticket number in it $tickets = new GroupTest('Tickets Tests', 'tickets'); $tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_Ayoub_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_381_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_384_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_424B_TestCase()); @@ -131,10 +132,10 @@ $tickets->addTestCase(new Doctrine_Ticket_1381_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_1383_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_1390_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_1395_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_1400_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_1419_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_1436_TestCase()); -$tickets->addTestCase(new Doctrine_Ticket_1452_TestCase()); $test->addTestCase($tickets); // Connection Tests (not yet fully tested) --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "doctrine-svn" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.co.uk/group/doctrine-svn?hl=en-GB -~----------~----~----~----~------~----~------~--~---
