/** * @vcr FamilySearchClientTests/testSetPendingModifications.json */ public function testSetPendingModifications() { $features = $this->createAuthenticatedFamilySearchClient()->getAvailablePendingModifications(); $modifications = array_map(function (Feature $feature) { return $feature->getName(); }, $features); $featuresHeader = null; $client = $this->createAuthenticatedFamilySearchClient(['pendingModifications' => $modifications, 'middleware' => [Middleware::tap(function (RequestInterface $request, $options) use(&$featuresHeader) { $featuresHeader = $request->getHeader('X-FS-Feature-Tag')[0]; })]]); $person = PersonBuilder::buildPerson(''); $responseState = $client->familytree()->addPerson($person); $this->queueForDelete($responseState); // Ensure a response came back $this->assertNotNull($responseState); $check = array(); // Ensure each requested feature was found in the request headers foreach ($features as $feature) { $this->assertTrue(strpos($featuresHeader, $feature->getName()) !== false, $feature->getName() . " was not found in the requested features."); } }
/** * @link https://familysearch.org/developers/docs/api/memories/Update_Memory_Persona_usecase */ public function testCreateUpdateDeleteMemoryPersona() { $filename = ArtifactBuilder::makeImage(); $artifact = new DataSource(); $artifact->setFile($filename); $description = SourceBuilder::newSource(); $factory = new FamilyTreeStateFactory(); /** @var FamilySearchMemories $memories */ $memories = $factory->newMemoriesState(); $memories = $this->authorize($memories); $this->assertNotEmpty($memories->getAccessToken()); /** @var \Gedcomx\Rs\Client\SourceDescriptionState $upload */ $upload = $memories->addArtifact($artifact, $description); $this->assertEquals(HttpStatus::CREATED, $upload->getStatus()); $upload = $upload->get(); $this->assertEquals(HttpStatus::OK, $upload->getStatus()); $factory = new StateFactory(); $this->collectionState($factory); /** @var FamilyTreePersonState $person1 */ $person1 = $this->createPerson('male'); $this->assertEquals(HttpStatus::CREATED, $person1->getStatus()); $person1 = $person1->get(); $this->assertEquals(HttpStatus::OK, $person1->getStatus()); $person2 = PersonBuilder::buildPerson('male'); $persona = $upload->addPersonPersona($person2); $this->assertEquals(HttpStatus::CREATED, $persona->getStatus()); $person1->addPersonaPersonState($persona); $personas = $person1->loadPersonaReferences(); $this->assertEquals(HttpStatus::OK, $personas->getStatus()); $personas = $personas->get(); $this->assertEquals(HttpStatus::OK, $personas->getStatus()); /** @var PersonState $updated */ $updated = $personas->update($personas->getPerson()); $this->assertEquals(HttpStatus::NO_CONTENT, $updated->getStatus(), $this->buildFailMessage(__METHOD__, $updated)); $persona = $persona->delete(); $this->assertEquals(HttpStatus::NO_CONTENT, $persona->getStatus(), $this->buildFailMessage(__METHOD__, $persona)); $personas = $upload->readPersonas(); $this->assertEquals(HttpStatus::NO_CONTENT, $personas->getStatus()); $this->assertNull($personas->getPersons()); $upload->delete(); $person1->delete(); }
/** * @vcr PersonTests/testDeletePersonNotAMatch.json * @link https://familysearch.org/developers/docs/api/tree/Delete_Person_Not-a-Match_usecase */ public function testDeletePersonNotAMatch() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); $personData = PersonBuilder::buildPerson(null); /** @var FamilyTreePersonState $one */ $one = $this->collectionState()->addPerson($personData)->get(); $two = $this->collectionState()->addPerson($personData)->get(); $this->queueForDelete($one, $two); $nonMatch = $one->addNonMatchPerson($two->getPerson()); $rematch = $nonMatch->removeNonMatch($two->getPerson()); $this->assertEquals(HttpStatus::NO_CONTENT, $rematch->getStatus(), "Restore person failed. Returned {$rematch->getStatus()}"); }
/** * @vcr SearchAndMatchTests/testUpdateMatchStatusForPersonRecordMatches.json * @link https://familysearch.org/developers/docs/api/tree/Update_Match_Status_for_Person_Record_Matches_usecase */ public function testUpdateMatchStatusForPersonRecordMatches() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); $collection = new QueryParameter(true, "collection", "https://familysearch.org/platform/collections/records"); $p = PersonBuilder::buildPerson(null); $person1 = $this->collectionState()->addPerson($p, $this->createCacheBreakerQueryParam()); $this->assertEquals(HttpStatus::CREATED, $person1->getStatus()); $person2 = $this->collectionState()->addPerson($p, $this->createCacheBreakerQueryParam()); $this->assertEquals(HttpStatus::CREATED, $person2->getStatus()); $person2 = $person2->get(); $this->assertEquals(HttpStatus::OK, $person2->getStatus()); $this->queueForDelete($person1, $person2); $this->waitForServerUpdates(); /** @var \Gedcomx\Extensions\FamilySearch\Rs\Client\PersonMatchResultsState $matches */ $matches = $person2->readMatches(); $this->assertEquals(HttpStatus::OK, $matches->getStatus(), $this->buildFailMessage(__METHOD__, $matches)); $accepted = new QueryParameter(true, "status", "accepted"); $this->assertNotNull($matches->getResults()); $this->assertNotEmpty($matches->getResults()->getEntries()); $entries = $matches->getResults()->getEntries(); /** @var \Gedcomx\Atom\Entry $entry */ $entry = array_shift($entries); $id = $entry->getId(); $state = $matches->updateMatchStatus($entry, $accepted, $collection); $this->assertNotNull($state->ifSuccessful()); $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus()); $statuses = new QueryParameter(true, "status", "accepted"); $matches = $person2->readMatches($statuses); $this->assertEquals(HttpStatus::OK, $person2->getStatus()); $this->assertNotNull($matches->getResults()); $this->assertNotEmpty($matches->getResults()->getEntries()); $entries = $matches->getResults()->getEntries(); /** @var \Gedcomx\Atom\Entry $entry */ $entry = array_shift($entries); $this->assertEquals($id, $entry->getId()); }
protected function createPerson($gender = null) { $person = PersonBuilder::buildPerson($gender); $state = $this->collectionState()->addPerson($person); $this->queueForDelete($state); return $state; }