diff --git a/backend/StoredFile.php b/backend/StoredFile.php index b5eb78c96..215c17afa 100644 --- a/backend/StoredFile.php +++ b/backend/StoredFile.php @@ -432,8 +432,17 @@ class StoredFile { if (empty($this->gunid)) { $this->gunid = StoredFile::generateGunid(); } - $this->exists = is_file($this->filepath) && is_readable($this->filepath); - $this->md = $this->loadMetadata(); + else { + $this->md = $this->loadMetadata(); + $this->exists = is_file($this->filepath) && is_readable($this->filepath); + } + } + + /** + * For testing only, do not use. + */ + public function __setGunid($p_guid) { + $this->gunid = $p_guid; } /** diff --git a/backend/tests/StoredFileTests.php b/backend/tests/StoredFileTests.php index 327825c76..322b94aab 100644 --- a/backend/tests/StoredFileTests.php +++ b/backend/tests/StoredFileTests.php @@ -62,8 +62,16 @@ class StoredFileTest extends PHPUnit_TestCase { $this->fail("StoredFile not created correctly. id = ".$id); return; } - } + $f = new StoredFile(); + $f->__setGunid($storedFile->getGunid()); + $f->loadMetadata(); + if (!is_array($md = $f->getMetadata())) { + $this->fail("Unable to load metadata."); + return; + } + //var_dump($md); + } } ?> \ No newline at end of file