function testReferees_insert()
 {
     global $t, $bx, $db;
     $db_config = new mock_db_configure(2);
     $args = $this->_generate_records(array('proid', 'user'), 1);
     $q = array(0 => $this->queries['show_referees'], 1 => $this->queries['referees_insert']);
     $db_config->add_query(sprintf($q[1], $args[0]['proid'], $args[0]['user']), 0);
     // for the show_referees call
     $db_config->add_query(sprintf($q[0], $args[0]['proid']), 0);
     $db_config->add_num_row(0, 0);
     $db_config->add_num_row(0, 0);
     // this is the database created by the monitor_mail call -- ignore
     // all errors
     $db_config->ignore_all_errors(1);
     // one and only test ....
     $bx = $this->_create_default_box();
     $db = new DB_SourceAgency();
     capture_reset_and_start();
     call_user_func_array('referees_insert', $args[0]);
     $this->set_text(capture_stop_and_get());
     $this->_testFor_String_length(72);
     $this->_check_db($db_config);
 }
 function testMilestone_not_possible()
 {
     global $t;
     $db_config = new mock_db_configure(1);
     // top_bar() uses a database
     $db_config->ignore_all_errors(0);
     capture_reset_and_start();
     $this->assertEquals(0, milestone_not_possible("proid", "page"), "rv");
     $this->set_text(capture_stop_and_get());
     $ps = array(0 => $t->translate('Milestone not possible'), 1 => $t->translate('Your milestones already reach 100%. ' . 'You should modify your existing ' . 'milestones before creating a new one.'));
     $this->_testFor_patterns($ps, 2);
     $this->_testFor_string_length(3245);
     $this->_check_db($db_config);
 }
 function testConsultants_insert()
 {
     global $db, $bx, $t;
     $db_config = new mock_db_configure(2);
     $db_q = array(0 => "INSERT consultants SET proid='%s'," . "consultant='%s',status='P'");
     $dat = $this->_generate_records(array("proid", "user"), 2);
     $db_config->add_query(sprintf($db_q[0], $dat[0]["proid"], $dat[0]["user"]), 0);
     // show_consultants also uses the global db and show_consultants
     // is called by consultants_insert.
     $db_config->ignore_all_errors(0);
     // instance 1 is created by monitor_mail(...) which is also called
     // by consultants_insert
     $db_config->ignore_all_errors(1);
     $db = new DB_SourceAgency();
     $bx = $this->_create_default_box();
     $this->capture_call('consultants_insert', 1494, &$dat[0]);
     // the basics for show_consultants(...), assume that the rest
     // is also present
     $this->_checkFor_a_box('Consultants');
     $this->_checkFor_columns(4);
     $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);
 }