Current File : //opt/RZphp74/includes/test/Text_Wiki/tests/Text_Wiki_Render_Test.php |
<?php
require_once 'Text/Wiki.php';
require_once 'Text/Wiki/Render.php';
require_once 'Text/Wiki/Render/Xhtml.php';
require_once 'Text/Wiki/Render/Xhtml/Address.php';
class Text_Wiki_Render_Test extends PHPUnit_Framework_TestCase
{
protected function setUp()
{
$obj = Text_Wiki::singleton();
$this->obj = new Text_Wiki_Render($obj);
$this->conf = array('firstConf' => 'firstConfValue',
'secondConf' => 'secondConfValue',
'thirdConf' => 'thirdConfValue',
'img_ext' => array('jpg', 'jpeg', 'gif', 'png'),
'css_table' => 'className',
);
}
public function testTextWikiRenderConstructor()
{
/* It is hard to test directly the constructor of the class Text_Wiki_Render as it
* internally has logic expecting a child class name (to define the $this->rule and
* $this->format variables). That is why we are creating an instance of
* Text_Wiki_Render_Xhtml and Text_Wiki_Render_Xhtml_Address instead. If you have a
* better idea feel free to improve this test
*/
$wiki = Text_Wiki::singleton();
$obj = new Text_Wiki_Render_Xhtml($wiki);
$this->assertEquals($wiki, $obj->wiki, 'Should set reference to Text_Wiki object');
$this->assertEquals('Xhtml', $obj->format);
$this->assertNull($obj->rule);
$this->assertEquals(array('translate' => 1, 'quotes' => 2, 'charset' => 'ISO-8859-1'), $obj->conf);
$obj = new Text_Wiki_Render_Xhtml_Address($wiki);
$this->assertEquals($wiki, $obj->wiki, 'Should set reference to Text_Wiki object');
$this->assertEquals('Xhtml', $obj->format);
$this->assertEquals('Address', $obj->rule);
$this->assertEquals(array('css' => null), $obj->conf);
}
public function testGetConfShouldReturnConfValue()
{
$this->obj->conf = $this->conf;
foreach ($this->conf as $key => $value) {
$this->assertEquals($value, $this->obj->getConf($key));
$this->assertEquals($value, $this->obj->getConf($key, 'DefaultValue'));
}
}
public function testGetConfShouldReturnDefaultValue()
{
$this->obj->conf = $this->conf;
$this->assertEquals('DefaultValue', $this->obj->getConf('InvalidKey', 'DefaultValue'));
}
public function testFormatConfShouldReturnSprinfFormatedValue()
{
$this->obj->conf = $this->conf;
foreach (array('firstConf', 'secondConf', 'thirdConf') as $key) {
$value = $this->conf[$key];
$this->assertEquals(" class=\"$value\"", (string)$this->obj->formatConf(' class="%s"', $key));
}
}
public function testFormatConfShouldReturnNull()
{
$this->obj->conf = $this->conf;
$this->assertNull($this->obj->formatConf(' class="%s"', 'InvalidKey'));
$this->assertNull($this->obj->formatConf(' class="%s"', null));
}
public function testUrlEncode()
{
$texts = array('ftp://user:foo @+%/@ftp.example.com/x.txt' => 'ftp%3A%2F%2Fuser%3Afoo%20%40%2B%25%2F%40ftp.example.com%2Fx.txt',
'http://example.com/department_list_script/sales and marketing/Miami' => 'http%3A%2F%2Fexample.com%2Fdepartment_list_script%2Fsales%20and%20marketing%2FMiami'
);
foreach ($texts as $inputString => $outputString) {
$this->assertEquals($outputString, $this->obj->urlEncode($inputString));
}
}
public function testTextEncode()
{
// need more strings to test
$text = "<a href='test'>Test</a>";
$this->assertEquals("<a href='test'>Test</a>", $this->obj->textEncode($text));
}
public function testMarkupToHtml()
{
$wiki = Text_Wiki::singleton();
$markup = <<<MARKUP
+ Sample Page for Wiki Markup
++ General Notes
The markup described is a combination of the [http://tavi.sourceforge.net \
WikkTikkiTavi] and [http://develnet.org/ coWiki] markup styles.
MARKUP;
$expected = <<<XHTML
<h1 id="toc0"> Sample Page for Wiki Markup</h1>
<h2 id="toc1"> General Notes</h2>
<p>The markup described is a combination of the <a href="http://tavi.sourceforge.net" onclick="window.open(this.href, '_blank'); return false;">WikkTikkiTavi</a> and <a href="http://develnet.org/" onclick="window.open(this.href, '_blank'); return false;">coWiki</a> markup styles.</p>
XHTML;
$this->assertEquals($expected, $wiki->transform($markup, 'Xhtml'));
}
}