function testShow_referees() { global $t, $bx, $db; $db_config = new mock_db_configure(2); $pid1 = "this sit he proid"; $pid2 = "this sit he proid two"; $q = $this->queries['show_referees']; $db_config->add_query(sprintf($q, $pid1), 0); $db_config->add_num_row(0, 0); $db_config->add_num_row(0, 0); $db_config->add_query(sprintf($q, $pid2), 1); $dat = $this->_generate_records(array('username', 'status', 'creation'), 5); $db_config->add_num_row(count($dat), 1); $db_config->add_num_row(count($dat), 1); for ($idx = 0; $idx < count($dat); $idx++) { $db_config->add_record($dat[$idx], 1); } // test one, no record/data $bx = $this->_create_default_box(); $db = new DB_SourceAgency(); capture_reset_and_start(); show_referees($pid1); $this->set_text(capture_stop_and_get()); $this->push_msg("Test One"); $this->_testFor_string_length(72); $msg = $t->translate("There are no developers that have " . "offered themselves as referees"); $this->_testFor_pattern($this->_to_regexp($msg)); $this->pop_msg(); // test two, data is defined $bx = $this->_create_default_box(); $db = new DB_SourceAgency(); capture_reset_and_start(); show_referees($pid2); $this->set_text(capture_stop_and_get()); $this->push_msg("Test Two"); $this->_testFor_string_length(4940); $msg = $t->translate("There are no developers that have " . "offered themselves as referees"); $this->reverse_next_test(); $this->_testFor_pattern($this->_to_regexp($msg)); $this->_checkFor_a_box('Referees'); $this->_checkFor_columns(4); $this->_checkFor_column_titles(array('Number', 'Username', 'Status', 'Creation'), '', '', ''); $colors = array(0 => '#FFFFFF', 1 => 'gold'); for ($idx = 0; $idx < count($dat); $idx++) { $v = array("<b>" . ($idx + 1) . "</b>", '<b>' . lib_nick($dat[$idx]['username']) . '</b>', '<b>' . show_status($dat[$idx]['status']) . '</b>', '<b>' . timestr(mktimestamp($dat[$idx]['creation'])) . '</b>'); $this->push_msg("Test {$idx}"); $this->_checkFor_column_values($v, '', '', $colors[$idx % 2]); $this->pop_msg(); } $this->pop_msg(); $this->_check_db($db_config); }
function testShow_consultants() { global $db, $t, $bx; $db_config = new mock_db_configure(2); $db_q = array(0 => "SELECT * FROM consultants,auth_user WHERE " . "proid='%s' AND username=consultant ORDER " . "BY creation"); $dat = $this->_generate_records(array("proid"), 2); $rows = $this->_generate_records(array("username", "status", "creation"), 3); $db_config->add_query(sprintf($db_q[0], $dat[0]["proid"]), 0); $db_config->add_query(sprintf($db_q[0], $dat[1]["proid"]), 1); $db_config->add_num_row(0, 0); $db_config->add_num_row(3, 1); $db_config->add_record($rows[0], 1); $db_config->add_record($rows[1], 1); $db_config->add_record($rows[2], 1); // first test: no data to list, print error message $db = new DB_SourceAgency(); $bx = new box(); $this->set_msg("test 1"); $this->capture_call('show_consultants', 64, &$dat[0]); $this->_testFor_pattern("No developers have offered " . "themselves as consultants yet"); // second test: three pieces of data $db = new DB_SourceAgency(); $bx = $this->_create_default_box(); $this->set_msg('test 2'); $this->capture_call('show_consultants', 3573, &$dat[1]); $this->_checkFor_a_box('Consultants'); $this->_checkFor_columns(4); $this->_checkFor_column_titles(array("Number", "Username", "Status", "Creation"), '', '', ''); $colors = array(1 => 'gold', 0 => '#FFFFFF'); for ($idx = 1; $idx < 4; $idx++) { $row = $rows[$idx - 1]; $this->set_msg("Test {$idx}"); $this->_testFor_box_next_row_of_columns(); $this->_checkFor_column_values(array('<b>' . $idx . '</b>', '<b>' . lib_nick($row['username']), '<b>' . show_status($row["status"]) . '</b>', '<b>' . timestr(mktimestamp($row["creation"])) . '</b>'), '', '', $colors[$idx % 2]); } $this->_check_db($db_config); }
function testComments_insert() { global $db, $t; $db_config = new mock_db_configure(2); $qs = array(0 => "SELECT * FROM comments WHERE proid='%s' AND " . "type='%s' AND number='%s'", 1 => "INSERT comments SET proid='%s',user_cmt='%s'," . "type='%s',number='%s',id='%s',ref='%s'," . "subject_cmt='%s',text_cmt='%s'", 2 => "SELECT * FROM comments, auth_user WHERE proid='%s' " . "AND type='%s' AND number='%s' AND id='%s' AND " . "ref='%s' AND user_cmt=username ORDER BY " . "creation_cmt ASC", 3 => "SELECT email_usr FROM auth_user,monitor WHERE " . "monitor.username=auth_user.username AND " . "proid='%s' AND (importance='middle' OR " . "importance='high')"); $args = $this->_generate_records(array('proid', 'user', 'type_cmt', 'number', 'ref', 'subject', 'text'), 1); $db_config->add_query(sprintf($qs[0], $args[0]['proid'], $args[0]['type_cmt'], $args[0]['number']), 0); $db_config->add_num_row(1, 0); $db_config->add_query(sprintf($qs[1], $args[0]['proid'], $args[0]['user'], $args[0]['type_cmt'], $args[0]['number'], '2', $args[0]['ref'], $args[0]['subject'], $args[0]['text']), 0); // ensure that monitor_mail sends no mail out $db_config->add_query(sprintf($qs[3], $args[0]['proid']), 1); $db_config->add_record(false, 1); // ensure that comments_show(..) shows no comments $db_config->add_query(sprintf($qs[2], $args[0]['proid'], $args[0]['type_cmt'], $args[0]['number'], '2', $args[0]['ref']), 0); $db_config->add_record(false, 0); $db = new DB_SourceAgency(); $this->capture_call('comments_insert', 0, $args[0]); $this->_check_db($db_config); }
function testShow_admprojects() { global $bx, $t, $sess; $db_config = new mock_db_configure(33); $qs = array(0 => "SELECT * FROM description,auth_user WHERE status='0' " . "AND description_user=username", 1 => "SELECT * FROM configure WHERE proid = '%s'", 2 => "SELECT perms FROM auth_user WHERE username='******'", 3 => "SELECT * FROM %s WHERE proid = '%s'"); $d = $this->_generate_records(array('perms', 'project_title', 'proid', 'type', 'description', 'volume', 'description_user', 'description_creation'), 8); $d2 = $this->_generate_records(array('perms'), 8); $table = array(0 => 'sponsoring', 1 => 'developing'); $bgc = array(0 => '#FEDCBA', 1 => '#ABCDEF'); for ($idx = 0; $idx < count($d); $idx++) { // tests 2 to 5 involve the sponsor, 5 to 9 the developer $d[$idx]['perms'] = $idx < 4 ? 'sponsor' : 'devel'; // user permission toggles between sponsor and developer $d2[$idx]['perms'] = $idx % 2 ? 'devel' : 'sponsor'; } // for test one $db_config->add_query($qs[0], 0); $db_config->add_num_row(0, 0); // the following is code for defining the queries which in implicately // set the value of the configured variable. The first 4 are for the // sponsor, the next four for the developer. // configured== 3 2 1 0 1 0 2 3 $nr_q2 = array(0 => 1, 1 => 0, 2 => 1, 3 => 0, 4 => 1, 5 => 0, 6 => 0, 7 => 1); $nr_q4 = array(0 => 1, 1 => 1, 2 => 0, 3 => 0, 4 => 0, 5 => 0, 6 => 1, 7 => 1); for ($idx = 0; $idx < count($d); $idx++) { $inst_idx = $idx * 4; $db_config->add_query($qs[0], $inst_idx + 1); $db_config->add_record($d[$idx], $inst_idx + 1); $db_config->add_num_row(1, $inst_idx + 1); $db_config->add_query(sprintf($qs[1], $d[$idx]['proid']), $inst_idx + 2); $db_config->add_num_row($nr_q2[$idx], $inst_idx + 2); $db_config->add_query(sprintf($qs[2], $d[$idx]['description_user']), $inst_idx + 3); $db_config->add_record($d2[$idx], $inst_idx + 3); $db_config->add_query(sprintf($qs[3], $table[$idx % 2], $d[$idx]['proid']), $inst_idx + 4); $db_config->add_num_row($nr_q4[$idx], $inst_idx + 4); } // test one, no projects $bx = $this->_create_default_box(); $this->capture_call('show_admprojects', 780); $this->_checkFor_box_full($t->translate('Pending Project Administration'), $t->translate('No pending projects')); // test two, test using the sponsor, configured == 3 $this->_call_show_admprojects(4800 + strlen($sess->self_url()), $d[0], $bgc[0]); $co = '<b>' . $t->translate('Yes') . '</b><br>' . html_link($table[0] . '.php3', array('proid' => $d[0]['proid']), $t->translate($table[0])) . '<br>' . html_link('configure.php3', array('proid' => $d[0]['proid']), $t->translate('Configuration')); $this->_testFor_box_column('center', '', $bgc[0], $co); $this->_testFor_html_form_hidden('proid', $d[0]['proid']); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); // test three, test using the sponsor, configured == 2 $this->_call_show_admprojects(4683 + strlen($sess->self_url()), $d[1], $bgc[0]); $co = '<b>' . $t->translate('Partially') . '</b><br>' . html_link($table[1] . '.php3', array('proid' => $d[1]['proid']), $t->translate($table[1])); $this->_testFor_box_column('center', '', $bgc[0], $co); $this->_testFor_html_form_hidden('proid', $d[1]['proid']); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); // test four, test using the sponsor, configured == 1 $this->_call_show_admprojects(4685 + strlen($sess->self_url()), $d[2], $bgc[0]); $co = '<b>' . $t->translate('Partially') . '</b><br>' . html_link('configure.php3', array('proid' => $d[2]['proid']), $t->translate('Configuration')); $this->_testFor_box_column('center', '', $bgc[0], $co); $this->_testFor_html_form_hidden('proid', $d[2]['proid']); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); // test five, test using the sponsor, configured == 0 $this->_call_show_admprojects(4613 + strlen($sess->self_url()), $d[3], $bgc[0]); $co = '<b>' . $t->translate('No') . '</b><br>'; $this->_testFor_box_column('center', '', $bgc[0], $co); $this->_testFor_html_form_hidden('proid', $d[3]['proid']); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); // test six: test using developer, configured == 1 $this->_call_show_admprojects(4733 + strlen($sess->self_url()), $d[4], $bgc[1]); $co = '<b>' . $t->translate('Yes') . '</b><br>' . html_link('configure.php3', array('proid' => $d[4]['proid']), $t->translate('Configuration')); $this->_testFor_box_column('center', '', $bgc[1], $co); $this->_testFor_html_form_hidden('proid', $d[4]['proid']); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); $this->_testFor_html_form_submit($t->translate('Accept'), 'accept'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); // test seven, eight, nine: test using developer, configured == {0,2,3} for ($idx = 5; $idx < 8; $idx++) { $this->_call_show_admprojects(4613 + strlen($sess->self_url()), $d[$idx], $bgc[1]); $co = '<b>' . $t->translate('No') . '</b><br>'; $this->_testFor_box_column('center', '', $bgc[1], $co); $this->_testFor_html_form_hidden('proid', $d[$idx]['proid']); $this->_testFor_html_form_submit($t->translate('Delete'), 'delete'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Review'), 'review'); $this->reverse_next_test(); $this->_testFor_html_form_submit($t->translate('Accept'), 'accept'); } $this->_check_db($db_config); }
function testShow_content() { global $db, $t, $bx, $sess; $db_config = new mock_db_configure(5); $qs = array(0 => $this->queries['show_content'], 1 => $this->queries['content_box_footer_1'], 2 => $this->queries['content_box_footer_2']); $dat = $this->_generate_records(array('creation', 'skills', 'platform', 'architecture', 'environment', 'docs', 'status', 'content_user', 'content_id', 'specification'), 2); $args = $this->_generate_records(array('proid', 'show_proposals', 'which_proposals'), 3); $dat2 = $this->_generate_records(array("COUNT(*)"), 4); // test one $db_config->add_query(sprintf($qs[0], $args[0]['proid']), 0); $db_config->add_num_row(0, 0); // test two $db_config->add_query(sprintf($qs[0], $args[1]['proid']), 1); $db_config->add_num_row(1, 1); $dat[0]['docs'] = ''; $db_config->add_record($dat[0], 1); $db_config->add_record(false, 1); $db_config->add_query(sprintf($qs[1], $args[1]['proid'], $dat[0]['content_id']), 2); $db_config->add_query(sprintf($qs[2], $args[1]['proid'], $dat[0]['content_id']), 2); $db_config->add_record($dat2[0], 2); $db_config->add_record($dat2[1], 2); // test three $db_config->add_query(sprintf($qs[0], $args[2]['proid']), 3); $db_config->add_num_row(1, 3); $dat[1]['docs'] = 'thsi si the documentation'; $db_config->add_record($dat[1], 3); $db_config->add_record(false, 3); $db_config->add_query(sprintf($qs[1], $args[2]['proid'], $dat[1]['content_id']), 4); $db_config->add_query(sprintf($qs[2], $args[2]['proid'], $dat[1]['content_id']), 4); $db_config->add_record($dat2[2], 4); $db_config->add_record($dat2[3], 4); // test one: no results $db = new DB_SourceAgency(); $this->capture_call('show_content', 67, $args[0]); $this->assertEquals('No technical content suggestions have been ' . "posted to this project.\n", $this->get_text()); // test two: one row, no documentation $args[1]['show_proposals'] = 'yes'; // but which_proposal is not set $bx = $this->_create_default_box(); $db = new DB_SourceAgency(); $this->capture_call('show_content', 2048, $args[1]); $this->_checkFor_show_content($args[1], $dat[0]); $args[1]['content_id'] = $dat[0]['content_id']; $this->_checkFor_content_box_footer($args[1], $dat2[0], $dat2[1], $dat[0]); // test three: one row, with documentation $args[1]['show_proposals'] = 'yes'; // but which_proposal is not set $bx = $this->_create_default_box(); $db = new DB_SourceAgency(); $this->capture_call('show_content', 2149, $args[2]); $this->_checkFor_show_content($args[2], $dat[1]); $args[2]['content_id'] = $dat[1]['content_id']; $this->_checkFor_content_box_footer($args[2], $dat2[2], $dat2[3], $dat[1]); $this->_check_db($db_config); }
function testDeveloping_modify_form() { global $bx, $t, $sess, $db; global $cost, $license, $cooperation, $valid_day, $valid_month, $valid_year, $start_day, $start_month, $start_year, $duration, $creation, $queries; $cost = 'ths is the cost'; $license = 'thsi is the license'; $cooperation = 'this is the coopeartion'; $valid_day = 'this is the valid_day'; $valid_month = 'thsi si the valid month'; $valid_year = 'this is the valid year'; $start_day = 'this is the start day'; $start_month = 'this is the start month'; $start_year = 'this is the start year'; $duration = 'this is the duration'; $creation = 'tjhis si the creation'; $args = $this->_generate_array(array('proid', 'content_id'), 10); $fname = 'developing_modify_form'; $db_config = new mock_db_configure(2); $qs = array(0 => $queries[$fname]); $db_config->add_query($qs[0], 0); $db_config->add_query($qs[0], 1); $db_config->add_num_row(1, 0); $db_config->add_num_row(1, 1); $db_config->add_record(false, 0); $db_config->add_record(false, 1); $bx = $this->_create_default_box(); capture_reset_and_start(); call_user_func_array($fname, $args); $this->set_text(capture_stop_and_get()); $this->_testFor_string_length(4217 + strlen($sess->self_url())); $this->assertRegexp('/Undefined variable: start/', $GLOBALS['err_msg']); $this->_checkFor_a_form('PHP_SELF', array('proid' => $args['proid']), 'POST'); $this->_checkFor_a_box('Developement proposal modification'); $this->_checkFor_submit_preview_buttons(); $start = ''; $valid = ''; $tv = array(html_input_text('cost', 12, 12, $cost) => array('Cost', '<b>%s</b> (12): '), license($license) => array('License', '<b>%s</b> (12): '), html_input_text('cooperation', 12, 12, $cooperation) => array('Developer cooperation wanted?', '<b>%s</b> (SELECT BOX) '), html_input_text('valid', 14, 14, $valid) => array('Valid until (select box)', '<b>%s</b>: '), html_input_text('start', 14, 14, $start) => array('Start (Select box)', '<b>%s</b>: '), html_input_text('duration', 3, 3, $duration) => array('Duration (Select box)', '<b>%s</b>: ')); while (list($val, $key) = each($tv)) { $this->_checkFor_column_titles(array($key[0]), 'right', '30%', '', $key[1]); $this->_checkFor_column_values(array($val)); } $this->_check_db($db_config); }
function testPut_decision_step5_into_database() { global $db, $auth, $queries; $uname = 'this is the username'; $auth->set_uname($uname); $fname = 'put_decision_step5_into_database'; $qs = array(0 => $queries[$fname . "_1"], 1 => $queries[$fname . "_2"], 2 => $queries[$fname . "_3"], 3 => $queries['monitor_mail']); $db_config = new mock_db_configure(6); $args = $this->_generate_records(array('proid', 'your_vote', 'milestone_number', 'count'), 10); // test one no records $db_config->add_query(sprintf($qs[0], $args[0]['proid'], $uname, $args[0]['milestone_number'], $args[0]['count']), 0); $db_config->add_num_row(0, 0); $db_config->add_query(sprintf($qs[1], $args[0]['proid'], $uname, $args[0]['milestone_number'], $args[0]['count'], $args[0]['your_vote']), 0); /* monitor_mail query */ $db_config->add_query(sprintf($qs[3], $args[0]['proid'], ''), 1); $db_config->add_record(false, 1); $db = new DB_SourceAgency(); $this->capture_call($fname, 0, $args[0]); // test two: one record, decision equals your_vote $db_config->add_query(sprintf($qs[0], $args[1]['proid'], $uname, $args[1]['milestone_number'], $args[1]['count']), 2); $db_config->add_num_row(1, 2); $db_config->add_record(array('decision' => $args[1]['your_vote']), 2); /* monitor_mail query */ $db_config->add_query(sprintf($qs[3], $args[1]['proid'], ''), 3); $db_config->add_record(false, 3); $db = new DB_SourceAgency(); $this->capture_call($fname, 28, $args[1]); $this->assertEquals("You have already voted that\n", $this->get_text()); // test three: one record, decision does not equal your_vote $db_config->add_query(sprintf($qs[0], $args[2]['proid'], $uname, $args[2]['milestone_number'], $args[2]['count']), 4); $db_config->add_num_row(1, 4); $db_config->add_record(array('decision' => $args[2]['your_vote'] . "NOT EQUALS"), 4); $db_config->add_query(sprintf($qs[2], $args[2]['your_vote'], $args[2]['proid'], $uname, $args[2]['milestone_number'], $args[2]['count']), 4); /* monitor_mail query */ $db_config->add_query(sprintf($qs[3], $args[2]['proid'], ''), 5); $db_config->add_record(false, 5); $db = new DB_SourceAgency(); $this->capture_call($fname, 71, $args[2]); $this->assertEquals("Vote changed. Old: <b>" . $args[2]['your_vote'] . "NOT EQUALS" . "</b> New: <b>" . $args[2]['your_vote'] . "</b>", $this->get_text()); $this->_check_db($db_config); }
function testTop_bar() { $db_config = new mock_db_configure(2); $fname = 'top_bar'; $qs = array(0 => $this->queries['summary_1']); $args = $this->_generate_records(array('proid', 'page'), 2); $db_config->add_query(sprintf($qs[0], $args[0]['proid']), 0); $db_config->add_num_row(0, 0); $db_config->add_query(sprintf($qs[0], $args[1]['proid']), 1); $db_config->add_num_row(1, 1); $db_config->add_record(array('project_title' => 'fubar', 'status' => 2), 1); // test one $this->capture_call($fname, 2258, $args[0]); // test two $this->capture_call($fname, 2564, $args[1]); $this->_check_db($db_config); }
function testNews_modify() { global $db; $db_config = new mock_db_configure(2); $row = array(0 => $this->_generate_array(array("proid", "user", "subject", "text", "creation"), 0)); $db_q = array(0 => "UPDATE news SET user_news='%s', subject_news=" . "'%s', text_news='%s' WHERE proid='%s' AND " . "creation_news='%s'", 1 => "SELECT email_usr FROM auth_user,monitor " . "WHERE monitor.username=auth_user.username " . "AND proid='%s' AND importance='high'", 2 => "SELECT * FROM news,auth_user WHERE proid='%s' " . "AND user_news=username ORDER BY " . "creation_news DESC"); $db_config->add_query(sprintf($db_q[0], $row[0]["user"], $row[0]["subject"], $row[0]["text"], $row[0]["proid"], $row[0]["creation"]), 0); $db_config->add_query(sprintf($db_q[1], $row[0]["proid"]), 1); $db_config->add_query(sprintf($db_q[2], $row[0]["proid"]), 0); $db_config->add_num_row(0, 0); $db_config->add_record(false, 0); $db_config->add_record(false, 1); // // first call, no records // $db = new DB_SourceAgency(); capture_reset_and_start(); news_modify($row[0]["proid"], $row[0]["user"], $row[0]["subject"], $row[0]["text"], $row[0]["creation"]); $this->set_text(capture_stop_and_get()); $this->set_msg('test 1'); $this->_testFor_string_length(67); $this->_testFor_pattern("<p>There have not been posted any news " . "by the project owner[(]s[)][.]<p>\n"); // check that the database component did not fail $this->_check_db($db_config); }
function testViews_show() { global $t, $bx, $db, $sess; $db_config = new mock_db_configure(3); $qs = array(0 => "SELECT * FROM views,description WHERE views.proid" . "=description.proid AND views.proid='%s'", 1 => "SELECT * FROM comments,auth_user WHERE proid='%s' AND " . "type='%s' AND number='%s' AND ref='%s' AND user_cmt" . "=username ORDER BY creation_cmt ASC"); $args = $this->_generate_records(array('proid'), 2); $d = $this->_generate_records(array('creation', 'description_user', 'configure', 'news', 'comments', 'history', 'step3', 'step4', 'step5', 'cooperation', 'views'), 1); // test one: no records $db_config->add_query(sprintf($qs[0], $args[0]['proid']), 0); $db_config->add_num_row(0, 0); // test two: one record $db_config->add_query(sprintf($qs[0], $args[1]['proid']), 1); $db_config->add_num_row(1, 1); $db_config->add_record($d[0], 1); $db_config->add_record(false, 1); $db_config->add_query(sprintf($qs[1], $args[1]['proid'], 'Views', '0', '0'), 2); $db_config->add_num_row(0, 2); // test one $db = new DB_SourceAgency(); $this->capture_call('views_show', 46, $args[0]); $this->assertEquals("<p>The views have not been configured yet.<p>\n", $this->get_text(), 'Line: ' . __LINE__); // test two $db = new DB_SourceAgency(); $bx = $this->_create_default_box(); $this->capture_call('views_show', 4698 + strlen(timestr(mktimestamp($d[0]['creation']))), $args[1]); $this->_checkFor_a_box('Project Information Access'); $this->_testFor_lib_nick($d[0]['description_user']); $str = " - " . timestr(mktimestamp($d[0]['creation'])) . "</b>"; $this->_testFor_pattern($this->_to_regexp($str)); $titles = array("View Project Configuration", "Write and Modify news", "Write comments", "See Project History", "See Step 3 (Milestones)", "See Step 4 (Referees)", "See Step 5 (Project Follow-up)", "See Developing Cooperation Proposals", "Project Permission Access"); $this->_checkFor_column_titles($titles, 'right', '30%', '', '<b>%s</b>: '); $this->_testFor_lib_comment_it($args[1]['proid'], "Views", "", "0", "", "Comments on the views?"); $values = array($d[0]["views"], $d[0]["cooperation"], $d[0]["step5"], $d[0]["step4"], $d[0]["step3"], $d[0]["history"], $d[0]["comments"], $d[0]["news"], $d[0]["configure"]); $this->_checkFor_column_values($values); $this->_check_db($db_config); }
function testCooperation_modify() { global $db; $qs = array(0 => "UPDATE cooperation SET developer='%s', cost='%s' " . "WHERE devid='%s' AND creation='%s'", 1 => "SELECT * FROM cooperation,auth_user WHERE devid='%s' " . "AND developer=username ORDER BY creation DESC"); $args = $this->_generate_records(array('devid', 'developer', 'cost', 'creation'), 2); $db_config = new mock_db_configure(1); $db_config->add_query(sprintf($qs[0], $args[0]['developer'], $args[0]['cost'], $args[0]['devid'], $args[0]['creation']), 0); $db_config->add_query(sprintf($qs[1], $args[0]['devid']), 0); $db_config->add_num_row(0, 0); $str = "<p>There have not been posted any cooperation proposals " . "by any developer.<p>\n"; $db = new DB_SourceAgency(); $this->capture_call('cooperation_modify', strlen($str), $args[0]); $this->assertEquals($str, $this->get_text()); $this->_check_db($db_config); }
function testShow_personal_rating() { global $t, $queries; $fname = 'show_personal_rating'; $qs = array(0 => $queries[$fname]); $db_config = new mock_db_configure(3); $args = $this->_generate_records(array('proid', 'username'), 10); $d1 = $this->_generate_records(array('rating'), 11); // test one: no rating $db_config->add_query(sprintf($qs[0], $args[0]['proid'], $args[0]['username']), 0); $db_config->add_num_row(0, 0); $this->capture_call($fname, 36, $args[0]); $str = "<p><b>" . $args[0]['username'] . "</b>: " . $t->translate('Not rated yet') . "\n"; $this->_testFor_pattern($this->_to_regexp($str)); // test two: one rating $db_config->add_query(sprintf($qs[0], $args[1]['proid'], $args[1]['username']), 1); $db_config->add_num_row(1, 1); $d1[0]['rating'] = 234; $db_config->add_record($d1[0], 1); $db_config->add_record(false, 1); $this->capture_call($fname, 42, $args[1]); $str = "<p><b>" . $args[1]['username'] . "</b>: " . round(234 * 100 / 1) / 100 . " (" . $t->translate('rated') . " 1 " . $t->translate('times') . ")\n"; $this->_testFor_pattern($this->_to_regexp($str)); // test three: 10 ratings $db_config->add_query(sprintf($qs[0], $args[2]['proid'], $args[2]['username']), 2); $db_config->add_num_row(1, 2); $total = 0; for ($idx = 1; $idx < 11; $idx++) { $d1[$idx]['rating'] = $idx; $db_config->add_record($d1[$idx], 2); $total += $idx; } $db_config->add_record(false, 2); $this->capture_call($fname, 43, $args[2]); $str = "<p><b>" . $args[2]['username'] . "</b>: " . round($total * 100 / 10) / 100 . " (" . $t->translate('rated') . " 10 " . $t->translate('times') . ")\n"; $this->_testFor_pattern($this->_to_regexp($str)); $this->_check_db($db_config); }
function testPersonal_ratings_short() { global $bx, $t; $fname = 'personal_ratings_short'; $q = "SELECT rating FROM ratings WHERE to_whom='%s'"; $db_config = new mock_db_configure(2); $args = $this->_generate_records(array('username'), 10); $d1 = $this->_generate_records(array('rating'), 10); // test one: no records $db_config->add_query(sprintf($q, $args[0]['username']), 0); $db_config->add_num_row(0, 0); $bx = $this->_create_default_box(); $this->capture_call($fname, 676, $args[0]); $this->_checkFor_a_box('Rating'); $str = $t->translate('Not rated yet'); $this->_testFor_pattern($this->_to_regexp($str)); // test two: records $db_config->add_query(sprintf($q, $args[1]['username']), 1); $db_config->add_num_row(1, 1); $avg = 0; for ($idx = 0; $idx < count($d1); $idx++) { $d1[$idx]['rating'] = $idx; $db_config->add_record($d1[$idx], 1); $avg += $idx; } $avg /= count($d1); $db_config->add_record(false, 1); $bx = $this->_create_default_box(); $this->capture_call($fname, 810, $args[1]); $this->_checkFor_a_box('Rating'); $str = $t->translate('Global personal rating: ') . $avg . " (rated " . count($d1) . " times)<p align=right>\n"; $this->_testFor_pattern($this->_to_regexp($str)); $this->_testFor_html_link('personal_ratings.php3', array('username' => $args[1]['username']), $t->translate('See complete ratings...')); $this->_check_db($db_config); }
function testConfigure_show() { global $t, $bx, $db, $sess, $queries; $qs = array(0 => $queries['configure_form']); $args = $this->_generate_records(array('proid'), 3); $dat = $this->_generate_records(array('quorum', 'consultants', 'other_tech_contents', 'sponsor', 'other_developing_proposals', 'developer'), 2); $db_config = new mock_db_configure(3); // test one $db_config->add_query(sprintf($qs[0], $args[0]['proid']), 0); $db_config->add_num_row(0, 0); // test two $db_config->add_query(sprintf($qs[0], $args[1]['proid']), 1); $db_config->add_num_row(1, 1); $db_config->add_record($dat[0], 1); $db_config->add_record(false, 1); // test three $db_config->add_query(sprintf($qs[0], $args[2]['proid']), 2); $db_config->add_num_row(1, 2); $dat[1]['quorum'] = ''; $dat[1]['sponsor'] = ''; $dat[1]['developer'] = ''; $db_config->add_record($dat[1], 2); $db_config->add_record(false, 2); // test one: no results $str = "<p>" . $t->translate("The project parameters have not been " . "configured by the project owner(s)") . ".<p>\n"; $db = new DB_SourceAgency(); $bx = $this->_create_default_box(); $this->capture_call('configure_show', strlen($str), $args[0]); $this->assertEquals($str, $this->get_text(), "test 1"); // test two: one record with all values set $db = new DB_SourceAgency(); $bx = $this->_create_default_box(); $this->capture_call('configure_show', 944, $args[1]); $this->_checkFor_configure_show($dat[0]); // test three: one record with unset values $db = new DB_SourceAgency(); $bx = $this->_create_default_box(); $this->capture_call('configure_show', 975, $args[2]); $this->_checkFor_configure_show($dat[1]); $this->_check_db($db_config); }
function testMonitor_insert() { global $db, $t; $fname = 'monitor_insert'; $qs = array(0 => $this->queries[$fname . '_1'], 1 => $this->queries[$fname . '_2'], 2 => $this->queries['monitor_modify'], 3 => $this->queries['monitor_mail_3'], 4 => $this->queries['monitor_show']); $db_config = new mock_db_configure(4); $args = $this->_generate_records(array('proid', 'username', 'importance'), 10); $creation = 'thisd ithe creation'; // test one: number of rows > 0 ==> monitor_modify called $db_config->add_query(sprintf($qs[0], $args[0]['proid'], $args[0]['username']), 0); $db_config->add_num_row(10, 0); $db_config->add_record(array('creation' => $creation), 0); $db_config->add_query(sprintf($qs[2], $args[0]['importance'], $args[0]['proid'], $args[0]['username']), 0); /** monitor mail call **/ $db_config->add_query(sprintf($qs[3], $args[0]['proid']), 1); $db_config->add_record(false, 1); /** monitor show call **/ $db_config->add_query(sprintf($qs[4], $args[0]['proid']), 0); $db_config->add_num_row(0, 0); $db = new DB_SourceAgency(); $this->capture_call($fname, 41, $args[0]); // test two: number of rows == 0, insert and monitor_{mail,show} called $db_config->add_query(sprintf($qs[0], $args[1]['proid'], $args[1]['username']), 2); $db_config->add_num_row(0, 2); $db_config->add_query(sprintf($qs[1], $args[1]['proid'], $args[1]['username'], $args[1]['importance']), 2); /** monitor mail call **/ $db_config->add_query(sprintf($qs[3], $args[1]['proid']), 3); $db_config->add_record(false, 3); /** monitor show call **/ $db_config->add_query(sprintf($qs[4], $args[1]['proid']), 2); $db_config->add_num_row(0, 2); $db = new DB_SourceAgency(); $this->capture_call($fname, 41, $args[1]); $this->_check_db($db_config); }
function testIs_first_sponsor_or_dev() { global $auth; $auth->set_perm("this is the permission"); $auth->set_uname("this is the user name"); $db_config = new mock_db_configure(10); $db_q = array(0 => $this->queries["is_main_developer"], 1 => $this->queries["is_first_sponsor_or_dev"], 2 => $this->queries["is_accepted_sponsor"], 3 => $this->queries["is_accepted_developer"]); $args = $this->_generate_records(array("proid"), 4); // case 1: is_main_developer => true $db_config->add_query(sprintf($db_q[3], $args[0]["proid"], $auth->auth["uname"]), 0); $db_config->add_num_row(1, 0); $db_config->add_query(sprintf($db_q[0], $args[0]["proid"], $auth->auth["uname"]), 1); $db_config->add_num_row(1, 1); $this->assertEquals(1, is_first_sponsor_or_dev($args[0]["proid"])); // case 2: is_main_developer => false, is_accepted_sponsor => false $db_config->add_query(sprintf($db_q[3], $args[1]["proid"], $auth->auth["uname"]), 2); $db_config->add_num_row(0, 2); // is_main_developer fails $db_config->add_query(sprintf($db_q[2], $args[1]["proid"], $auth->auth["uname"]), 3); $db_config->add_num_row(0, 3); // is_accepted_sponsor fails // FIXME: this is a bug, is_first_sponsor_or_dev should // FIXME: return something $this->assertEquals("", is_first_sponsor_or_dev($args[1]["proid"])); // case 3: is_main_developer => false, is_accepted_sponser => true // case 3: and num_rows returns value greater than zero $db_config->add_query(sprintf($db_q[3], $args[2]["proid"], $auth->auth["uname"]), 4); $db_config->add_num_row(0, 4); // is_main_developer fails $db_config->add_query(sprintf($db_q[2], $args[2]["proid"], $auth->auth["uname"]), 5); $db_config->add_num_row(1, 5); // is_accepted_sponsor succeeds $db_config->add_query(sprintf($db_q[1], $auth->auth["uname"]), 6); $db_config->add_num_row(1, 6); // is_first_sponsor_or_dev succeeds $this->assertEquals(1, is_first_sponsor_or_dev($args[2]["proid"])); // case 4: is_main_developer => false, is_accepted_sponser => true // case 4: and num_rows returns zero or less. $db_config->add_query(sprintf($db_q[3], $args[3]["proid"], $auth->auth["uname"]), 7); $db_config->add_num_row(0, 7); // is_main_developer fails $db_config->add_query(sprintf($db_q[2], $args[3]["proid"], $auth->auth["uname"]), 8); $db_config->add_num_row(1, 8); // is_accepted_sponsor succeeds $db_config->add_query(sprintf($db_q[1], $auth->auth["uname"]), 9); $db_config->add_num_row(0, 9); // is_first_sponsor_or_dev succeeds $this->assertEquals(0, is_first_sponsor_or_dev($args[3]["proid"])); $this->_check_db($db_config); }
function testSponsoring_insert() { global $db, $auth; $auth->set_uname("this is the username"); $auth->set_perm("this is the permission"); $db_config = new mock_db_configure(14); $db_q = array(0 => "SELECT COUNT(*) FROM sponsoring WHERE " . "proid='%s'", 1 => "INSERT sponsoring SET proid='%s',sponsor='%s'" . ",sponsoring_text='%s',budget='%s', status=" . "'%s', valid='%s',begin='%s',finish='%s'", 2 => "UPDATE configure SET sponsor='%s' WHERE " . "proid='%s'", 3 => "SELECT * FROM description WHERE proid='%s' " . "AND description_user='******'", 4 => "SELECT * FROM sponsoring,auth_user WHERE " . "proid='%s' AND sponsor=username ORDER BY " . "sponsoring.creation ASC", 5 => "SELECT * FROM sponsoring WHERE proid='%s' AND " . "sponsor='%s'", 6 => "UPDATE sponsoring SET sponsoring_text='%s', " . "budget='%s', status='%s', valid='%s'," . "begin='%s', finish='%s' " . "WHERE proid='%s' AND sponsor='%s'"); $args = $this->_generate_records(array("proid", "user", "s_text", "budget", "v_day", "v_month", "v_year", "b_day", "b_month", "b_year", "f_day", "f_month", "f_year"), 4); $rows = $this->_generate_records(array("COUNT(*)"), 4); // first call $db_config->add_query(sprintf($db_q[0], $args[0]["proid"]), 0); $v = date_to_timestamp($args[0]["v_day"], $args[0]["v_month"], $args[0]["v_year"]); $b = date_to_timestamp($args[0]["b_day"], $args[0]["b_month"], $args[0]["b_year"]); $f = date_to_timestamp($args[0]["f_day"], $args[0]["f_month"], $args[0]["f_year"]); // query for checking the number of sponsoring the user has made $db_config->add_query(sprintf($db_q[5], $args[0]["proid"], $args[0]["user"]), 0); // insert query $db_config->add_query(sprintf($db_q[1], $args[0]["proid"], $args[0]["user"], $args[0]["s_text"], $args[0]["budget"], "P", $v, $b, $f), 0); // query for the show_sponsorings call $db_config->add_query(sprintf($db_q[4], $args[0]["proid"]), 0); // instance for the monitor_mail call $db_config->ignore_all_errors(1); // instance created by the is_project_initiator $db_config->add_query(sprintf($db_q[3], $args[0]["proid"], $auth->auth["uname"]), 2); $rows[0]["COUNT(*)"] = 1; // status is 'P' (proposed) $db_config->add_record($rows[0], 0); // sponsoring_insert $db_config->add_record(false, 0); // show_sponsorings // two if statements $db_config->add_num_row(0, 0); $db_config->add_num_row(0, 0); $db_config->add_num_row(1, 0); // show_sponsorings $db_config->add_num_row(1, 2); // 2nd call to is_project_initiator // second call $db_config->add_query(sprintf($db_q[0], $args[1]["proid"]), 3); $v = date_to_timestamp($args[1]["v_day"], $args[1]["v_month"], $args[1]["v_year"]); $b = date_to_timestamp($args[1]["b_day"], $args[1]["b_month"], $args[1]["b_year"]); $f = date_to_timestamp($args[1]["f_day"], $args[1]["f_month"], $args[1]["f_year"]); // query for checking the number of sponsoring the user has made $db_config->add_query(sprintf($db_q[5], $args[1]["proid"], $args[1]["user"]), 3); $db_config->add_query(sprintf($db_q[1], $args[1]["proid"], $args[1]["user"], $args[1]["s_text"], $args[1]["budget"], "A", $v, $b, $f), 3); // this is the update query $db_config->add_query(sprintf($db_q[2], $auth->auth["uname"], $args[1]["proid"]), 3); // query for the show_sponsorings call $db_config->add_query(sprintf($db_q[4], $args[1]["proid"]), 3); // 1st call to is_project_initiator $db_config->add_query(sprintf($db_q[3], $args[1]["proid"], $auth->auth["uname"]), 4); // instance for the monitor_mail call $db_config->ignore_all_errors(5); // instance created by the second call to is_project_initiator $db_config->add_query(sprintf($db_q[3], $args[1]["proid"], $auth->auth["uname"]), 6); $rows[1]["COUNT(*)"] = 0; // status is 'A' $db_config->add_record($rows[1], 3); // sponsoring_insert $db_config->add_record(false, 3); // show_sponsorings $db_config->add_num_row(0, 3); // if ( $db->num_rows() == 1 ) { $db_config->add_num_row(0, 3); // if ( $db->num_rows() == 0 ) { $db_config->add_num_row(1, 3); // show_sponsorings $db_config->add_num_row(0, 4); // 1st call to is_project_initiator $db_config->add_num_row(0, 6); // 2nd call to is_project_initiator // third call, check that an update query is executed if the // user already has a sponsorship. $db_config->add_query(sprintf($db_q[0], $args[2]["proid"]), 7); $v = date_to_timestamp($args[2]["v_day"], $args[2]["v_month"], $args[2]["v_year"]); $b = date_to_timestamp($args[2]["b_day"], $args[2]["b_month"], $args[2]["b_year"]); $f = date_to_timestamp($args[2]["f_day"], $args[2]["f_month"], $args[2]["f_year"]); // query for checking the number of sponsoring the user has made $db_config->add_query(sprintf($db_q[5], $args[2]["proid"], $args[2]["user"]), 7); // update query because user has already contributed $args[2]["budget"] = 1; $db_config->add_query(sprintf($db_q[6], $args[2]["s_text"], $args[2]["budget"], "P", $v, $b, $f, $args[2]["proid"], $args[2]["user"]), 7); // query for the show_sponsorings call $db_config->add_query(sprintf($db_q[4], $args[2]["proid"]), 7); // instance for the monitor_mail call $db_config->ignore_all_errors(8); $db_config->ignore_all_errors(9); // instance created by the is_project_initiator $db_config->add_query(sprintf($db_q[3], $args[2]["proid"], $auth->auth["uname"]), 10); $rows[2]["COUNT(*)"] = 1; // status is 'P' (proposed) $rows[2]["budget"] = 0; // old_budget should be less than new budget $db_config->add_record($rows[2], 7); // sponsoring_insert $db_config->add_record($rows[2], 7); // sponsoring_insert $db_config->add_record(false, 7); // show_sponsorings $db_config->add_num_row(1, 7); // user has already contributed $db_config->add_num_row(1, 7); // show_sponsorings $db_config->add_num_row(0, 10); // call to is_project_initiator // fourth call, this time the user has more than one sponsorship $db_config->add_query(sprintf($db_q[0], $args[3]["proid"]), 11); $v = date_to_timestamp($args[3]["v_day"], $args[3]["v_month"], $args[3]["v_year"]); $b = date_to_timestamp($args[3]["b_day"], $args[3]["b_month"], $args[3]["b_year"]); $f = date_to_timestamp($args[3]["f_day"], $args[3]["f_month"], $args[3]["f_year"]); // query for checking the number of sponsoring the user has made $db_config->add_query(sprintf($db_q[5], $args[3]["proid"], $args[3]["user"]), 11); // query for the show_sponsorings call $db_config->add_query(sprintf($db_q[4], $args[3]["proid"]), 11); // instance for the monitor_mail call $db_config->ignore_all_errors(11); $db_config->ignore_all_errors(12); // instance created by the is_project_initiator $db_config->add_query(sprintf($db_q[3], $args[3]["proid"], $auth->auth["uname"]), 13); $rows[3]["COUNT(*)"] = 1; // status is 'P' (proposed) $db_config->add_record($rows[3], 11); // sponsoring_insert $db_config->add_record(false, 11); // show_sponsorings $db_config->add_num_row(2, 11); // user has already contributed $db_config->add_num_row(2, 11); // user has already contributed $db_config->add_num_row(1, 11); // show_sponsorings $db_config->add_num_row(0, 13); // call to is_project_initiator // ******************************************************************** // first call $db = new DB_SourceAgency(); $this->set_msg('test 1'); $this->capture_call('sponsoring_insert', 442, $args[0]); $this->_testFor_pattern("<a href=\"personal[.]php3[?]username="******"this[+]is[+]the[+]username\" class=" . "\"\">Personal Page<\\/a>"); // second call, status = A and is not project initiator $db = new DB_SourceAgency(); $this->set_msg('test 2'); $this->capture_call('sponsoring_insert', 141, $args[1]); $this->_testFor_pattern("<p><b>Congratulations<\\/b>. You are the " . "first sponsor. You can <a href=\"" . "configure_edit.php3[?]proid=proid_1\" " . "class=\"\">configure this project<\\/a>"); // third call: user has already contributed and wishes to make // a change to that contribution $db = new DB_SourceAgency(); $this->set_msg('test 3'); $this->capture_call('sponsoring_insert', 0, $args[2]); // fourth call: user has made too many contributions $db = new DB_SourceAgency(); $this->set_msg('test 4'); $this->capture_call('sponsoring_insert', 137, $args[3]); $this->_testFor_pattern("<p><b>Database Failure:<\\/b> it seems you " . "have more than one sponsorship! Please " . "advice the administrator and have the " . "database corrected."); // finally check that everything went smoothly with the DB $this->_check_db($db_config); }