Exemplo n.º 1
0
 /**
  * @vcr GedcomxFileTests/testCreateGedxFile.json
  */
 public function testCreateGedxFile()
 {
     $people = XMLBuilder::XMLRelationshipData();
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     $father = $this->collectionState()->addPerson($people['father']);
     $mother = $this->collectionState()->addPerson($people['mother']);
     $child = $this->collectionState()->addPerson($people['child']);
     $this->queueForDelete($father, $mother, $child);
     $family = new ChildAndParentsRelationship();
     $family->setChild($child->getResourceReference());
     $family->setFather($father->getResourceReference());
     $family->setMother($mother->getResourceReference());
     $relationship = $this->collectionState()->addChildAndParentsRelationship($family)->get();
     $this->queueForDelete($relationship);
     $image1 = ArtifactBuilder::makeImage();
     $image2 = ArtifactBuilder::makeImage();
     $testfile = $this->tempDir . "test.gedx";
     $writeIt = new GedcomxOutput();
     $writeIt->addFamilySearchResource($relationship->getEntity());
     $writeIt->addFileResource($image1);
     $writeIt->addFileResource($image2);
     $writeIt->writeToFile($testfile);
     $this->assertFileExists($testfile, "test.gedx not written.");
     $readIt = new GedcomxFile($testfile);
     $this->assertEmpty($readIt->getWarnings(), "No warnings should have been generated.");
 }
 /**
  * Adds a child and parents relationship to the current relationships collection.
  *
  * @param \Gedcomx\Rs\Client\PersonState                   $child
  * @param \Gedcomx\Rs\Client\PersonState                   $father
  * @param \Gedcomx\Rs\Client\PersonState                   $mother
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\ChildAndParentsRelationshipState
  */
 public function addChildAndParents(PersonState $child, PersonState $father = null, PersonState $mother = null, StateTransitionOption $option = null)
 {
     $chap = new ChildAndParentsRelationship();
     $chap->setChild(new ResourceReference($child->getSelfUri()));
     if ($father != null) {
         $chap->setFather(new ResourceReference($father->getSelfUri()));
     }
     if ($mother != null) {
         $chap->setMother(new ResourceReference($mother->getSelfUri()));
     }
     return $this->passOptionsTo('addChildAndParentsRelationship', array($chap), func_get_args());
 }
Exemplo n.º 3
0
 public function testReadChildAndParentsRelationshipChangeHistory()
 {
     $factory = new FamilyTreeStateFactory();
     $collection = $this->collectionState($factory);
     /** @var FamilyTreePersonState $father */
     $father = $this->createPerson('male')->get();
     /** @var FamilyTreePersonState $mother */
     $mother = $this->createPerson('female');
     /** @var FamilyTreePersonState $son */
     $son = $this->createPerson('male');
     $chap = new ChildAndParentsRelationship();
     $chap->setFather($father->getResourceReference());
     $chap->setMother($mother->getResourceReference());
     $chap->setChild($son->getResourceReference());
     /** @var ChildAndParentsRelationshipState $relationship */
     $relationship = $collection->addChildAndParentsRelationship($chap)->get();
     $this->queueForDelete($relationship);
     /** @var ChangeHistoryState $state */
     $state = $relationship->readChangeHistory();
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals((int) $state->getResponse()->getStatusCode(), 200);
     $this->assertNotNull($state->getEntity());
     $this->assertNotNull($state->getEntity()->getEntries());
     $this->assertGreaterThan(0, $state->getEntity()->getEntries());
 }
Exemplo n.º 4
0
 /**
  * @link https://familysearch.org/developers/docs/api/tree/Read_Child-and-Parents_Relationship_Sources_usecase
  * @see SourcesTests::testReadChildAndParentsRelationshipSources
  */
 public function testReadChildAndParentsRelationshipSources()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     $this->assertNotNull($this->collectionState());
     $this->assertTrue($this->collectionState()->isAuthenticated());
     $this->assertNotNull($this->collectionState()->getClient());
     $client = $this->collectionState()->getClient();
     $this->assertNotEmpty($this->collectionState()->getAccessToken());
     $token = $this->collectionState()->getAccessToken();
     /** @var FamilyTreePersonState $father */
     $father = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $father->getResponse()->getStatusCode());
     $father = $father->get();
     $this->assertEquals(HttpStatus::OK, $father->getResponse()->getStatusCode());
     $child = $this->createPerson();
     $this->assertEquals(HttpStatus::CREATED, $child->getResponse()->getStatusCode());
     $chapr = new ChildAndParentsRelationship();
     $this->assertNotEmpty($father->getResourceReference());
     $chapr->setFather($father->getResourceReference());
     $this->assertnotnull($child->getResourceReference());
     $chapr->setChild($child->getResourceReference());
     /** @var ChildAndParentsRelationshipState $relation */
     $relation = $this->collectionState()->addChildAndParentsRelationship($chapr);
     $this->queueForDelete($relation);
     $this->assertEquals(HttpStatus::CREATED, $relation->getResponse()->getStatusCode());
     $relation = $relation->get();
     $this->assertEquals(HttpStatus::OK, $relation->getResponse()->getStatusCode());
     /** @var SourceDescriptionState $sds */
     $sds = $this->collectionState()->addSourceDescription(SourceBuilder::hitchhiker());
     $this->queueForDelete($sds);
     $this->assertEquals(HttpStatus::CREATED, $sds->getResponse()->getStatusCode());
     $sds = $sds->get();
     $this->assertEquals(HttpStatus::OK, $sds->getResponse()->getStatusCode());
     $relation->addSourceReferenceState($sds);
     $this->assertNotNull($father->getLink(Rel::CHILD_RELATIONSHIPS));
     $relationships = $father->loadChildRelationships()->getChildAndParentsRelationships();
     $this->assertNotEmpty($relationships);
     $relationship = array_shift($relationships);
     $link1 = $relationship->getLink(Rel::RELATIONSHIP);
     $link2 = $relationship->getLink(Rel::SELF);
     $this->assertTrue($link1 != null || $link2 != null);
     $relation = $father->readChildAndParentsRelationship($relationship);
     $linkObj = $relation->getLink(Rel::SOURCE_DESCRIPTIONS);
     $this->assertNotNull($linkObj);
     $link = $linkObj->getHref();
     $this->assertNotEmpty($link);
     $request = $client->createRequest(Request::GET, $link);
     $request->setHeader('Accept', FamilySearchPlatform::JSON_MEDIA_TYPE);
     $request->setHeader('Authorization', "Bearer {$token}");
     $response = $client->send($request);
     $state = new FamilySearchSourceDescriptionState($client, $request, $response, $token, $factory);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::OK, $state->getResponse()->getStatusCode());
     $this->assertNotNull($state->getSourceDescription());
 }
 /**
  * Create an copy of this state with no data.
  *
  * @return ChildAndParentsRelationship
  */
 protected function createEmptySelf()
 {
     $relationship = new ChildAndParentsRelationship();
     $relationship->setId($this->getLocalSelfId());
     return $relationship;
 }
