From 2567ac6cbcba64258be3340c4359f0cce077961b Mon Sep 17 00:00:00 2001 From: rurban Date: Mon, 21 Nov 2005 22:16:46 +0000 Subject: [PATCH] IncludePageTest added, various minor enhancements git-svn-id: svn://svn.code.sf.net/p/phpwiki/code/trunk@4994 96ab9672-09ca-45d6-a79d-3d69d39ca109 --- tests/unit/lib/InlineParserTest.php | 4 +- tests/unit/lib/SetupWiki.php | 8 +-- tests/unit/lib/TextSearchTest.php | 4 ++ tests/unit/lib/plugin/IncludePageTest.php | 67 +++++++++++++++++++++++ tests/unit/mysql-test-initialize.sql | 6 +- tests/unit/runme_all | 12 +++- tests/unit/test.php | 21 ++++--- 7 files changed, 102 insertions(+), 20 deletions(-) create mode 100644 tests/unit/lib/plugin/IncludePageTest.php diff --git a/tests/unit/lib/InlineParserTest.php b/tests/unit/lib/InlineParserTest.php index e96c21325..f495405b7 100644 --- a/tests/unit/lib/InlineParserTest.php +++ b/tests/unit/lib/InlineParserTest.php @@ -1,5 +1,5 @@ * testLinks: Reini Urban @@ -83,7 +83,7 @@ actual $this->assertEquals($expected, $actual); } } - + } // (c-file-style: "gnu") diff --git a/tests/unit/lib/SetupWiki.php b/tests/unit/lib/SetupWiki.php index 5a324de59..47865311c 100644 --- a/tests/unit/lib/SetupWiki.php +++ b/tests/unit/lib/SetupWiki.php @@ -14,7 +14,7 @@ class SetupWiki extends phpwiki_TestCase { $dbi->purgePage($pagename); $this->assertFalse($dbi->isWikiPage($pagename)); - $request->setArg('source', FindFile('pgsrc/'.$pagename)); + $request->setArg('source', FindFile('pgsrc/'.urlencode($pagename))); $request->setArg('overwrite', 1); LoadAny($request, $request->getArg('source')); $request->setArg('source', false); @@ -23,12 +23,12 @@ class SetupWiki extends phpwiki_TestCase { /* PCRE memory problem (crash) with such big pages and anchored blocks */ function testOldMarkupTestPage() { - $this->_loadPage('OldMarkupTestPage'); + $this->_loadPage('Help/OldMarkupTestPage'); } - + /* ADODB set_links _id_cache error: IncludePagePlugin => HomePage */ function testIncludePagePlugin() { - $this->_loadPage('IncludePagePlugin'); + $this->_loadPage('Help/IncludePagePlugin'); } function testSetupWiki() { diff --git a/tests/unit/lib/TextSearchTest.php b/tests/unit/lib/TextSearchTest.php index 815c3a8cf..eada518d8 100644 --- a/tests/unit/lib/TextSearchTest.php +++ b/tests/unit/lib/TextSearchTest.php @@ -47,6 +47,10 @@ class TextSearchTest extends phpwiki_TestCase { $this->assertTrue(in_array("AddCommentPlugin", $result), "found all, no regex"); $query = new TextSearchQuery('WikiPlugin* to let users attach comments*', false); // auto + /* => (LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%') + SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (LOWER(pagename) LIKE '%to%') AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) + SELECT page.id AS id, page.pagename AS pagename, page.hits AS hits,page.pagedata as pagedata,version.version AS version, version.mtime AS mtime, version.minor_edit AS minor_edit, version.content AS content, version.versiondata AS versiondata FROM nonempty, page, recent, version WHERE nonempty.id=page.id AND page.id=recent.id AND page.id=version.id AND latestversion=version AND ((LOWER(pagename) LIKE 'wikiplugin%' OR content LIKE 'wikiplugin%') AND (1=1) AND (LOWER(pagename) LIKE '%let%' OR content LIKE '%let%') AND (LOWER(pagename) LIKE '%users%' OR content LIKE '%users%') AND (LOWER(pagename) LIKE '%attach%' OR content LIKE '%attach%') AND (LOWER(pagename) LIKE 'comments%' OR content LIKE 'comments%')) + */ $pages = $dbi->fullSearch($query, $sortby, $limit, $exclude); $result = array(); while ($page = $pages->next()) diff --git a/tests/unit/lib/plugin/IncludePageTest.php b/tests/unit/lib/plugin/IncludePageTest.php new file mode 100644 index 000000000..5170357e4 --- /dev/null +++ b/tests/unit/lib/plugin/IncludePageTest.php @@ -0,0 +1,67 @@ +getDbh(); + if (! $dbi->isWikiPage($pagename)) { + require_once 'lib/loadsave.php'; + + $request->setArg('source', FindFile('pgsrc/'.urlencode($pagename))); + $request->setArg('overwrite', 1); + LoadAny($request, $request->getArg('source')); + $request->setArg('source', false); + } + } + + // extract Synopsis + function testOldTextFormattingRules() { + global $request; + + $pagename = 'Help/OldTextFormattingRules'; + $this->_ensure_loaded($pagename); + $dbi = $request->getDbh(); + $p = $dbi->getPage($pagename); + $r = $p->getCurrentRevision(); + $c = $r->getContent(); + $section = extractSection('Synopsis', $c, $pagename, 1); + $this->assertTrue(strstr(join("", $section), "OldTextFormattingRules%%%")); + } + + // extract Synopsis + function testTextFormattingRules() { + global $request; + + $pagename = 'Help/TextFormattingRules'; + $this->_ensure_loaded($pagename); + $dbi = $request->getDbh(); + $p = $dbi->getPage($pagename); + $r = $p->getCurrentRevision(); + $c = $r->getContent(); + $section = extractSection('Synopsis', $c, $pagename, 1); + $this->assertTrue(strstr(join("", $section), "TextFormattingRules%%%")); + } + + /** + * Test the plugin with the typical editpage template call. + */ + function testIncludePageSynopsis() { + global $request; + $pagename = 'Help/TextFormattingRules'; + + $lp = new WikiPlugin_IncludePage(); + $this->assertEquals("IncludePage", $lp->getName()); + $dbi = $request->getDbh(); + $result = $lp->run($dbi, "page=$pagename section=Synopsis quiet=1", + $request, "IncludePage"); + $this->assertType('object', $result, 'isa HtmlElement'); + //TODO: check content for found and extracted section + } +} + +?> diff --git a/tests/unit/mysql-test-initialize.sql b/tests/unit/mysql-test-initialize.sql index 26e2f8f20..345c8b46c 100644 --- a/tests/unit/mysql-test-initialize.sql +++ b/tests/unit/mysql-test-initialize.sql @@ -1,4 +1,4 @@ --- $Id: mysql-test-initialize.sql,v 1.3 2004-12-22 15:05:18 rurban Exp $ +-- $Id: mysql-test-initialize.sql,v 1.4 2005-11-21 22:16:46 rurban Exp $ -- for the regression suite drop table if exists test_page; @@ -54,8 +54,10 @@ CREATE TABLE test_nonempty ( CREATE TABLE test_link ( linkfrom INT NOT NULL, linkto INT NOT NULL, + relation INT DEFAULT 0, INDEX (linkfrom), - INDEX (linkto) + INDEX (linkto), + INDEX (relation) ); CREATE TABLE test_session ( diff --git a/tests/unit/runme_all b/tests/unit/runme_all index 0e200cdcb..e15403db6 100755 --- a/tests/unit/runme_all +++ b/tests/unit/runme_all @@ -1,10 +1,16 @@ #!/bin/sh -# TODO: need to check write perms to the .testbox/* (mixed web/cli perms) +# check write perms to the .testbox/* (mixed web/cli perms) chmod -R a+rw .testbox .dumphtml if [ -d .testbox/page_data -a ! -w .testbox/page_data/AllPages ]; then rm -rf .testbox/* fi -for db in file dba SQL ADODB; do - php -Cq -d register_argc_argv=1 test.php debug=1 level=10 db=$db | tee all_$db.result + +for db in file dba SQL ADODB cvs \ + PearDB_mysql PearDB_pgsql PearDB_sqlite \ + ADODB_mysql ADODB_postgres7 ADODB_sqlite + PDO_mysql PDO_pgsql PDO_sqlite +do + php -Cq -d register_argc_argv=1 test.php debug=1 level=10 db=$db | \ + tee all_$db.result done diff --git a/tests/unit/test.php b/tests/unit/test.php index a463afa47..8d1fda507 100644 --- a/tests/unit/test.php +++ b/tests/unit/test.php @@ -79,16 +79,16 @@ $database_backends = array( 'dba', 'SQL', // default backend defined in the config.ini DSN 'ADODB', // same backend as defined in the config.ini DSN - // specific backends (need to be setup) + // specific backends (need to be setup as db=test_phpwiki 'PearDB_pgsql', 'PearDB_sqlite', 'PearDB_mysql', - //'PearDB_oci8', - //'PearDB_mssql', + //'PearDB_oci8','PearDB_mssql', 'ADODB_postgres7', 'ADODB_sqlite', 'ADODB_mysql', - //'ADODB_oci8', - //'ADODB_mssql', - 'PDO_pqsql', 'PDO_sqlite', 'PDO_mysql', - //'PDO_oci', 'PDO_odbc', + //'ADODB_oci8', 'ADODB_mssql', ); +if ((int)substr(phpversion(), 1) >= 5) + array_push($database_backends, 'PDO_pqsql', 'PDO_sqlite', 'PDO_mysql'); + //'PDO_oci', 'PDO_odbc' + //TODO: convert cvs test //TODO: read some database values from config.ini, just use the "test_" prefix // "flatfile" testing occurs in "tests/unit/.testbox/" @@ -373,7 +373,8 @@ $user_level = 1; // BOGO (conflicts with RateIt) $alltests = array('InlineParserTest','HtmlParserTest', 'PageListTest','ListPagesTest', 'SetupWiki', - 'AllPagesTest','AllUsersTest','OrphanedPagesTest','WantedPagesTest','TextSearchTest', + 'AllPagesTest','AllUsersTest','OrphanedPagesTest','WantedPagesTest', + 'TextSearchTest','IncludePageTest', 'DumpHtml'); // support db=file db=dba test=SetupWiki test=DumpHtml debug=num -dconstant=value // or db=file,dba test=SetupWiki,DumpHtml debug=num -dconstant=value @@ -394,6 +395,7 @@ if (!empty($argv)) { $runtests = array(); $define = array(); $run_database_backends = array(); + $m = array(); foreach ($argv as $arg) { if (preg_match("/^test=(.+)$/",$arg,$m) and in_array($m[1], $alltests)) $runtests[] = $m[1]; @@ -480,7 +482,7 @@ global $ErrorManager; $ErrorManager->setPostponedErrorMask(EM_FATAL_ERRORS|EM_WARNING_ERRORS|EM_NOTICE_ERRORS); // FIXME: ignore cached requests (if-modified-since) from cli class MockRequest extends WikiRequest { - function MockRequest(&$dbparams) { + function MockRequest($dbparams) { $this->_dbi = WikiDB::open($dbparams); $this->_user = new MockUser("a_user", $GLOBALS['user_level']); $this->_group = new GroupNone(); @@ -533,6 +535,7 @@ if (DEBUG & _DEBUG_TRACE) // provide a nice input form for all options if (isset($HTTP_SERVER_VARS['REQUEST_METHOD'])) { echo html_option_form(); + flush(); } // save and restore all args for each test. -- 2.45.0