From f4f9d7e821dda932a7a29ed125087caa714c2274 Mon Sep 17 00:00:00 2001 From: Jordan Dukart Date: Tue, 26 Sep 2017 10:41:30 -0300 Subject: [PATCH] Loss of potential RELS-INT statements when the RELS-INT does not exist (#162) * Add tests that show errors with RELS-INT. * Fix RELS-INT, mark incomplete other bug in ISLANDORA-2068. * Actually mark the test incomplete. --- FedoraRelationships.php | 3 ++ tests/FedoraRelationshipsInternalTest.php | 34 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/FedoraRelationships.php b/FedoraRelationships.php index 595a190..2b6e608 100644 --- a/FedoraRelationships.php +++ b/FedoraRelationships.php @@ -799,6 +799,9 @@ public function add($predicate_uri, $predicate, $object, $type = RELS_TYPE_URI) * TRUE if relationships were removed, FALSE otherwise. */ public function remove($predicate_uri = NULL, $predicate = NULL, $object = NULL, $type = RELS_TYPE_URI) { + if (!isset($this->aboutDs->parent['RELS-INT'])) { + return FALSE; + } $this->initializeDatastream(); $return = parent::internalRemove("{$this->aboutDs->parent->id}/{$this->aboutDs->id}", $predicate_uri, $predicate, $object, $type); diff --git a/tests/FedoraRelationshipsInternalTest.php b/tests/FedoraRelationshipsInternalTest.php index 807c8a9..59311ea 100644 --- a/tests/FedoraRelationshipsInternalTest.php +++ b/tests/FedoraRelationshipsInternalTest.php @@ -89,4 +89,38 @@ function testNullPredicateURI() { function testPurge() { $this->assertTrue($this->object->purgeDatastream('RELS-INT')); } + + function testMultipleWritesWhenPurging() { + $this->markTestIncomplete('This is a current bug that needs to be addressed in ISLANDORA-2068.'); + $this->object->purgeDatastream('RELS-INT'); + $this->object->ingestDatastream($this->datastream); + $this->object->ingestDatastream($this->datastream2); + + $this->datastream->relationships->remove(ISLANDORA_RELS_INT_URI, 'whargarbl'); + $this->datastream2->relationships->remove(ISLANDORA_RELS_INT_URI, 'omnomnom'); + + $this->datastream->relationships->add(ISLANDORA_RELS_INT_URI, 'isWhargarbl', 'whargarbl', TRUE); + $this->datastream2->relationships->add(ISLANDORA_RELS_INT_URI, 'isOmNom', 'omnom', TRUE); + $this->assertEquals(1, count($this->datastream->relationships->get(ISLANDORA_RELS_INT_URI, 'isWhargarbl'))); + $this->assertEquals(1, count($this->datastream->relationships->get(ISLANDORA_RELS_INT_URI, 'isOmNom'))); + } + + function testMultipleWritesWithoutPurging() { + $connection = new RepositoryConnection(FEDORAURL, FEDORAUSER, FEDORAPASS); + $this->api = new FedoraApi($connection); + $cache = new SimpleCache(); + $repository = new FedoraRepository($this->api, $cache); + $object = $repository->constructObject('om:nom'); + $ds = $object->constructDatastream('om'); + $ds2 = $object->constructDatastream('nom'); + + $ds->relationships->remove(ISLANDORA_RELS_INT_URI, 'whargarbl'); + $ds2->relationships->remove(ISLANDORA_RELS_INT_URI, 'omnomnom'); + + $ds->relationships->add(ISLANDORA_RELS_INT_URI, 'isWhargarbl', 'whargarbl', TRUE); + $ds2->relationships->add(ISLANDORA_RELS_INT_URI, 'isOmNom', 'omnom', TRUE); + $this->assertEquals(1, count($ds->relationships->get(ISLANDORA_RELS_INT_URI, 'isWhargarbl'))); + $this->assertEquals(1, count($ds2->relationships->get(ISLANDORA_RELS_INT_URI, 'isOmNom'))); + } + }