Exemplo n.º 1
0
 /**
  * @link https://familysearch.org/developers/docs/api/sources/Create_User-Uploaded_Source_usecase
  */
 public function testCreateUserUploadedSource()
 {
     $this->collectionState(new FamilyTreeStateFactory());
     /** @var FamilyTreePersonState $person */
     $person = $this->createPerson();
     $this->assertEquals(HttpStatus::CREATED, $person->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__ . '(create person)', $person));
     $person = $person->get();
     $this->assertEquals(HttpStatus::OK, $person->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__ . '(read person)', $person));
     $ds = new DataSource();
     $ds->setTitle("Sample Memory");
     $ds->setFile(ArtifactBuilder::makeTextFile());
     $a1 = $person->addArtifact($ds);
     $this->assertEquals(HttpStatus::CREATED, $a1->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__ . '(add artifact)', $a1));
     $this->queueForDelete($a1);
     $this->assertEquals(HttpStatus::CREATED, $a1->getResponse()->getStatusCode());
     $artifacts = $person->readArtifacts();
     $this->assertEquals(HttpStatus::OK, $artifacts->getResponse()->getStatusCode());
     /** @var \Gedcomx\Rs\Client\SourceDescriptionState $artifact */
     $artifact = $person->readArtifacts();
     $this->assertEquals(HttpStatus::OK, $artifact->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__ . '(read artifact)', $artifact));
     $artifact = $artifact->getSourceDescription();
     $memoryUri = $artifact->getLink("memory")->getHref();
     $source = SourceBuilder::newSource();
     $source->setAbout($memoryUri);
     $state = $this->collectionState()->addSourceDescription($source);
     $this->queueForDelete($state);
     $this->assertNotNull($state->ifSuccessful());
     $this->assertEquals(HttpStatus::CREATED, $state->getResponse()->getStatusCode(), $this->buildFailMessage(__METHOD__ . '(source description)', $state));
 }
Exemplo n.º 2
0
 /**
  * @link https://familysearch.org/developers/docs/api/memories/Upload_Photo_usecase
  * Use shows uploading a photo with an image content type. SDK only supports uploading
  *       via multi-part form uploads.
  */
 public function testUploadPhoto()
 {
     $filename = ArtifactBuilder::makeImage();
     $artifact = new DataSource();
     $artifact->setFile($filename);
     $artifact->setTitle(TestBuilder::faker()->sentence(4));
     $factory = new FamilySearchStateFactory();
     /** @var FamilySearchMemories $memories */
     $memories = $factory->newMemoriesState();
     $memories = $this->authorize($memories);
     $this->assertNotEmpty($memories->getAccessToken());
     $upload = $memories->addArtifact($artifact);
     $this->queueForDelete($upload);
     $this->assertEquals(HttpStatus::CREATED, $upload->getStatus(), $this->buildFailMessage(__METHOD__, $upload));
     $upload = $upload->get();
     $this->assertEquals(HttpStatus::OK, $upload->getStatus());
 }