Exemplo n.º 1
0
 function &capture_call($func_name, $exp_length, $args = array(), $debug = FALSE, $check_for_warning = TRUE)
 {
     if ($debug) {
         capture_stop();
         capture_reset_text();
     } else {
         capture_reset_and_start();
     }
     $rval = call_user_func_array($func_name, &$args);
     $this->set_text(capture_stop_and_get());
     capture_reset_text();
     $this->_testFor_string_length($exp_length);
     // this is a paranoia check: make sure that no PHP warnings were
     // generated, if so, then print a warning and the entire text
     if ($check_for_warning && (preg_match('/[<]b[>]Warning[<]\\/b[>]:/', $this->get_text()) || preg_match('/[<]b[>]Fatal error[<]\\/b[>]:/', $this->test_text))) {
         print "<b>CaptureCall: Warning: captured text contained a " . "warning message?</b>\n";
         $this->print_text_as_html();
     }
     return $rval;
 }
Exemplo n.º 2
0
 function _test_html_function($name, &$args, $exp_length)
 {
     $test_for_func = '_testFor_' . $name;
     $print_func = ereg_replace('^html_', 'htmlp_', $name);
     $no_chance = 0;
     if (!function_exists($name) && ($no_chance = 1)) {
         $this->assert(false, "Function not defined '{$name}' " . "(_test_html_function)");
     }
     if (!function_exists($print_func) && ($no_chance = 1)) {
         $this->assert(false, "Print function not defined '{$print_func}' " . "(_test_html_function)");
     }
     if (!method_exists($this, $test_for_func) && ($no_chance = 1)) {
         $this->assert(false, "Test for function not defined " . "'{$test_for_func}' on this object " . "(_test_html_function)");
     }
     // no_chance flag is set if one or more of the required functions
     // are not defined, then there is no point in continuing
     if ($no_chance) {
         return;
     }
     for ($idx = 0; $idx < count($args); $idx++) {
         // first test the function that returns a value, i.e. html_XXXX
         $this->set_text(call_user_func_array($name, $args[$idx]));
         $this->set_msg("test {$idx}");
         // call the _testFor_html_XXXX method of the class which
         // generates an expected value for the htmlp_XXXX function call
         // This method is normally defined in the UnitTest class.
         $expect = $this->_call_method($test_for_func, $args[$idx]);
         $this->assertEquals($expect, $this->get_text(), "assert 1: test {$idx}");
         // call the print variation of the function assuming that it's
         // called htmlp_XXXX instead of html_XXXX
         capture_reset_and_start();
         call_user_func_array($print_func, $args[$idx]);
         $this->set_text(capture_stop_and_get());
         $this->_testFor_string_length($exp_length[$idx]);
         $this->assertEquals($expect, $this->get_text(), "assert 2: test {$idx}");
     }
 }
 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 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);
 }
