diff --git a/module/VuDL/src/VuDL/Connection/Fedora.php b/module/VuDL/src/VuDL/Connection/Fedora.php index 3fb1ad0c49e0ebcc4fb5b868301dd23ee4161f34..e4a4293edd639c32f43455c5f151b4a2725eb3c2 100644 --- a/module/VuDL/src/VuDL/Connection/Fedora.php +++ b/module/VuDL/src/VuDL/Connection/Fedora.php @@ -68,9 +68,7 @@ class Fedora extends AbstractBase */ public function getClasses($id) { - $data = file_get_contents( - $this->getBase() . $id . '/datastreams/RELS-EXT/content' - ); + $data = $this->getDatastreamContent($id, 'RELS-EXT'); $matches = array(); preg_match_all( '/rdf:resource="info:fedora\/vudl-system:([^"]+)/', @@ -91,8 +89,10 @@ class Fedora extends AbstractBase public function getDatastreams($id, $xml = false) { if (!isset($this->datastreams[$id])) { - $this->datastreams[$id] = file_get_contents( - $this->getBase() . $id . '/datastreams?format=xml' + $this->datastreams[$id] = $this->getDatastreamContent( + $id, + '/datastreams?format=xml', + true ); } if ($xml) { @@ -110,11 +110,14 @@ class Fedora extends AbstractBase * * @return string */ - public function getDatastreamContent($id, $stream) + public function getDatastreamContent($id, $stream, $justStream = false) { - return file_get_contents( - $this->getBase() . $id . '/datastreams/' . $stream . '/content' - ); + if ($justStream) { + $url = $this->getBase() . $id . '/datastreams' . $stream; + } else { + $url = $this->getBase() . $id . '/datastreams/' . $stream . '/content'; + } + return file_get_contents($url); } /** diff --git a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/FedoraTest.php b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/FedoraTest.php new file mode 100644 index 0000000000000000000000000000000000000000..10c6b238ddeadf5a43df219ec26e85dec858b6bf --- /dev/null +++ b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/FedoraTest.php @@ -0,0 +1,77 @@ +<?php +/** + * VuDL Fedora Test Class + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +namespace VuDLTest; + +/** + * VuDL Fedora Test Class + * + * @category VuFind2 + * @package Tests + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org/wiki/vufind2:unit_tests Wiki + */ +class FedoraTest extends \VuFindTest\Unit\TestCase +{ + public function testAllWithMock() + { + $subject = $this->getMock( + '\VuDL\Connection\Fedora', + array('getDatastreamContent'), + array((object) array( + 'Fedora'=>(object) array( + 'url_base' => 'http://jsontest.com/', + 'query_url' => 'QUERY', + 'adminUser' => 'ADMIN', + 'adminPass' => 'ADMINPASS' + ) + )) + ); + $subject->method('getDatastreamContent')->will( + $this->onConsecutiveCalls( + '<hasModel xmlns="info:fedora/fedora-system:def/model#" rdf:resource="info:fedora/vudl-system:CLASS1"/><hasModel xmlns="info:fedora/fedora-system:def/model#" rdf:resource="info:fedora/vudl-system:CLASS2"/>', + '<xml><a><b id="c"></b></a></xml>', + '<dc:title>T</dc:title><dc:id>ID</dc:id>' + ) + ); + + $this->assertEquals('http://jsontest.com/', $subject->getBase()); + + $this->assertEquals(array('CLASS1','CLASS2'), $subject->getClasses('id')); + + $this->assertEquals('<xml><a><b id="c"></b></a></xml>', $subject->getDatastreams('id')); + $this->assertEquals('SimpleXMLElement', get_class($subject->getDatastreams('id', true))); + + $this->assertTrue(is_array($subject->getDatastreamHeaders('id', 'fake'))); + + $this->assertEquals(array('title'=>'T','id'=>'ID'), $subject->getDetails('id')); + // Detail formatting tested in Solr + + $this->assertEquals('Zend\Http\Client', get_class($subject->getHttpClient('url'))); + } +} diff --git a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php index 46f6e9347da7320567b244483de628308bfa7e8b..64de44efaba33fa90afc8d809b6e993da06a6c3c 100644 --- a/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php +++ b/module/VuDL/tests/unit-tests/src/VuDLTest/Connection/SolrTest.php @@ -105,7 +105,6 @@ class SolrTest extends \VuFindTest\Unit\TestCase $this->assertEquals(array("CLASS_ONE", "CLASS_TWO"), $subject->getClasses('id')); $this->assertEquals(null, $subject->getDetails('id', false)); - // Test for exception later $this->assertEquals(array("author"=>array("A1","A2"),"series"=>"S1"), $subject->getDetails('id', false)); $this->assertEquals(array( "author"=>array("title"=>"Author", "value"=>array("A1","A2")),