]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit_test_backend_cvs.php
Harmonize file footer
[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  * $Id$
9  */
10
11 // assume that the we've cd'ed to the tests directory
12 ini_set('include_path', '..' );
13
14 if ( $USER == "root" ) {
15   // root user can't check in to a CVS repository
16   print( "can not be run as root\n" );
17   exit();
18 }
19
20 // set to false if something went wrong
21 $REMOVE_DEBUG = true;
22
23 require_once( 'lib/WikiDB/backend/cvs.php' );
24
25 $db_params                           = array();
26 /**
27  * These are the parameters required by the backend. 
28  */
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";
35
36 //
37 // Check the creation of a new CVS repository and the importing of
38 // the default pages.
39 //
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 );
47     
48     if ( !is_dir( $db_params[CVS_PAGE_SOURCE] . "/" . $entry )) {
49         $allPageNames[] = $entry;
50         
51         if ( $cmdRetval ) {
52             print "*** Error: [$entry] was not checked in -- view " 
53                 . $db_params[CVS_DEBUG_FILE] . " for details\n";
54             $REMOVE_DEBUG = false;
55         }
56     }
57 }
58 closedir( $d );
59
60 //
61 // Check that the meta data files were created
62 //
63 function get_pagedata( $page_name, $key, &$cvsdb ) 
64 {
65     global $REMOVE_DEBUG;
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;
71     }
72
73     $new_data = array();
74     $new_data[CMD_CONTENT] = "";
75     $cvsdb->update_pagedata( $page_name, $new_data );
76
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;
82     }
83 }
84 array_walk( $allPageNames, 'get_pagedata', $cvsdb );
85
86 //
87 // test the add and delete pages
88 //
89 $new_page_data = array();
90 $pname = "Hello_World_Fubar";
91
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");
96     $REMOVE_DEBUG=false;
97 }
98
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");
103     $REMOVE_DEBUG=false;
104 }
105
106 //
107 // clean up after ourselves
108 //
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";
114 } else {
115     print "It appears something went wrong, nothing being removed\n";
116 }
117
118 ?>