Exemplo n.º 5
0
 function testBox_strip()
 {
     $title = "thsi is teh title";
     capture_reset_and_start();
     $this->box->box_strip($title);
     $this->set_text(capture_stop_and_get());
     $this->_testFor_string_length(479);
     $this->_testFor_box_begin();
     $this->_testFor_box_title($title);
     $this->_testFor_box_end();
 }
 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 testDecisions_step5_votes()
 {
     global $db, $queries;
     $fname = 'decisions_step5_votes';
     $qs = array(0 => $queries['decisions_step5_votes'], 1 => $queries['project_budget']);
     $db_config = new mock_db_configure(8);
     $args = $this->_generate_records(array('proid', 'milestone_number', 'count', 'decision'), 4);
     for ($idx = 0, $jdx = 1; $idx < count($args); $idx++, $jdx += 2) {
         $db_config->add_query(sprintf($qs[0], $args[$idx]['proid'], $args[$idx]['proid'], $args[$idx]['milestone_number'], $args[$idx]['count'], $args[$idx]['decision']), $jdx);
     }
     // test one: num rows == 0
     $db_config->add_num_row(0, 1);
     $db = new DB_SourceAgency();
     $this->assertEquals(0, $this->capture_call($fname, 0, $args[0]));
     // test two: project budget == 0, division by zero warning
     $db_config->add_num_row(1, 3);
     $db_config->add_record(array('sum_step5' => -1), 3);
     $db_config->add_query(sprintf($qs[1], $args[1]['proid']), 2);
     $db_config->add_record(array('SUM(budget)' => 0), 2);
     $db = new DB_SourceAgency();
     capture_reset_and_start();
     $this->assertEquals(0, call_user_func_array($fname, $args[1]));
     $this->set_text(capture_stop_and_get());
     $this->_testFor_string_length(0);
     $this->assertRegexp('/Division by zero/', $GLOBALS['err_msg']);
     // test three: sum_step5 == 0
     $db_config->add_num_row(1, 5);
     $db_config->add_record(array('sum_step5' => 0), 5);
     $db_config->add_query(sprintf($qs[1], $args[2]['proid']), 4);
     $db_config->add_record(array('SUM(budget)' => 10), 4);
     $db = new DB_SourceAgency();
     $this->assertEquals(0, $this->capture_call($fname, 0, $args[2]));
     // test four: all clear
     $db_config->add_num_row(1, 7);
     $db_config->add_record(array('sum_step5' => 10), 7);
     $db_config->add_query(sprintf($qs[1], $args[3]['proid']), 6);
     $db_config->add_record(array('SUM(budget)' => 10), 6);
     $db = new DB_SourceAgency();
     $this->assertEquals(100, $this->capture_call($fname, 0, $args[3]));
     $this->_check_db($db_config);
 }
 function testMonitor_form()
 {
     global $importance, $sess, $bx, $t;
     $importance = "low";
     $proid = "proid_0";
     $bx = $this->_create_default_box();
     capture_reset_and_start();
     monitor_form($proid);
     $this->set_text(capture_stop_and_get());
     $this->_testFor_string_length(1897 + strlen($sess->self_url()));
     $this->_checkFor_a_box('Monitor this project');
     $this->_checkFor_a_form('PHP_SELF', array('proid' => $proid));
     $this->_checkFor_columns(2);
     $this->_checkFor_column_titles(array('Importance'));
     $this->_checkFor_submit_preview_buttons();
 }
 function testShow_participants_rating()
 {
     global $bx, $db, $queries, $sess;
     $fname = 'show_participants_rating';
     $qs = array(0 => $queries[$fname]);
     $args = $this->_generate_records(array('proid', 'part_type'), 10);
     $db_config = new mock_db_configure(4);
     // test one: unknown participant_type, Warning message
     $args[0]['part_type'] = 'UNKNOWN';
     $db_config->add_query(sprintf($qs[0], $args[0]['part_type'], '', $args[0]['proid']), 0);
     $db_config->add_record(false, 0);
     $bx = $this->_create_default_box();
     $db = new DB_SourceAgency();
     capture_reset_and_start();
     call_user_func_array($fname, $args[0]);
     $this->set_text(capture_stop_and_get());
     $this->_checkFor_a_box($args[0]['part_type']);
     $this->_testFor_string_length(674);
     $str = '/Undefined variable:  table/';
     $this->assertRegexp($str, $GLOBALS['err_msg']);
     // test two: participant_type = 'developer'
     $args[1]['part_type'] = 'developer';
     $db_config->add_query(sprintf($qs[0], $args[1]['part_type'], 'developing', $args[1]['proid']), 1);
     $db_config->add_record(false, 1);
     $bx = $this->_create_default_box();
     $db = new DB_SourceAgency();
     $this->capture_call($fname, 676, $args[1]);
     $this->_checkFor_a_box($args[1]['part_type']);
     // test three: participant_type = 'referee'
     $args[2]['part_type'] = 'referee';
     $db_config->add_query(sprintf($qs[0], $args[2]['part_type'], 'referees', $args[2]['proid']), 2);
     $db_config->add_record(false, 2);
     $bx = $this->_create_default_box();
     $db = new DB_SourceAgency();
     $this->capture_call($fname, 674, $args[2]);
     $this->_checkFor_a_box($args[2]['part_type']);
     // test four: participant_type = 'sponsor'
     $args[3]['part_type'] = 'sponsor';
     $db_config->add_query(sprintf($qs[0], $args[3]['part_type'], 'sponsoring', $args[3]['proid']), 3);
     $db_config->add_record(false, 3);
     $bx = $this->_create_default_box();
     $db = new DB_SourceAgency();
     $this->capture_call($fname, 674, $args[3]);
     $this->_checkFor_a_box($args[3]['part_type']);
     $this->_check_db($db_config);
 }
 function testPersonal_monitored_projects()
 {
     global $bx;
     $db_q = "SELECT * FROM monitor,description WHERE " . "monitor.proid=description.proid AND monitor" . ".username='******' ORDER BY creation DESC";
     $db_config = new mock_db_configure(3);
     $db_config->add_num_row(0, 0);
     $db_config->add_num_row(1, 1);
     $db_config->add_num_row(2, 2);
     $db_config->add_query(sprintf($db_q, "fubar"), 0);
     $db_config->add_query(sprintf($db_q, "snafu"), 1);
     $db_config->add_query(sprintf($db_q, "fritz"), 2);
     // this is for the snafu query
     $row1 = $this->_generate_array(array('status', 'proid', 'project_title'), 1);
     $db_config->add_record($row1, 1);
     $db_config->add_record(false, 1);
     // this is for the fritz query
     $row2 = $this->_generate_array(array('status', 'proid', 'project_title'), 2);
     $db_config->add_record($row2, 2);
     $row3 = $this->_generate_array(array('status', 'proid', 'project_title'), 3);
     $db_config->add_record($row3, 2);
     $db_config->add_record(false, 2);
     // test one
     $bx = $this->_create_default_box();
     capture_reset_and_start();
     // here next_record will not be called
     personal_monitored_projects("fubar");
     $this->set_text(capture_stop_and_get());
     $this->set_msg('test 1');
     $this->_testFor_string_length(696);
     $this->_testFor_pattern("Monitored Projects");
     // title
     $this->_testFor_pattern("No monitored projects\n");
     // test two
     $bx = $this->_create_default_box();
     capture_reset_and_start();
     // here next_record should be called once --> num_row == 1
     personal_monitored_projects("snafu");
     $this->set_text(capture_stop_and_get());
     $this->set_msg('test 2');
     $this->_testFor_string_length(776);
     $this->_testFor_pattern("Monitored Projects");
     // title
     $this->_testFor_project_link($row1['proid'], $row1['project_title'], $row1['status']);
     // test three
     $bx = $this->_create_default_box();
     capture_reset_and_start();
     // here next_record should be called once --> num_row == 1
     personal_monitored_projects("fritz");
     $this->set_text(capture_stop_and_get());
     $this->set_msg('test 3');
     $this->_testFor_string_length(878);
     $this->_testFor_pattern("Monitored Projects");
     // title
     $this->_testFor_project_link($row2['proid'], $row2['project_title'], $row2['status']);
     $this->_testFor_project_link($row3['proid'], $row3['project_title'], $row3['status']);
     // if using a database, then ensure that it didn't fail
     $this->_check_db($db_config);
 }
Exemplo n.º 11
0
 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);
 }