예제 #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 Trip($testTripId1);
     $object->setName('Test Trip');
     $object->setDescription('Test Description');
     $object->setBannerImg('test-01.png');
     $object->setStartDate('2015-08-01');
     $object->setEndDate('2015-09-30');
     $object->setActive('Y');
     $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 Trip($testTripId2);
     $object->setName('Test Trip 2');
     $object->setDescription('Test Description 2');
     $object->setBannerImg('test-02.png');
     $object->setStartDate('2014-08-01');
     $object->setEndDate('2014-09-30');
     $object->setActive('N');
     $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));
     $this->assertEquals($testTripId1, $object->getTripId());
     $this->assertEquals($created1, $object->getCreated());
     $this->assertEquals($updated1, $object->getUpdated());
     $this->assertEquals('Test Trip', $object->getName());
     $this->assertEquals('Test Description', $object->getDescription());
     $this->assertEquals('test-01.png', $object->getBannerImg());
     $this->assertEquals('2015-08-01', $object->getStartDate());
     $this->assertEquals('2015-09-30', $object->getEndDate());
     $this->assertEquals('Y', $object->getActive());
     $this->assertEquals('Y', $object->getDeleted());
     $this->assertEquals($hash1, $object->getHash());
     // Load the second object, which overrides all the attributes
     $this->assertTrue($object->load($testTripId2));
     $this->assertEquals($testTripId2, $object->getTripId());
     $this->assertEquals($created2, $object->getCreated());
     $this->assertEquals($updated2, $object->getUpdated());
     $this->assertEquals('Test Trip 2', $object->getName());
     $this->assertEquals('Test Description 2', $object->getDescription());
     $this->assertEquals('test-02.png', $object->getBannerImg());
     $this->assertEquals('2014-08-01', $object->getStartDate());
     $this->assertEquals('2014-09-30', $object->getEndDate());
     $this->assertEquals('N', $object->getActive());
     $this->assertEquals('N', $object->getDeleted());
     $this->assertEquals($hash2, $object->getHash());
 }