The Gitlab instance will be restarted on Monday April 28th at 2AM. There will be a short interruption of service.

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

More robust AJAX tab handling.

- Added another test case.
parent ed61b06d
No related merge requests found
......@@ -42,14 +42,17 @@ class RecordTest extends \VuFindTest\Unit\MinkTestCase
/**
* Test record tabs for a particular ID.
*
* @param Session $session Session
* @param string $id ID to load
* @param Session $session Session
* @param string $id ID to load
* @param bool $encodeId Should we URL encode the ID?
*
* @return void
*/
protected function tryRecordTabsOnId(Session $session, $id)
protected function tryRecordTabsOnId(Session $session, $id, $encodeId = true)
{
$url = $this->getVuFindUrl('/Record/' . str_replace('+', '%20', urlencode($id)));
$url = $this->getVuFindUrl(
'/Record/' . ($encodeId ? rawurlencode($id) : $id)
);
$session->visit($url);
$this->assertEquals(200, $session->getStatusCode());
$page = $session->getPage();
......@@ -77,15 +80,30 @@ class RecordTest extends \VuFindTest\Unit\MinkTestCase
}
/**
* Test that record tabs work with a "weird" ID.
* Test that record tabs work with an ID with a space in it.
*
* @return void
*/
public function testRecordTabsOnWeirdId()
public function testRecordTabsOnSpacedId()
{
$session = $this->getMinkSession();
$session->start();
$this->tryRecordTabsOnId($session, 'dot.dash-underscore__3.space suffix');
$session->stop();
}
/**
* Test that record tabs work with an ID with a plus in it.
*
* @return void
*/
public function testRecordTabsOnPlusId()
{
$session = $this->getMinkSession();
$session->start();
// Skip encoding on this one, because Zend Framework doesn't URL encode
// plus signs in route segments!
$this->tryRecordTabsOnId($session, 'theplus+andtheminus-', false);
$session->stop();
}
}
This diff is collapsed.
......@@ -147,14 +147,20 @@ function registerTabEvents() {
}
function ajaxLoadTab(tabid) {
var id = $('.hiddenId')[0].value;
// Try to parse out the controller portion of the URL. If this fails, or if
// we're flagged to skip AJAX for this tab, just return true and let the
// if we're flagged to skip AJAX for this tab, just return true and let the
// browser handle it.
var urlroot = document.URL.match(new RegExp('/[^/]+/' + encodeURIComponent(id)));
if(!urlroot || document.getElementById(tabid).parentNode.className.indexOf('noajax') > -1) {
if(document.getElementById(tabid).parentNode.className.indexOf('noajax') > -1) {
return true;
}
// Parse out the base URL for the current record:
var urlParts = document.URL.split('#');
var urlWithoutFragment = urlParts[0];
var pathInUrl = urlWithoutFragment.indexOf(path);
var chunks = urlWithoutFragment.substring(pathInUrl + path.length + 1).split('/');
var urlroot = '/' + chunks[0] + '/' + chunks[1];
// Request the tab via AJAX:
$.ajax({
url: path + urlroot + '/AjaxTab',
type: 'POST',
......
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