[limb-svn] r6298 - in 3.x/trunk/limb/active_record: src tests/cases
svn at limb-project.com
svn at limb-project.com
Fri Sep 14 11:08:03 MSD 2007
Author: pachanga
Date: 2007-09-14 11:08:02 +0400 (Fri, 14 Sep 2007)
New Revision: 6298
URL: http://fisheye.limb-project.com/changelog/limb/?cs=6298
Modified:
3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
3.x/trunk/limb/active_record/tests/cases/lmbARImportTest.class.php
Log:
-- restoring previous implementation of lmbActiveRecord :: import(..). experimental stuff failed
Modified: 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php
===================================================================
--- 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-09-13 20:38:57 UTC (rev 6297)
+++ 3.x/trunk/limb/active_record/src/lmbActiveRecord.class.php 2007-09-14 07:08:02 UTC (rev 6298)
@@ -1692,7 +1692,7 @@
* </code>
* @param array|object
*/
- function import($source, $error_list = null)
+ function import($source)
{
if(is_object($source))
{
@@ -1700,42 +1700,30 @@
{
$this->importRaw($source->exportRaw());
$this->setIsNew($source->isNew());
- return true;//is this assumption correct?
}
else
- return $this->import($source->export(), $error_list);
+ $this->import($source->export());
+ return;
}
- if($error_list)
- $this->_error_list = $error_list;
-
- try
+ foreach($source as $property => $value)
{
- foreach($source as $property => $value)
- {
- if(isset($this->_composed_of[$property]))
- $this->_importValueObject($property, $value);
- elseif(isset($this->_has_many[$property]))
- $this->_importCollection($property, $value, $this->_has_many[$property]['class']);
- elseif(isset($this->_has_many_to_many[$property]))
- $this->_importCollection($property, $value, $this->_has_many_to_many[$property]['class']);
- elseif(isset($this->_belongs_to[$property]))
- $this->_importEntity($property, $value, $this->_belongs_to[$property]['class']);
- elseif(isset($this->_many_belongs_to[$property]))
- $this->_importEntity($property, $value, $this->_many_belongs_to[$property]['class']);
- elseif(isset($this->_has_one[$property]))
- $this->_importEntity($property, $value, $this->_has_one[$property]['class']);
- elseif($this->_canImportProperty($property))
- $this->set($property, $value);
- }
- $this->_onAfterImport();
+ if(isset($this->_composed_of[$property]))
+ $this->_importValueObject($property, $value);
+ elseif(isset($this->_has_many[$property]))
+ $this->_importCollection($property, $value, $this->_has_many[$property]['class']);
+ elseif(isset($this->_has_many_to_many[$property]))
+ $this->_importCollection($property, $value, $this->_has_many_to_many[$property]['class']);
+ elseif(isset($this->_belongs_to[$property]))
+ $this->_importEntity($property, $value, $this->_belongs_to[$property]['class']);
+ elseif(isset($this->_many_belongs_to[$property]))
+ $this->_importEntity($property, $value, $this->_many_belongs_to[$property]['class']);
+ elseif(isset($this->_has_one[$property]))
+ $this->_importEntity($property, $value, $this->_has_one[$property]['class']);
+ elseif($this->_canImportProperty($property))
+ $this->set($property, $value);
}
- catch(Exception $e)
- {
- $this->_error_list->addError($e->getMessage());
- }
-
- return $this->_error_list->isValid();
+ $this->_onAfterImport();
}
/**
* Plain import of data into object
Modified: 3.x/trunk/limb/active_record/tests/cases/lmbARImportTest.class.php
===================================================================
--- 3.x/trunk/limb/active_record/tests/cases/lmbARImportTest.class.php 2007-09-13 20:38:57 UTC (rev 6297)
+++ 3.x/trunk/limb/active_record/tests/cases/lmbARImportTest.class.php 2007-09-14 07:08:02 UTC (rev 6298)
@@ -16,24 +16,15 @@
require_once(dirname(__FILE__) . '/lmbARValueObjectTest.class.php');
require_once(dirname(__FILE__) . '/lmbARAttributesLazyLoadingTest.class.php');
-class LessonForTestWithCustomImporter extends lmbActiveRecord
+class LessonForTestWithCustomImport extends lmbActiveRecord
{
protected $_db_table_name = 'lesson_for_test';
- protected $_composed_of = array('date_start' => array('field' => 'date_start',
- 'class' => 'TestingValueObject',
- 'getter' => 'getValue'),
- 'date_end' => array('field' => 'date_end',
- 'class' => 'TestingValueObject',
- 'getter' => 'getValue'));
public $echo_on_after_import;
- public $raise;
function _onAfterImport()
{
if($this->echo_on_after_import)
echo $this->echo_on_after_import;
- if($this->raise)
- throw new Exception($this->raise);
}
}
@@ -67,8 +58,7 @@
function testImportingObjectCallsItsExportMethod()
{
$object = new TestOneTableObject();
- $res = $object->import(new lmbSet(array('annotation' => 'Some annotation')));
- $this->assertTrue($res);
+ $object->import(new lmbSet(array('annotation' => 'Some annotation')));
$this->assertEqual($object->getAnnotation(), 'Some annotation');
}
@@ -79,8 +69,7 @@
$object1->setAnnotation($annotation = 'Some annotation');
$object2 = new TestOneTableObject();
- $res = $object2->import($object1);
- $this->assertTrue($res);
+ $object2->import($object1);
$this->assertEqual($object2->getId(), $object1->getId());
$this->assertEqual($object2->getAnnotation(), $annotation);
$this->assertTrue($object2->isNew());
@@ -94,8 +83,7 @@
$object1->save();
$object2 = new TestOneTableObject();
- $res = $object2->import($object1);
- $this->assertTrue($res);
+ $object2->import($object1);
$this->assertEqual($object2->getId(), $object1->getId());
$this->assertEqual($object2->getAnnotation(), $annotation);
$this->assertFalse($object2->isNew());
@@ -125,8 +113,7 @@
$object1 = new LazyTestOneTableObject();
$object2 = new LazyTestOneTableObject($object->getId());
- $res = $object1->import($object2);
- $this->assertTrue($res);
+ $object1->import($object2);
$this->assertFalse($object1->hasAttribute('annotation'));
$this->assertEqual($object1->getAnnotation(), $annotation);
$this->assertFalse($object1->hasAttribute('content'));
@@ -143,8 +130,7 @@
'content' => 'Some content',
);
- $res = $object->import($source);
- $this->assertTrue($res);
+ $object->import($source);
$this->assertEqual($object->getId(), 1000);
$this->assertEqual($object->getAnnotation(), 'Some annotation');
$this->assertEqual($object->getContent(), 'Some content');
@@ -163,8 +149,7 @@
'content' => 'Some content',
);
- $res = $object->import($source);
- $this->assertTrue($res);
+ $object->import($source);
$this->assertEqual($object->getId(), $id);
$this->assertNotEqual($object->getId(), 1000);// just one extra check
$this->assertEqual($object->getAnnotation(), 'Some annotation');
@@ -203,8 +188,7 @@
'lectures' => array($l1->getId(), $l2->getId()));
$course2 = new CourseForTest();
- $res = $course2->import($source);
- $this->assertTrue($res);
+ $course2->import($source);
$this->assertEqual($course2->getTitle(), $course->getTitle());
$this->assertEqual($course2->getLectures()->count(), 2);
$this->assertEqual($course2->getLectures()->at(0)->getTitle(), $l1->getTitle());
@@ -230,8 +214,7 @@
'lectures' => array($l1->getId(), $l2));
$course2 = new CourseForTest();
- $res = $course2->import($source);
- $this->assertTrue($res);
+ $course2->import($source);
$this->assertEqual($course2->getTitle(), $course->getTitle());
$this->assertEqual($course2->getLectures()->count(), 2);
$this->assertEqual($course2->getLectures()->at(0)->getTitle(), $l1->getTitle());
@@ -258,8 +241,7 @@
$course2 = new CourseForTest($course->getId());
- $res = $course2->import($source);
- $this->assertTrue($res);
+ $course2->import($source);
$this->assertEqual($course2->getTitle(), $course->getTitle());
$this->assertEqual($course2->getLectures()->count(), 1);
$this->assertEqual($course2->getLectures()->at(0)->getTitle(), $l2->getTitle());
@@ -284,8 +266,7 @@
'users' => array($u2->getId()));
$group2 = new GroupForTest($group->getId());
- $res = $group2->import($source);
- $this->assertTrue($res);
+ $group2->import($source);
$this->assertEqual($group2->getTitle(), $group->getTitle());
$this->assertEqual($group2->getUsers()->count(), 1);
$this->assertEqual($group2->getUsers()->at(0)->getFirstName(), $u2->getFirstName());
@@ -306,8 +287,7 @@
'course' => $course->getId());
$l2 = new LectureForTest();
- $res = $l2->import($source);
- $this->assertTrue($res);
+ $l2->import($source);
$this->assertEqual($l2->getTitle(), $l->getTitle());
$this->assertEqual($l2->getCourse()->getTitle(), $course->getTitle());
@@ -328,8 +308,7 @@
'course' => $course);
$l2 = new LectureForTest();
- $res = $l2->import($source);
- $this->assertTrue($res);
+ $l2->import($source);
$this->assertEqual($l2->getTitle(), $l->getTitle());
$this->assertEqual($l2->getCourse()->getTitle(), $course->getTitle());
}
@@ -352,8 +331,7 @@
'groups' => array($g1->getId(), $g2->getId()));
$user2 = new UserForTest();
- $res = $user2->import($source);
- $this->assertTrue($res);
+ $user2->import($source);
$this->assertEqual($user2->getFirstName(), $user1->getFirstName());
$this->assertEqual($user2->getGroups()->count(), 2);
$this->assertEqual($user2->getGroups()->at(0)->getTitle(), $g1->getTitle());
@@ -378,8 +356,7 @@
'groups' => array($g1->getId(), $g2));
$user2 = new UserForTest();
- $res = $user2->import($source);
- $this->assertTrue($res);
+ $user2->import($source);
$this->assertEqual($user2->getFirstName(), $user1->getFirstName());
$this->assertEqual($user2->getGroups()->count(), 2);
$this->assertEqual($user2->getGroups()->at(0)->getTitle(), $g1->getTitle());
@@ -399,8 +376,7 @@
'person' => $person->getId());
$number2 = new SocialSecurityForTest();
- $res = $number2->import($source);
- $this->assertTrue($res);
+ $number2->import($source);
$this->assertEqual($number2->getCode(), $number->getCode());
$this->assertEqual($number2->getPerson()->getName(), $person->getName());
}
@@ -418,8 +394,7 @@
'person' => $person);
$number2 = new SocialSecurityForTest();
- $res = $number2->import($source);
- $this->assertTrue($res);
+ $number2->import($source);
$this->assertEqual($number2->getCode(), $number->getCode());
$this->assertEqual($number2->getPerson()->getName(), $person->getName());
}
@@ -437,8 +412,7 @@
'social_security' => $number->getId());
$person2 = new PersonForTest();
- $res = $person2->import($source);
- $this->assertTrue($res);
+ $person2->import($source);
$this->assertEqual($person2->getName(), $person->getName());
$this->assertEqual($person2->getSocialSecurity()->getCode(), $number->getCode());
}
@@ -456,8 +430,7 @@
'social_security' => $number);
$person2 = new PersonForTest();
- $res = $person2->import($source);
- $this->assertTrue($res);
+ $person2->import($source);
$this->assertEqual($person2->getName(), $person->getName());
$this->assertEqual($person2->getSocialSecurity()->getCode(), $number->getCode());
}
@@ -475,8 +448,7 @@
'social_security' => null);
$person2 = clone $person;
- $res = $person2->import($source);
- $this->assertTrue($res);
+ $person2->import($source);
$this->assertEqual($person2->getName(), $person->getName());
$this->assertNull($person2->getSocialSecurity());
}
@@ -494,8 +466,7 @@
'social_security' => 'null');
$person2 = clone $person;
- $res = $person2->import($source);
- $this->assertTrue($res);
+ $person2->import($source);
$this->assertEqual($person2->getName(), $person->getName());
$this->assertNull($person2->getSocialSecurity());
}
@@ -513,8 +484,7 @@
'social_security' => '');
$person2 = clone $person;
- $res = $person2->import($source);
- $this->assertTrue($res);
+ $person2->import($source);
$this->assertEqual($person2->getName(), $person->getName());
$this->assertNull($person2->getSocialSecurity());
}
@@ -523,9 +493,8 @@
{
$lesson = new LessonForTest();
- $res = $lesson->import(array('date_start' => $v1 = time() - 100,
+ $lesson->import(array('date_start' => $v1 = time() - 100,
'date_end' => $v2 = time() + 100));
- $this->assertTrue($res);
$this->assertEqual($lesson->getDateStart()->getValue(), $v1);
$this->assertEqual($lesson->getDateEnd()->getValue(), $v2);
@@ -533,7 +502,7 @@
function testOnAfterImport()
{
- $lesson = new LessonForTestWithCustomImporter();
+ $lesson = new LessonForTestWithCustomImport();
$lesson->echo_on_after_import = 'Halo!';
ob_start();
@@ -543,21 +512,6 @@
$this->assertEqual($what, 'Halo!');
}
-
- function testImportWritesExceptionToErrorList()
- {
- $lesson = new LessonForTestWithCustomImporter();
- $lesson->raise = 'Booo';
-
- $res = $lesson->import(array('date_start' => 100));
- $this->assertFalse($res);
-
- $error_list = $lesson->getErrorList();
- $this->assertFalse($error_list->isValid());
-
- $this->assertEqual($error_list[0]->getMessage(), 'Booo');
- $this->assertEqual(sizeof($error_list), 1);
- }
}
More information about the limb-svn
mailing list