3 * Unit tests the 'lib/WikiDB/backend/cvs.php' file and with it
4 * the class WikiDB_backend_cvs. This isn't based on the PhpUnit, and
5 * is designed to be run directly using the php4 command.
7 * Author: Gerrit Riessen, gerrit.riessen@open-source-consultants.de
11 // assume that the we've cd'ed to the tests directory
12 ini_set('include_path', '..' );
14 if ( $USER == "root" ) {
15 // root user can't check in to a CVS repository
16 print( "can not be run as root\n" );
20 // set to false if something went wrong
23 require_once( 'lib/WikiDB/backend/cvs.php' );
27 * These are the parameters required by the backend.
29 $db_params[CVS_PAGE_SOURCE] = "../pgsrc";
30 $db_params[CVS_CHECK_FOR_REPOSITORY] = true;
31 // the following three are removed if the test succeeds.
32 $db_params[CVS_DOC_DIR] = "/tmp/wiki_docs";
33 $db_params[CVS_REPOSITORY] = "/tmp/wiki_repository";
34 $db_params[CVS_DEBUG_FILE] = "/tmp/php_cvs.log";
37 // Check the creation of a new CVS repository and the importing of
40 $cvsdb = new WikiDB_backend_cvs( $db_params );
41 // check that all files contained in page source where checked in.
42 $allPageNames = array();
43 $d = opendir( $db_params[CVS_PAGE_SOURCE] );
44 while ( $entry = readdir( $d ) ) {
45 exec( "grep 'Checking in $entry' " . $db_params[CVS_DEBUG_FILE],
46 $cmdOutput, $cmdRetval );
48 if ( !is_dir( $db_params[CVS_PAGE_SOURCE] . "/" . $entry )) {
49 $allPageNames[] = $entry;
52 print "*** Error: [$entry] was not checked in -- view "
53 . $db_params[CVS_DEBUG_FILE] . " for details\n";
54 $REMOVE_DEBUG = false;
61 // Check that the meta data files were created
63 function get_pagedata( $page_name, $key, &$cvsdb )
66 $pageHash = $cvsdb->get_pagedata( $page_name );
67 if ( $pageHash[CMD_VERSION] != "1" ) {
68 print ( "*** Error: [$page_name] version wrong 1 != "
69 . $pageHash[CMD_VERSION] ."\n" );
70 $REMOVE_DEBUG = false;
74 $new_data[CMD_CONTENT] = "";
75 $cvsdb->update_pagedata( $page_name, $new_data );
77 $pageHash = $cvsdb->get_pagedata( $page_name );
78 if ( $pageHash[CMD_VERSION] != "2" ) {
79 print ( "*** Error: [$page_name] version wrong 2 != "
80 . $pageHash[CMD_VERSION] ."\n" );
81 $REMOVE_DEBUG = false;
84 array_walk( $allPageNames, 'get_pagedata', $cvsdb );
87 // test the add and delete pages
89 $new_page_data = array();
90 $pname = "Hello_World_Fubar";
92 $new_page_data[CMD_CONTENT] = "hello world\nPlease to meet you\n\n";
93 $cvsdb->update_pagedata( $pname, $new_page_data );
94 if ( $cvsdb->get_latest_version( $pname ) != "1" ) {
95 print( "***Error Line " . __LINE__ . ": expecting version number 1\n");
99 $new_page_data[CMD_CONTENT] = "goodbye cruel world\nbye bye....\n";
100 $cvsdb->update_pagedata( $pname, $new_page_data );
101 if ( $cvsdb->get_latest_version( $pname ) != "2" ) {
102 print( "***Error Line " . __LINE__ . ": expecting version number 2\n");
107 // clean up after ourselves
109 if ( $REMOVE_DEBUG ) {
110 exec( "rm -fr " . $db_params[CVS_DOC_DIR], $cmdout, $retval );
111 exec( "rm -fr " . $db_params[CVS_REPOSITORY], $cmdout, $retval );
112 exec( "rm -f " . $db_params[CVS_DEBUG_FILE], $cmdout, $retval );
113 print "Test was succesful\n";
115 print "It appears something went wrong, nothing being removed\n";