',
'expected' => '
'),
11 => array(
'input' => '
Test ',
'expected' => '
Test '
),
12 => array(
'input' => "From here > to there",
'expected' => "From here > to there"
),
13 => array(
'input' => "[html]
Hello World!
[/html]",
'expected' => '[html]
Hello World!
[/html]'
),
14 => array(
'input' => "Something & something",
'expected' => 'Something & something'
),
15 => array(
'input' => array('news_category', '2', '0'),
'expected' => array('news_category', '2', '0')
),
16 => array(
'input' => array('my/customer/key' => 'news_category', 3 => '2', 'bla' => 5, 'true' => true, 'false' => false, 'empty' => ''),
'expected' => array('my/customer/key' => 'news_category', 3 => '2', 'bla' => 5, 'true' => true, 'false' => false, 'empty' => ''),
),
17 => array(
'input' => array('Some long string & stuff' => 0, 'other' => null, 'extra' => 0.3, 'null' => null),
'expected' => array('Some long string & stuff' => 0, 'other' => null, 'extra' => 0.3, 'null' => null),
),
/* 18 => array(
'input' => '">',
'expected' => '',
'mode' => 'model',
'parm' => array('type'=>'text', 'field'=>'news_title')
),*/
19 => array( // admin log simulation
'input' => "Array[!br!]([!br!] [0] => zero[!br!] [1] => one[!br!] [2] => two[!br!])[!br!]",
'expected' => "Array[!br!]([!br!] [0] => zero[!br!] [1] => one[!br!] [2] => two[!br!])[!br!]",
'mode' => 'no_html',
),
20 => array(
'input' => '\\',
'expected' => '\',
'mode' => 'no_html',
),
21 => array(
'input' => '
Hello ',
'expected' => '<a href="">Hello</a>',
'mode' => 'no_html',
),
22 => array(
'input' => '< 200',
'expected' => '< 200',
),
23 => array(
'input' => '[html]
echo {e_BASE}."index.php"; [/html]',
'expected' => '[html]
echo {e_BASE}."index.php"; [/html]'
),
24 => array(
'input' => '[html]
echo {e_BASE}."index.php";
[/html]',
'expected' => '[html]
echo {e_BASE}."index.php";
[/html]'
),
25 => array(
'input' => '[html]
[/html]',
'expected' => '[html]
[/html]'
),
26 => array(
'input' => "[html]
function sc_my_shortcode(){\nreturn \"Something\";}
[/html]",
'expected' => "[html]
function sc_my_shortcode(){\nreturn "Something";}
[/html]"
),
27 => array(
'input' => "[html]
require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF); ",
'expected' => "[html]
require_once("class2.php");\nrequire_once(HEADERF);\necho "test";<br>\nrequire_once(FOOTERF); ",
),
28 => array(
'html' => "
{THEME_PREF: code=header_width&default=container} ",
'expected' => "
{THEME_PREF: code=header_width&default=container} ",
),
29 => array(
'html' => "
/* {THEME_PREF: code=header_width&default=container} */ ",
'expected' => "
/* {THEME_PREF: code=header_width&default=container} */ ",
),
30 => array(
'html' => "
",
'expected' => "
",
),
);
foreach ($tests as $k => $var)
{
if (empty($var['input']))
{
continue;
}
$mode = varset($var['mode']);
$parm = varset($var['parm']);
$result = $this->tp->toDB($var['input'], false, false, $mode, $parm);
self::assertSame($var['expected'], $result, 'Test #' . $k . " failed." . print_r($this->tp->getRemoved(), true));
}
}
/*
public function testToJSONhelper()
{
}
public function testToJSON()
{
}
*/
public function testPostToForm()
{
$text = "
My Test
";
$expected = '<div class='something'>My Test</div>';
$result = $this->tp->post_toForm($text);
self::assertSame($expected, $result);
$array = array($text);
$arrayExp = array($expected);
$result = $this->tp->post_toForm($array);
self::assertSame($arrayExp, $result);
}
public function testHtml_truncate()
{
$this->tp->setMultibyte(true);
$tests = array(
0 => array(
'input' => '
Lorem ipsum dolor sit amet.
',
'expected' => '
Lorem ipsum dolor...
',
),
1 => array(
'input' => '
Lorem ipsum dolor sit amet.
',
'expected' => '
Lorem ipsum dolor...
',
),
2 => array(
'input' => '
Lorem ipsum dolor sit amet.
',
'expected' => '
Lorem ipsum dolo...
',
),
3 => array(
'input' => '
Это предложение на русском языке
',
'expected' => '
Это предложение н...
',
),
4 => array(
'input' => '
Lorem ipsum & dolor sit amet.
',
'expected' => '
Lorem ipsum & dol...
',
),
5 => array(
'input' => '
Это предложение на русском языке
',
'expected' => '
Это предложение...
',
'exact' => false,
),
/* 6 => array(
'input' => '
Lorem
ipsum dolor sit amet',
'expected' => '',
),
*/
);
foreach ($tests as $index => $var)
{
if (empty($var['input']))
{
continue;
}
$exact = isset($var['exact']) ? $var['exact'] : true;
$result = $this->tp->html_truncate($var['input'], 17, '...', $exact);
if (empty($var['expected']))
{
echo $result . "\n\n";
continue;
}
self::assertSame($var['expected'], $result, "Failed on test #" . $index);
}
}
/*
public function testCheckHighlighting()
{
}
public function testThumbWidth()
{
}
*/
public function testReplaceConstants()
{
$tests = array(
0 => array(
'path' => '{e_BASE}news',
'type' => 'abs',
'match' => e_HTTP,
),
1 => array(
'path' => '{e_BASE}news.php',
'type' => 'full',
'match' => 'https://localhost/e107/news.php',
),
2 => array(
'path' => '{e_PLUGIN}news/index.php',
'type' => null,
'match' => 'e107_plugins/news/index.php',
),
);
foreach ($tests as $var)
{
$actual = $this->tp->replaceConstants($var['path'], $var['type']);
self::assertStringContainsString($var['match'], $actual);
}
}
/*
public function testHtmlwrap()
{
$html = "
";
$result = $this->tp->htmlwrap($html, 20);
}*/
public function testToRss()
{
/* if(PHP_VERSION_ID < 71000 )
{
$this->markTestSkipped("testToRSS() skipped. Requires a healthy libxml installation");
return null;
}*/
$tests = array(
'[html]
</p><p><core name="e_jslib_plugin"><![CDATA[Array]]></core></p><p><core name="e_jslib_theme"><![CDATA[Array]]></core> [/html]',
'
One & Two < and > " or \'
',
);
foreach ($tests as $html)
{
$result = $this->tp->toRss($html, true);
$valid = $this->isValidXML($result);
self::assertTrue($valid);
}
// Test with $tags = false;
$html = '
One & Two < and > " or \'
';
$result = $this->tp->toRss($html);
self::assertSame("One & Two < and > \" or '", $result);
$valid = $this->isValidXML('
' . $result . ' ');
self::assertTrue($valid);
}
private function isValidXML($xmlContent)
{
if (trim($xmlContent) == '')
{
return false;
}
$xmlContent = '' . "\n" . '
' . $xmlContent . ' ';
libxml_use_internal_errors(true);
libxml_clear_errors();
$doc = new DOMDocument('1.0', 'utf-8');
$doc->loadXML($xmlContent);
$errors = libxml_get_errors();
if (!empty($errors))
{
codecept_debug($errors);
}
libxml_clear_errors();
return empty($errors);
}
/*
public function testPreFilter()
{
}
*/
public function testThumbUrl()
{
$urls = array(
0 => array(
'path' => '{e_PLUGIN}gallery/images/butterfly.jpg',
'options' => array('w' => 300, 'h' => 200),
'expected' => '/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=200'
),
1 => array(
'path' => '{e_PLUGIN}dummy/Freesample.svg',
'options' => array('w' => 300, 'h' => 200),
'expected' => '/e107_plugins/dummy/Freesample.svg'
),
2 => array(
'path' => '{e_PLUGIN}gallery/images/butterfly.jpg',
'options' => array('w' => 300, 'h' => 200, 'type' => 'webp'),
'expected' => '/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=300&h=200&type=webp'
),
3 => array(
'path' => '{e_PLUGIN}gallery/images/butterfly.jpg',
'options' => array('w' => 300, 'h' => 200, 'scale' => '2x'),
'expected' => '/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fbutterfly.jpg&w=600&h=400'
),
4 => array(
'path' => '{e_PLUGIN}gallery/images/horse.jpg',
'options' => array('w' => 300, 'h' => 200, 'scale' => '2x', 'type' => 'webp'),
'expected' => '/thumb.php?src=e_PLUGIN%2Fgallery%2Fimages%2Fhorse.jpg&w=600&h=400&type=webp'
),
);
foreach ($urls as $val)
{
$actual = $this->tp->thumbUrl($val['path'], $val['options']);
self::assertStringContainsString($val['expected'], $actual);
//echo $$actual."\n\n";
}
}
public function testThumbUrlSEF()
{
$urls = array(
0 => array(
'path' => '{e_MEDIA_IMAGE}butterfly.jpg',
'options' => array('w' => 300, 'h' => 200),
'expected' => '/media/img/300x200/butterfly.jpg'
),
1 => array(
'path' => '{e_THEME}dummy/Freesample.svg',
'options' => array('w' => 300, 'h' => 200),
'expected' => '/theme/img/300x200/dummy/Freesample.svg'
),
2 => array(
'path' => '{e_AVATAR}avatar.jpg',
'options' => array('w' => 100, 'h' => 100),
'expected' => '/media/avatar/100x100/avatar.jpg'
),
/*2 => array(
'path' => '{e_MEDIA_IMAGE}gallery/images/butterfly.jpg',
'options' => array('w'=>300, 'h'=>200, 'type'=>'webp'),
'expected' =>'/media/img/300x200/gallery/images/butterfly.webp'
),*/
3 => array(
'path' => '{e_MEDIA_IMAGE}gallery/images/butterfly.jpg',
'options' => array('w' => 300, 'h' => 200, 'scale' => '2x'),
'expected' => '/media/img/600x400/gallery/images/butterfly.jpg'
),
);
foreach ($urls as $val)
{
$actual = $this->tp->thumbUrlSEF($val['path'], $val['options']);
self::assertStringContainsString($val['expected'], $actual);
//echo $$actual."\n\n";
}
}
/*
public function testParseBBCodes()
{
}
public function testGetEmotes()
{
}
public function testThumbHeight()
{
}
public function testDataFilter()
{
}
*/
public function testToAttributeReplaceConstants()
{
$input = "This is e_THEME: {e_THEME}";
$expected = "This is e_THEME: ./e107_themes/";
$actual = $this->tp->toAttribute($input);
self::assertEquals($expected, $actual);
}
public function testToAttributeDoesNotReplaceConstantsWhenStringHasSingleQuote()
{
$input = "This isn't e_THEME: {e_THEME}";
$expected = "This isn't e_THEME: {e_THEME}";
$actual = $this->tp->toAttribute($input);
self::assertEquals($expected, $actual);
}
public function testToAttributeDoesReplaceConstantsWhenStringHasLeftAngleBracket()
{
$input = "{e_THEME} <-- e_THEME";
$expected = "./e107_themes/ <-- e_THEME";
$actual = $this->tp->toAttribute($input);
self::assertEquals($expected, $actual);
}
public function testToAttributeExplicitPure()
{
$input = "{e_THEME} <-- Not e_THEME";
$expected = "{e_THEME} <-- Not e_THEME";
$actual = $this->tp->toAttribute($input, true);
self::assertEquals($expected, $actual);
}
public function testToAttributeImplicitPure()
{
$input = "\"It's a Wonderful Life (1946)\"";
$expected = ""It's a Wonderful Life (1946)"";
$actual = $this->tp->toAttribute($input);
self::assertEquals($expected, $actual);
}
public function testToAttributesEmpty()
{
$input = [];
$expected = "";
$actual = $this->tp->toAttributes($input);
self::assertEquals($expected, $actual);
}
public function testToAttributesOne()
{
$input = ["href" => "https://e107.org"];
$expected = " href='https://e107.org'";
$actual = $this->tp->toAttributes($input);
self::assertEquals($expected, $actual);
}
public function testToAttributesMixedPureAndReplaceConstants()
{
$input = [
"href" => "{e_THEME}",
"title" => "I would say, \"I'm the e_THEME folder!\"",
"alt" => "'{e_THEME}'",
];
$expected = " href='./e107_themes/'" .
" title='I would say, "I'm the e_THEME folder!"'" .
" alt=''{e_THEME}''";
$actual = $this->tp->toAttributes($input);
self::assertEquals($expected, $actual);
}
public function testThumbCacheFile()
{
$tests = array(
0 => array(
'file' => 'e107_plugins/gallery/images/butterfly.jpg',
'options' => array('w' => 222, 'h' => 272, 'aw' => 0, 'ah' => 0, 'c' => 0,),
'expected' => array('prefix' => 'thumb_butterfly_', 'suffix' => '.jpg.cache.bin'),
),
1 => array(
'file' => 'e107_plugins/gallery/images/butterfly.jpg',
'options' => array('w' => 222, 'h' => 272, 'aw' => 0, 'ah' => 0, 'c' => 0, 'type' => 'webp'),
'expected' => array('prefix' => 'thumb_butterfly_', 'suffix' => '.webp.cache.bin'),
),
2 => array(
'file' => 'e107_plugins/gallery/images/butterfly.jpg',
'options' => array('w' => 222, 'h' => 272, 'c' => 0, 'type' => 'webp'),
'expected' => array('prefix' => 'thumb_butterfly_', 'suffix' => '.webp.cache.bin'),
),
);
foreach ($tests as $var)
{
$result = $this->tp->thumbCacheFile($var['file'], $var['options']);
self::assertStringStartsWith($var['expected']['prefix'], $result);
self::assertStringEndsWith($var['expected']['suffix'], $result);
}
}
public function testText_truncate()
{
$string = "This is a long string that will be truncated.";
$result = $this->tp->text_truncate($string, 20);
self::assertSame('This is a long ... ', $result);
$string = "This is has something & something";
$result = $this->tp->text_truncate($string, 29);
self::assertSame('This is has something & ... ', $result);
$string = "Can't fail me now [b]Bold[/b]";
$result = $this->tp->text_truncate($string, 25);
self::assertSame("Can't fail me now Bold", $result);
$string = "Can't fail me now
Bold ";
$result = $this->tp->text_truncate($string, 25);
self::assertSame("Can't fail me now Bold", $result);
}
public function testTruncate()
{
// html
$string = "Can't fail me now
Bold ";
$result = $this->tp->truncate($string, 25);
self::assertSame("Can't fail me now
Bold ", $result); // html ignored in char count.
// bbcode - stripped.
$string = "Can't fail me now [b]Bold[/b]";
$result = $this->tp->truncate($string, 25);
self::assertSame("Can't fail me now Bold", $result);
// text
$string = "This is a long string that will be truncated.";
$result = $this->tp->truncate($string, 20);
self::assertSame('This is a long st...', $result);
}
/*
public function testSetThumbSize()
{
}
public function testToJS()
{
}
*/
public function testSimpleParse()
{
$vars = array(
'CONTACT_SUBJECT' => "My Subject",
'CONTACT_PERSON' => "My Name"
);
$template = "{CONTACT_SUBJECT}
{CONTACT_PERSON} {MISSING_SHORTCODE}";
$result = $this->tp->simpleParse($template, $vars);
self::assertEquals("My Subject
My Name ", $result);
$result = $this->tp->simpleParse($template, null);
self::assertEquals("
", $result);
$vars = array(
'aaBB_123' => "Simple Replacement"
);
$template = "-- {aaBB_123} --";
$result = $this->tp->simpleParse($template, $vars);
self::assertEquals('-- Simple Replacement --', $result);
}
public function testGetModifierList()
{
$expected = array(
'TITLE' =>
array(
'context' => 'TITLE',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => false,
'hook' => true,
'scripts' => true,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'TITLE_PLAIN' =>
array(
'context' => 'TITLE_PLAIN',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => false,
'hook' => true,
'scripts' => true,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => true,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'USER_TITLE' =>
array(
'context' => 'USER_TITLE',
'fromadmin' => false,
'emotes' => false,
'defs' => false,
'constants' => false,
'hook' => false,
'scripts' => false,
'link_click' => false,
'link_replace' => true,
'parse_sc' => false,
'no_tags' => false,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'E_TITLE' =>
array(
'context' => 'E_TITLE',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => false,
'hook' => true,
'scripts' => false,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'SUMMARY' =>
array(
'context' => 'SUMMARY',
'fromadmin' => false,
'emotes' => true,
'defs' => true,
'constants' => 'full',
'hook' => true,
'scripts' => true,
'link_click' => true,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
),
'DESCRIPTION' =>
array(
'context' => 'DESCRIPTION',
'fromadmin' => false,
'emotes' => true,
'defs' => true,
'constants' => 'full',
'hook' => true,
'scripts' => true,
'link_click' => true,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
),
'BODY' =>
array(
'context' => 'BODY',
'fromadmin' => false,
'emotes' => true,
'defs' => true,
'constants' => 'full',
'hook' => true,
'scripts' => true,
'link_click' => true,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
),
'WYSIWYG' =>
array(
'context' => 'WYSIWYG',
'fromadmin' => false,
'emotes' => true,
'defs' => false,
'constants' => false,
'hook' => false,
'scripts' => true,
'link_click' => false,
'link_replace' => false,
'parse_sc' => false,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => true,
),
'USER_BODY' =>
array(
'context' => 'USER_BODY',
'fromadmin' => false,
'emotes' => true,
'defs' => false,
'constants' => 'full',
'hook' => true,
'scripts' => false,
'link_click' => true,
'link_replace' => true,
'parse_sc' => false,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
'nostrip' => false,
),
'E_BODY' =>
array(
'context' => 'E_BODY',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => 'full',
'hook' => true,
'scripts' => false,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
),
'E_BODY_PLAIN' =>
array(
'context' => 'E_BODY_PLAIN',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => 'full',
'hook' => true,
'scripts' => false,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => true,
'value' => false,
'nobreak' => false,
'retain_nl' => true,
),
'LINKTEXT' =>
array(
'context' => 'LINKTEXT',
'fromadmin' => false,
'emotes' => false,
'defs' => true,
'constants' => false,
'hook' => false,
'scripts' => true,
'link_click' => false,
'link_replace' => true,
'parse_sc' => true,
'no_tags' => false,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'RAWTEXT' =>
array(
'context' => 'RAWTEXT',
'fromadmin' => false,
'emotes' => false,
'defs' => false,
'constants' => false,
'hook' => false,
'scripts' => true,
'link_click' => false,
'link_replace' => true,
'parse_sc' => false,
'no_tags' => true,
'value' => false,
'nobreak' => true,
'retain_nl' => true,
),
'NODEFAULT' => array(
'context' => 'NODEFAULT',
'fromadmin' => false,
'emotes' => false,
'defs' => false,
'constants' => false,
'hook' => false,
'scripts' => false,
'link_click' => false,
'link_replace' => false,
'parse_sc' => false,
'no_tags' => false,
'value' => false,
'nobreak' => false,
'retain_nl' => false,
)
);
$list = $this->tp->getModifierList('super');
self::assertSame($expected, $list);
}
public function testToText()
{
$arr = array(
// Basic Cases
0 => array('html' => "
", 'expected' => 'My Caption'),
1 => array('html' => "
", 'expected' => 'My Caption'),
2 => array('html' => 'Line 1
Line 2
Line 3
', 'expected' => "Line 1\nLine 2\nLine 3\n"),
3 => array('html' => "Line 1
\nLine 2
\nLine 3
", 'expected' => "Line 1\nLine 2\nLine 3\n"),
// Special Characters
/*
4 => array('html' => 'Text & More Text', 'expected' => 'Text & More Text'),
5 => array('html' => 'Text <b>Bold</b>', 'expected' => 'Text
Bold '),
6 => array('html' => '
Bold & Italic ', 'expected' => 'Bold & Italic'),
// HTML Entities
7 => array('html' => '<div>Hello World</div>', 'expected' => '
Hello World
'),
8 => array('html' => 'Text with © and ®', 'expected' => 'Text with © and ®'),
// Empty and Plain Text
9 => array('html' => '', 'expected' => ''),
10 => array('html' => null, 'expected' => ''), // If null should be handled as empty string.
11 => array('html' => 'Plain Text', 'expected' => 'Plain Text'),
// Whitespace and Non-breaking Spaces
12 => array('html' => ' Text surrounded by spaces ', 'expected' => ' Text surrounded by spaces '),
13 => array('html' => 'Text with non-breaking spaces', 'expected' => 'Text with non-breaking spaces'),
// Nested Tags
14 => array('html' => '
Deeply Nested
', 'expected' => 'Deeply Nested'),
15 => array('html' => '
', 'expected' => "Item 1\nItem 2\nItem 3"),
// Void Tags
16 => array('html' => 'Text
More Text', 'expected' => 'TextMore Text'),
17 => array('html' => '
Line Break
', 'expected' => "Line Break"),
// Malformed/Invalid HTML
18 => array('html' => '
Unclosed tag', 'expected' => 'Unclosed tag'), // Closes should be handled.
19 => array('html' => 'Text
Bold Text', 'expected' => "TextBold Text"), // Handle even broken tags.
*/
);
foreach ($arr as $k=>$var)
{
$result = $this->tp->toText($var['html']);
self::assertEquals($var['expected'], $result, "Test $k failed");
}
}
/*
public function testUstrtolower()
{
}
public function testObfuscate()
{
}
public function testDoReplace()
{
}
*/
public function testStaticUrl()
{
$tests = array(
0 => array(
'expected' => 'https://static.mydomain.com/',
'input' => null,
'static' => true,
),
1 => array(
'expected' => 'https://static.mydomain.com/e107_web/lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'input' => e_WEB_ABS . 'lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'static' => true,
),
2 => array(
'expected' => 'https://static.mydomain.com/e107_media/000000test/myimage.jpg',
'input' => e_MEDIA_ABS . 'myimage.jpg',
'static' => true,
),
3 => array(
'expected' => 'https://static.mydomain.com/e107_themes/bootstrap3/images/myimage.jpg',
'input' => '{THEME}images/myimage.jpg',
'static' => true,
),
4 => array(
'expected' => e_WEB_ABS . 'lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'input' => '{e_WEB}lib/font-awesome/4.7.0/fonts/fontawesome-webfont.woff2?v=4.7.0',
'static' => false,
),
);
foreach ($tests as $val)
{
$static = !empty($val['static']) ? 'https://static.mydomain.com/' : null;
$this->tp->setStaticUrl($static);
$actual = $this->tp->staticUrl($val['input']);
self::assertSame($val['expected'], $actual);
}
$this->tp->setStaticUrl(null);
// Test with Static Array
$static = [
'https://static1.mydomain.com/',
'https://static2.mydomain.com/',
'https://static3.mydomain.com/',
];
$this->tp->setStaticUrl($static);
$tests = [
1 => array(
'expected' => 'https://static1.mydomain.com/e107_themes/bootstrap3/images/myimage1.jpg',
'input' => '{THEME}images/myimage1.jpg',
'static' => true,
),
2 => array(
'expected' => 'https://static2.mydomain.com/e107_themes/bootstrap3/images/myimage2.jpg',
'input' => '{THEME}images/myimage2.jpg',
'static' => true,
),
3 => array(
'expected' => 'https://static3.mydomain.com/e107_themes/bootstrap3/images/myimage3.jpg',
'input' => '{THEME}images/myimage3.jpg',
'static' => true,
),
4 => array( // test that previously generated static URL retains the same static domain when called again.
'expected' => 'https://static3.mydomain.com/e107_themes/bootstrap3/images/myimage3.jpg',
'input' => '{THEME}images/myimage3.jpg',
'static' => true,
),
5 => array( // test that previously generated static URL retains the same static domain when called again.
'expected' => 'https://static2.mydomain.com/e107_themes/bootstrap3/images/myimage2.jpg',
'input' => '{THEME}images/myimage2.jpg',
'static' => true,
),
];
foreach($tests as $val)
{
$actual = $this->tp->staticUrl($val['input']);
self::assertSame($val['expected'], $actual);
}
$map = $this->tp->getStaticUrlMap();
self::assertStringContainsString('https://static2.mydomain.com', $map['e107-themes/bootstrap3/images/myimage2.jpg'] );
$this->tp->setStaticUrl(null);
e107::getParser()->setStaticUrl(null);
}
/*
public function testGetUrlConstants()
{
}
public function testUstrrpos()
{
}
*/
public function testPost_toHTML()
{
$text = "
Test "; // invalid html.
$result = $this->tp->post_toHTML($text);
self::assertEmpty($result);
$text = "
Test
"; // valid html.
$cleaned = '
Test
'; // valid and cleaned html.
$result = $this->tp->post_toHTML($text);
self::assertSame($cleaned, $result);
}
/*
public function testAddAllowedTag()
{
}
public function testAddAllowedAttribute()
{
}
public function testSetAllowedTags()
{
}
*/
public function testSetScriptAccess()
{
$this->tp->setScriptAccess(e_UC_PUBLIC);
$result = $this->tp->getScriptAccess();
self::assertEquals(e_UC_PUBLIC, $result);
}
/*
public function testGetAllowedTags()
{
}
*/
public function testGetScriptAccess()
{
$result = $this->tp->getScriptAccess();
self::assertFalse($result);
}
public function testGetAllowedAttributes()
{
$expected = array(
'default' =>
array(
0 => 'id',
1 => 'style',
2 => 'class',
3 => 'title',
4 => 'lang',
5 => 'accesskey',
),
'img' =>
array(
0 => 'src',
1 => 'alt',
2 => 'width',
3 => 'height',
4 => 'id',
5 => 'style',
6 => 'class',
7 => 'title',
8 => 'lang',
9 => 'accesskey',
),
'a' =>
array(
0 => 'href',
1 => 'target',
2 => 'rel',
3 => 'id',
4 => 'style',
5 => 'class',
6 => 'title',
7 => 'lang',
8 => 'accesskey',
),
'script' =>
array(
0 => 'type',
1 => 'src',
2 => 'language',
3 => 'async',
4 => 'id',
5 => 'style',
6 => 'class',
7 => 'title',
8 => 'lang',
9 => 'accesskey',
),
'iframe' =>
array(
'src',
'frameborder',
'width',
'height',
'allowfullscreen',
'allow',
'id',
'style',
'class',
'title',
'lang',
'accesskey',
),
'input' =>
array(
0 => 'type',
1 => 'name',
2 => 'value',
3 => 'id',
4 => 'style',
5 => 'class',
6 => 'title',
7 => 'lang',
8 => 'accesskey',
),
'form' =>
array(
0 => 'action',
1 => 'method',
2 => 'target',
3 => 'id',
4 => 'style',
5 => 'class',
6 => 'title',
7 => 'lang',
8 => 'accesskey',
),
'audio' =>
array(
0 => 'src',
1 => 'controls',
2 => 'autoplay',
3 => 'loop',
4 => 'muted',
5 => 'preload',
6 => 'id',
7 => 'style',
8 => 'class',
9 => 'title',
10 => 'lang',
11 => 'accesskey',
),
'video' =>
array(
0 => 'autoplay',
1 => 'controls',
2 => 'height',
3 => 'loop',
4 => 'muted',
5 => 'poster',
6 => 'preload',
7 => 'src',
8 => 'width',
9 => 'id',
10 => 'style',
11 => 'class',
12 => 'title',
13 => 'lang',
14 => 'accesskey',
),
'table' => array(
0 => 'border',
1 => 'cellpadding',
2 => 'cellspacing',
3 => 'id',
4 => 'style',
5 => 'class',
6 => 'title',
7 => 'lang',
8 => 'accesskey',
),
'td' =>
array(
0 => 'colspan',
1 => 'rowspan',
2 => 'name',
3 => 'bgcolor',
4 => 'id',
5 => 'style',
6 => 'class',
7 => 'title',
8 => 'lang',
9 => 'accesskey',
),
'th' =>
array(
0 => 'colspan',
1 => 'rowspan',
2 => 'id',
3 => 'style',
4 => 'class',
5 => 'title',
6 => 'lang',
7 => 'accesskey',
),
'col' =>
array(
0 => 'span',
1 => 'id',
2 => 'style',
3 => 'class',
4 => 'title',
5 => 'lang',
6 => 'accesskey',
),
'embed' =>
array(
0 => 'src',
1 => 'wmode',
2 => 'type',
3 => 'width',
4 => 'height',
5 => 'id',
6 => 'style',
7 => 'class',
8 => 'title',
9 => 'lang',
10 => 'accesskey',
),
'x-bbcode' =>
array(
0 => 'alt',
1 => 'id',
2 => 'style',
3 => 'class',
4 => 'title',
5 => 'lang',
6 => 'accesskey',
),
'label' =>
array(
0 => 'for',
1 => 'id',
2 => 'style',
3 => 'class',
4 => 'title',
5 => 'lang',
6 => 'accesskey',
),
'source' =>
array(
0 => 'media',
1 => 'sizes',
2 => 'src',
3 => 'srcset',
4 => 'type',
5 => 'id',
6 => 'style',
7 => 'class',
8 => 'title',
9 => 'lang',
10 => 'accesskey',
),
);
$result = $this->tp->getAllowedAttributes();
self::assertSame($expected, $result);
// var_export($result);
// $true = is_array($result) && in_array('style',$result['img']);
// self::assertTrue($true);
}
/*
public function testSetScriptTags()
{
}
public function testLeadingZeros()
{
}
public function testLanVars()
{
}
*/
public function testGetTags()
{
$html = "
";
$result = $this->tp->getTags($html, 'img');
$expected = array(
'img' =>
array(
0 =>
array(
'src' => '#',
'alt' => 'whatever',
'@value' => '
',
),
),
);
if (empty($expected['img'][0]))
{
self::assertTrue(false, "getTags() didn't return the correct value");
}
self::assertSame($expected['img'][0]['src'], $result['img'][0]['src']);
self::assertSame($expected['img'][0]['alt'], $result['img'][0]['alt']);
}
public function testToGlyph()
{
$this->tp->setFontAwesome(4);
$result = $this->tp->toGlyph('fa-envelope.glyph');
$expected = "
";
self::assertEquals($expected, $result);
$this->tp->setFontAwesome(5);
$result = $this->tp->toGlyph('fa-mailchimp');
$expected = "
";
self::assertEquals($expected, $result);
$this->tp->setFontAwesome(6);
$result = $this->tp->toGlyph('fa-wine-glass-empty');
$expected = "
";
self::assertSame($expected, $result);
$result = $this->tp->toGlyph('fa-virus-covid');
self::assertSame("
", $result);
$this->tp->setFontAwesome(4);
$result = $this->tp->toGlyph('fab-mailchimp'); // spefific call
$expected = "
";
self::assertEquals($expected, $result);
$result = $this->tp->toGlyph('fas-camera'); // spefific call
self::assertSame("
", $result);
// test core, shims and old identifiers with FontAwesome 5 installed.
$this->tp->setFontAwesome(5);
$tests = array(
'e-database-16' => "
",
'e-database-32' => "
",
'fa-sun-o' => "
",
'fa-comments-o' => " ",
'fa-file-text-o' => "
",
'fa-bank' => "
",
'fa-warning' => "
",
'glyphicon-star' => "
",
'icon-star' => "
",
'floppy-disk' => "
",
'icon-user' => "
",
'user' => "
",
'flag' => "
",
'fa-' => null,
);
foreach ($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
self::assertSame($expected, $result);
}
// test core, shims and old identifiers with FontAwesome 4 installed.
$this->tp->setFontAwesome(4);
$tests = array(
'e-database-16' => "
",
'e-database-32' => "
",
'fa-sun-o' => "
",
'fa-comments-o' => " ",
'fa-file-text-o' => "
",
'fa-bank' => "
",
'fa-warning' => "
",
'glyphicon-star' => "
",
'icon-star' => "
",
'floppy-disk' => "
",
'icon-user' => "
",
'user' => "
",
'flag' => "
",
'fa-' => null,
);
foreach ($tests as $icon => $expected)
{
$result = $this->tp->toGlyph($icon);
self::assertSame($expected, $result, 'Input was: ' . $icon);
}
// test options.
$this->tp->setFontAwesome(5);
$opts = array(
0 => ['size'=>'3x', 'expected' => "
"],
1 => ['spin'=>1, 'expected' => "
"],
2 => ['rotate'=>180, 'expected' => "
"],
3 => ['fw'=>1, 'expected' => "
"],
);
foreach($opts as $parm)
{
$expected = $parm['expected'];
unset($parm['expected']);
$result = $this->tp->toGlyph('fa-camera', $parm);
self::assertSame($expected, $result);
}
// test options.
$this->tp->setFontAwesome(4);
$opts = array(
0 => ['size'=>'3x', 'expected' => "
"],
1 => ['spin'=>1, 'expected' => "
"],
2 => ['rotate'=>180, 'expected' => "
"],
3 => ['fw'=>1, 'expected' => "
"],
);
foreach($opts as $parm)
{
$expected = $parm['expected'];
unset($parm['expected']);
$result = $this->tp->toGlyph('fa-camera', $parm);
self::assertSame($expected, $result);
}
}
function testToGlyphFallback()
{
$this->tp->setFontAwesome(5);
$result = $this->tp->toGlyph('fa-paypal.glyph');
self::assertSame("
", $result);
$this->tp->setFontAwesome(6);
$result = $this->tp->toGlyph('fa-paypal.glyph');
self::assertSame("
", $result);
$result = $this->tp->toGlyph('fa-clock.glyph');
self::assertSame("
", $result);
$result = $this->tp->toGlyph('clock.glyph');
self::assertSame("
", $result);
$this->tp->setFontAwesome(5);
}
/*
public function testToBadge()
{
}
public function testToLabel()
{
}
public function testToFile()
{
}
*/
public function testToAvatar()
{
$icon = codecept_data_dir() . "icon_64.png";
if (!is_dir(e_AVATAR_UPLOAD))
{
mkdir(e_AVATAR_UPLOAD, 0755, true);
}
if (!is_dir(e_AVATAR_DEFAULT))
{
mkdir(e_AVATAR_DEFAULT, 0755, true);
}
if (!copy($icon, e_AVATAR_UPLOAD . "avatartest.png"))
{
echo "Couldn't copy the avatar";
}
if (!copy($icon, e_AVATAR_DEFAULT . "avatartest.png"))
{
echo "Couldn't copy the avatar";
}
$tests = array(
0 => array(
'input' => array('user_image' => '-upload-avatartest.png'),
'parms' => array('w' => 50, 'h' => 50, 'crop' => false),
'expected' => array(
"thumb.php?src=%7Be_AVATAR%7Dupload%2Favatartest.png&w=50&h=50",
"class='img-rounded rounded user-avatar'"
)
),
1 => array(
'input' => array('user_image' => 'avatartest.png'),
'parms' => array('w' => 50, 'h' => 50, 'crop' => false),
'expected' => array(
"thumb.php?src=%7Be_AVATAR%7Ddefault%2Favatartest.png&w=50&h=50",
"class='img-rounded rounded user-avatar'"
)
),
2 => array(
'input' => array('user_image' => ''),
'parms' => array('w' => 50, 'h' => 50, 'crop' => false),
'expected' => array(
"thumb.php?src=%7Be_IMAGE%7Dgeneric%2Fblank_avatar.jpg&w=50&h=50",
"class='img-rounded rounded user-avatar'"
)
),
3 => array(
'input' => array('user_image' => 'https://mydomain.com/remoteavatar.jpg'),
'parms' => array('w' => 50, 'h' => 50, 'crop' => false,),
'expected' => array(
"src='https://mydomain.com/remoteavatar.jpg'",
"class='img-rounded rounded user-avatar'",
"width='50' height='50'",
)
),
4 => array(
'input' => array('user_image' => '', 'user_id' => 1),
'parms' => array('w' => 50, 'h' => 50, 'crop' => false, 'link' => true),
'expected' => array(
"thumb.php?src=%7Be_IMAGE%7Dgeneric%2Fblank_avatar.jpg&w=50&h=50",
"class='img-rounded rounded user-avatar'",
"
array(
'input' => array('user_image' => 'avatartest.png'),
'parms' => array('w' => 30, 'h' => 30, 'crop' => false, 'shape' => 'circle', 'alt' => 'mytitle'),
'expected' => array(
"thumb.php?src=%7Be_AVATAR%7Ddefault%2Favatartest.png&w=30&h=30",
"class='img-circle rounded-circle user-avatar'",
'alt="mytitle"',
)
),
7 => array(
'input' => array('user_image'=>'avatartest.png'),
'parms' => array('w'=>50, 'h'=>50, 'crop'=>true, 'base64'=>true, 'shape'=>'circle'),
'expected' => array(
"src='data:image/png;base64,",
"class='img-circle rounded-circle user-avatar'"
)
),
8 => array(
'input' => array('user_image'=>'https://e107.org/e107_images/generic/blank_avatar.jpg'), // Test remote avatar
'parms' => array('w'=>50, 'h'=>50, 'crop'=>true, 'base64'=>true, 'shape'=>'circle'),
'expected' => array(
"src='data:image/jpg;base64,",
"class='img-circle rounded-circle user-avatar'"
)
),
);
foreach ($tests as $index => $var)
{
$result = $this->tp->toAvatar($var['input'], $var['parms']);
foreach ($var['expected'] as $str)
{
self::assertStringContainsString($str, $result, "Failed on index #" . $index);
}
}
}
public function testToIcon()
{
$icon = codecept_data_dir() . "icon_64.png";
if (!copy($icon, e_MEDIA_IMAGE . "icon_64.png"))
{
echo "Couldn't copy the icon";
}
if (!copy($icon, e_MEDIA_ICON . "icon_64.png"))
{
echo "Couldn't copy the icon";
}
$tests = array(
0 => array('input' => '{e_IMAGE}e107_icon_32.png', 'parms' => null, 'expected' => '/e107_images/e107_icon_32.png'),
1 => array('input' => '{e_MEDIA_IMAGE}icon_64.png', 'parms' => null, 'expected' => 'thumb.php?src=e_MEDIA_IMAGE'),
2 => array('input' => '{e_MEDIA_ICON}icon_64.png', 'parms' => null, 'expected' => '/e107_media/000000test/icons/icon_64.png'),
3 => array('input' => '{e_PLUGIN}gallery/images/gallery_32.png', 'parms' => null, 'expected' => '/e107_plugins/gallery/images/gallery_32.png'),
4 => array('input' => 'config_16.png', 'parms' => array('legacy' => "{e_IMAGE}icons/"), 'expected' => '/e107_images/icons/config_16.png'),
);
foreach ($tests as $var)
{
$result = $this->tp->toIcon($var['input'], $var['parms']);
self::assertStringContainsString($var['expected'], $result);
}
}
public function testToImage()
{
$src = "{e_PLUGIN}gallery/images/butterfly.jpg";
$this->tp->setThumbSize(80, 80); // set defaults.
// test with defaults set above.
$result = $this->tp->toImage($src);
self::assertStringContainsString('butterfly.jpg&w=80&h=80', $result); // src
self::assertStringContainsString('butterfly.jpg&w=320&h=320', $result); // srcset 4x the size on small images.
// test overriding of defaults.
$override = array('w' => 800, 'h' => 0);
$result2 = $this->tp->toImage($src, $override);
self::assertStringContainsString('butterfly.jpg&w=800&h=0', $result2); // src
self::assertStringContainsString('Fbutterfly.jpg&w=1600&h=0', $result2); // srcset
$override = array('w' => 0, 'h' => 0); // display image without resizing
$result3 = $this->tp->toImage($src, $override);
self::assertStringContainsString('Fbutterfly.jpg&w=0&h=0', $result3); // src
$result4 = $this->tp->toImage($src, ['loading' => 'lazy']);
self::assertStringContainsString('loading="lazy"', $result4); // src
$result5 = $this->tp->toImage($src, ['type' => 'webp']);
self::assertStringContainsString('&type=webp', $result5); // src
$result6 = $this->tp->toImage($src, ['return' => 'url']);
self::assertStringContainsString('http', $result6); // src
$tests = array(
0 => array(
'src' => '{e_PLUGIN}gallery/images/butterfly.jpg',
'parms' => array('w' => 300, 'alt' => "Custom"),
'expected' => ' '
),
);
foreach ($tests as $index => $var)
{
$result = $this->tp->toImage($var['src'], $var['parms']);
$result = preg_replace('/"([^"]*)thumb.php/', '"thumb.php', $result);
self::assertSame($var['expected'], $result);
}
// news image scenario with empty value.
$srcPath = '';
$imgParms = array(
'class' => 'news-image',
'alt' => 'placeholder image',
'style' => 'display:block',
'placeholder' => 1,
'legacy' => '{e_IMAGE}newspost_images',
'w' => 400,
'h' => 325
);
$result = $this->tp->toImage($srcPath, $imgParms);
$expected = ' ';
self::assertSame($expected, $result);
}
public function testThumbSrcSet()
{
$src = "{e_PLUGIN}gallery/images/butterfly.jpg";
$parms = array('w' => 800, 'h' => 0, 'size' => '2x');
$result = $this->tp->thumbSrcSet($src, $parms);
self::assertStringContainsString('butterfly.jpg&w=1600&h=0', $result);
$this->tp->setThumbSize(80, 80); // set defaults.
$result2 = $this->tp->thumbSrcSet($src, $parms); // testing overrides
self::assertStringContainsString('butterfly.jpg&w=1600&h=0', $result2);
$result3 = $this->tp->thumbSrcSet($src, array('w' => 800, 'size' => '2x')); // testing overrides without 'h' being set.
self::assertStringContainsString('butterfly.jpg&w=1600&h=0', $result3);
$result4 = $this->tp->thumbSrcSet($src); // no overrides
self::assertStringContainsString('butterfly.jpg&w=160&h=160', $result4);
}
public function testIsBBcode()
{
$tests = array(
0 => array("My Simple Text", false), // input , expected result
1 => array(" ", false),
2 => array("[b]Bbcode[/b]", true),
3 => array("[code]something[/code]
", false),
4 => array("[code]<b>someting</b>[/code]", true),
5 => array("[html]something[/html]", false),
6 => array("http://something.com/index.php?what=ever", false)
);
foreach ($tests as $val)
{
list($input, $expected) = $val;
$actual = $this->tp->isBBcode($input);
self::assertEquals($expected, $actual, $input);
}
}
public function testIsHtml()
{
$tests = array(
0 => array("My Simple Text", false), // input , expected result
1 => array(" ", true),
2 => array("[b]Bbcode[/b]", false),
3 => array("[code]something[/code]
", true),
4 => array("[code]<b>someting</b>[/code]", false),
5 => array("[html]something[/html]", true),
6 => array("http://something.com/index.php?what=ever", false),
7 => array("< 200", false),
8 => array("<200>", true),
);
foreach ($tests as $val)
{
list($input, $expected) = $val;
$actual = $this->tp->isHtml($input);
self::assertEquals($expected, $actual, $input);
}
}
/*
public function testIsJSON()
{
}
public function testIsUTF8()
{
}
public function testIsVideo()
{
}
*/
public function testIsImage()
{
self::assertTrue($this->tp->isImage('/path-to-file/myfile.jpg'));
self::assertFalse($this->tp->isImage('/path-to-file/myfile.mov'));
}
public function testtoAudio()
{
$expected = '
Your browser does not support the audio tag.
';
$result = $this->tp->toAudio('{e_MEDIA}myfile.mp3');
self::assertEquals($expected, $result);
$expected = '
Your browser does not support the audio tag.
';
$result = $this->tp->toAudio('{e_MEDIA}myfile.wav');
self::assertEquals($expected, $result);
// Override mime.
$expected = '
Your browser does not support the audio tag.
';
$result = $this->tp->toAudio('{e_MEDIA}myfile.php', ['mime' => 'audio/wav']);
self::assertEquals($expected, $result);
}
public function testToVideo()
{
$tests = [
0 => [
'file' => '{e_MEDIA}myfile.mp4',
'parms' =>[],
'expected' => ''
],
1 => [
'file' => '{e_MEDIA}myfile.mp4',
'parms' =>['w'=>500],
'expected' => ''
],
2 => [
'file' => '{e_MEDIA}myfile.mp4',
'parms' =>['w'=>300, 'h'=>0],
'expected' => ''
],
3 => [
'file' => '{e_MEDIA}myfile.mp4',
'parms' =>['w'=>300, 'h'=>'auto'],
'expected' => ''
],
];
foreach ($tests as $index => $var)
{
$result = $this->tp->toVideo($var['file'], $var['parms']);
self::assertStringContainsString($var['expected'], $result, 'Failed on index #'.$index);
}
}
public function testMakeClickable()
{
$email = 'myemail@somewhere.com.tk';
$tp = $this->tp;
// ----
$result = $tp->makeClickable($email, 'email', array('sub' => '[email]'));
self::assertStringContainsString('[email] ', $result);
// -----
$result = $tp->makeClickable($email, 'email', array('sub' => 'fa-envelope.glyph'));
self::assertStringContainsString("fa-envelope' >", $result);
// links standard.
$tests = array(
array("before www.somewhere.com after", 'before
www.somewhere.com after'),
array("before http://something.com after", 'before
http://something.com after'),
array("before https://someplace.com after", 'before
https://someplace.com after'),
array("before (www.something.com) after", 'before (
www.something.com ) after'),
array('', ''),
);
foreach ($tests as $row)
{
list($sample, $expected) = $row;
$result = $tp->makeClickable($sample, 'url');
self::assertEquals($expected, $result);
}
// links with substituion..
$tests = array(
array("before www.somewhere.com after", 'before
[link] after'),
array("before http://something.com after", 'before
[link] after'),
array("before https://someplace.com after", 'before
[link] after'),
array("before (www.something.com) after", 'before (
[link] ) after'),
);
foreach ($tests as $row)
{
list($sample, $expected) = $row;
$result = $tp->makeClickable($sample, 'url', array('sub' => '[link]'));
self::assertEquals($expected, $result);
}
// links with substituion and target.
$tests = array(
array("before www.somewhere.com after", 'before
[link] after'),
array("before http://something.com after", 'before
[link] after'),
array("before https://someplace.com after", 'before
[link] after'),
array("before (www.something.com) after", 'before (
[link] ) after'),
);
foreach ($tests as $row)
{
list($sample, $expected) = $row;
$result = $tp->makeClickable($sample, 'url', array('sub' => '[link]', 'ext' => true));
self::assertEquals($expected, $result);
}
}
public function testToDate()
{
$class = $this->tp;
$time = 1519512067; // Saturday 24 February 2018 - 22:41:07
$long = $class->toDate($time, 'long');
self::assertStringContainsString('Saturday 24 February 2018', $long);
$short = $class->toDate($time, 'short');
self::assertStringContainsString('Feb 2018', $short);
$rel = $class->toDate($time, 'relative');
self::assertStringContainsString('ago', $rel);
self::assertStringContainsString('data-livestamp="1519512067"', $rel);
$custom = $class->toDate($time, 'dd-M-yy');
self::assertStringContainsString('
24-Feb-18 ', $custom);
}
/*
public function testParseBBTags()
{
}
*/
public function testFilter()
{
$url = 'http://www.domain.com/folder/folder2//1234_1_0.jpg';
// Filter tests.
$tests = array(
0 => array('input' => 'test123 xxx', 'mode' => 'w', 'expected' => 'test123xxx'),
1 => array('input' => 'test123 xxx', 'mode' => 'd', 'expected' => '123'),
2 => array('input' => 'test123 xxx', 'mode' => 'wd', 'expected' => 'test123xxx'),
3 => array('input' => 'test123 xxx', 'mode' => 'wds', 'expected' => 'test123 xxx'),
4 => array('input' => 'test123 xxx.jpg', 'mode' => 'file', 'expected' => 'test123-xxx.jpg'),
5 => array('input' => '2.1.4 (test)', 'mode' => 'version', 'expected' => '2.1.4'),
6 => array('input' => $url, 'mode' => 'url', 'expected' => $url),
7 => array('input' => array('1', 'xxx'), 'mode' => 'str', 'expected' => array('1', 'xxx')),
8 => array('input' => 'myemail@email.com', 'mode' => 'email', 'expected' => 'myemail@email.com'),
);
foreach ($tests as $index => $var)
{
$result = $this->tp->filter($var['input'], $var['mode']);
self::assertEquals($var['expected'], $result, "Failed on index: " . $index);
}
// Validate.
$tests2 = array(
0 => array('input' => 'http://www.domain.com/folder/file.zip', 'mode' => 'url'), // good url
1 => array('input' => 'http:/www.domain.com/folder/file.zip', 'mode' => 'url'), // bad url
2 => array('input' => array('1', 'xxx'), 'mode' => 'int'), // good and bad integer
3 => array('input' => 'myemail@email.com', 'mode' => 'email'), // good email
4 => array('input' => 'bad-email.com', 'mode' => 'email'), // bad email
5 => array('input' => '123.23.123.125', 'mode' => 'ip'), // good ip
6 => array('input' => 'xx.23.123.125', 'mode' => 'ip'), // bad ip
);
$expected2 = array(
0 => 'http://www.domain.com/folder/file.zip',
1 => false,
2 => array(1, false),
3 => 'myemail@email.com',
4 => false,
5 => '123.23.123.125',
6 => false,
);
// $ret = [];
foreach ($tests2 as $index => $var)
{
$result = $this->tp->filter($var['input'], $var['mode'], true);
// $ret[$index] = $result;
self::assertSame($expected2[$index], $result);
}
}
/**
* e107 v0.6.0 requires strings to be passed around with quotation marks escaped for HTML as a way to prevent
* both SQL injection and cross-site scripting. Although {@see e_parse::toDB()} is supposed to do that, some
* usages, specifically {@see e_front_model::sanitizeValue()} call {@see e_parse::filter()} instead.
*
* @version 2.3.1
*/
public function testFilterStr()
{
$input = "
\"e107's\" ";
$expected = ""e107's"";
$actual = $this->tp->filter($input, 'str');
self::assertEquals($expected, $actual);
}
public function testCleanHtml()
{
global $_E107;
$_E107['phpunit'] = true; // disable CLI "all access" permissions to simulated a non-cli scenario.
$this->tp->setScriptAccess(e_UC_NOBODY);
$tests = array(
0 => array(
'html' => "
'<svg/onload=prompt(1)//'
),
// 1 => array('html' => '', 'expected'=>''),
// 2 => array('html' => '">', 'expected'=>'">'),
3 => array(
'html' => '< 200',
'expected' => '< 200'
),
4 => array(
'html' => "function sc_my_shortcode(){\nreturn \"Something\";}
",
'expected' => "function sc_my_shortcode(){\nreturn \"Something\";}
"
),
5 => array(
'html' => "function sc_my_shortcode(){\nreturn \"Something\";} ",
'expected' => "function sc_my_shortcode(){\nreturn \"Something\";} "
),
6 => array(
'html' => ' ',
'expected' => ' '
),
7 => array( // with inside ie. TinyMce
'html' => 'require_once("class2.php"); require_once(HEADERF); echo "test";<br> require_once(FOOTERF); ',
'expected' => "require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF); "
),
8 => array( // with \n
'html' => "require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF); ",
'expected' => "require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF); "
),
9 => array( // with \r\n (windows) line-breaks.
'html' => "require_once(\"class2.php\");\r\nrequire_once(HEADERF);\r\necho \"test\";<br>\r\nrequire_once(FOOTERF); ",
'expected' => "require_once(\"class2.php\");\nrequire_once(HEADERF);\necho \"test\";<br>\nrequire_once(FOOTERF); "
),
10 => array(
'html' => 'Test ',
'expected' => 'Test '
),
11 => array(
'html' => "{THEME_PREF: code=header_width&default=container} ",
'expected' => "{THEME_PREF: code=header_width&default=container} ",
),
12 => array(
'html' => "/* {THEME_PREF: code=header_width&default=container} */ ",
'expected' => "/* {THEME_PREF: code=header_width&default=container} */ ",
),
13 => array(
'html' => 'Your browser does not support the video tag.
',
'expected' => 'Your browser does not support the video tag.
'
),
14 => array(
'html' => '', // test removal of 'script' tags
'expected' => ''
),
15 => array(
'html' => '',
'expected' => ''
),
// BC Compat.
16 => array(
'html' => ' ',
'expected' => '',
),
// BC Compat.
17 => array(
'html' => 'colored ',
'expected' => 'colored ',
),
18 => array(
'html' => 'Τη γλώσσα μου έδωσαν ελληνική 您好,世界 こんにちは、世界',
'expected' => 'Τη γλώσσα μου έδωσαν ελληνική 您好,世界 こんにちは、世界',
),
);
foreach ($tests as $var)
{
$result = $this->tp->cleanHtml($var['html']);
self::assertEquals($var['expected'], $result);
}
// ----------- Test with Script access enabled --------------
$this->tp->setScriptAccess(e_UC_PUBLIC);
$scriptAccess = array(
0 => array(
'html' => 'Test ',
'expected' => 'Test '
),
1 => array(
'html' => '', // test support for 'script' tags
'expected' => ''
)
);
foreach ($scriptAccess as $var)
{
$result = $this->tp->cleanHtml($var['html']);
self::assertEquals($var['expected'], $result);
}
$this->tp->setScriptAccess(false);
unset($_E107['phpunit']);
}
public function testToUTF8()
{
$converter = $this->tp;
// Test simple string
$this::assertEquals('Hello World',
$converter->toUTF8('Hello World'),
'Simple ASCII string should remain unchanged'
);
// Test special characters
$this::assertEquals('café',
$converter->toUTF8(mb_convert_encoding('café', 'ISO-8859-1', 'UTF-8')),
'Latin-1 encoded string should be converted correctly'
);
// Test array with special characters
$inputArray = [
'name' => mb_convert_encoding('café', 'ISO-8859-1', 'UTF-8'),
'city' => mb_convert_encoding('München', 'ISO-8859-1', 'UTF-8')
];
$expectedArray = [
'name' => 'café',
'city' => 'München'
];
$this::assertEquals($expectedArray,
$converter->toUTF8($inputArray),
'Array with special characters should be converted correctly'
);
// Test nested array
$nestedArray = [
'level1' => [
'level2' => mb_convert_encoding('São Paulo', 'ISO-8859-1', 'UTF-8'),
'array' => ['deep' => mb_convert_encoding('über', 'ISO-8859-1', 'UTF-8')]
]
];
$expectedNested = [
'level1' => [
'level2' => 'São Paulo',
'array' => ['deep' => 'über']
]
];
$this::assertEquals($expectedNested,
$converter->toUTF8($nestedArray),
'Nested array should be converted correctly'
);
// Test object
$testObject = new stdClass();
$testObject->name = mb_convert_encoding('café', 'ISO-8859-1', 'UTF-8');
$testObject->location = mb_convert_encoding('München', 'ISO-8859-1', 'UTF-8');
$expectedObject = new stdClass();
$expectedObject->name = 'café';
$expectedObject->location = 'München';
$this::assertEquals($expectedObject,
$converter->toUTF8($testObject),
'Object properties should be converted correctly'
);
// Test array with various Western European characters
$inputArray = [
'french' => mb_convert_encoding('café', 'ISO-8859-1', 'UTF-8'),
'german' => mb_convert_encoding('Köln', 'ISO-8859-1', 'UTF-8'),
'spanish' => mb_convert_encoding('año', 'ISO-8859-1', 'UTF-8'),
'swedish' => mb_convert_encoding('björn', 'ISO-8859-1', 'UTF-8')
];
$expectedArray = [
'french' => 'café',
'german' => 'Köln',
'spanish' => 'año',
'swedish' => 'björn'
];
$this::assertEquals($expectedArray,
$converter->toUTF8($inputArray),
'Array with Western European characters should be converted correctly'
);
}
/*
public function testSecureAttributeValue()
{
}
public function testInvalidAttributeValue()
{
}
*/
/*
public function testGrantScriptAccess()
{
$before = $this->tp->getAllowedAttributes();
$this->tp->grantScriptAccess();
$after = $this->tp->getAllowedAttributes();
}*/
}