*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*/
require_once 'lib/classes/SimpleORMap.php';
require_once 'lib/visual.inc.php';
require_once 'lib/classes/Config.php';
class VisualFunctionsTest extends \Codeception\Test\Unit
{
public function setUp(): void
{
static $config = [
'LOAD_EXTERNAL_MEDIA' => 'allow',
'OPENGRAPH_ENABLE' => false,
'CONVERT_IDNA_URL' => true,
];
Config::set(new Config($config));
$GLOBALS['SYMBOL_SHORT'] = [];
}
public function testFormatReady()
{
$expected = 'some code';
$expected = $this->wrap($expected);
$this->assertEquals($expected, formatReady('*some*code*'));
}
public function testHtmlReady()
{
$pairs = [
'abc' => 'abc',
'äöü' => 'äöü',
'<' => '<',
'"' => '"',
"'" => ''',
'&' => '&',
''' => ''',
'' => '',
];
foreach ($pairs as $string => $expected) {
$this->assertEquals($expected, htmlReady($string));
}
$this->assertEquals(null, htmlReady(null));
}
public function testFormatReadyTicket1255()
{
$input = "!\nHallo Welt";
$expected = "!
Hallo Welt";
$expected = $this->wrap($expected);
$this->assertEquals($expected, formatReady($input));
}
public function testLine()
{
$input = "Test\n--\nTest";
$expected = 'Test
';
$expected = $this->wrap($expected);
$this->assertEquals($expected, formatReady($input));
}
public function testTable()
{
$input = "|Name|Matrikelnummer|Studiengang|\n|Max Mustermann|55555|Mathe Diplom|\n";
$expected = '| Name | ' .'Matrikelnummer | ' .'Studiengang | ' .'
| Max Mustermann | ' .'55555 | ' .'Mathe Diplom | ' .'
A'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testQuote() { $input = '[quote=__Anonymous__]some text[/quote]'; $expected = 'C
' .'some text' .''; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testLink() { $input = '[Testlink]https://www.studip.de/'; $expected = 'Testlink'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testMail() { $input = '[Mail]some.user+tag@example.com'; $expected = 'Mail'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testIdnaLink() { $input = htmlentities('https://www.täst-dömäne-mit-ümläuten.de'); $this->assertEquals( 'https://www.xn--tst-dmne-mit-mluten-gwbfj61b7e.de', idna_link($input) ); } private function wrap($string) { return sprintf(FORMATTED_CONTENT_WRAPPER, $string); } }