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
10 // assume that the we've cd'ed to the tests directory
11 ini_set('include_path', '..' );
17 if ( $USER == "root" ) {
18 // root user can't check in to a CVS repository
19 print( "can not be run as root\n" );
23 // set to false if something went wrong
26 require_once( 'lib/WikiDB/backend/cvs.php' );
30 * These are the parameters required by the backend.
32 $db_params[CVS_PAGE_SOURCE] = "../pgsrc";
33 $db_params[CVS_CHECK_FOR_REPOSITORY] = true;
34 // the following three are removed if the test succeeds.
35 $db_params[CVS_DOC_DIR] = "/tmp/wiki_docs";
36 $db_params[CVS_REPOSITORY] = "/tmp/wiki_repository";
37 $db_params[CVS_DEBUG_FILE] = "/tmp/php_cvs.log";
40 // Check the creation of a new CVS repository and the importing of
43 $cvsdb = new WikiDB_backend_cvs( $db_params );
44 // check that all files contained in page source where checked in.
45 $allPageNames = array();
46 $d = opendir( $db_params[CVS_PAGE_SOURCE] );
47 while ( $entry = readdir( $d ) ) {
48 exec( "grep 'Checking in $entry' " . $db_params[CVS_DEBUG_FILE],
49 $cmdOutput, $cmdRetval );
51 if ( !is_dir( $db_params[CVS_PAGE_SOURCE] . "/" . $entry )) {
52 $allPageNames[] = $entry;
55 print "*** Error: [$entry] was not checked in -- view "
56 . $db_params[CVS_DEBUG_FILE] . " for details\n";
57 $REMOVE_DEBUG = false;
64 // Check that the meta data files were created
66 function get_pagedata( $page_name, $key, &$cvsdb )
69 $pageHash = $cvsdb->get_pagedata( $page_name );
70 if ( $pageHash[CMD_VERSION] != "1" ) {
71 print ( "*** Error: [$page_name] version wrong 1 != "
72 . $pageHash[CMD_VERSION] ."\n" );
73 $REMOVE_DEBUG = false;
77 $new_data[CMD_CONTENT] = "";
78 $cvsdb->update_pagedata( $page_name, $new_data );
80 $pageHash = $cvsdb->get_pagedata( $page_name );
81 if ( $pageHash[CMD_VERSION] != "2" ) {
82 print ( "*** Error: [$page_name] version wrong 2 != "
83 . $pageHash[CMD_VERSION] ."\n" );
84 $REMOVE_DEBUG = false;
87 array_walk( $allPageNames, 'get_pagedata', $cvsdb );
90 // test the add and delete pages
92 $new_page_data = array();
93 $pname = "Hello_World_Fubar";
95 $new_page_data[CMD_CONTENT] = "hello world\nPlease to meet you\n\n";
96 $cvsdb->update_pagedata( $pname, $new_page_data );
97 if ( $cvsdb->get_latest_version( $pname ) != "1" ) {
98 print( "***Error Line " . __LINE__ . ": expecting version number 1\n");
102 $new_page_data[CMD_CONTENT] = "goodbye cruel world\nbye bye....\n";
103 $cvsdb->update_pagedata( $pname, $new_page_data );
104 if ( $cvsdb->get_latest_version( $pname ) != "2" ) {
105 print( "***Error Line " . __LINE__ . ": expecting version number 2\n");
110 // clean up after ourselves
112 if ( $REMOVE_DEBUG ) {
113 exec( "rm -fr " . $db_params[CVS_DOC_DIR], $cmdout, $retval );
114 exec( "rm -fr " . $db_params[CVS_REPOSITORY], $cmdout, $retval );
115 exec( "rm -f " . $db_params[CVS_DEBUG_FILE], $cmdout, $retval );
116 print "Test was succesful\n";
118 print "It appears something went wrong, nothing being removed\n";