コード例 #1
0
 function testCustomLazyFieldsInFindFirst()
 {
     $object = new TestOneTableObject();
     $object->setAnnotation($annotation = "Annotation");
     $object->setContent($content = "Content");
     $object->save();
     $object2 = lmbActiveRecord::findFirst('TestOneTableObject', array('fields' => array('annotation')));
     $fields = $object2->exportRaw();
     //checking which props were actually loaded
     $this->assertEqual($fields, array('id' => $object->getId(), 'annotation' => $annotation));
     //lazy loading in action
     $this->assertEqual($object2->getAnnotation(), $annotation);
     $this->assertEqual($object2->getContent(), $content);
 }
コード例 #2
0
 function testSettingSameTablePropertyValueDoesntMakeObjectDirty()
 {
     $object = new TestOneTableObject();
     $object->setContent('whatever');
     $object->save();
     $this->assertFalse($object->isDirty());
     $object->setContent($object->getContent());
     $this->assertFalse($object->isDirty());
     $object->setContent('whatever else');
     $this->assertTrue($object->isDirty());
 }
コード例 #3
0
 function testDestroyRecordForGlobalListener()
 {
     $object = new TestOneTableObject();
     $object->set('annotation', 'Super annotation');
     $object->set('content', 'Super content');
     $object->set('news_date', '2005-01-10');
     $object->save();
     $delegate = new lmbActiveRecordEventHaldlerStubDelegate();
     $delegate->subscribeGloballyForEvents($object);
     $object->destroy();
     $this->assertEqual($delegate->getCallsOrder(), '|onBeforeDestroy TestOneTableObject||onAfterDestroy TestOneTableObject|');
 }
コード例 #4
0
 function testSaveNewRecord()
 {
     $object = new TestOneTableObject();
     $object->set('annotation', $annotation = 'Super annotation');
     $object->set('content', $content = 'Super content');
     $object->set('news_date', $news_date = '2005-01-10');
     $this->assertTrue($object->isNew());
     $id = $object->save();
     $this->assertFalse($object->isNew());
     $this->assertNotNull($object->getId());
     $this->assertEqual($object->getId(), $id);
     $this->assertEqual($this->db->count('test_one_table_object'), 1);
     $record = $this->db->selectRecord('test_one_table_object');
     $this->assertEqual($record->get('id'), $id);
     $this->assertEqual($record->get('annotation'), $annotation);
     $this->assertEqual($record->get('content'), $content);
     $this->assertEqual($record->get('news_date'), $news_date);
     $this->assertEqual($record->get('id'), $object->getId());
 }
コード例 #5
0
 function testImportPreservesIdOfExistingObject()
 {
     $object = new TestOneTableObject();
     $object->setAnnotation('Initial annotation');
     $object->save();
     $id = $object->getId();
     $source = array('id' => 10000, 'annotation' => 'Some annotation', 'content' => 'Some content');
     $object->import($source);
     $this->assertEqual($object->getId(), $id);
     $this->assertNotEqual($object->getId(), 1000);
     // just one extra check
     $this->assertEqual($object->getAnnotation(), 'Some annotation');
     $this->assertEqual($object->getContent(), 'Some content');
 }