From faf9aafd35fdcd0ff499985f58ac777e8f30db8b Mon Sep 17 00:00:00 2001 From: rurban Date: Tue, 29 May 2007 16:57:05 +0000 Subject: [PATCH] Split into seperate tests git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@5710 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- tests/unit/lib/InlineParserTest.php | 119 ++++++++++++++++++---------- 1 file changed, 76 insertions(+), 43 deletions(-) diff --git a/tests/unit/lib/InlineParserTest.php b/tests/unit/lib/InlineParserTest.php index 023d95688..0cba80069 100644 --- a/tests/unit/lib/InlineParserTest.php +++ b/tests/unit/lib/InlineParserTest.php @@ -1,8 +1,8 @@ - * testLinks: Reini Urban +/* Copyright (C) 2004 Dan Frankowski + * (C) 2006, 2007 Reini Urban */ require_once 'lib/InlineParser.php'; @@ -10,33 +10,11 @@ require_once 'PHPUnit.php'; class InlineParserTest extends phpwiki_TestCase { - function testNoWikiWords() { - $str1 = 'This has no wiki words, and is all text.'; - $xmlc1 = TransformInline($str1); - $this->assertTrue(isa($xmlc1, 'XmlContent')); - $c1 = $xmlc1->getContent(); - $this->assertEquals(1, count($c1)); - $this->assertEquals($str1, $c1[0]); - } - - function testWikiWord() { - $ww = 'WikiWord'; - $str1 = "This has 1 $ww."; - $xml = TransformInline($str1); - $this->assertTrue(isa($xml, 'XmlContent')); - $c1 = $xml->getContent(); - $this->assertEquals(3, count($c1)); - $this->assertTrue(isa($c1[1], 'Cached_WikiLink')); - - $this->assertEquals('This has 1 ', $c1[0]); - $this->assertEquals($ww, $c1[1]->asString()); - $this->assertEquals('.', $c1[2]); - } + //var $ta; - function testLinks() { - $uplink = 'http://'.(defined('SERVER_NAME')?SERVER_NAME:'').DATA_PATH.'/uploads/image.jpg'; - $tests = array( - // last update: 1.3.13 + function _tests() { + // last update: 1.3.13 + return array( "[label|link]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ label | link.jpg ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "[ image.jpg | link ]" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"Cached_WikiLink":3:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"HtmlElement":4:{s:4:"_tag";s:6:"object";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:1:{i:0;O:11:"HtmlElement":4:{s:4:"_tag";s:5:"embed";s:5:"_attr";a:5:{s:3:"src";s:0:"";s:3:"alt";s:4:"link";s:5:"title";s:4:"link";s:5:"class";s:12:"inlineobject";s:4:"type";b:0;}s:8:"_content";a:0:{}s:11:"_properties";i:4;}}s:11:"_properties";i:6;}s:9:"_basepage";b:0;}i:2;s:0:"";}}', @@ -64,21 +42,76 @@ class InlineParserTest extends phpwiki_TestCase { "This is a :=PageAttr" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:12:"This is a :=";i:1;O:15:"Cached_WikiLink":2:{s:5:"_page";s:8:"PageAttr";s:9:"_basepage";b:0;}i:2;s:0:"";}}', "This is :~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:9:"This is :";i:1;s:6:"NoLink";i:2;s:0:"";}}', "This is ::~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is ::";i:1;s:6:"NoLink";i:2;s:0:"";}}', - "This is :=~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is :=";i:1;s:6:"NoLink";i:2;s:0:"";}}', - ); - //$i = 0; - foreach ($tests as $wiki => $expected) { - //print $i++ . " .. "; - $xml = TransformInline($wiki); - $this->assertTrue(isa($xml, 'XmlContent')); - $expectobj = unserialize($expected); - if (DEBUG & _DEBUG_VERBOSE) - echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); - $this->assertEquals($expectobj, $xml); - } + "This is :=~NoLink" => 'O:10:"XmlContent":1:{s:8:"_content";a:3:{i:0;s:10:"This is :=";i:1;s:6:"NoLink";i:2;s:0:"";}}'); + } +/* + function _setUp() { + $i = 0; + foreach ($this->_tests() as $wiki => $expected) { + $this->ta[$i] = $wiki; + $i++; + } + } +*/ + function runTest() { + if (substr($this->_name,0,5) == "_test") { + $name = rawurldecode(substr($this->_name,5)); + $this->_testLink($name); + } else { + call_user_func( + array( + &$this, + $this->_name + ) + ); + } + } + + function testNoWikiWords() { + $str1 = 'This has no wiki words, and is all text.'; + $xmlc1 = TransformInline($str1); + $this->assertTrue(isa($xmlc1, 'XmlContent')); + $c1 = $xmlc1->getContent(); + $this->assertEquals(1, count($c1)); + $this->assertEquals($str1, $c1[0]); } - + + function testWikiWord() { + $ww = 'WikiWord'; + $str1 = "This has 1 $ww."; + $xml = TransformInline($str1); + $this->assertTrue(isa($xml, 'XmlContent')); + $c1 = $xml->getContent(); + $this->assertEquals(3, count($c1)); + $this->assertTrue(isa($c1[1], 'Cached_WikiLink')); + + $this->assertEquals('This has 1 ', $c1[0]); + $this->assertEquals($ww, $c1[1]->asString()); + $this->assertEquals('.', $c1[2]); + } + + function _testLink($wiki, $expected = null) { + $uplink = 'http://'.(defined('SERVER_NAME')?SERVER_NAME:'').DATA_PATH.'/uploads/image.jpg'; + if (is_null($expected)) { + $ta = $this->_tests(); + $expected = $ta[$wiki]; + } + $xml = TransformInline($wiki); + $this->assertTrue(isa($xml, 'XmlContent')); + $expectobj = unserialize($expected); + /* if (DEBUG & _DEBUG_VERBOSE) + echo "\t\"",$wiki,'" => \'',serialize($xml),"',\n"; flush(); */ + $this->assertEquals($expectobj, $xml); + } +} + +//$i = 0; +foreach (InlineParserTest::_tests() as $wiki => $expected) { + $name = "_test".rawurlencode($wiki); + $GLOBALS['suite']->addTest(new InlineParserTest($name)); + //$i++; } +//unset($i); // (c-file-style: "gnu") // Local Variables: @@ -88,4 +121,4 @@ class InlineParserTest extends phpwiki_TestCase { // c-hanging-comment-ender-p: nil // indent-tabs-mode: nil // End: -?> \ No newline at end of file +?> -- 2.45.0