Skip to content
Snippets Groups Projects
Commit 37cc7b73 authored by Demian Katz's avatar Demian Katz
Browse files

Test progress.

parent 76c36781
Branches
Tags
No related merge requests found
...@@ -421,17 +421,89 @@ class RecordTest extends \PHPUnit_Framework_TestCase ...@@ -421,17 +421,89 @@ class RecordTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(array(), $record->getLinkDetails()); $this->assertEquals(array(), $record->getLinkDetails());
} }
/**
* Test getLinkDetails with valid details
*
* @return void
*/
public function testGetLinkDetailsSuccess()
{
$driver = new \VuFindTest\RecordDriver\TestHarness();
$driver->setRawData(
array(
'URLs' => array(
array('route' => 'fake-route', 'prefix' => 'http://proxy?_=', 'desc' => 'a link')
)
)
);
$record = $this->getRecord($driver, array(), null, '1:fake-route', 2);
$this->assertEquals(
array(
array('route' => 'fake-route', 'prefix' => 'http://proxy?_=', 'desc' => 'a link', 'url' => 'http://proxy?_=http://server-foo/baz')
),
$record->getLinkDetails()
);
}
/**
* Test getLinkDetails with invalid details
*
* @return void
* @expectedException Exception
* @expectedExceptionMessage Invalid URL array.
*/
public function testGetLinkDetailsFailure()
{
$driver = new \VuFindTest\RecordDriver\TestHarness();
$driver->setRawData(
array(
'URLs' => array(
array('bad' => 'junk')
)
)
);
$record = $this->getRecord($driver);
$this->assertEquals(
array(
array('route' => 'fake-route', 'prefix' => 'http://proxy?_=', 'desc' => 'a link', 'url' => 'http://proxy?_=http://server-foo/baz')
),
$record->getLinkDetails()
);
}
/**
* Test getUrlList
*
* @return void
*/
public function testGetUrlList()
{
$driver = new \VuFindTest\RecordDriver\TestHarness();
$driver->setRawData(
array(
'URLs' => array(
array('route' => 'fake-route', 'prefix' => 'http://proxy?_=', 'desc' => 'a link')
)
)
);
$record = $this->getRecord($driver, array(), null, '1:fake-route', 2);
$this->assertEquals(
array('http://proxy?_=http://server-foo/baz'), $record->getUrlList()
);
}
/** /**
* Get a Record object ready for testing. * Get a Record object ready for testing.
* *
* @param \VuFind\RecordDriver\AbstractBase $driver Record driver * @param \VuFind\RecordDriver\AbstractBase $driver Record driver
* @param array|Config $config Configuration * @param array|Config $config Configuration
* @param \VuFind\View\Helper\Root\Context $context Context helper * @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. * @param bool|string $url Should we add a URL helper? False if no, expected timing + : + expected route if yes.
* @param bool|int $serverurl Should we add a ServerURL helper? False if no, expected timing if yes.
* *
* @return Record * @return Record
*/ */
protected function getRecord($driver, $config = array(), $context = null, $url = false) protected function getRecord($driver, $config = array(), $context = null, $url = false, $serverurl = false)
{ {
if (null === $context) { if (null === $context) {
$context = $this->getMockContext(); $context = $this->getMockContext();
...@@ -446,6 +518,11 @@ class RecordTest extends \PHPUnit_Framework_TestCase ...@@ -446,6 +518,11 @@ class RecordTest extends \PHPUnit_Framework_TestCase
->with($this->equalTo('url')) ->with($this->equalTo('url'))
->will($this->returnValue($this->getMockUrl($route))); ->will($this->returnValue($this->getMockUrl($route)));
} }
if (false !== $serverurl) {
$view->expects($this->at($serverurl))->method('plugin')
->with($this->equalTo('serverurl'))
->will($this->returnValue($this->getMockServerUrl()));
}
$config = is_array($config) ? new \Zend\Config\Config($config) : $config; $config = is_array($config) ? new \Zend\Config\Config($config) : $config;
$record = new Record($config); $record = new Record($config);
$record->setView($view); $record->setView($view);
...@@ -481,6 +558,21 @@ class RecordTest extends \PHPUnit_Framework_TestCase ...@@ -481,6 +558,21 @@ class RecordTest extends \PHPUnit_Framework_TestCase
return $url; return $url;
} }
/**
* Get a mock server URL helper
*
* @param string $expectedRoute Route expected by mock helper
*
* @return \Zend\View\Helper\ServerUrl
*/
protected function getMockServerUrl()
{
$url = $this->getMock('Zend\View\Helper\ServerUrl');
$url->expects($this->once())->method('__invoke')
->will($this->returnValue('http://server-foo/baz'));
return $url;
}
/** /**
* Load a fixture file. * Load a fixture file.
* *
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment