/** * @link https://familysearch.org/developers/docs/api/tree/Read_Couple_Relationship_Sources_usecase */ public function testReadCoupleRelationshipSources() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); $this->assertTrue($this->collectionState()->isAuthenticated()); $this->assertNotNull($this->collectionState()->getClient()); $client = $this->collectionState()->getClient(); $this->assertNotNull($this->collectionState()->getAccessToken()); $token = $this->collectionState()->getAccessToken(); /** @var FamilyTreePersonState $husband */ $husband = $this->createPerson('male'); $this->assertEquals(HttpStatus::CREATED, $husband->getResponse()->getStatusCode()); $husband = $husband->get(); $this->assertEquals(HttpStatus::OK, $husband->getResponse()->getStatusCode()); $wife = $this->createPerson('female'); $this->assertEquals(HttpStatus::CREATED, $wife->getResponse()->getStatusCode()); /** @var RelationshipState $relation */ $relation = $husband->addSpouse($wife); $this->queueForDelete($relation); $this->assertEquals(HttpStatus::CREATED, $relation->getResponse()->getStatusCode()); $sds = $this->collectionState()->addSourceDescription(SourceBuilder::hitchhiker()); $this->queueForDelete($sds); $this->assertEquals(HttpStatus::CREATED, $sds->getResponse()->getStatusCode()); $relation->addSourceDescriptionState($sds); $relationships = $husband->loadSpouseRelationships(); $this->assertEquals(HttpStatus::OK, $relationships->getResponse()->getStatusCode()); $relations = $relationships->getRelationships(); $this->assertNotEmpty($relations); $relationship = array_shift($relations); $relation = $husband->readRelationship($relationship); $this->assertEquals(HttpStatus::OK, $relation->getResponse()->getStatusCode()); $linkObj = $relation->getLink(Rel::SOURCE_DESCRIPTIONS); $this->assertNotNull($linkObj); $link = $linkObj->getHref(); $this->assertNotEmpty($link); $request = $client->createRequest(Request::GET, $link); $request->setHeader('Accept', Gedcomx::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()); $this->assertNotEmpty($state->getEntity()->getRelationships()); }
/** * @vcr SourcesTests/testReadCoupleRelationshipSources.json * @link https://familysearch.org/developers/docs/api/tree/Read_Couple_Relationship_Sources_usecase */ public function testReadCoupleRelationshipSources() { $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); $this->assertTrue($this->collectionState()->isAuthenticated()); $this->assertNotNull($this->collectionState()->getClient()); $client = $this->collectionState()->getClient(); $this->assertNotNull($this->collectionState()->getAccessToken()); $token = $this->collectionState()->getAccessToken(); /** @var FamilyTreePersonState $husband */ $husband = $this->createPerson('male'); $this->assertEquals(HttpStatus::CREATED, $husband->getStatus()); $husband = $husband->get(); $this->assertEquals(HttpStatus::OK, $husband->getStatus()); $wife = $this->createPerson('female'); $this->assertEquals(HttpStatus::CREATED, $wife->getStatus()); /** @var RelationshipState $relation */ $relation = $husband->addSpouse($wife); $this->queueForDelete($relation); $this->assertEquals(HttpStatus::CREATED, $relation->getStatus()); $sds = $this->collectionState()->addSourceDescription(SourceBuilder::hitchhiker()); $this->queueForDelete($sds); $this->assertEquals(HttpStatus::CREATED, $sds->getStatus()); $relation->addSourceDescriptionState($sds); $relationships = $husband->loadSpouseRelationships(); $this->assertEquals(HttpStatus::OK, $relationships->getStatus()); $relations = $relationships->getRelationships(); $this->assertNotEmpty($relations); $relationship = array_shift($relations); $relation = $husband->readRelationship($relationship); $state = $relation->readSources(); $this->assertNotNull($state->ifSuccessful()); $this->assertEquals(HttpStatus::OK, $state->getStatus()); $this->assertNotNull($state->getSourceDescription()); $this->assertNotEmpty($state->getEntity()->getRelationships()); }