Skip to content
Snippets Groups Projects
Commit a4701002 authored by llaffont's avatar llaffont Committed by gloas
Browse files

Cosmogramme: add test coverage for javascript url redirection

parent 4a74ec6a
Branches
Tags
2 merge requests!258Dev/13872 Orphee Allow Hold Available Items,!4dev#12091 Moulins portail jeunesse
<?PHP
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class JSRedirect {
public function render($url) {
if ((0!== strpos($url, URL_BASE)) && (strleft($url,4) != "http"))
$url=URL_BASE."php/".$url;
return
'<script>'
.'document.location="'.$url.'"'
.'</script>';
}
}
?>
\ No newline at end of file
......@@ -52,16 +52,13 @@ function getClefSecurite()
$clef=md5($clef);
return $clef;
}
// Redirection en javascript
function redirection( $url )
{
if ((0!== strpos($url, URL_BASE)) && (strleft($url,4) != "http"))
$url=URL_BASE."php/".$url;
print("<script>");
print("document.location='".$url."'");
print("</script>");
print("</body>");
print("</html>");
function redirection( $url ) {
require_once('classe_jsredirect.php');
$html = (new JSRedirect())->render($url);
print ($html.'</body></html');
exit;
}
......
<?php
/**
* Copyright (c) 2012, Agence Française Informatique (AFI). All rights reserved.
*
* AFI-OPAC 2.0 is free software; you can redistribute it and/or modify
* it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE as published by
* the Free Software Foundation.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* AFI-OPAC 2.0 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
require_once('classe_jsredirect.php');
class JSRedirectTest extends PHPUnit_Framework_TestCase {
public function setUp() {
$this->_redirect = new JSRedirect();
}
/** @test */
public function withUrlBaseAsPrefixShouldNotChangeURL() {
$this->assertContains('document.location="'.URL_BASE.'/url.php"',
$this->_redirect->render(URL_BASE.'/url.php'));
}
/** @test */
public function withNoHttpAsPrefixShouldNotAddUrlBase() {
$this->assertContains('document.location="'.URL_BASE.'php/url.php"',
$this->_redirect->render('url.php'));
}
/** @test */
public function withHttpAsPrefixShouldNChangeUrl() {
$this->assertContains('document.location="http://wikipedia.org"',
$this->_redirect->render('http://wikipedia.org'));
}
}
?>
\ No newline at end of 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