Remove the redirector setting

Fixes 
This commit is contained in:
ArthurHoaro 2019-02-09 13:52:12 +01:00
parent 905f8675a7
commit 520d29578c
12 changed files with 50 additions and 168 deletions

View file

@ -361,36 +361,6 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
);
}
/**
* Test real_url without redirector.
*/
public function testLinkRealUrlWithoutRedirector()
{
$db = new LinkDB(self::$testDatastore, false, false);
foreach ($db as $link) {
$this->assertEquals($link['url'], $link['real_url']);
}
}
/**
* Test real_url with redirector.
*/
public function testLinkRealUrlWithRedirector()
{
$redirector = 'http://redirector.to?';
$db = new LinkDB(self::$testDatastore, false, false, $redirector);
foreach ($db as $link) {
$this->assertStringStartsWith($redirector, $link['real_url']);
$this->assertNotFalse(strpos($link['real_url'], urlencode('://')));
}
$db = new LinkDB(self::$testDatastore, false, false, $redirector, false);
foreach ($db as $link) {
$this->assertStringStartsWith($redirector, $link['real_url']);
$this->assertFalse(strpos($link['real_url'], urlencode('://')));
}
}
/**
* Test filter with string.
*/
@ -516,7 +486,7 @@ class LinkDBTest extends \PHPUnit\Framework\TestCase
public function testRenameTagCaseSensitive()
{
self::$refDB->write(self::$testDatastore);
$linkDB = new LinkDB(self::$testDatastore, true, false, '');
$linkDB = new LinkDB(self::$testDatastore, true, false);
$res = $linkDB->renameTag('sTuff', 'Taz');
$this->assertEquals(1, count($res));

View file

@ -216,56 +216,27 @@ class LinkUtilsTest extends \PHPUnit\Framework\TestCase
}
/**
* Test text2clickable without a redirector being set.
* Test text2clickable.
*/
public function testText2clickableWithoutRedirector()
public function testText2clickable()
{
$text = 'stuff http://hello.there/is=someone#here otherstuff';
$expectedText = 'stuff <a href="http://hello.there/is=someone#here">'
. 'http://hello.there/is=someone#here</a> otherstuff';
$processedText = text2clickable($text, '');
$processedText = text2clickable($text);
$this->assertEquals($expectedText, $processedText);
$text = 'stuff http://hello.there/is=someone#here(please) otherstuff';
$expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)">'
. 'http://hello.there/is=someone#here(please)</a> otherstuff';
$processedText = text2clickable($text, '');
$processedText = text2clickable($text);
$this->assertEquals($expectedText, $processedText);
$text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
$text = 'stuff http://hello.there/is=someone#here(please)&no otherstuff';
$expectedText = 'stuff <a href="http://hello.there/is=someone#here(please)&no">'
. 'http://hello.there/is=someone#here(please)&no</a> otherstuff';
$processedText = text2clickable($text, '');
$this->assertEquals($expectedText, $processedText);
}
/**
* Test text2clickable with a redirector set.
*/
public function testText2clickableWithRedirector()
{
$text = 'stuff http://hello.there/is=someone#here otherstuff';
$redirector = 'http://redirector.to';
$expectedText = 'stuff <a href="' .
$redirector .
urlencode('http://hello.there/is=someone#here') .
'">http://hello.there/is=someone#here</a> otherstuff';
$processedText = text2clickable($text, $redirector);
$this->assertEquals($expectedText, $processedText);
}
/**
* Test text2clickable a redirector set and without URL encode.
*/
public function testText2clickableWithRedirectorDontEncode()
{
$text = 'stuff http://hello.there/?is=someone&or=something#here otherstuff';
$redirector = 'http://redirector.to';
$expectedText = 'stuff <a href="' .
$redirector .
'http://hello.there/?is=someone&or=something#here' .
'">http://hello.there/?is=someone&or=something#here</a> otherstuff';
$processedText = text2clickable($text, $redirector, false);
$processedText = text2clickable($text);
$this->assertEquals($expectedText, $processedText);
}

View file

@ -107,7 +107,7 @@ class PluginMarkdownTest extends \PHPUnit\Framework\TestCase
public function testReverseText2clickable()
{
$text = 'stuff http://hello.there/is=someone#here otherstuff';
$clickableText = text2clickable($text, '');
$clickableText = text2clickable($text);
$reversedText = reverse_text2clickable($clickableText);
$this->assertEquals($text, $reversedText);
}

View file

@ -287,17 +287,14 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
$this->conf = new ConfigManager($sandbox);
$title = '<script>alert("title");</script>';
$headerLink = '<script>alert("header_link");</script>';
$redirectorUrl = '<script>alert("redirector");</script>';
$this->conf->set('general.title', $title);
$this->conf->set('general.header_link', $headerLink);
$this->conf->set('redirector.url', $redirectorUrl);
$updater = new Updater(array(), array(), $this->conf, true);
$done = $updater->updateMethodEscapeUnescapedConfig();
$this->assertTrue($done);
$this->conf->reload();
$this->assertEquals(escape($title), $this->conf->get('general.title'));
$this->assertEquals(escape($headerLink), $this->conf->get('general.header_link'));
$this->assertEquals(escape($redirectorUrl), $this->conf->get('redirector.url'));
unlink($sandbox . '.json.php');
}
@ -707,7 +704,6 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
}
/**
<<<<<<< HEAD
* Test updateMethodWebThumbnailer with thumbnails enabled.
*/
public function testUpdateMethodWebThumbnailerEnabled()
@ -812,4 +808,19 @@ $GLOBALS[\'privateLinkByDefault\'] = true;';
$linkDB = new LinkDB(self::$testDatastore, true, false);
$this->assertTrue($linkDB[1]['sticky']);
}
/**
* Test updateMethodRemoveRedirector().
*/
public function testUpdateRemoveRedirector()
{
$sandboxConf = 'sandbox/config';
copy(self::$configFile . '.json.php', $sandboxConf . '.json.php');
$this->conf = new ConfigManager($sandboxConf);
$updater = new Updater([], null, $this->conf, true);
$this->assertTrue($updater->updateMethodRemoveRedirector());
$this->assertFalse($this->conf->exists('redirector'));
$this->conf = new ConfigManager($sandboxConf);
$this->assertFalse($this->conf->exists('redirector'));
}
}