/** * 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, $testJournalId1, $testUserId1; global $testTripId2, $testJournalId2, $testUserId2; // create a first instance $object = new Journal($testTripId1, $testJournalId1); $object->setUserId($testUserId1); $object->setJournalDate('2015-09-30'); $object->setJournalTitle('Journal Title'); $object->setJournalText('journal text'); $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 Journal($testTripId2, $testJournalId2); $object->setUserId($testUserId2); $object->setJournalDate('2015-10-01'); $object->setJournalTitle('Journal Title 2'); $object->setJournalText('journal text 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, $testJournalId1)); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testJournalId1, $object->getJournalId()); $this->assertEquals($created1, $object->getCreated()); $this->assertEquals($updated1, $object->getUpdated()); $this->assertEquals($testUserId1, $object->getUserId()); $this->assertEquals('2015-09-30', $object->getJournalDate()); $this->assertEquals('Journal Title', $object->getJournalTitle()); $this->assertEquals('journal text', $object->getJournalText()); $this->assertEquals('Y', $object->getDeleted()); $this->assertEquals($hash1, $object->getHash()); // Load the second object, which overrides all the attributes $this->assertTrue($object->load($testTripId2, $testJournalId2)); $this->assertEquals($testTripId2, $object->getTripId()); $this->assertEquals($testJournalId2, $object->getJournalId()); $this->assertEquals($created2, $object->getCreated()); $this->assertEquals($updated2, $object->getUpdated()); $this->assertEquals($testUserId2, $object->getUserId()); $this->assertEquals('2015-10-01', $object->getJournalDate()); $this->assertEquals('Journal Title 2', $object->getJournalTitle()); $this->assertEquals('journal text 2', $object->getJournalText()); $this->assertEquals('N', $object->getDeleted()); $this->assertEquals($hash2, $object->getHash()); }