From 10bac42a5d7ee4d1d9faf7b58a406c923eedf76f Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 24 May 2004 17:33:17 +0000 Subject: [PATCH] renamed testbox to .testbox fixed InlineParser link tests added HtmlParser tests enhanced MockRequest git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@3550 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- tests/unit/lib/HtmlParserTest.php | 58 ++++++++++++++++++++ tests/unit/lib/InlineParserTest.php | 41 ++++++++------- tests/unit/readme.html | 6 +-- tests/unit/test.php | 82 +++++++++++++++++++++++------ tests/unit_test_backend_cvs.php | 4 +- 5 files changed, 149 insertions(+), 42 deletions(-) create mode 100644 tests/unit/lib/HtmlParserTest.php diff --git a/tests/unit/lib/HtmlParserTest.php b/tests/unit/lib/HtmlParserTest.php new file mode 100644 index 000000000..c5883865c --- /dev/null +++ b/tests/unit/lib/HtmlParserTest.php @@ -0,0 +1,58 @@ + + */ + +require_once 'lib/HtmlParser.php'; +require_once 'PHPUnit.php'; + +define('USE_GLOBAL_SAX',false); // this seems to be a xml bug + +class HtmlParserTest extends PHPUnit_TestCase { + + // constructor of the test suite + function HtmlParserTest($name) { + $this->PHPUnit_TestCase($name); + } + + function testSimple() { + $html2wiki = array( + "bold" => "*bold*", + "strong" => "*strong*", + "italic" => "_italic_", + "emphasized" => "_emphasized_", + "
" => "----", + "
Indent
" => ";:Indent", + "nowiki" => "\nnowiki\n", + "
Def
List
" => "; Def : List", + ); + if (USE_GLOBAL_SAX) + $parser = new HtmlParser("PhpWiki2"); // will not work! + foreach ($html2wiki as $html => $wiki) { + if (!USE_GLOBAL_SAX) // redefine it for every run. + $parser = new HtmlParser("PhpWiki2"); + if (USE_GLOBAL_SAX) + $parser->parse($html,false); // is_final is false + else + $parser->parse($html); + $this->assertEquals($wiki, trim($parser->output())); + if (USE_GLOBAL_SAX) + unset($GLOBALS['xml_parser_root']); + else + $parser->__destruct(); + } + } + +} + + +// (c-file-style: "gnu") +// Local Variables: +// mode: php +// tab-width: 8 +// c-basic-offset: 4 +// c-hanging-comment-ender-p: nil +// indent-tabs-mode: nil +// End: +?> diff --git a/tests/unit/lib/InlineParserTest.php b/tests/unit/lib/InlineParserTest.php index 34d7da5da..26e7ff50a 100644 --- a/tests/unit/lib/InlineParserTest.php +++ b/tests/unit/lib/InlineParserTest.php @@ -1,7 +1,8 @@ + * testLinks: Reini Urban */ require_once 'lib/InlineParser.php'; @@ -37,28 +38,28 @@ class InlineParserTest extends PHPUnit_TestCase { $this->assertEquals('.', $c1[2]); } - // todo... function testLinks() { - $tests = array("[label|link]", - "[ label | link.jpg ]", - "[ image.jpg | link ]", - "[ Upload:image.jpg | link ]", - "[ http://server/image.jpg | link ]", - "[ label | http://server/link ]", - "[ label | Upload:link ]", - "[ label | phpwiki:action=link ]", - "Upload:image.jpg", - "http://server/image.jpg", - "http://server/link", - "[http:/server/~name/]", - "http:/server/~name/" + $uplink = 'http://'.(defined('SERVER_NAME')?SERVER_NAME:'').DATA_PATH.'/uploads/image.jpg'; + $tests = array("[label|link]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";s:5:"label";}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":2:{s:5:"_page";s:8:"link.jpg";s:6:"_label";s:5:"label";}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":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";b:0;s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}', + "[ Upload:image.jpg | link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";s:'.strlen($uplink).':"'.$uplink.'";s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}', + "[ http://server/image.jpg | link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:15:"cached_wikilink":2:{s:5:"_page";s:4:"link";s:6:"_label";O:11:"htmlelement":4:{s:8:"_content";a:0:{}s:4:"_tag";s:3:"img";s:5:"_attr";a:3:{s:3:"src";s:23:"http://server/image.jpg";s:3:"alt";s:4:"link";s:5:"class";s:11:"inlineimage";}s:11:"_properties";i:7;}}i:2;s:0:"";}}', + "[ label | http://server/link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":2:{s:4:"_url";s:18:"http://server/link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "[ label | Upload:link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"cached_interwikilink":2:{s:5:"_link";s:11:"Upload:link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "[ label | phpwiki:action=link ]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:17:"cached_phpwikiurl":2:{s:4:"_url";s:19:"phpwiki:action=link";s:6:"_label";s:5:"label";}i:2;s:0:"";}}', + "Upload:image.jpg" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:20:"cached_interwikilink":1:{s:5:"_link";s:16:"Upload:image.jpg";}i:2;s:0:"";}}', + "http://server/image.jpg" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:23:"http://server/image.jpg";}i:2;s:0:"";}}', + "http://server/link" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http://server/link";}i:2;s:0:"";}}', + "[http:/server/~name/]" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}', + "http:/server/~name/" => 'O:10:"xmlcontent":1:{s:8:"_content";a:3:{i:0;s:0:"";i:1;O:19:"cached_externallink":1:{s:4:"_url";s:18:"http:/server/name/";}i:2;s:0:"";}}' ); - for ($i=0; $i < count($tests); $i++) { - $xml = TransformInline($tests[$i]); + foreach ($tests as $wiki => $dump) { + $xml = TransformInline($wiki); $this->assertTrue(isa($xml, 'XmlContent')); - $cl = $xml->getContent(); - $this->assertEquals(1, count($c1)); - $this->assertTrue(isa($c1[0], 'Cached_WikiLink')); + //echo var_export($xml),"\n"; + //echo serialize($xml),"\n"; + $this->assertEquals($dump, serialize($xml)); } } diff --git a/tests/unit/readme.html b/tests/unit/readme.html index 52169125c..db25dd14f 100644 --- a/tests/unit/readme.html +++ b/tests/unit/readme.html @@ -14,12 +14,12 @@ one, which do not use PHPUnit.

Prerequisites

PHP

-You need the php command-line -interface. It was experimental as of PHP 4.2.0, default as of PHP +interface. It was experimental as of PHP 4.2.0 (php-cli), default as of PHP 4.3.0. -You also need the 'pear' executable. +You also need the 'pear' executable to install or update the required pear libraries.

PHPUnit

diff --git a/tests/unit/test.php b/tests/unit/test.php index 7a0eb2fc1..9dcc6f328 100644 --- a/tests/unit/test.php +++ b/tests/unit/test.php @@ -1,6 +1,6 @@ -#! /usr/local/bin/php -Cq - + * Copyright (C) 2004, Reini Urban * * This file is part of PhpWiki. * @@ -24,6 +24,7 @@ * * You must have PEAR's PHPUnit package . * These tests are unrelated to test/maketest.pl, which do not use PHPUnit. + * These tests run from the command-line as well as from the browser. */ #################################################################### @@ -33,17 +34,18 @@ #################################################################### +$cur_dir = getcwd(); # Add root dir to the path -$rootdir = getcwd() . '/../../'; -ini_set('include_path', ini_get('include_path') . (substr(PHP_OS,0,3) == 'WIN' ? ';' : ':') . $rootdir); +$rootdir = $cur_dir . '/../../'; +$ini_sep = substr(PHP_OS,0,3) == 'WIN' ? ';' : ':'; +ini_set('include_path', ini_get('include_path') . $ini_sep . $rootdir); # This quiets a warning in config.php $HTTP_SERVER_VARS['REMOTE_ADDR'] = '127.0.0.1'; # Other needed files -require_once 'index.php'; -require_once 'lib/stdlib.php'; -require_once 'lib/config.php'; // Needed for $WikiNameRegExp +require_once $rootdir.'index.php'; +require_once $rootdir.'lib/stdlib.php'; # Show lots of detail when an assert() in the code fails function assert_callback( $script, $line, $message ) { @@ -58,29 +60,67 @@ $foo = assert_options( ASSERT_CALLBACK, 'assert_callback'); # This is the test DB backend #require_once( 'lib/WikiDB/backend/cvs.php' ); $db_params = array(); -$db_params['directory'] = getcwd() . '/testbox'; +$db_params['directory'] = $cur_dir . '/.testbox'; $db_params['dbtype'] = 'file'; # Mock objects to allow tests to run -require_once( 'lib/WikiDB.php' ); -class MockRequest { +require_once($rootdir.'lib/Request.php'); +require_once($rootdir.'lib/WikiDB.php'); +if (ENABLE_USER_NEW) + require_once($rootdir."lib/WikiUserNew.php"); +else + require_once($rootdir."lib/WikiUser.php"); +require_once($rootdir."lib/WikiGroup.php"); +require_once($rootdir."lib/PagePerm.php"); + +class MockRequest extends Request { function MockRequest(&$dbparams) { + global $Theme, $request; $this->_dbi = WikiDB::open(&$dbparams); + $this->_args = array('pagename' => 'HomePage','action' => 'browse'); + $this->Request(); } - function addArg($arg, $value) { - $this->args[$arg] = $value; + function setArg($arg, $value) { + $this->_args[$arg] = $value; } function getArg($arg) { - return $this->args[$arg]; + return $this->_args[$arg]; } - function getDbh() { return $this->_dbi; } + function getUser () { + if (isset($this->_user)) + return $this->_user; + else + return $GLOBALS['ForbiddenUser']; + } + function getPage ($pagename = false) { + if (!isset($this->_dbi)) + $this->getDbh(); + if (!$pagename) + $pagename = $this->getArg('pagename'); + return $this->_dbi->getPage($pagename); + } + function getPrefs () { + return $this->_prefs; + } + function getPref ($key) { + if (isset($this->_prefs)) + return $this->_prefs->get($key); + } } $request = new MockRequest($db_params); +if (ENABLE_USER_NEW) + $request->_user = WikiUser('AnonUser'); +else { + $request->_user = new WikiUser($request, 'AnonUser'); + $request->_prefs = $request->_user->getPreferences(); +} +include_once("themes/" . THEME . "/themeinfo.php"); + #################################################################### # # End of preamble, run the test suite .. @@ -89,15 +129,25 @@ $request = new MockRequest($db_params); # Test files require_once ('PHPUnit.php'); +if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) + echo "
\n";
+    
+print "Run tests ..\n";
+
 # lib/config.php might do a cwd()
 require_once (dirname(__FILE__).'/lib/InlineParserTest.php');
-
-print "Run tests ..\n";
 $suite  = new PHPUnit_TestSuite("InlineParserTest");
 $result = PHPUnit::run($suite);
+echo $result -> toString();
 
+require_once (dirname(__FILE__).'/lib/HtmlParserTest.php');
+$suite  = new PHPUnit_TestSuite("HtmlParserTest");
+$result = PHPUnit::run($suite);
 echo $result -> toString();
 
+if (isset($HTTP_SERVER_VARS['REQUEST_METHOD']))
+    echo "
\n"; + // (c-file-style: "gnu") // Local Variables: // mode: php diff --git a/tests/unit_test_backend_cvs.php b/tests/unit_test_backend_cvs.php index 55148dede..8b6b2a16a 100644 --- a/tests/unit_test_backend_cvs.php +++ b/tests/unit_test_backend_cvs.php @@ -10,9 +10,7 @@ // assume that the we've cd'ed to the tests directory ini_set('include_path', '..' ); -function rcs_id() -{ -} +function rcs_id() {} if ( $USER == "root" ) { // root user can't check in to a CVS repository -- 2.45.0