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); }
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()); }
function testUpdateWhileNoDirtyFields() { $object = new TestOneTableObject(); $object->setAnnotation($initial_annotation = 'some annotation'); $object->setContent($initial_content = 'some content'); $object->save(); $object->setAnnotation('some other annotation'); $object->setContent('some other content'); $object->resetPropertyDirtiness('content'); $object->resetPropertyDirtiness('annotation'); $object->save(); $loaded_object = lmbActiveRecord::findById('TestOneTableObject', $object->getId()); $this->assertEqual($loaded_object->getAnnotation(), $initial_annotation); $this->assertEqual($loaded_object->getContent(), $initial_content); }
function testPassingArrayToConstructorCallsImport() { $source = array('id' => 1000, 'annotation' => 'Some annotation', 'content' => 'Some content'); $object = new TestOneTableObject($source); $this->assertEqual($object->getId(), 1000); $this->assertEqual($object->getAnnotation(), 'Some annotation'); $this->assertEqual($object->getContent(), 'Some content'); }