blob: 8d389b649467c1ea3ccb83301072666379dc1d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh

# The index page, one row per repository in cgitrc. The checks look for each
# fixture repository and its description, for the escaping a name with a
# plus or a space needs in a link, and for the absence of the tree and log
# links that belong to a repository's own pages unless enable-index-links
# asks for them. The page's head also stands in for every page's, with one
# link per css and js entry.

test_description='Check content on index page'
. ./setup.sh

test_expect_success 'generate index page' 'cgit_url "" >tmp'
test_expect_success 'find foo repo' 'grep "foo" tmp'
test_expect_success 'find foo description' 'grep "\[no description\]" tmp'
test_expect_success 'find bar repo' 'grep "bar" tmp'
test_expect_success 'find bar description' 'grep "the bar repo" tmp'
test_expect_success 'find foo+bar repo' 'grep ">foo+bar<" tmp'
test_expect_success 'verify foo+bar links' 'test $(grep -o "href=./foo%2Bbar/." tmp | wc -l) = 2'
test_expect_success 'verify "with%20space" links' 'test $(grep -o "href=./with%20space/." tmp | wc -l) = 2'
test_expect_success 'no tree-link' '! grep "foo/tree" tmp'
test_expect_success 'no log-link' '! grep "foo/log" tmp'

test_expect_success 'index links lead to the summary, log and tree' '
	echo "enable-index-links=1" >links-cgitrc &&
	sed "s/^cache-size=.*/cache-size=0/" cgitrc >>links-cgitrc &&
	CGIT_CONFIG="$PWD/links-cgitrc" QUERY_STRING="url=" cgit >tmp &&
	grep ">summary</a><a class=.button. href=./foo/log/.>log</a>" tmp &&
	grep "href=./foo/log/.>log</a><a class=.button. href=./foo/tree/.>tree<" tmp
'

test_expect_success 'each css and js entry gets a link of its own' '
	{
		echo "css=/a.css" &&
		echo "css=/b.css" &&
		echo "js=/a.js" &&
		echo "js=" &&
		echo "js=/b.js"
	} >headrc &&
	sed "s/^cache-size=.*/cache-size=0/" cgitrc >>headrc &&
	CGIT_CONFIG="$PWD/headrc" QUERY_STRING="url=" cgit >tmp &&
	grep "<link rel=.stylesheet. href=./a.css.>" tmp &&
	grep "<link rel=.stylesheet. href=./b.css.>" tmp &&
	grep "<script src=" tmp >scripts &&
	test_line_count = 2 scripts &&
	grep "/a.js" scripts &&
	grep "/b.js" scripts
'

test_expect_success 'the feed link encodes the repository and the branch' '
	sed "s/^cache-size=.*/cache-size=0/" cgitrc >feedrc &&
	CGIT_CONFIG="$PWD/feedrc" HTTP_HOST=example.org QUERY_STRING="url=foo%2Bbar/log/&h=1%2B2" cgit >tmp &&
	grep "title=.Atom feed. href=.http://example.org/foo%2Bbar/atom/?h=1%2B2." tmp
'

# The description limit counts bytes, so a cut has to land between
# characters rather than leave half of one on the page.
test_expect_success 'a cut description keeps whole characters' '
	{
		echo "max-repodesc-length=10" &&
		sed "s/^cache-size=.*/cache-size=0/" cgitrc &&
		echo "repo.url=mb" &&
		echo "repo.path=$PWD/repos/foo/.git" &&
		echo "repo.desc=日本語の説明文です"
	} >descrc &&
	CGIT_CONFIG="$PWD/descrc" QUERY_STRING="url=" cgit >tmp &&
	grep ">日本語\.\.\.</a>" tmp
'

# The index sorts by a column only when asked, which nothing else exercises.
test_expect_success 'the index sorts by a column on request' '
	cgit_query "s=name" >tmp &&
	bar=$(grep -n ">bar</a>" tmp | head -1 | cut -d: -f1) &&
	foo=$(grep -n ">foo</a>" tmp | head -1 | cut -d: -f1) &&
	test "$bar" -lt "$foo" &&
	for s in desc owner idle
	do
		cgit_query "s=$s" >tmp &&
		grep ">foo</a>" tmp || return 1
	done
'

test_done