Esempio n. 1
0
 /**
  * test #9.
  * Loading a valid, existing key overrides all the attributes with the
  * loaded values. The load() function returns true, indicating that
  * data was found.
  * @depends testSaveEmptyObject
  * @depends testSetAttributes
  */
 public function testLoadExistent()
 {
     global $testTripId1;
     global $testTripId2;
     // create a first instance
     $object = new TripAttribute($testTripId1, 'name');
     $object->setValue('value');
     $object->setDeleted('Y');
     $this->assertTrue($object->save());
     $this->assertEquals(1, $this->countTestRows());
     // Get the automatically created attributes for this instance
     $created1 = $object->getCreated();
     $updated1 = $object->getUpdated();
     $hash1 = $object->getHash();
     // create a second instance
     $object = new TripAttribute($testTripId2, 'name2');
     $object->setValue('value 2');
     $object->setDeleted('N');
     $object->save();
     $this->assertEquals(2, $this->countTestRows());
     // Get the automatically created attributes for this instance, and
     // make sure they are different from those of the first instance.
     $created2 = $object->getCreated();
     $updated2 = $object->getUpdated();
     $hash2 = $object->getHash();
     $this->assertNotEquals($created1, $created2);
     $this->assertNotEquals($updated1, $updated2);
     $this->assertNotEquals($hash1, $hash2);
     // Load the first object, which overrides all the attributes
     $this->assertTrue($object->load($testTripId1, 'name'));
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($created1, $object->getCreated());
     $this->assertEquals($updated1, $object->getUpdated());
     $this->assertEquals('name', $object->getName());
     $this->assertEquals('value', $object->getValue());
     $this->assertEquals('Y', $object->getDeleted());
     $this->assertEquals($hash1, $object->getHash());
     // Load the second object, which overrides all the attributes
     $this->assertTrue($object->load($testTripId2, 'name2'));
     $this->assertEquals($testTripId2, $object->getTripId());
     $this->assertEquals($created2, $object->getCreated());
     $this->assertEquals($updated2, $object->getUpdated());
     $this->assertEquals('name2', $object->getName());
     $this->assertEquals('value 2', $object->getValue());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals($hash2, $object->getHash());
 }