/** * 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, $testUserId1, $testUserId1; global $testTripId2, $testUserId2, $testUserId2; // create a first instance $object = new TripUser($testTripId1, $testUserId1); $object->setRole('role-1'); $object->setMessage('message'); $object->setDeleted('Y'); $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 TripUser($testTripId2, $testUserId2); $object->setRole('role-2'); $object->setMessage('message 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, $testUserId1)); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testUserId1, $object->getUserId()); $this->assertEquals($created1, $object->getCreated()); $this->assertEquals($updated1, $object->getUpdated()); $this->assertEquals('role-1', $object->getRole()); $this->assertEquals('message', $object->getMessage()); $this->assertEquals('Y', $object->getDeleted()); $this->assertEquals($hash1, $object->getHash()); // Load the second object, which overrides all the attributes $this->assertTrue($object->load($testTripId2, $testUserId2)); $this->assertEquals($testTripId2, $object->getTripId()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals($created2, $object->getCreated()); $this->assertEquals($updated2, $object->getUpdated()); $this->assertEquals('role-2', $object->getRole()); $this->assertEquals('message 2', $object->getMessage()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals($hash2, $object->getHash()); }