function _createCourseWithTwoLectures()
 {
     $course = new CourseForTest();
     $course->setTitle($title = 'General Course');
     $l1 = new LectureForTest();
     $l1->setTitle('Physics');
     $l2 = new LectureForTest();
     $l2->setTitle('Math');
     $course->addToLectures($l1);
     $course->addToLectures($l2);
     $course->save();
     return $course;
 }
 function createLecture($course, $alt_course = null, $title = '')
 {
     $lecture = new LectureForTest();
     $title = $title ?: 'Lecture_' . rand(0, 100);
     $lecture->setTitle($title);
     $lecture->setCourse($course);
     if ($alt_course) {
         $lecture->setAltCourse($alt_course);
     }
     $lecture->save();
     return $lecture;
 }
 protected function _createLecture($title = '')
 {
     $title = $title ?: 'Lecture' . mt_rand();
     $l = new LectureForTest();
     $l->setTitle($title);
     return $l;
 }
 function testSetFlushesPreviousCollectionInDatabaseToo()
 {
     $course = $this->_initCourse();
     $l1 = new LectureForTest();
     $l1->setTitle('Physics');
     $l2 = new LectureForTest();
     $l2->setTitle('Math');
     $course->addToLectures($l1);
     $course->addToLectures($l2);
     $course->save();
     $course2 = lmbActiveRecord::findById('CourseForTest', $course->getId());
     $l3 = new LectureForTest();
     $l3->setTitle('Math');
     $course2->setLectures(array($l3));
     $course2->save();
     $course3 = lmbActiveRecord::findById('CourseForTest', $course->getId());
     $lectures = $course3->getLectures();
     $this->assertEqual($lectures->count(), 1);
     $this->assertEqual($lectures->at(0)->getTitle(), $l3->getTitle());
 }
Esempio n. 5
0
 function testSettingExistingParentMakesExistingObjectDirty()
 {
     $course = new CourseForTest();
     $course->setTitle('course');
     $course->save();
     $lecture = new LectureForTest();
     $lecture->setTitle('test');
     $lecture->save();
     $lecture->setCourse($course);
     $this->assertTrue($lecture->isDirty());
     $lecture->save();
     $lecture2 = new LectureForTest($lecture->getId());
     $this->assertEqual($lecture2->getCourse()->getTitle(), $course->getTitle());
 }
Esempio n. 6
0
 function testImportWhereOne2ManyParentIsObject()
 {
     $course = new CourseForTest();
     $course->setTitle('Some course');
     $l = new LectureForTest();
     $l->setTitle('Physics');
     $l->setCourse($course);
     $l->save();
     $source = array('title' => $l->getTitle(), 'course' => $course);
     $l2 = new LectureForTest();
     $l2->import($source);
     $this->assertEqual($l2->getTitle(), $l->getTitle());
     $this->assertEqual($l2->getCourse()->getTitle(), $course->getTitle());
 }