Add tests for MD_STD_IN::sanitize_url() and ensure it supports rewriting
unencoded cyrillic inputs Close #7
This commit is contained in:
37
tests/MD_STD_IN_Test.php
Normal file
37
tests/MD_STD_IN_Test.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?PHP
|
||||
/**
|
||||
* Tests for MD_STD_IN.
|
||||
*
|
||||
* @author Joshua Ramon Enslin <joshua@museum-digital.de>
|
||||
*/
|
||||
declare(strict_types = 1);
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Tests for MD_STD_IN.
|
||||
*/
|
||||
final class MD_STD_IN_Test extends TestCase {
|
||||
/**
|
||||
* Function for testing sanitize_url().
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testSanitizeUrlWorksBasically():void {
|
||||
|
||||
// Ensure empty inputs return empty output
|
||||
self::assertEquals("", MD_STD_IN::sanitize_url(""));
|
||||
self::assertEquals("https://www.museum-digital.org", MD_STD_IN::sanitize_url("https://www.museum-digital.org"));
|
||||
|
||||
// Ensure that cyrillic characters are accepted
|
||||
self::assertEquals("https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4", MD_STD_IN::sanitize_url("https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4"));
|
||||
self::assertEquals("https://sr.wikipedia.org/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4", MD_STD_IN::sanitize_url("https://sr.wikipedia.org/wiki/Београд"));
|
||||
|
||||
self::assertEquals("https://username:password@sr.wikipedia.org:9000/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4", MD_STD_IN::sanitize_url("https://username:password@sr.wikipedia.org:9000/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4"));
|
||||
self::assertEquals("https://username:password@sr.wikipedia.org:9000/wiki/%D0%91%D0%B5%D0%BE%D0%B3%D1%80%D0%B0%D0%B4", MD_STD_IN::sanitize_url("https://username:password@sr.wikipedia.org:9000/wiki/Београд"));
|
||||
|
||||
self::expectException(MDInvalidUrl::class);
|
||||
MD_STD_IN::sanitize_url("h ttps://www.museum-digital.org");
|
||||
|
||||
}
|
||||
}
|
25
tests/bootstrap.php
Normal file
25
tests/bootstrap.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?PHP
|
||||
declare(strict_types = 1);
|
||||
|
||||
/**
|
||||
* Autoloader for musdb.
|
||||
*
|
||||
* @param string $className Name of the class to load.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
\spl_autoload_register(function(string $className):void {
|
||||
|
||||
// Try using class map as defined through /scripts/buildClassMap.php
|
||||
|
||||
foreach (array_merge([__DIR__ . '/../tests', __DIR__ . '/../src', __DIR__ . '/../../MDErrorReporter', __DIR__ . '/../../MDErrorReporter/exceptions', __DIR__ . '/../../MDErrorReporter/exceptions/generic', __DIR__ . '/../../MDErrorReporter/exceptions/updates']) as $classDir) {
|
||||
|
||||
if (\file_exists("$classDir/$className.php")) {
|
||||
include "$classDir/$className.php";
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user