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 (b2ac4e2d5363d99081c93e7859728667ac9fafca) (2,782B) (mode 100644) [raw]
<?php
error_reporting(E_ALL | E_STRICT);
ini_set("track_errors", "On");

$test_normal = TRUE;
$rg_cache_debug = TRUE;

$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");

$_testns = 'bug';

rg_test_create_user($db, $u1);
rg_test_create_user($db, $u2);
rg_test_create_repo($db, $u1, $new);

$data = array("bug_id" => 0,
	"title" => "Bug title<xss>",
	"body" => "This is the body\nof the\nbug.<xss>",
	"labels" => "label2,label1<xss>",
	"state" => 1,
	"assigned_uid" => 6);
$ri = array("repo_id" => $new['repo_id'], "name" => "repoX");
$r = rg_bug_edit($db, $u1, $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<xss>") != 0) {
	rg_log("Ordering the labels seems to not work.");
	exit(1);
}
if (strcmp($r[1], "label2") != 0) {
	rg_log("Ordering the labels seems to not work.");
	exit(1);
}

$data = array("note" => "This is just a note.<xss>");
$r = rg_bug_note_add($db, $new['repo_id'], $bug_id, $u2['uid'], $data);
if ($r === FALSE) {
	rg_log("Cannot add a note by u2 (" . 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" => $u1['username'],
	"assigned_to" => $u2['username'],
	"state" => "1",
	"start" => "2000-01-01",
	"end" => "2001-01-01",
	"title_string" => "IMPOSSIBLE TITLE<xss>",
	"body_string" => "IMPOSSIBLE BODY<xss>",
	"bugs_per_page" => "1");
$r = rg_bug_search($db, $new['repo_id'], $u1['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'], $u1['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