예제 #1
0
 function test_snapshots()
 {
     $s = new Dataface_Record('Profiles', array());
     $snapshot =& $s->getSnapshot();
     //$this->assertTrue(is_array($snapshot));
     /*$temp = array();
     		
     		foreach ( array_keys($snapshot) as $key){
     			if ( strlen($snapshot[$key]) > 0 ) $temp[$key] = $snapshot[$key];
     		}
     		
     		$this->assertEquals(array(), $temp);
     		*/
     $this->assertEquals(null, $snapshot);
     $s->setValue('id', 10);
     $s->setSnapshot();
     $this->assertTrue($s->snapshotExists());
     $expected = array();
     foreach (array_keys($s->_table->fields()) as $field) {
         $expected[$field] = null;
     }
     $expected['id'] = 10;
     $this->assertEquals($expected, $s->getSnapshot());
     $this->assertTrue(!$s->valueChanged('id'));
     $this->assertTrue(!$s->valueChanged('fname'));
     $s->setValue('id', 50);
     $this->assertEquals($expected, $s->getSnapshot());
     $this->assertTrue($s->valueChanged('id'));
     $this->assertTrue(!$s->valueChanged('fname'));
     $this->assertEquals(array('id' => 10), $s->snapshotKeys());
 }
예제 #2
0
 function test_query_builder_update_snapshot()
 {
     $builder = new Dataface_QueryBuilder('Profiles');
     // test default update functionality.
     $s = new Dataface_Record('Profiles', array());
     $s->clearValues();
     $s->setValues(array('id' => 10, 'fname' => 'John', 'lname' => 'Smith', 'title' => 'President Financial Accounting', 'phone1' => '555-555-5555', 'description' => 'This is a description', 'favtime' => '14:23:56', 'dob' => '1978-12-27', 'datecreated' => '19991224060708', 'lastlogin' => '1978-12-27 14:45:23'));
     $s->setSnapshot();
     $s->setValues(array('id' => 50, 'fname' => 'Susan', 'lname' => 'Moore', 'phone1' => '555-555-5556', 'description' => 'This is another description', 'favtime' => '14:23:57', 'dob' => '1978-12-28', 'datecreated' => '19991224060709', 'lastlogin' => '1978-12-28 14:45:24'));
     $this->assertEquals($builder->update($s), "UPDATE `Profiles` SET `id` = '50', `fname` = 'Susan', `lname` = 'Moore', `description` = 'This is another description', `dob` = '1978-12-28', `phone1` = '555-555-5556', `datecreated` = '19991224060709', `favtime` = '14:23:57', `lastlogin` = '1978-12-28 14:45:24' WHERE `Profiles`.`id` = '10' LIMIT 1");
 }