diff --git a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php index b3f38ea4256b3a6454b98d4f7799ae2da5d03c03..e79a752d264283b3f08c000d2ced6ee7e6ca285b 100644 --- a/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php +++ b/module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/RecordTest.php @@ -135,6 +135,20 @@ class RecordTest extends \PHPUnit_Framework_TestCase $this->assertEquals('success', $record->getToolbar()); } + /** + * Test getCollectionMetadata. + * + * @return void + */ + public function testGetCollectionMetadata() + { + $record = $this->getRecord($this->loadRecordFixture('testbug1.json')); + $record->getView()->expects($this->at(0))->method('render') + ->with($this->equalTo('RecordDriver/SolrMarc/collection-info.phtml')) + ->will($this->returnValue('success')); + $this->assertEquals('success', $record->getCollectionMetadata()); + } + /** * Test getSearchResult. * @@ -310,16 +324,114 @@ class RecordTest extends \PHPUnit_Framework_TestCase $this->assertEquals('success', $record->getTab($tab)); } + /** + * Test various ways of making getQrCode() fail. + * + * @return void + */ + public function testGetQrCodeFailures() + { + // Disabled by default: + $record = $this->getRecord($this->loadRecordFixture('testbug1.json')); + $this->assertFalse($record->getQrCode('core')); + + // Disabled mode: + $config = array('QRCode' => array('showInCore' => false)); + $record = $this->getRecord($this->loadRecordFixture('testbug1.json'), $config); + $this->assertFalse($record->getQrCode('core')); + + // Invalid mode: + $this->assertFalse($record->getQrCode('bad-bad-bad')); + } + + /** + * Test successful getQrCode() call. + * + * @return void + */ + public function testGetQrCodeSuccess() + { + $driver = $this->loadRecordFixture('testbug1.json'); + $context = $this->getMockContext(); + $context->expects($this->once())->method('apply') + ->with($this->equalTo(array('driver' => $driver, 'extra' => 'xyzzy'))) + ->will($this->returnValue(array('bar' => 'baz'))); + $context->expects($this->once())->method('restore') + ->with($this->equalTo(array('bar' => 'baz'))); + $config = array('QRCode' => array('showInCore' => true)); + $record = $this->getRecord($driver, $config, $context, '2:qrcode-show'); + $record->getView()->expects($this->at(0))->method('render') + ->with($this->equalTo('RecordDriver/SolrMarc/core-qrcode.phtml')) + ->will($this->returnValue('success')); + $this->assertEquals('http://foo/bar?text=success&level=L&size=3&margin=4', $record->getQrCode('core', array('extra' => 'xyzzy'))); + } + + /** + * Test getThumbnail() - no thumbnail case + * + * @return void + */ + public function testGetThumbnailNone() + { + // No thumbnail: + $driver = new \VuFindTest\RecordDriver\TestHarness(); + $driver->setRawData(array('Thumbnail' => false)); + $record = $this->getRecord($driver); + $this->assertFalse($record->getThumbnail()); + } + + /** + * Test getThumbnail() - hardcoded thumbnail case + * + * @return void + */ + public function testGetThumbnailHardCoded() + { + // Hard-coded thumbnail: + $driver = new \VuFindTest\RecordDriver\TestHarness(); + $driver->setRawData(array('Thumbnail' => 'http://foo/this.jpg')); + $record = $this->getRecord($driver); + $this->assertEquals('http://foo/this.jpg', $record->getThumbnail()); + } + + /** + * Test getThumbnail() - dynamic thumbnail case + * + * @return void + */ + public function testGetThumbnailDynamic() + { + // Hard-coded thumbnail: + $driver = new \VuFindTest\RecordDriver\TestHarness(); + $driver->setRawData(array('Thumbnail' => array('bar' => 'baz'))); + $record = $this->getRecord($driver, array(), null, '1:cover-show'); + $this->assertEquals('http://foo/bar?bar=baz', $record->getThumbnail()); + } + + /** + * Test getLinkDetails with an empty list + * + * @return void + */ + public function testGetLinkDetailsEmpty() + { + // Hard-coded thumbnail: + $driver = new \VuFindTest\RecordDriver\TestHarness(); + $record = $this->getRecord($driver); + $this->assertEquals(array(), $record->getLinkDetails()); + } + /** * Get a Record object ready for testing. * * @param \VuFind\RecordDriver\AbstractBase $driver Record driver * @param array|Config $config Configuration * @param \VuFind\View\Helper\Root\Context $context Context helper + * @param bool|string $url Should we add a URL helper? False if no, expected timing + : + expected route if yes. * * @return Record */ - protected function getRecord($driver, $config = array(), $context = null) + protected function getRecord($driver, $config = array(), $context = null, $url = false) { if (null === $context) { $context = $this->getMockContext(); @@ -328,6 +440,12 @@ class RecordTest extends \PHPUnit_Framework_TestCase $view->expects($this->at(0))->method('plugin') ->with($this->equalTo('context')) ->will($this->returnValue($context)); + if ($url) { + list($at, $route) = explode(':', $url); + $view->expects($this->at($at))->method('plugin') + ->with($this->equalTo('url')) + ->will($this->returnValue($this->getMockUrl($route))); + } $config = is_array($config) ? new \Zend\Config\Config($config) : $config; $record = new Record($config); $record->setView($view); @@ -347,6 +465,22 @@ class RecordTest extends \PHPUnit_Framework_TestCase return $context; } + /** + * Get a mock URL helper + * + * @param string $expectedRoute Route expected by mock helper + * + * @return \Zend\View\Helper\Url + */ + protected function getMockUrl($expectedRoute) + { + $url = $this->getMock('Zend\View\Helper\Url'); + $url->expects($this->once())->method('__invoke') + ->with($this->equalTo($expectedRoute)) + ->will($this->returnValue('http://foo/bar')); + return $url; + } + /** * Load a fixture file. *