| 1 | #! /usr/bin/env php |
|---|
| 2 | <?php |
|---|
| 3 | |
|---|
| 4 | require_once(dirname($argv[0]) . "/utilities.php"); |
|---|
| 5 | require_once(IA_ROOT_DIR.'www/utilities.php'); |
|---|
| 6 | require_once(IA_ROOT_DIR.'common/db/db.php'); |
|---|
| 7 | |
|---|
| 8 | test_cleanup(); |
|---|
| 9 | test_prepare(); |
|---|
| 10 | |
|---|
| 11 | log_print("WARNING: This test requires the evaluator."); |
|---|
| 12 | |
|---|
| 13 | log_print("Helper1 looks at new round page, works"); |
|---|
| 14 | $res = curl_test(array( |
|---|
| 15 | 'url' => url_round_create(), |
|---|
| 16 | 'user' => 'test_helper1', |
|---|
| 17 | )); |
|---|
| 18 | log_assert_equal($res['url'], url_absolute(url_round_create())); |
|---|
| 19 | |
|---|
| 20 | |
|---|
| 21 | log_print("Helper1 tries to create a new round, works"); |
|---|
| 22 | $res = curl_test(array( |
|---|
| 23 | 'url' => url_round_create(), |
|---|
| 24 | 'user' => 'test_helper1', |
|---|
| 25 | 'post' => array( |
|---|
| 26 | 'id' => 'tEst_Round', |
|---|
| 27 | 'type' => 'user-defined', |
|---|
| 28 | ))); |
|---|
| 29 | log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); |
|---|
| 30 | |
|---|
| 31 | |
|---|
| 32 | log_print("Helper1 tries to create a new round, fails"); |
|---|
| 33 | $res = curl_test(array( |
|---|
| 34 | 'url' => url_round_create(), |
|---|
| 35 | 'user' => 'test_helper1', |
|---|
| 36 | 'post' => array( |
|---|
| 37 | 'id' => 'tEst_Round', |
|---|
| 38 | 'type' => 'classic', |
|---|
| 39 | ))); |
|---|
| 40 | log_assert_equal($res['url'], url_absolute(url_round_create())); |
|---|
| 41 | |
|---|
| 42 | |
|---|
| 43 | log_print("Helper2 looks at round page, and it's there"); |
|---|
| 44 | $res = curl_test(array( |
|---|
| 45 | 'url' => url_textblock('runda/tEst_Round'), |
|---|
| 46 | 'user' => 'test_helper2', |
|---|
| 47 | )); |
|---|
| 48 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 49 | |
|---|
| 50 | |
|---|
| 51 | log_print("Admin looks at new round page, ok"); |
|---|
| 52 | $res = curl_test(array( |
|---|
| 53 | 'url' => url_round_create(), |
|---|
| 54 | 'user' => 'test_admin', |
|---|
| 55 | )); |
|---|
| 56 | log_assert_equal($res['url'], url_absolute(url_round_create())); |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | log_print("Admin creates round, already exists."); |
|---|
| 60 | $res = curl_test(array( |
|---|
| 61 | 'url' => url_round_create(), |
|---|
| 62 | 'user' => 'test_admin', |
|---|
| 63 | 'post' => array( |
|---|
| 64 | 'id' => 'tEst_Round', |
|---|
| 65 | ))); |
|---|
| 66 | log_assert_equal($res['url'], url_absolute(url_round_create())); |
|---|
| 67 | log_assert(strstr($res['content'], 'test_round')); |
|---|
| 68 | |
|---|
| 69 | log_print("Admin changes round to classic."); |
|---|
| 70 | $res = curl_test(array( |
|---|
| 71 | 'url' => url_round_edit('tEst_Round'), |
|---|
| 72 | 'user' => 'test_admin', |
|---|
| 73 | 'post' => array( |
|---|
| 74 | 'type' => 'classic', |
|---|
| 75 | 'rating_update' => true, |
|---|
| 76 | 'start_time' => db_date_format(time() + 3600), |
|---|
| 77 | ))); |
|---|
| 78 | log_assert(!strstr($res['content'], '<span class="fieldError"')); |
|---|
| 79 | log_assert(strstr($res['content'], '<option value="classic" selected="selected">Concurs clasic')); |
|---|
| 80 | log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); |
|---|
| 81 | |
|---|
| 82 | log_print("Admin adds tasks adunare and cmmdc to round."); |
|---|
| 83 | $res = curl_test(array( |
|---|
| 84 | 'url' => url_round_edit('tEst_Round'), |
|---|
| 85 | 'user' => 'test_admin', |
|---|
| 86 | 'post' => array( |
|---|
| 87 | 'title' => 'xzx-round-title-xzx', |
|---|
| 88 | 'tasks' => array('adunare', 'cmmdc'), |
|---|
| 89 | ))); |
|---|
| 90 | log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); |
|---|
| 91 | log_assert(!strstr($res['content'], '<span class="fieldError"')); |
|---|
| 92 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 93 | |
|---|
| 94 | |
|---|
| 95 | log_print("Admin looks at round page, sees links to tasks"); |
|---|
| 96 | $res = curl_test(array( |
|---|
| 97 | 'url' => url_textblock("runda/tEst_Round"), |
|---|
| 98 | 'user' => 'test_admin', |
|---|
| 99 | )); |
|---|
| 100 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 101 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 102 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 103 | url_textblock('problema/adunare'))); |
|---|
| 104 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 105 | url_textblock('problema/cmmdc'))); |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | log_print("Admin removes task adunare, adds flip and biti."); |
|---|
| 109 | $res = curl_test(array( |
|---|
| 110 | 'url' => url_round_edit('tEst_Round'), |
|---|
| 111 | 'user' => 'test_admin', |
|---|
| 112 | 'post' => array( |
|---|
| 113 | 'tasks' => array('cmmdc', 'flip', 'biti'), |
|---|
| 114 | ))); |
|---|
| 115 | log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); |
|---|
| 116 | log_assert(!strstr($res['content'], '<span class="fieldError"')); |
|---|
| 117 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 118 | |
|---|
| 119 | |
|---|
| 120 | log_print("Admin looks at round page again, adunare is gone"); |
|---|
| 121 | $res = curl_test(array( |
|---|
| 122 | 'url' => url_textblock("runda/tEst_Round"), |
|---|
| 123 | 'user' => 'test_admin', |
|---|
| 124 | )); |
|---|
| 125 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 126 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 127 | log_assert(!strstr($res['content'], '<a href="'. |
|---|
| 128 | url_textblock('problema/adunare'))); |
|---|
| 129 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 130 | url_textblock('problema/cmmdc'))); |
|---|
| 131 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 132 | url_textblock('problema/flip'))); |
|---|
| 133 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 134 | url_textblock('problema/biti'))); |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | log_print("Anon looks at round page, sees that round hasn't started"); |
|---|
| 138 | $res = curl_test(array( |
|---|
| 139 | 'url' => url_textblock("runda/tEst_Round"), |
|---|
| 140 | )); |
|---|
| 141 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 142 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 143 | log_assert(strstr($res['content'], 'Nu esti inscris la')); |
|---|
| 144 | log_assert(!strstr($res['content'], '<a href="'. |
|---|
| 145 | url_textblock('problema/cmmdc'))); |
|---|
| 146 | log_assert(!strstr($res['content'], '<a href="'. |
|---|
| 147 | url_textblock('problema/flip'))); |
|---|
| 148 | log_assert(!strstr($res['content'], '<a href="'. |
|---|
| 149 | url_textblock('problema/biti'))); |
|---|
| 150 | |
|---|
| 151 | |
|---|
| 152 | log_print("Admin makes round an archive starting 3 seconds in the future"); |
|---|
| 153 | $start_date = db_date_format(time() + 3); |
|---|
| 154 | $res = curl_test(array( |
|---|
| 155 | 'url' => url_round_edit('tEst_Round'), |
|---|
| 156 | 'user' => 'test_admin', |
|---|
| 157 | 'post' => array( |
|---|
| 158 | 'type' => 'archive', |
|---|
| 159 | 'start_time' => $start_date, |
|---|
| 160 | 'tasks' => array('cmmdc', 'flip', 'biti'), |
|---|
| 161 | ), |
|---|
| 162 | )); |
|---|
| 163 | log_assert_equal($res['url'], url_absolute(url_round_edit('test_round'))); |
|---|
| 164 | log_assert(!strstr($res['content'], '<span class="fieldError"')); |
|---|
| 165 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 166 | log_assert(strstr($res['content'], $start_date)); |
|---|
| 167 | |
|---|
| 168 | |
|---|
| 169 | log_print("Admin looks at round page, round still not started"); |
|---|
| 170 | $res = curl_test(array( |
|---|
| 171 | 'url' => url_textblock("runda/tEst_Round"), |
|---|
| 172 | 'user' => 'test_admin', |
|---|
| 173 | )); |
|---|
| 174 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 175 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 176 | log_assert(strstr($res['content'], 'Nu esti inscris la')); |
|---|
| 177 | log_assert(!strstr($res['content'], 'Nu se mai pot face inscrieri')); |
|---|
| 178 | log_assert(!strstr($res['content'], 'Runda s-a incheiat')); |
|---|
| 179 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 180 | url_textblock('problema/cmmdc'))); |
|---|
| 181 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 182 | url_textblock('problema/flip'))); |
|---|
| 183 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 184 | url_textblock('problema/biti'))); |
|---|
| 185 | |
|---|
| 186 | |
|---|
| 187 | // Yuck |
|---|
| 188 | $wait = 4; |
|---|
| 189 | if (IA_MEM_CACHE_METHOD != "none") { |
|---|
| 190 | $wait += IA_MEM_CACHE_ROUND_EXPIRATION; |
|---|
| 191 | } |
|---|
| 192 | log_print("Waiting for $wait seconds..."); |
|---|
| 193 | usleep($wait * 1000000); |
|---|
| 194 | |
|---|
| 195 | log_print("Anon looks at round page, sees that round started"); |
|---|
| 196 | $res = curl_test(array( |
|---|
| 197 | 'url' => url_textblock("runda/tEst_Round"), |
|---|
| 198 | )); |
|---|
| 199 | log_assert_equal($res['url'], url_absolute(url_textblock('runda/tEst_Round'))); |
|---|
| 200 | log_assert(strstr($res['content'], 'xzx-round-title-xzx')); |
|---|
| 201 | log_assert(!strstr($res['content'], 'Nu esti inscris la'), |
|---|
| 202 | "Round still waiting, is the evaluator ON?"); |
|---|
| 203 | log_assert(strstr($res['content'], 'Nu se mai pot face inscrieri')); |
|---|
| 204 | log_assert(!strstr($res['content'], 'Runda s-a incheiat')); |
|---|
| 205 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 206 | url_textblock('problema/cmmdc'))); |
|---|
| 207 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 208 | url_textblock('problema/flip'))); |
|---|
| 209 | log_assert(strstr($res['content'], '<a href="'. |
|---|
| 210 | url_textblock('problema/biti'))); |
|---|
| 211 | |
|---|
| 212 | |
|---|
| 213 | log_print("Basic round passed"); |
|---|
| 214 | test_cleanup(); |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | ?> |
|---|