Exemplo n.º 6
0
 /**
  * @vcr PedigreeTests/testReadPersonDescendancyWithSpecifiedSpouseAndAdditionalPersonAndMarriageDetails.json
  * @link https://familysearch.org/developers/docs/api/tree/Read_Person_Descendancy_with_Specified_Spouse_and_additional_person_and_marriage_details_usecase
  * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  */
 public function testReadPersonDescendancyWithSpecifiedSpouseAndAdditionalPersonAndMarriageDetails()
 {
     $factory = new FamilyTreeStateFactory();
     $collection = $this->collectionState($factory);
     $father = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $father->getStatus());
     $father = $father->get();
     $this->assertEquals(HttpStatus::OK, $father->getStatus());
     $mother = $this->createPerson('female');
     $this->assertEquals(HttpStatus::CREATED, $mother->getStatus());
     $son = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $son->getStatus());
     $fact = new Fact();
     $attribution = new Attribution();
     $attribution->setChangeMessage("Change message");
     $fact->setType("http://gedcomx.org/Marriage");
     $fact->setAttribution($attribution);
     $date = new DateInfo();
     $date->setOriginal("3 Apr 1930");
     $date->setFormal("+1930");
     $fact->setDate($date);
     $place = new PlaceReference();
     $place->setOriginal("Moscow, Russia");
     $fact->setPlace($place);
     $father->addSpouse($mother)->addFact($fact);
     $relationship = new ChildAndParentsRelationship();
     $relationship->setFather($father->getResourceReference());
     $relationship->setMother($mother->getResourceReference());
     $relationship->setChild($son->getResourceReference());
     $r1 = $collection->addChildAndParentsRelationship($relationship);
     $this->queueForDelete($r1);
     $this->assertEquals(HttpStatus::CREATED, $r1->getStatus());
     $state = $father->readDescendancy(new QueryParameter(true, "spouse", $mother->getHeader("X-ENTITY-ID")[0]), new QueryParameter(true, "personDetails", "true"), new QueryParameter(true, "marriageDetails", "true"));
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals((int) $state->getStatus(), 200);
     $this->assertNotNull($state->getTree());
     $this->assertNotNull($state->getTree()->getRoot());
     $this->assertNotNull($state->getTree()->getRoot()->getPerson());
     $this->assertNotNull($state->getTree()->getRoot()->getSpouse());
     $this->assertNotNull($state->getTree()->getRoot()->getChildren());
     $this->assertNotNull($state->getTree()->getRoot()->getSpouse()->getDisplayExtension());
     $this->assertNotNull($state->getTree()->getRoot()->getSpouse()->getDisplayExtension()->getMarriageDate());
     $this->assertNotNull($state->getTree()->getRoot()->getPerson()->getFacts());
     $this->assertNotNull($state->getTree()->getRoot()->getSpouse()->getFacts());
     $this->assertEquals(1, count($state->getTree()->getRoot()->getChildren()));
     $this->assertNotNull($state->getTree()->getRoot()->Children[0]->getPerson());
     $this->assertEquals($father->getPerson()->getId(), $state->getTree()->getRoot()->getPerson()->getId());
     $this->assertEquals($mother->getHeader("X-ENTITY-ID")[0], $state->getTree()->getRoot()->getSpouse()->getId());
     $this->assertEquals($son->getHeader("X-ENTITY-ID")[0], $state->getTree()->getRoot()->Children[0]->getPerson()->getId());
 }
Exemplo n.º 7
0
 /**
  * @vcr SourcesTests/testReadChildAndParentsRelationshipSources.json
  * @link https://familysearch.org/developers/docs/api/tree/Read_Child-and-Parents_Relationship_Sources_usecase
  * @see SourcesTests::testReadChildAndParentsRelationshipSources
  */
 public function testReadChildAndParentsRelationshipSources()
 {
     $factory = new FamilyTreeStateFactory();
     $this->collectionState($factory);
     $this->assertNotNull($this->collectionState());
     $this->assertTrue($this->collectionState()->isAuthenticated());
     $this->assertNotNull($this->collectionState()->getClient());
     $client = $this->collectionState()->getClient();
     $this->assertNotEmpty($this->collectionState()->getAccessToken());
     $token = $this->collectionState()->getAccessToken();
     /** @var FamilyTreePersonState $father */
     $father = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $father->getStatus());
     $father = $father->get();
     $this->assertEquals(HttpStatus::OK, $father->getStatus());
     $child = $this->createPerson();
     $this->assertEquals(HttpStatus::CREATED, $child->getStatus());
     $chapr = new ChildAndParentsRelationship();
     $this->assertNotEmpty($father->getResourceReference());
     $chapr->setFather($father->getResourceReference());
     $this->assertnotnull($child->getResourceReference());
     $chapr->setChild($child->getResourceReference());
     /** @var ChildAndParentsRelationshipState $relation */
     $relation = $this->collectionState()->addChildAndParentsRelationship($chapr);
     $this->queueForDelete($relation);
     $this->assertEquals(HttpStatus::CREATED, $relation->getStatus());
     $relation = $relation->get();
     $this->assertEquals(HttpStatus::OK, $relation->getStatus());
     /** @var SourceDescriptionState $sds */
     $sds = $this->collectionState()->addSourceDescription(SourceBuilder::hitchhiker());
     $this->queueForDelete($sds);
     $this->assertEquals(HttpStatus::CREATED, $sds->getStatus());
     $sds = $sds->get();
     $this->assertEquals(HttpStatus::OK, $sds->getStatus());
     $relation->addSourceReferenceState($sds);
     $this->assertNotNull($father->getLink(Rel::CHILD_RELATIONSHIPS));
     $relationships = $father->loadChildRelationships()->getChildAndParentsRelationships();
     $this->assertNotEmpty($relationships);
     $relationship = array_shift($relationships);
     $link1 = $relationship->getLink(Rel::RELATIONSHIP);
     $link2 = $relationship->getLink(Rel::SELF);
     $this->assertTrue($link1 != null || $link2 != null);
     $relation = $father->readChildAndParentsRelationship($relationship);
     $state = $relation->readSources();
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::OK, $state->getStatus());
     $this->assertNotNull($state->getSourceDescription());
 }
