source: trunk/tests/account.php @ 1184

Revision 929, 5.1 KB checked in by bogdan2412, 4 years ago (diff)

Bring tests up to date with codebase.

Reviewed by Mircea: http://reviewboard.infoarena.ro/r/14/

  • 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("Anon looks at new account page");
11$res = curl_test(array(
12        'url' => url_register(),
13));
14log_assert_equal($res['url'], url_absolute(url_register()));
15
16log_print("Admin looks at new account page, allowed");
17$res = curl_test(array(
18        'url' => url_register(),
19        'user' => 'test_admin',
20));
21log_assert_equal($res['url'], url_absolute(url_register()));
22
23$test_username = "test_".mt_rand();
24$test_password = "pwd".mt_rand();
25log_print("Creating $test_username");
26$res = curl_test(array(
27        'url' => url_register(),
28        'post' => array(
29                'username' => $test_username,
30                'password' => $test_password,
31                'password2' => $test_password,
32                'full_name' => "xzx-FULL-NAME-xzx",
33                'email' => "$test_username@gmail.com",
34                'tnc' => 1,
35        ),
36));
37log_assert_equal($res['url'], url_absolute(url_login()));
38
39log_print("Looking at the new user's page");
40$res = curl_test(array(
41        'url' => url_user_profile($test_username),
42        'user' => $test_username,
43        'pwd' => $test_password,
44));
45log_assert_equal($res['redirect_count'], 0);
46
47log_print("Looking at the new user's page stats");
48$res = curl_test(array(
49        'url' => url_user_stats($test_username),
50        'user' => $test_username,
51        'pwd' => $test_password,
52));
53log_assert_equal($res['redirect_count'], 0);
54log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx'));
55
56log_print("Looking at the new user's rating page");
57$res = curl_test(array(
58        'url' => url_user_rating($test_username),
59));
60log_assert_equal($res['redirect_count'], 0);
61log_assert(strstr($res['content'], 'normal'));
62
63log_print("Looking at the new user's stats page");
64$res = curl_test(array(
65        'url' => url_user_profile($test_username),
66));
67log_assert_equal($res['redirect_count'], 0);
68log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx'));
69
70$test_newpassword = "newpwd".mt_rand();
71log_print("User changes his password but is wrong");
72$res = curl_test(array(
73        'url' => url_account(),
74        'user' => $test_username,
75        'pwd' => $test_password,
76        'post' => array (
77                'oldpassword' => $test_password,
78                'password' => $test_newpassword,
79                'password2' => $test_newpassword + 1,
80)));
81log_assert_equal($res['redirect_count'], 0);
82log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx'));
83
84$test_newpassword = "newpwd".mt_rand();
85log_print("User changes his password correctly");
86$res = curl_test(array(
87        'url' => url_account(),
88        'user' => $test_username,
89        'pwd' => $test_password,
90        'post' => array (
91                'passwordold' => $test_password,
92                'password' => $test_newpassword,
93                'password2' => $test_newpassword,
94)));
95log_assert_equal($res['redirect_count'], 0);
96log_assert(strstr($res['content'], 'xzx-FULL-NAME-xzx'));
97log_assert(!strstr($res['content'], 'fieldError'));
98
99log_print("User changes his name");
100$res = curl_test(array(
101        'url' => url_account(),
102        'user' => $test_username,
103        'pwd' => $test_newpassword,
104        'post' => array (
105                'full_name' => 'xzx-NEW-FULL-NAME-xzx',
106)));
107log_assert_equal($res['redirect_count'], 0);
108log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx'));
109
110log_print("Admin looks at user account page");
111$res = curl_test(array(
112        'url' => url_account($test_username),
113        'user' => 'test_admin'
114));
115log_assert_equal($res['redirect_count'], 0);
116log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx'));
117
118log_print("Admin makes new user into a helper.");
119$res = curl_test(array(
120        'url' => url_account($test_username),
121        'user' => 'test_admin',
122        'post' => array(
123                'security_level' => 'helper',
124)));
125log_assert_equal($res['redirect_count'], 0);
126log_assert(strstr($res['content'], 'xzx-NEW-FULL-NAME-xzx'));
127log_assert(!strstr($res['content'], 'fieldError'));
128
129log_print("User can now see new-task page. Awesome");
130$res = curl_test(array(
131        'url' => url_task_create(),
132        'user' => $test_username,
133        'pwd' => $test_newpassword,
134));
135log_assert_equal($res['redirect_count'], 0);
136
137log_print("User tries to hack himself into an admin");
138$res = curl_test(array(
139        'url' => url_account(),
140        'user' => $test_username,
141        'pwd' => $test_newpassword,
142        'post' => array(
143                'security_level' => 'admin',
144)));
145log_assert_equal($res['redirect_count'], 1);
146
147log_print("User can't even see security level switched");
148$res = curl_test(array(
149        'url' => url_account(),
150        'user' => $test_username,
151        'pwd' => $test_newpassword,
152));
153log_assert_equal($res['redirect_count'], 0);
154log_assert(!stristr($res['content'], 'security_level'));
155
156log_print("Looking at the user page, still a helper");
157$res = curl_test(array(
158        'url' => url_user_profile($test_username),
159        'user' => $test_username,
160        'pwd' => $test_password,
161));
162log_assert_equal($res['redirect_count'], 0);
163log_assert(stristr($res['content'], 'helper'));
164
165test_cleanup();
Note: See TracBrowser for help on using the repository browser.