added some git repo create validation
[gwvp-mini.git] / unittests / createlotsofreposandusers.php
1 <?php
2 $WEB_ROOT_FS = realpath(dirname(__FILE__));\r
3 $BASE_URL = dirname($_SERVER["PHP_SELF"]);\r
4 \r
5 global $WEB_ROOT_FS, $BASE_URL, $data_directory, $db_type, $db_name, $db_username, $db_password;\r
6
7 require_once("../www/config.php");\r
8 \r
9 if(file_exists("../gwvpmini/gwvpmini.php")) require_once("../gwvpmini/gwvpmini.php");\r
10 else if(file_exists("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php")) require_once("/usr/share/gwvpmini/lib/gwvpmini/gwvpmini.php");\r
11 \r
12 \r
13 \r
14 if(isset($noconfig)) {\r
15         gwvpmini_goSetup();\r
16         return;\r
17 }\r
18 \r
19 // need to make this db agnostic\r
20 if(!gwvpmini_DBExists($db_name)) {\r
21         if(!is_dir("$data_directory/repos")) mkdir("$data_directory/repos");\r
22 \r
23         error_log("CREATEDATABASE");\r
24         gwvpmini_dbCreateSQLiteStructure($db_name);\r
25         gwvpmini_setConfigVal("repodir", "$data_directory/repos");\r
26 }\r
27
28
29 $nrepos = 50;
30 $nusers = 100;
31
32 if(isset($_REQUEST["GO"])) {
33         for($i = 0; $i < $nusers; $i++) {
34                 $username = randomStr(rand(6,12));
35                 $password = "Asdf";
36                 $fullname = "asdf";
37                 $email = "Aasdf@asdf";
38                 $desc = "asdf";
39                 $level = 1;
40                 $status = 0;
41                 $uid = gwvpmini_AddUser($username, $password, $fullname, $email, $desc, $level, $status);
42                 echo "Created user, $username with uid of $uid<br>";
43         }
44         
45         for($i = 0; $i < $nrepos; $i++) {
46                 $reponame = randomStr(rand(6,12));
47                 $repodesc = "desc";
48                 $uid = rand(10,$nusers-1);
49                 gwvpmini_createGitRepo($reponame, $uid, $repodesc);
50                 echo "Created repo, $reponame owned by $uid as $repodesc<br>";
51         }
52 } else {
53         echo "click <a href=\"?GO=GO\">Go</a> to populate";
54 }
55
56 function randomStr($len)
57 {
58         $strl = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
59         
60         $retval = "";
61         for($i=0; $i<$len; $i++) {
62                 $retval .= $strl[rand(0,strlen($strl)-1)];
63         }
64         
65         return $retval;
66 }
67 ?>