/** * Test #11. SYNCH get an existent object. * @depends testDataWipedBeforeTest * @depends testGetExistent */ public function testSynchGet() { global $testTripId1; global $testJournalId1; global $synchAuthToken; // Create the object and set attributes $object = new Journal($testTripId1, $testJournalId1); $object->setUserId('user'); $object->setJournalDate('2015-09-30'); $object->setJournalTitle('Journal Title'); $object->setJournalText('Journal Text'); $object->setDeleted('Y'); // Save the object and confirm a row is added to the database $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $data = array('hash' => $object->getHash()); $result = getApi('synchJournal.php', $data, $synchAuthToken); $this->assertEquals(RESPONSE_SUCCESS, $result['resultCode']); $this->assertTrue(isset($result['tripId'])); $this->assertTrue(isset($result['journalId'])); $this->assertTrue(isset($result['created'])); $this->assertTrue(isset($result['updated'])); $this->assertTrue(isset($result['userId'])); $this->assertTrue(isset($result['journalDate'])); $this->assertTrue(isset($result['journalTitle'])); $this->assertTrue(isset($result['journalText'])); $this->assertTrue(isset($result['deleted'])); $this->assertTrue(isset($result['hash'])); $this->assertEquals($testTripId1, $result['tripId']); $this->assertEquals($testJournalId1, $result['journalId']); $this->assertEquals($object->getCreated(), $result['created']); $this->assertEquals($object->getUpdated(), $result['updated']); $this->assertEquals('user', $result['userId']); $this->assertEquals('2015-09-30', $result['journalDate']); $this->assertEquals('Journal Title', $result['journalTitle']); $this->assertEquals('Journal Text', $result['journalText']); $this->assertEquals('Y', $result['deleted']); $this->assertEquals($object->getHash(), $result['hash']); }
$object->setUpdated($data['updated']); } if (isset($data['userId'])) { $object->setUserId($data['userId']); } if (isset($data['journalDate'])) { $object->setJournalDate($data['journalDate']); } if (isset($data['journalTitle'])) { $object->setJournalTitle($data['journalTitle']); } if (isset($data['journalText'])) { $object->setJournalText($data['journalText']); } if (isset($data['deleted'])) { $object->setDeleted($data['deleted']); } if (isset($data['hash'])) { $object->setHash($data['hash']); } if ($object->save()) { $response = successResponse(); } else { $response = errorResponse(RESPONSE_INTERNAL_ERROR); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST, 'tripId or journalId not set'); } } else { $response = errorResponse(RESPONSE_BAD_REQUEST, 'not GET or PUT response'); }
/** * Test #17. * The findByHash function returns an object populated with previous * values if a hash for a previous instance is given. * @depends testUpdate * @depends testHashGetInstance */ public function testHashOldInstance() { global $testTripId1, $testJournalId1, $testUserId1; global $testUserId2; // create the object and save it $object = new Journal($testTripId1, $testJournalId1); $object->setUserId($testUserId1); $object->setJournalDate('2015-09-30'); $object->setJournalTitle('Journal Title'); $object->setJournalText('journal text'); $object->setDeleted('N'); $this->assertTrue($object->save()); $this->assertEquals(1, $this->countTestRows()); $old_hash = $object->getHash(); // change values and update the object $object->setUserId($testUserId2); $object->setJournalDate('2015-10-01'); $object->setJournalTitle('Journal Title 2'); $object->setJournalText('journal text 2'); $object->setDeleted('Y'); $this->assertTrue($object->save()); $this->assertEquals(2, $this->countTestRows()); $new_hash = $object->getHash(); // read the object from the database and confirm that the old // values are returned $object = Journal::findByHash($old_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testJournalId1, $object->getJournalId()); $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('N', $object->getDeleted()); $this->assertEquals($old_hash, $object->getHash()); // read the new object from the database and confirm that the new // values are returned $object = Journal::findByHash($new_hash); $this->assertNotNull($object); $this->assertEquals($testTripId1, $object->getTripId()); $this->assertEquals($testJournalId1, $object->getJournalId()); $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('Y', $object->getDeleted()); $this->assertEquals($new_hash, $object->getHash()); }