source: trunk/tests/task.php @ 1184

Revision 1091, 8.4 KB checked in by bogdan2412, 2 years ago (diff)

Many many small fixes.

  • Changed task-tag action from simple-critical to simple-edit.
  • Fixed downloading attachments containing grader from normal (non-task) pages.
  • Moved a call to remote_ip_info() from common/ to www/ where it's supposed to be in MVC.
  • Fixed round and task tests.
  • Fixed test cleanup to delete only the created users and to delete them from the forum also.
  • Check that the username doesn't exist in the forum when someone tries to register (there are users on the forum that are not on infoarena, because of the import from info.devnet.ro i guess). Having two smf users with the same name crashes things.
  • Allow rounds to have no tasks.

Reviewed: http://reviewboard.infoarena.ro/r/126/

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1#! /usr/bin/env php
2<?php
3
4require_once(dirname($argv[0]) . "/utilities.php");
5require_once(IA_ROOT_DIR.'www/utilities.php');
6
7test_cleanup();
8test_prepare();
9
10log_print("Dude1 tries to look at new task page, redirect to login");
11$res = curl_test(array(
12        'url' => url_task_create(),
13        'user' => 'test_dude1'
14));
15log_assert_equal($res['url'],  url_absolute(url_home()));
16
17log_print("Helper1 looks at new task page, ok");
18$res = curl_test(array(
19        'url' => url_task_create(),
20        'user' => 'test_helper1'
21));
22log_assert_equal($res['url'],  url_absolute(url_task_create()));
23
24log_print("Helper1 creates a new task, ok");
25$res = curl_test(array(
26        'url' => url_task_create(),
27        'user' => 'test_helper1',
28        'post' => array(
29                'id' => 'test_task1',
30                'type' => 'classic',
31)));
32log_assert_equal($res['url'], url_absolute(url_task_edit('test_task1')));
33
34// Our edit forms pick up defaults for missing post fields. Helps with testing.
35log_print("Helper1 changes task title, author, source, it's ok");
36$res = curl_test(array(
37        'url' => url_task_edit('test_task1'),
38        'user' => 'test_helper1',
39        'post' => array(
40                'title' => 'xzx-task1-title-xzx',
41                'tag_author' => 'xzx-task1-author-xzx',
42                'source' => 'xzx-task1-source-xzx',
43)));
44log_assert_equal($res['url'], url_absolute(url_task_edit('test_task1')));
45// Evil
46log_assert(!strstr($res['content'], '<span class="fieldError"'));
47log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
48log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
49log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
50
51log_print("Helper2 tries to look at task page, fails(hidden)");
52$res = curl_test(array(
53        'url' => url_textblock('problema/teSt_Task1'),
54        'user' => 'test_helper2',
55));
56log_assert_equal($res['url'], url_absolute(url_home()));
57log_assert(!strstr($res['content'], 'xzx-task1-title-xzx'));
58log_assert(!strstr($res['content'], 'xzx-task1-author-xzx'));
59log_assert(!strstr($res['content'], 'xzx-task1-source-xzx'));
60
61log_print("Admin looks at task page, ok");
62$res = curl_test(array(
63        'url' => url_textblock('problema/teSt_Task1'),
64        'user' => 'test_admin',
65));
66log_assert_equal($res['url'], url_absolute(
67        url_textblock('problema/teSt_Task1')));
68log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
69log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
70log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
71
72log_print("Helper1 looks at task page, ok");
73$res = curl_test(array(
74        'url' => url_textblock('problema/teSt_Task1'),
75        'user' => 'test_helper1',
76));
77log_assert_equal($res['url'], url_absolute(
78        url_textblock('problema/teSt_Task1')));
79log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
80log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
81log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
82
83log_print("Helper1 tries to make task visible, fails");
84$res = curl_test(array(
85        'url' => url_task_edit('test_task1'),
86        'user' => 'test_helper1',
87        'post' => array(
88                'hidden' => 0,
89)));
90log_assert_equal($res['url'], url_absolute(url_home()));
91
92log_print("Dude1 still can't see the task page");
93$res = curl_test(array(
94        'url' => url_textblock('problema/teSt_Task1'),
95        'user' => 'test_dude1',
96));
97log_assert_equal($res['url'], url_absolute(url_home()));
98log_assert(!strstr($res['content'], 'xzx-task1-title-xzx'));
99log_assert(!strstr($res['content'], 'xzx-task1-author-xzx'));
100log_assert(!strstr($res['content'], 'xzx-task1-source-xzx'));
101
102log_print("Admin makes task visible, ok");
103$res = curl_test(array(
104        'url' => url_task_edit('test_task1'),
105        'user' => 'test_admin',
106        'post' => array(
107                'hidden' => 0,
108)));
109log_assert_equal($res['url'], url_absolute(url_task_edit('test_task1')));
110log_assert(!strstr($res['content'], '<span class="fieldError">'));
111
112log_print("Anon can now see the task page");
113$res = curl_test(array(
114        'url' => url_textblock('problema/teSt_Task1'),
115));
116log_assert_equal($res['url'], url_absolute(
117            url_textblock('problema/teSt_Task1')));
118log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
119log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
120log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
121
122log_print("Admin uploads a grader file");
123// FIXME: easily borked.
124file_put_contents('/tmp/grader_test', 'xzx-grader-xzx');
125$res = curl_test(array(
126        'url' => url_attachment_new('problema/teSt_Task1'),
127        'user' => 'test_admin',
128        'post' => array(
129                'file_name' => '@/tmp/grader_test'),
130));
131log_assert_equal($res['url'],  url_absolute(
132            url_textblock('problema/test_task1')));
133log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
134log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
135log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
136
137log_print("Helper1 looks at grader file");
138$res = curl_test(array(
139        'url' => url_attachment('problema/teSt_Task1', 'grader_test'),
140        'validate_html' => false,
141        'user' => 'test_helper1',
142));
143log_assert_equal($res['content'],  'xzx-grader-xzx');
144
145log_print("Helper2 can't see grader file");
146$res = curl_test(array(
147        'url' => url_attachment('problema/teSt_Task1', 'grader_test'),
148        'validate_html' => false,
149        'user' => 'test_helper2',
150));
151log_assert(!strstr($res['content'], 'xzx-grader-xzx'));
152
153log_print("Helper2 can see the task page however");
154$res = curl_test(array(
155        'url' => url_textblock('problema/teSt_Task1'),
156        'user' => 'test_helper',
157));
158log_assert_equal($res['url'], url_absolute(
159            url_textblock('problema/teSt_Task1')));
160log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
161log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
162log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
163
164log_print("Helper1 changes grader");
165// FIXME: easily borked.
166file_put_contents('/tmp/grader_test', 'xzx-grader-changed-xzx');
167$res = curl_test(array(
168        'url' => url_attachment_new('problema/teSt_Task1'),
169        'user' => 'test_admin',
170        'post' => array(
171                'file_name' => '@/tmp/grader_test'),
172));
173log_assert_equal($res['url'],  url_absolute(
174            url_textblock('problema/test_task1')));
175log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
176log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
177log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
178
179log_print("Admin sees grader file changed");
180$res = curl_test(array(
181        'url' => url_attachment('problema/teSt_Task1', 'grader_test'),
182        'validate_html' => false,
183        'user' => 'test_admin',
184));
185log_assert_equal($res['content'],  'xzx-grader-changed-xzx');
186
187log_print("Helper1 tries to make task hidden, fails");
188$res = curl_test(array(
189        'url' => url_task_edit('test_task1'),
190        'user' => 'test_helper1',
191        'post' => array(
192                'hidden' => 1,
193)));
194log_assert($res['url'] == url_absolute(url_home()));
195
196log_print("Anon can still see the task page");
197$res = curl_test(array(
198        'url' => url_textblock('problema/teSt_Task1'),
199));
200log_assert_equal($res['url'], url_absolute(
201            url_textblock('problema/teSt_Task1')));
202log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
203log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
204log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
205
206log_print("Helper2 tries to look at edit page, can't");
207$res = curl_test(array(
208        'url' => url_task_edit('test_task1'),
209        'user' => 'test_helper2',
210));
211log_assert($res['url'] == url_absolute(url_home()));
212log_assert(!strstr($res['content'], 'xzx-task1-title-xzx'));
213log_assert(!strstr($res['content'], 'xzx-task1-author-xzx'));
214log_assert(!strstr($res['content'], 'xzx-task1-source-xzx'));
215
216log_print("Helper1 looks at task edit page, doesn't even see security flipper");
217$res = curl_test(array(
218        'url' => url_task_edit('test_task1'),
219        'user' => 'test_helper1',
220));
221log_assert_equal($res['url'], url_absolute(url_task_edit('test_task1')));
222log_assert(strstr($res['content'], 'xzx-task1-title-xzx'));
223log_assert(strstr($res['content'], 'xzx-task1-author-xzx'));
224log_assert(strstr($res['content'], 'xzx-task1-source-xzx'));
225log_assert(strstr($res['content'], 'name="tag_author"'));
226log_assert(!strstr($res['content'], 'name="hidden"'));
227
228test_cleanup();
229log_print("Task tests all passed");
230
231?>
Note: See TracBrowser for help on using the repository browser.