el = new EditLib();
}
protected function tearDown(): void
{
}
public function testParseColor(): void
{
$el = new EditLib();
$col = 'rgb(255 , 0 , 0)';
$hex = $el->parseColor($col);
$this->assertEquals('#FF0000', $hex);
$col = 'rgb(255,0,0)';
$hex = $el->parseColor($col);
$this->assertEquals('#FF0000', $hex);
$col = 'rgb(0, 255,0)';
$hex = $el->parseColor($col);
$this->assertEquals('#00FF00', $hex);
$col = 'rgb(0,0,255)';
$hex = $el->parseColor($col);
$this->assertEquals('#0000FF', $hex);
$col = '#FF0000';
$hex = $el->parseColor($col);
$this->assertEquals('#FF0000', $hex);
}
public function testParseStyleAttribute(): void
{
$el = new EditLib();
/*
* empty style -> empty array
*/
$style = '';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(0, $parsed);
/*
* delimiters only -> empty array
*/
$style = ' ; ; ';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(0, $parsed);
/*
* examples, no shortand lists
*/
$style = 'unknown-list:rgb(1,2,3) url(background.gif);unknown-size:12;';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(2, $parsed);
$this->assertTrue(isset($parsed['unknown-list']));
$this->assertEquals('rgb(1,2,3) url(background.gif)', $parsed['unknown-list']);
$this->assertTrue(isset($parsed['unknown-size']));
$this->assertEquals(12, $parsed['unknown-size']);
$style = 'unknown-list:rgb(1,2,3) url(background.gif);unknown-size:12';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(2, $parsed);
$this->assertTrue(isset($parsed['unknown-list']));
$this->assertEquals('rgb(1,2,3) url(background.gif)', $parsed['unknown-list']);
$this->assertTrue(isset($parsed['unknown-size']));
$this->assertEquals(12, $parsed['unknown-size']);
$style = ' unknown-list : rgb( 1 , 2 , 3 ) url( background.gif ) ; unknown-size: 12 ; ';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(2, $parsed);
$this->assertTrue(isset($parsed['unknown-list']));
$this->assertEquals('rgb( 1 , 2 , 3 ) url( background.gif )', $parsed['unknown-list']);
$this->assertTrue(isset($parsed['unknown-size']));
$this->assertEquals(12, $parsed['unknown-size']);
/*
* examples with shorthand list 'background'
*/
$style = 'background-color:#FF0000';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('#FF0000', $parsed['background-color']);
$style = 'background:#FF0000';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('#FF0000', $parsed['background-color']);
$style = 'background:rgb(0, 0, 0);';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('rgb(0, 0, 0)', $parsed['background-color']);
$style = 'background: rgb(0, 255, 0); background-color:rgb(255, 0, 0);';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('rgb(255, 0, 0)', $parsed['background-color']);
$style = 'background-color:rgb(255, 0, 0); background: rgb(0, 255, 0);';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('rgb(0, 255, 0)', $parsed['background-color']);
$style = 'background-color:rgb(255, 0, 0); background: rgb(0, 255, 0) #0000FF;';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(1, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('#0000FF', $parsed['background-color']);
$style = 'background-color:rgb(255, 0, 0); background: rgb(0, 255, 0) unknown1 #0000FF unknown2;';
$parsed = [];
$el->parseStyleAttribute($style, $parsed);
$this->assertCount(2, $parsed);
$this->assertTrue(isset($parsed['background-color']));
$this->assertEquals('#0000FF', $parsed['background-color']);
$this->assertTrue(isset($parsed['background']));
$this->assertEquals('unknown1 unknown2', $parsed['background']);
}
public function testParseStyleList(): void
{
$el = new EditLib();
/*
* empty
*/
$list = '';
$parsed = [];
$el->parseStyleList($list, $parsed);
$this->assertCount(0, $parsed);
/*
* mixed examples
*/
$list = 'rgb(0, 255, 0) #0000FF';
$parsed = [];
$el->parseStyleList($list, $parsed);
$this->assertCount(2, $parsed);
$this->assertEquals('rgb(0, 255, 0)', $parsed[0]);
$this->assertEquals('#0000FF', $parsed[1]);
$list = 'rgb( 1 , 2 , 3 ) 20px url( background-example.gif )';
$parsed = [];
$el->parseStyleList($list, $parsed);
$this->assertCount(3, $parsed);
$this->assertEquals('rgb( 1 , 2 , 3 )', $parsed[0]);
$this->assertEquals('20px', $parsed[1]);
$this->assertEquals('url( background-example.gif )', $parsed[2]);
}
public function testParseToWikiSpaces(): void
{
/*
* The EditLib eats spaces after the tags
*/
$inData = 'abc bold def';
$res = $this->el->parseToWiki($inData);
$this->assertEquals('abc __ bold __ def', $res);
}
/**
* Nested color specifications
*
* In HTML, color specifications can be nested.
* In Wiki, the colors specifications cannot be nested.
* Hence some reordering is required.
*/
public function testParseToWikiNestedColors(): void
{
/*
* text
*/
$inData = '';
$inData .= '';
$inData .= 'fg and bg colored';
$inData .= '';
$res = $this->el->parseToWiki($inData);
$ex = '~~#FF0000:~~ ,#FFFF00:fg and bg colored~~~~';
$this->assertEquals($ex, $res);
/*
* texttexttexttext
*/
$inData = '';
$inData .= 'fg colored ';
$inData .= '';
$inData .= 'both colored ';
$inData .= '';
$inData .= 'fg colored ';
$inData .= '';
$inData .= 'regular';
$res = $this->el->parseToWiki($inData);
$ex = '~~#FF0000:fg colored ~~ ,#FFFF00:both colored ~~fg colored ~~regular';
$this->assertEquals($ex, $res);
$inData = '';
$inData .= 'bg colored ';
$inData .= '';
$inData .= 'both colored ';
$inData .= '';
$inData .= 'bg colored ';
$inData .= '';
$inData .= 'regular';
$res = $this->el->parseToWiki($inData);
$ex = '~~ ,#FF0000:bg colored ~~#FFFF00:both colored ~~bg colored ~~regular';
$this->assertEquals($ex, $res);
}
/**
* Nested colors with wiki inline
*/
public function testParseToWikiNestedColorsWithWikiInline(): void
{
$inData = '';
$inData .= 'red ';
$inData .= '';
$inData .= 'bold ';
$inData .= '';
$inData .= 'yellow ';
$inData .= '';
$inData .= 'bold ';
$inData .= '';
$inData .= 'red';
$inData .= '';
$ex = '~~#FF0000:red __bold ~~ ,#FFFF00:yellow ~~bold __red~~';
$res = $this->el->parseToWiki($inData);
$this->assertEquals($ex, $res);
}
/**
* Nested wiki inline tags
*
* This test verifies that the tags are written in the correct
* order to the output stream.
*/
public function testParseToWikiNestedInline(): void
{
$ex = '__bold\'\'bold italic\'\'__\n__\'\'bold italic\'\'__';
$inData = 'boldbold italic
bold italic';
$res = $this->el->parseToWiki($inData);
$res = preg_replace('/\n/', '\n', $res); // fix LF encoding for comparison
$this->assertEquals($ex, $res);
$ex = '__bold\'\'bold italic\'\'__\n__bold__';
$inData = 'boldbold italic
bold';
$res = $this->el->parseToWiki($inData);
$res = preg_replace('/\n/', '\n', $res); // fix LF encoding for comparison
$this->assertEquals($ex, $res);
$ex = '__\'\'bold italic\'\'__\n__\'\'BOLD ITALIC\'\'__';
$inData = 'bold italic
BOLD ITALIC';
$res = $this->el->parseToWiki($inData);
$res = preg_replace('/\n/', '\n', $res); // fix LF encoding for comparison
$this->assertEquals($ex, $res);
}
/**
* @group marked-as-incomplete
*/
public function testSpanNestedTitle(): void
{
$this->markTestIncomplete('Work in progress.');
$ex = '--===text===--';
$inData = 'text';
$res = $this->el->parseToWiki($inData);
$this->assertEquals($ex, $res);
}
}