Exemplo n.º 8
0
 /**
  * Initialize a ChildAndParentRelationship for tests requiring one.
  *
  * @return \Gedcomx\Extensions\FamilySearch\Rs\Client\FamilyTree\ChildAndParentsRelationshipState
  * @throws \Gedcomx\Rs\Client\Exception\GedcomxApplicationException
  */
 protected function createRelationship()
 {
     /** @var PersonState $father */
     $father = $this->createPerson('male');
     $this->assertEquals(HttpStatus::CREATED, $father->getStatus(), $this->buildFailMessage(__METHOD__ . '(createFather)', $father));
     /** @var PersonState $mother */
     $mother = $this->createPerson('female');
     $this->assertEquals(HttpStatus::CREATED, $mother->getStatus(), $this->buildFailMessage(__METHOD__ . '(createMother)', $mother));
     /** @var PersonState $child */
     $child = $this->createPerson();
     $this->assertEquals(HttpStatus::CREATED, $child->getStatus(), $this->buildFailMessage(__METHOD__ . '(createChild)', $child));
     $this->queueForDelete($father, $child, $mother);
     $rel = new ChildAndParentsRelationship();
     $rel->setChild($child->getResourceReference());
     $rel->setFather($father->getResourceReference());
     $rel->setMother($mother->getResourceReference());
     /** @var ChildAndParentsRelationshipState $rState */
     $rState = $this->collectionState()->addChildAndParentsRelationship($rel);
     $this->assertEquals(HttpStatus::CREATED, $rState->getStatus(), $this->buildFailMessage(__METHOD__ . '(createFamily)', $rState));
     $this->queueForDelete($rState);
     return $rState;
 }
Exemplo n.º 9
0
 /**
  * Read the child and parent relationships for this person
  *
  * @param ChildAndParentsRelationship $relationship
  * @param \Gedcomx\Rs\Client\Options\StateTransitionOption $option,...
  *
  * @return ChildAndParentsRelationshipState
  */
 public function readChildAndParentsRelationship(ChildAndParentsRelationship $relationship, StateTransitionOption $option = null)
 {
     $link = $relationship->getLink(Rel::RELATIONSHIP);
     if ($link == null) {
         $link = $relationship->getLink(Rel::SELF);
     }
     if ($link == null || $link->getHref() == null) {
         return null;
     }
     $request = $this->createAuthenticatedRequest('GET', $link->getHref(), FamilySearchRequest::getMediaTypes());
     return $this->stateFactory->createState('ChildAndParentsRelationshipState', $this->client, $request, $this->passOptionsTo('invoke', array($request), func_get_args()), $this->accessToken);
 }