xaizek / rocketgit (License: AGPLv3+) (since 2018-12-09)
Light and fast Git hosting solution suitable to serve both as a hub or as a personal code storage with its tickets, pull requests, API and much more.
<root> / tests / bug.php (02800c3ef200b768c6b6810e982af7c8665a1717) (3,191B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);
ini_set("track_errors", "On");

$INC = dirname(__FILE__) . "/../inc";
require_once(dirname(__FILE__) . "/config.php");
require_once($INC . "/init.inc.php");
require_once($INC . "/bug.inc.php");
require_once($INC . "/sql.inc.php");
require_once($INC . "/struct.inc.php");
require_once($INC . "/fixes.inc.php");
require_once("helpers.inc.php");

rg_log_set_file("bug.log");

require_once("common.php");

// defaults
$uid = 1;
$ui = array("uid" => $uid, "username" => "userX", "organization" => 0, "email" => "test@embedromix.ro",
	"confirmed" => 1);
$repo_name = "bug-A";


rg_test_create_repo($db, $ui, $new);

$data = array("bug_id" => 0,
	"title" => "Bug title",
	"body" => "This is the body\nof the\nbug. <>",
	"labels" => "label3,label1,label2",
	"state" => 1,
	"assigned_uid" => 6);
$ri = array("repo_id" => $new['repo_id'], "name" => "repoX");
$r = rg_bug_edit($db, $ui, $ri, $data);
if ($r === FALSE) {
	rg_log("Cannot insert a bug (" . rg_bug_error() . ")!");
	exit(1);
}
$bug_id = $r;
// verify that labels were inserted
$r = rg_bug_label_get($db, $new['repo_id'], $bug_id);
if ($r === FALSE) {
	rg_log("Cannot get labels (" . rg_bug_error() . ")!");
	exit(1);
}
if (strcmp($r[0], "label1") != 0) {
	rg_log("Ordering the labels seems to not work.");
	exit(1);
}
if (strcmp($r[2], "label3") != 0) {
	rg_log("Ordering the labels seems to not work.");
	exit(1);
}

// add user
$_u['uid'] = 0;
$_u['realname'] = "user-bug-A real name";
$_u['username'] = "user-bug-A";
$_u['email'] = "rg@localhost";
$_u['pass'] = "pass1";
$_u['pass2'] = "pass1";
$_u['is_admin'] = 1;
$_u['rights'] = "C";
$_u['session_time'] = 3600;
$_u['confirm_token'] = "";
$_u['plan_id'] = 1000;
$uid = rg_user_edit($db, $_u);
if ($uid === FALSE) {
	rg_log("Cannot add user (" . rg_user_error() . ")!");
	exit(1);
}

$data = array("note" => "This is just a note.");
$r = rg_bug_note_add($db, $new['repo_id'], $bug_id, $uid, $data);
if ($r === FALSE) {
	rg_log("Cannot add a note (" . rg_bug_error() . ")!");
	exit(1);
}

$r = rg_bug_info($db, $new['repo_id'], $bug_id);
if ($r['exists'] != 1) {
	rg_log("Cannot lookup a bug (" . rg_bug_error() . ")!");
	exit(1);
}

// test a non existing bug
$r = rg_bug_info($db, $new['repo_id'], 0);
if ($r['exists'] != 0) {
	rg_log("Wrong bug number (0) returned valid data!");
	exit(1);
}

// Search bugs
$q = array("reported_by" => "user-bug-A",
	"assigned_to" => "user-bug-A",
	"state" => "1",
	"start" => "2000-01-01",
	"end" => "2001-01-01",
	"title_string" => "IMPOSSIBLE TITLE",
	"body_string" => "IMPOSSIBLE BODY",
	"bugs_per_page" => "1");
$r = rg_bug_search($db, $new['repo_id'], $uid, $q);
if ($r === FALSE) {
	rg_log("Cannot search bugs 1 (" . rg_bug_error() . ")!");
	exit(1);
}
if (count($r) > 0) {
	rg_log("Search 1 returned a bug but the filtering should not allow it!");
	exit(1);
}

$q = array("title_string" => "g t",
	"body_string" => "");
$r = rg_bug_search($db, $new['repo_id'], $uid, $q);
if ($r === FALSE) {
	rg_log("Cannot search bugs 2 (" . rg_bug_error() . ")!");
	exit(1);
}
if (count($r) == 0) {
	rg_log("Search 2 did not returned a bug we were expecting!");
	exit(1);
}

rg_sql_close($db);

rg_log("OK!");
?>
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/rocketgit

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/rocketgit

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master