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