From a73a73da664206f16e2a2ae9659359288734594b Mon Sep 17 00:00:00 2001 From: jackbravo Date: Sat, 1 Dec 2007 01:21:55 +0000 Subject: [PATCH] Fix tickets #583 and #576 --- lib/Doctrine/Record.php | 6 ++--- tests/Ticket/576TestCase.php | 52 ++++++++++++++++++++++++++++++++++++ tests/Ticket/583TestCase.php | 39 +++++++++++++++++++++++++++ tests/run.php | 2 ++ 4 files changed, 96 insertions(+), 3 deletions(-) create mode 100644 tests/Ticket/576TestCase.php create mode 100644 tests/Ticket/583TestCase.php diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index 209820df4..5ba520c77 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -436,10 +436,10 @@ abstract class Doctrine_Record extends Doctrine_Record_Abstract implements Count $data = array(); foreach ($this->getTable()->getFieldNames() as $fieldName) { - if ( ! isset($tmp[$fieldName])) { - $data[$fieldName] = self::$_null; - } else { + if (isset($tmp[$fieldName])) { $data[$fieldName] = $tmp[$fieldName]; + } else if (!isset($this->_data[$fieldName])) { + $data[$fieldName] = self::$_null; } unset($tmp[$fieldName]); } diff --git a/tests/Ticket/576TestCase.php b/tests/Ticket/576TestCase.php new file mode 100644 index 000000000..d9d500bbc --- /dev/null +++ b/tests/Ticket/576TestCase.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_576_TestCase extends Doctrine_UnitTestCase +{ + public function prepareTables() + { + $this->tables = array('Entity'); + parent::prepareTables(); + } + + public function prepareData() { } + + public function testInit() + { + $entity = new Entity(); + $entity->name = 'myname'; + $entity->loginname = 'test'; + $entity->save(); + } + + public function testBug() + { + // load our user and our collection of pages + $user = Doctrine_Query::create()->from('Entity')->fetchOne(); + $this->assertEqual($user->name, 'myname'); + $this->assertEqual($user->loginname, 'test'); + + $user->name = null; + $this->assertEqual($user->name, null); + + $data = Doctrine_Query::create() + ->select('name') + ->from('Entity') + ->fetchOne(array(), Doctrine::FETCH_ARRAY); + + $user->hydrate($data); + $this->assertEqual($user->name, 'myname'); + $this->assertEqual($user->loginname, 'test'); // <<----- this is what the bug is about + } +} diff --git a/tests/Ticket/583TestCase.php b/tests/Ticket/583TestCase.php new file mode 100644 index 000000000..a4f8cac2e --- /dev/null +++ b/tests/Ticket/583TestCase.php @@ -0,0 +1,39 @@ + + * @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_583_TestCase extends Doctrine_UnitTestCase +{ + public function prepareTables() + { + $this->tables = array('Entity'); + parent::prepareTables(); + } + + public function prepareData() { } + + public function testBug() + { + $entity = new Entity(); + $entity->name = 'myname'; + $entity->save(); + + // load our user and our collection of pages + $user = Doctrine_Query::create()->select('id')->from('Entity')->fetchOne(); + $this->assertEqual($user->name, 'myname'); + + // load our user and our collection of pages + $user = Doctrine_Query::create()->select('*')->from('Entity')->fetchOne(); + $this->assertEqual($user->name, 'myname'); + } +} diff --git a/tests/run.php b/tests/run.php index 994a8a92f..4c29578e6 100644 --- a/tests/run.php +++ b/tests/run.php @@ -15,6 +15,8 @@ $tickets->addTestCase(new Doctrine_Ticket_Njero_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_428_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_480_TestCase()); $tickets->addTestCase(new Doctrine_Ticket_587_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_576_TestCase()); +$tickets->addTestCase(new Doctrine_Ticket_583_TestCase()); //If you write a ticket testcase add it here like shown above! $test->addTestCase($tickets);