]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - tests/unit_test_backend_cvs.php
unit test for the cvs backend class
[SourceForge/phpwiki.git] / tests / unit_test_backend_cvs.php
1 <?php
2
3 /**
4  * Unit tests the 'lib/WikiDB/backend/cvs.php' file and with it
5  * the class WikiDB_backend_cvs
6  *
7  * Author: Gerrit Riessen, gerrit.riessen@open-source-consultants.de
8  */
9
10 // need to set this to be something sensible ....
11 ini_set('include_path', '/www/development/phpwiki' );
12
13 function rcs_id()
14 {
15 }
16
17 if ( $USER == "root" ) {
18   // root user can't check in to a CVS repository
19   print( "can not be run as root\n" );
20   exit(1);
21 }
22
23 // set to false if something went wrong
24 $REMOVE_DEBUG = true;
25
26 require_once( 'lib/WikiDB/backend/cvs.php' );
27
28 $db_params                           = array();
29 /**
30  * These are the parameters required by the backend. 
31  */
32 $db_params[CVS_PAGE_SOURCE]          = "/www/development/phpwiki/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";
38
39 //
40 // Check the creation of a new CVS repository and the importing of
41 // the default pages.
42 //
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 );
50     
51     if ( !is_dir( $db_params[CVS_PAGE_SOURCE] . "/" . $entry )) {
52         $allPageNames[] = $entry;
53         
54         if ( $cmdRetval ) {
55             print "*** Error: [$entry] was not checked in -- view " 
56                 . $db_params[CVS_DEBUG_FILE] . " for details\n";
57             $REMOVE_DEBUG = false;
58         }
59     }
60 }
61 closedir( $d );
62
63 //
64 // Check that the meta data files were created
65 //
66 function get_pagedata( $item, $key, $cvsdb ) 
67 {
68     global $REMOVE_DEBUG;
69     $pageHash = $cvsdb->get_pagedata( $item );
70     if ( $pageHash[CMD_VERSION] != "2" ) {
71         print "*** Error: [$item] version wrong (". $pageHash[CMD_VERSION]
72             .")\n";
73         $REMOVE_DEBUG = false;
74     }
75 }
76 array_walk( $allPageNames, 'get_pagedata', $cvsdb );
77
78 //
79 // clean up after ourselves
80 //
81 if ( $REMOVE_DEBUG ) {
82     exec( "rm -fr " . $db_params[CVS_DOC_DIR], $cmdout, $retval );
83     exec( "rm -fr " . $db_params[CVS_REPOSITORY], $cmdout, $retval );
84     exec( "rm -f " . $db_params[CVS_DEBUG_FILE], $cmdout, $retval );
85 } else {
86     print "It appears something went wrong, nothing being removed\n";
87 }
88
89 ?>