]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit_test_backend_cvs.php
testsuite starters
[SourceForge/phpwiki.git] / tests / unit_test_backend_cvs.php
1 <?php
2 /**
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.
6  *
7  * Author: Gerrit Riessen, gerrit.riessen@open-source-consultants.de
8  */
9
10 // assume that the we've cd'ed to the tests directory
11 ini_set('include_path', '..' );
12
13 function rcs_id() {}
14
15 if ( $USER == "root" ) {
16   // root user can't check in to a CVS repository
17   print( "can not be run as root\n" );
18   exit();
19 }
20
21 // set to false if something went wrong
22 $REMOVE_DEBUG = true;
23
24 require_once( 'lib/WikiDB/backend/cvs.php' );
25
26 $db_params                           = array();
27 /**
28  * These are the parameters required by the backend. 
29  */
30 $db_params[CVS_PAGE_SOURCE]          = "../pgsrc";
31 $db_params[CVS_CHECK_FOR_REPOSITORY] = true;
32 // the following three are removed if the test succeeds.
33 $db_params[CVS_DOC_DIR]              = "/tmp/wiki_docs";
34 $db_params[CVS_REPOSITORY]           = "/tmp/wiki_repository";
35 $db_params[CVS_DEBUG_FILE]           = "/tmp/php_cvs.log";
36
37 //
38 // Check the creation of a new CVS repository and the importing of
39 // the default pages.
40 //
41 $cvsdb = new WikiDB_backend_cvs( $db_params );
42 // check that all files contained in page source where checked in.
43 $allPageNames = array();
44 $d = opendir( $db_params[CVS_PAGE_SOURCE] );
45 while ( $entry = readdir( $d ) ) {
46     exec( "grep 'Checking in $entry' " . $db_params[CVS_DEBUG_FILE],
47           $cmdOutput, $cmdRetval );
48     
49     if ( !is_dir( $db_params[CVS_PAGE_SOURCE] . "/" . $entry )) {
50         $allPageNames[] = $entry;
51         
52         if ( $cmdRetval ) {
53             print "*** Error: [$entry] was not checked in -- view " 
54                 . $db_params[CVS_DEBUG_FILE] . " for details\n";
55             $REMOVE_DEBUG = false;
56         }
57     }
58 }
59 closedir( $d );
60
61 //
62 // Check that the meta data files were created
63 //
64 function get_pagedata( $page_name, $key, &$cvsdb ) 
65 {
66     global $REMOVE_DEBUG;
67     $pageHash = $cvsdb->get_pagedata( $page_name );
68     if ( $pageHash[CMD_VERSION] != "1" ) {
69         print ( "*** Error: [$page_name] version wrong 1 != "
70                 . $pageHash[CMD_VERSION] ."\n" );
71         $REMOVE_DEBUG = false;
72     }
73
74     $new_data = array();
75     $new_data[CMD_CONTENT] = "";
76     $cvsdb->update_pagedata( $page_name, $new_data );
77
78     $pageHash = $cvsdb->get_pagedata( $page_name );
79     if ( $pageHash[CMD_VERSION] != "2" ) {
80         print ( "*** Error: [$page_name] version wrong 2 != "
81                 . $pageHash[CMD_VERSION] ."\n" );
82         $REMOVE_DEBUG = false;
83     }
84 }
85 array_walk( $allPageNames, 'get_pagedata', $cvsdb );
86
87 //
88 // test the add and delete pages
89 //
90 $new_page_data = array();
91 $pname = "Hello_World_Fubar";
92
93 $new_page_data[CMD_CONTENT] = "hello world\nPlease to meet you\n\n";
94 $cvsdb->update_pagedata( $pname, $new_page_data );
95 if ( $cvsdb->get_latest_version( $pname ) != "1" ) {
96     print( "***Error Line " . __LINE__ . ": expecting version number 1\n");
97     $REMOVE_DEBUG=false;
98 }
99
100 $new_page_data[CMD_CONTENT] = "goodbye cruel world\nbye bye....\n";
101 $cvsdb->update_pagedata( $pname, $new_page_data );
102 if ( $cvsdb->get_latest_version( $pname ) != "2" ) {
103     print( "***Error Line " . __LINE__ . ": expecting version number 2\n");
104     $REMOVE_DEBUG=false;
105 }
106
107 //
108 // clean up after ourselves
109 //
110 if ( $REMOVE_DEBUG ) {
111     exec( "rm -fr " . $db_params[CVS_DOC_DIR], $cmdout, $retval );
112     exec( "rm -fr " . $db_params[CVS_REPOSITORY], $cmdout, $retval );
113     exec( "rm -f " . $db_params[CVS_DEBUG_FILE], $cmdout, $retval );
114     print "Test was succesful\n";
115 } else {
116     print "It appears something went wrong, nothing being removed\n";
117 }
118
119 ?>