/** * @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."); }
public function setUp() { TestBuilder::seed(1123546); $this->testRootDir = dirname(__DIR__) . DIRECTORY_SEPARATOR . "tests" . DIRECTORY_SEPARATOR; $this->tempDir = $this->testRootDir . "tmp" . DIRECTORY_SEPARATOR; ArtifactBuilder::setTempDir($this->tempDir); }
/** * @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)); }
/** * @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()); }
/** * @link https://familysearch.org/developers/docs/api/tree/Read_Person_Portraits_usecase */ public function testReadPersonPortraits() { $this->markTestSkipped("Memories tests are slow and unreliable."); $factory = new FamilyTreeStateFactory(); $this->collectionState($factory); $memories = $factory->newMemoriesState(); $memories = $this->authorize($memories); $filename = ArtifactBuilder::makeImage(); $artifact = new DataSource(); $artifact->setFile($filename); /** @var FamilyTreePersonState $person */ $person = $this->createPerson(); $this->assertEquals(HttpStatus::CREATED, $person->getStatus()); $person = $person->get(); $this->assertEquals(HttpStatus::OK, $person->getStatus()); $description = $this->createSource()->get()->getSourceDescription(); /** @var \Gedcomx\Rs\Client\SourceDescriptionState $upload */ $upload = $memories->addArtifact($artifact, $description)->get(); $this->queueForDelete($upload); $persona = $upload->addPersonPersona(PersonBuilder::buildPerson('male'))->get(); $this->queueForDelete($persona); $person->addPersonaPersonState($persona); $portraits = $person->readPortraits(); $this->assertEquals(HttpStatus::OK, $portraits->getStatus(), $this->buildFailMessage(__METHOD__, $portraits)); $this->assertNotNull($portraits->getEntity()); $this->assertNotNull($portraits->getEntity()->getSourceDescriptions()); $this->assertGreaterThan(0, count($portraits->getEntity()->getSourceDescriptions())); }