diff --git a/module/VuFind/src/VuFind/Export.php b/module/VuFind/src/VuFind/Export.php index 82a72f392bc8945d4d5a49b1f9fd87986be2f168..c9aef8d4b1e846a230696438013f1685e3e1ad7c 100644 --- a/module/VuFind/src/VuFind/Export.php +++ b/module/VuFind/src/VuFind/Export.php @@ -53,6 +53,13 @@ class Export */ protected $exportConfig; + /** + * Bulk options (initialized to boolean false, populated later) + * + * @var array|bool + */ + protected $bulkOptions = false; + /** * Constructor * @@ -72,10 +79,8 @@ class Export */ public function getBulkOptions() { - static $options = false; - - if ($options === false) { - $options = array(); + if ($this->bulkOptions === false) { + $this->bulkOptions = array(); if (isset($this->mainConfig->BulkExport->enabled) && isset($this->mainConfig->BulkExport->options) && $this->mainConfig->BulkExport->enabled @@ -85,13 +90,13 @@ class Export if (isset($this->mainConfig->Export->$option) && $this->mainConfig->Export->$option == true ) { - $options[] = $option; + $this->bulkOptions[] = $option; } } } } - return $options; + return $this->bulkOptions; } /** diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php index 710f3dd1053a1d06dfc8d59324c4803496ca791d..66ea4bf0efc1e5213629307fdf08184db6123291 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/ExportTest.php @@ -117,6 +117,97 @@ class ExportTest extends \PHPUnit_Framework_TestCase ); } + /** + * Test recordSupportsFormat + * + * @return void + */ + public function testRecordSupportsFormat() + { + $config = array( + 'foo' => array('requiredMethods' => array('getTitle')), + 'bar' => array('requiredMethods' => array('getThingThatDoesNotExist')) + ); + + $export = $this->getExport(array(), $config); + $primo = new \VuFind\RecordDriver\Primo(); + $solr = new \VuFind\RecordDriver\SolrDefault(); + + // Case 1: Primo doesn't support any kind of export. + $this->assertFalse($export->recordSupportsFormat($primo, 'foo')); + + // Case 2: Solr has a getTitle method. + $this->assertTrue($export->recordSupportsFormat($solr, 'foo')); + + // Case 3: Solr lacks a getThingThatDoesNotExist method. + $this->assertFalse($export->recordSupportsFormat($solr, 'bar')); + + // Case 4: Format 'baz' is undefined. + $this->assertFalse($export->recordSupportsFormat($solr, 'baz')); + } + + /** + * Test getFormatsForRecord + * + * @return void + */ + public function testGetFormatsForRecord() + { + // Use RefWorks and EndNote as our test data, since these are the items + // turned on by default if no main config is passed in. + $config = array( + 'RefWorks' => array('requiredMethods' => array('getTitle')), + 'EndNote' => array('requiredMethods' => array('getThingThatDoesNotExist')) + ); + + $export = $this->getExport(array(), $config); + $solr = new \VuFind\RecordDriver\SolrDefault(); + $this->assertEquals(array('RefWorks'), $export->getFormatsForRecord($solr)); + } + + /** + * Test getFormatsForRecords + * + * @return void + */ + public function testGetFormatsForRecords() + { + $mainConfig = array( + 'BulkExport' => array( + 'enabled' => 1, + 'options' => 'anything:marc', + ), + 'Export' => array( + 'anything' => 1, + 'marc' => 1, + ), + ); + $exportConfig = array( + 'anything' => array('requiredMethods' => array('getTitle')), + 'marc' => array('requiredMethods' => array('getMarcRecord')) + ); + $export = $this->getExport($mainConfig, $exportConfig); + $solrDefault = new \VuFind\RecordDriver\SolrDefault(); + $solrMarc = new \VuFind\RecordDriver\SolrMarc(); + + // Only $solrMarc supports the 'marc' option, so we should lose the 'marc' option when we add + // the non-supporting $solrDefault to the array: + $this->assertEquals(array('anything', 'marc'), $export->getFormatsForRecords(array($solrMarc))); + $this->assertEquals(array('anything'), $export->getFormatsForRecords(array($solrMarc, $solrDefault))); + } + + /** + * Test getHeaders + * + * @return void + */ + public function testGetHeaders() + { + $config = array('foo' => array('headers' => array('bar'))); + $export = $this->getExport(array(), $config); + $this->assertEquals(array('bar'), $export->getHeaders('foo')->toArray()); + } + /** * Get a fake MARCXML record * @@ -124,7 +215,7 @@ class ExportTest extends \PHPUnit_Framework_TestCase * * @return string */ - public function getFakeMARCXML($id) + protected function getFakeMARCXML($id) { return '<collection xmlns="http://www.loc.gov/MARC21/slim"><record><id>' . $id . '</id></record></collection>';