Ejemplo n.º 1
0
 /**
  * @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());
 }
Ejemplo n.º 2
0
 /**
  * @link https://familysearch.org/developers/docs/api/memories/Upload_Story_usecase
  * SDK only supports uploading via multi-part form uploads.
  */
 public function testUploadStory()
 {
     $filename = ArtifactBuilder::makeTextFile();
     $artifact = new DataSource();
     $artifact->setFile($filename);
     $description = SourceBuilder::newSource();
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchMemories $memories */
     $memories = $factory->newMemoriesState();
     $memories = $this->authorize($memories);
     $this->assertNotEmpty($memories->getAccessToken());
     $upload = $memories->addArtifact($artifact, $description);
     $this->queueForDelete($upload);
     $this->assertEquals(HttpStatus::CREATED, $upload->getStatus(), $this->buildFailMessage(__METHOD__, $upload));
     $upload = $upload->get();
     $this->assertEquals(HttpStatus::OK, $upload->getStatus());
 }
Ejemplo n.º 3
0
 protected function createSource()
 {
     $source = SourceBuilder::newSource();
     $link = $this->collectionState()->getLink(Rel::SOURCE_DESCRIPTIONS);
     if ($link === null || $link->getHref() === null) {
         return null;
     }
     $state = $this->collectionState()->addSourceDescription($source);
     $this->queueForDelete($state);
     return $state;
 }
Ejemplo n.º 4
0
 /**
  * @vcr SourcesTests/testDeleteSourceDescription.json
  * @link https://familysearch.org/developers/docs/api/sources/Delete_Source_Description_usecase
  */
 public function testDeleteSourceDescription()
 {
     $this->collectionState(new FamilyTreeStateFactory());
     $sd = SourceBuilder::newSource();
     /** @var SourceDescriptionState $description */
     $description = $this->collectionState()->addSourceDescription($sd);
     $this->assertEquals(HttpStatus::CREATED, $description->getStatus());
     $this->queueForDelete($description);
     $description = $description->get();
     $this->assertEquals(HttpStatus::OK, $description->getStatus());
     $state = $description->delete();
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
 }
Ejemplo n.º 5
0
 /**
  * @vcr SourceBoxTests/testMoveSourcesToAUserDefinedCollection.json
  * @link https://familysearch.org/developers/docs/api/sources/Move_Sources_to_a_User-Defined_Collection_usecase
  */
 public function testMoveSourcesToAUserDefinedCollection()
 {
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchCollectionState $collection */
     $collection = $this->collectionState($factory, "https://sandbox.familysearch.org/platform/collections/sources");
     $sd = SourceBuilder::newSource();
     /** @var FamilySearchSourceDescriptionState $description */
     $description = $collection->addSourceDescription($sd);
     $this->queueForDelete($description);
     $this->assertEquals(HttpStatus::CREATED, $description->getStatus());
     $description = $description->get();
     $this->assertEquals(HttpStatus::OK, $description->getStatus());
     /** @var CollectionState $subcollection */
     $c = new Collection();
     $c->setTitle(TestBuilder::faker()->sha1);
     $subcollection = $collection->addCollection($c)->get();
     $this->queueForDelete($subcollection);
     /** @var FamilySearchSourceDescriptionState $state */
     $state = $description->moveToCollection($subcollection);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::NO_CONTENT, $state->getStatus());
     // Ensure it doesn't exist in the old collection
     $rootCollection = $this->getRootCollection($collection);
     $found = $this->findInCollection($description->getSourceDescription(), $rootCollection->readSourceDescriptions()->getEntity()->getSourceDescriptions());
     $this->assertFalse($found);
     // Ensure it exists in the new collection
     $found = $this->findInCollection($description->getSourceDescription(), $subcollection->readSourceDescriptions()->getEntity()->getSourceDescriptions());
     $this->assertTrue($found);
 }