tp = $this->make('e_parse'); } catch (Exception $e) { self::assertTrue(false, "Couldn't load e_parser object"); } $this->tp->__construct(); } public function testInit() { $this->tp->init(); } public function testToRoute() { $posted = array( 'myfield' => array( 'computer' => array( 'apple' => array('imac' => '1') ), 'os' => array( 'microsoft' => array('windows' => 'xp') ) ), 'myfield2' => array( 'house' => array('car' => 'red') ), 'myfield3' => 'string', ); $expected = array( 'myfield/computer/apple/imac' => 'myfield', 'myfield/os/microsoft/windows' => 'myfield', 'myfield2/house/car' => 'myfield2', 'myfield3' => 'myfield3', ); $result = $this->tp->toRoute($posted); self::assertSame($expected, $result); } public function testSetGetImageAltCacheFile() { $path = '{e_THEME}basic/screenshot.png'; $value = 'Test Alt Text'; // Call setImageAltCacheFile to generate the cache file $this->tp->setImageAltCacheFile($path, $value); $retrievedValue = $this->tp->getImageAltCacheFile($path); self::assertSame($value, $retrievedValue, "Retrieved value does not match the expected value"); } public function testStripBlockTags() { $tests = array( 0 => array( 'text' => '

Paragraph 1

Paragraph 2
Line 3

', 'expected' => "Paragraph 1Paragraph 2
Line 3
", ), ); foreach ($tests as $var) { $result = $this->tp->stripBlockTags($var['text']); if (empty($var['expected'])) { echo $result . "\n\n"; continue; } self::assertEquals($var['expected'], $result); } } /* public function testHtmlAbuseFilter() { } public function testE_highlight() { }*/ public function testToHTML() { $src = <<tp->toHTML($src, true); self::assertEquals($expected, $actual, "BBcode parsing failed"); $src = "[center][img]{e_IMAGE}generic/blank_avatar.jpg[/img][/center]"; $actual = $this->tp->toHTML($src, true); $expected = "
Blank Avatar
"; self::assertEquals($expected, $actual, "BBcode parsing failed on [img]"); $src = << [/center] SRC; $expected = << EXPECTED; $actual = $this->tp->toHTML($src, true); self::assertEquals($expected, $actual); /* $src = "[html]
$sql = e107::getDb();
		$sql->select('tablename', 'field1, field2', 'field_id = 1');
		while($row = $sql->fetch())
		{
			echo $row['field1'];
		}
[/html]"; $actual = $this->tp->toHTML($src,true); $expected = ''; self::assertEquals($expected, $actual, "BBcode parsing failed on
");*/


	}

	/*
			public function testUstrpos()
			{

			}
	*/
	public function testThumbUrlDecode()
	{
		$tests = array(
			0 => array(
				'input'    => '/media/img/a400xa500/myimage.jpg',
				'expected' => array(
					'src' => 'e_MEDIA_IMAGE/myimage.jpg',
					'aw'  => '400',
					'ah'  => '500',
				)
			),
			1 => array(
				'input'    => '/media/img/400x500/myimage2.jpg',
				'expected' => array(
					'src' => 'e_MEDIA_IMAGE/myimage2.jpg',
					'w'   => '400',
					'h'   => '500',
				)
			),
			2 => array(
				'input'    => '/theme/img/a400xa500/mytheme/myimage.jpg',
				'expected' => array(
					'src' => 'e_THEME/mytheme/myimage.jpg',
					'aw'  => '400',
					'ah'  => '500',
				)
			),
			3 => array(
				'input'    => '/theme/img/400x500/mytheme/myimage2.jpg',
				'expected' => array(
					'src' => 'e_THEME/mytheme/myimage2.jpg',
					'w'   => '400',
					'h'   => '500',
				)
			),

		);

		foreach ($tests as $var)
		{
			$result = $this->tp->thumbUrlDecode($var['input']);
			self::assertSame($var['expected'], $result);
		}


	}


	function testToHTMLModifiers()
	{
		//	e107::getConfig()->set('make_clickable', 0)->save(false, true);

		$list = $this->tp->getModifierList();

		$tests = array(
			'emotes_off'        =>
				array(
					'input'    => ":-)",
					'expected' => ':-)',
				),
			'emotes_on'         =>
				array(
					'input'    => ":-)",
					'expected' => 'smile',
				),
			'no_hook'           =>
				array(
					'input'    => "",
					'expected' => '',
				),
			'do_hook'           =>
				array(
					'input'    => "",
					'expected' => '',
				),
			'scripts_off'       =>
				array(
					'input'    => "",
					'expected' => '',
				),
			'scripts_on'        =>
				array(
					'input'    => "",
					'expected' => '',
				),
			'no_make_clickable' =>
				array(
					'input'    => "www.somewhere.com mailto:myemail@somewhere.com",
					'expected' => 'www.somewhere.com mailto:myemail@somewhere.com',
				),
			'make_clickable'    =>
				array(
					'input'    => "www.somewhere.com mailto:myemail@somewhere.com",
					'expected' => '', // random obfiscation
				),
			'no_replace'        =>
				array(
					'input'    => "www.somewhere.com",
					'expected' => '',
				),
			'replace'           =>
				array(
					'input'    => "www.somewhere.com",
					'expected' => '',
				),
			'consts_off'        =>
				array(
					'input'    => "{e_PLUGIN}",
					'expected' => '{e_PLUGIN}',
				),
			'consts_rel'        =>
				array(
					'input'    => "{e_PLUGIN}",
					'expected' => 'e107_plugins/',
				),
			'consts_abs'        =>
				array(
					'input'    => "{e_PLUGIN}",
					'expected' => '/e107_plugins/',
				),
			'consts_full'       =>
				array(
					'input'    => "{e_PLUGIN}",
					'expected' => 'https://localhost/e107/e107_plugins/',
				),
			'scparse_off'       =>
				array(
					'input'    => "{SITENAME}",
					'expected' => '{SITENAME}',
				),
			'scparse_on'        =>
				array(
					'input'    => "{SITENAME}",
					'expected' => 'e107',
				),
			'no_tags'           =>
				array(
					'input'    => "bold",
					'expected' => 'bold',
				),
			'do_tags'           =>
				array(
					'input'    => "bold",
					'expected' => 'bold',
				),
			'fromadmin'         =>
				array(
					'input'    => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
					'expected' => '',
				),
			'notadmin'          =>
				array(
					'input'    => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
					'expected' => '',
				),
			'er_off'            =>
				array(
					'input'    => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
					'expected' => '',
				),
			'er_on'             =>
				array(
					'input'    => "My Text {SITENAME} {e_PLUGIN} www.somewhere.com \nNew line :-)",
					'expected' => '',
				),
			'defs_off'          =>
				array(
					'input'    => "LAN_THANK_YOU",
					'expected' => 'LAN_THANK_YOU',
				),
			'defs_on'           =>
				array(
					'input'    => "LAN_THANK_YOU",
					'expected' => 'Thank you',
				),
			'dobreak'           =>
				array(
					'input'    => "Line 1\nLine 2\nLine 3",
					'expected' => 'Line 1
Line 2
Line 3', ), 'nobreak' => array( 'input' => "Line 1\nLine 2\nLine 3", 'expected' => "Line 1\nLine 2\nLine 3", ), 'lb_nl' => array( 'input' => "Line 1\nLine 2\nLine 3", 'expected' => "Line 1\nLine 2\nLine 3", ), 'lb_br' => array( 'input' => "Line 1\nLine 2\nLine 3", 'expected' => 'Line 1
Line 2
Line 3', ), 'retain_nl' => array( 'input' => "Line 1\nLine 2\nLine 3", 'expected' => "Line 1\nLine 2\nLine 3", ), 'defs' => array( 'input' => "LAN_THANK_YOU", 'expected' => 'Thank you', ), 'parse_sc' => array( 'input' => "{SITENAME}", 'expected' => 'e107', ), 'constants' => array( 'input' => "{e_PLUGIN}", 'expected' => 'e107_plugins/', ), 'value' => array( 'input' => "", 'expected' => '', ), 'wysiwyg' => array( 'input' => "", 'expected' => '', ), ); $ret = []; foreach ($list as $mod => $val) { if (empty($tests[$mod]['expected'])) { continue; } $result = $this->tp->toHTML($tests[$mod]['input'], false, 'defaults_off,' . $mod); self::assertSame($tests[$mod]['expected'], $result, $mod . " didn't match the expected result."); // $ret[$mod] = $result; } // e107::getConfig()->set('make_clickable', 0)->save(false, true); // var_export($ret); } function testToHTMLWithBBcode() { $tests = array( 0 => array( 'text' => '[code]$something = "something";[/code]', 'expected' => "
\$something = "something";
", ), 1 => array( 'text' => '[b]Title[/b][code]$something = "something"; [b]Not parsed[/b][/code]', 'expected' => "Title
\$something = "something"; [b]Not parsed[/b]
", ), 2 => array( 'text' => '[php] "", ), 3 => array( 'text' => "[table][tr]\n[td]cell[/td]\n[/tr][/table]", 'expected' => "\n\n
cell
", ), 4 => array( 'text' => "Test\n[b]first line[/b][b]\nsecond line[/b]", 'expected' => "Test
first line
second line
", ), 5 => array( 'text' => "Test\n[code]1st [b]line[/b] of code[/code]\n[code]2nd line of code[/code]", 'expected' => "Test
1st [b]line[/b] of code
2nd line of code
", ), ); foreach ($tests as $index => $var) { $result = $this->tp->toHTML($var['text'], true); if (!isset($var['expected'])) { echo $result . "\n\n"; continue; } self::assertEquals($var['expected'], $result, 'Test #' . $index . ' failed.'); } } public function testParseTemplateWithEnabledCoreShortcodes() { $needle = '