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