* * 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.class.php'; require_once 'lib/models/OpenGraphURL.class.php'; require_once 'lib/visual.inc.php'; require_once 'lib/classes/Config.class.php'; class VisualFunctionsTest extends \Codeception\Test\Unit { public function setUp(): void { static $config = [ 'LOAD_EXTERNAL_MEDIA' => 'allow', 'OPENGRAPH_ENABLE' => false, ]; 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', 'äöü' => 'äöü', '<' => '<', '"' => '"', "'" => ''', '&' => '&amp;', ''' => '&#039;', '' => '', ]; 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


Test'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testHeading() { $input = '!!%%Überschrift%%'; $expected = '

Überschrift

'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testBoldItalics() { $input = '**some %%code%%**'; $expected = 'some code'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testBigSmall() { $input = '++some --code--++'; $expected = 'some code'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testSimpleBoldItalics() { $input = '*bold*text* %some%italics%'; $expected = 'bold text some italics'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testMissingClose() { $input = '**missing %%close'; $expected = $this->wrap($input); $this->assertEquals($expected, formatReady($input)); } public function testCloseBeforeOpen() { $input = 'there is -}no markup{- here'; $expected = $this->wrap($input); $this->assertEquals($expected, formatReady($input)); } public function testIncorrectNesting() { $input = '** test %% test ** test %%'; $expected = '** test test ** test '; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testImage() { $input = '[img=Stud.IP-Logo]http://www.studip.de/logo.png'; $expected = 'Stud.IP-Logo'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testTable() { $input = "|Name|Matrikelnummer|Studiengang|\n|Max Mustermann|55555|Mathe Diplom|\n"; $expected = '' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'' .'
NameMatrikelnummerStudiengang
Max Mustermann55555Mathe Diplom
'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testList() { $input = "- Einführung\n- Hauptteil\n-= Argument 1\n-= Argument 2\n- Schluss\n"; $expected = ''; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testIndent() { $input = " Ebene 1\n Ebene 2\n Ebene 2\n Ebene 1\n"; $expected = '
' .'Ebene 1
' .'
' .'Ebene 2
' .'Ebene 2
' .'
' .'Ebene 1
' .'
'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input, false)); } public function testNop() { $input = '[nop]**A**[quote]B[/quote]{-C-}[/nop]'; $expected = '**A**[quote]B[/quote]{-C-}'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testPre() { $input = '[pre]**A**{-C-}[/pre]'; $expected = '
AC
'; $expected = $this->wrap($expected); $this->assertEquals($expected, formatReady($input)); } public function testQuote() { $input = '[quote=__Anonymous__]some text[/quote]'; $expected = '
' .'
Anonymous hat geschrieben:
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)); } private function wrap($string) { return sprintf(FORMATTED_CONTENT_WRAPPER, $string); } }