/** * create one test case * * @param integer $case * @param integer $stopcase * @return mixed null after one stopcase, false after one branchcase, true after last case */ function create_case($case, $stopcase) { global $bcase, $date, $login, $proposal, $proposal2, $casetitle, $ngroup; $stop = 0; $branch = 0; $casedesc = $case." (stop: ".$stopcase.", branches:"; foreach ($bcase as $value) $casedesc .= " ".$value; $casedesc .= ")"; echo "Test case ".$casedesc."\n"; Login::$member = $login; $proposal = null; $proposal2 = null; $casetitle = ""; // create area $area = new Area; $area->ngroup = $ngroup->id; $area->name = "Test area case ".$casedesc; $area->create(); // create new proposal $proposal = new Proposal; $proposal->title = "Test ".$date." case ".$casedesc; $proposal->content = "Test content"; $proposal->reason = "Test reason"; $proposal->create("Test proponent ".$date." proposal case ".$casedesc, $area->id); $proponents = array(Login::$member); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "draft"; return; } $issue = $proposal->issue(); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $proposal->remove_proponent(Login::$member); cron(); $casetitle = "remove proponent from draft"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $proposal->remove_proponent(Login::$member); time_warp($issue, "1 week"); cron(); $casetitle = "remove proponent from draft and finally revoke proposal"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $proposal->remove_proponent(Login::$member); add_proponent($proposal, "px"); time_warp($issue, "1 week"); cron(); $casetitle = "remove proponent from draft, add new proponent"; return; } // add proponents for ( $i=2; $i<=REQUIRED_PROPONENTS; $i++ ) { add_proponent($proposal, "pi".$i); $proponents[] = Login::$member; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "draft with proponents"; return; } $proposal->submit(); if ($proposal->state=="submitted") { if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { foreach ($proponents as $proponent) { $proposal->remove_proponent($proponent); } cron(); $casetitle = "remove all proponents from submitted proposal"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { foreach ($proponents as $proponent) { $proposal->remove_proponent($proponent); } for ( $i=1; $i<=REQUIRED_PROPONENTS-1; $i++ ) { add_proponent($proposal, "pr".$i); } time_warp($issue, "1 week"); cron(); $casetitle = "remove all proponents from submitted proposal, add less than required new proponents and finally revoke proposal"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { foreach ($proponents as $proponent) { $proposal->remove_proponent($proponent); } for ( $i=1; $i<=REQUIRED_PROPONENTS; $i++ ) { add_proponent($proposal, "pr".$i); } time_warp($issue, "1 week"); cron(); $casetitle = "remove all proponents from submitted proposal, add sufficient new proponents"; return; } $required_supporters = $proposal->quorum_required(); ${'branch'.++$branch.'_array'} = array(0, $required_supporters-1, $required_supporters); $supporter_count = ${'branch'.$branch.'_array'}[$bcase[$branch]]; for ( $i=1; $i<=$supporter_count-REQUIRED_PROPONENTS; $i++ ) { add_supporter($proposal, "a".$i); } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "alternative proposal with $supporter_count supporters"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { time_warp($issue, CANCEL_NOT_ADMITTED_INTERVAL); cron(); $casetitle = "cancel long time not admitted proposal"; return; } // create alternative proposal $proposal2 = new Proposal; $proposal2->title = "Test ".$date." alternative proposal case ".$casedesc; $proposal2->content = "Test content"; $proposal2->reason = "Test reason"; $proposal2->issue = $proposal->issue; $proposal2->create("Test proponent ".$date." alternative proposal case ".$casedesc, $area->id); $proponents = array(Login::$member); if ($stopcase == ++$stop) { $casetitle = "alternative draft"; return; } // add proponents for ( $i=1; $i<=4; $i++ ) { add_proponent($proposal2, "qi".$i); $proponents[] = Login::$member; } if ($stopcase == ++$stop) { $casetitle = "alternative draft with proponents"; return; } $proposal2->submit(); if ($proposal2->state=="submitted" and $stopcase == ++$stop) { foreach ($proponents as $proponent) { $proposal2->remove_proponent($proponent); } cron(); $casetitle = "remove all proponents from submitted alternative proposal"; return; } $required_supporters = $proposal2->quorum_required(); ${'branch'.++$branch.'_array'} = array(0, $required_supporters-1, $required_supporters); $supporter_count2 = ${'branch'.$branch.'_array'}[$bcase[$branch]]; for ( $i=1; $i<=$supporter_count2; $i++ ) { add_supporter($proposal2, "a".$i); } if ($stopcase == ++$stop) { $casetitle = "alternative proposal with $supporter_count2 supporters"; return; } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { time_warp($issue, CANCEL_NOT_ADMITTED_INTERVAL); cron(); $casetitle = "cancel long time not admitted alternative proposal"; return; } if ($proposal->state=="admitted" or $proposal2->state=="admitted") { // create period $sql = "INSERT INTO period (debate, preparation, voting, counting, ballot_voting, ngroup) VALUES ( now() + interval '1 week', now() + interval '2 weeks', now() + interval '3 weeks', now() + interval '4 weeks', false, ".$ngroup->id." ) RETURNING id"; $result = DB::query($sql); $row = DB::fetch_row($result); $period = $row[0]; // assign issue to period $issue->period = $period; /** @var $issue Issue */ $issue->update(["period"]); // assigned, but not yet started cron(); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "assigned issue"; return; } // move on to state "debate" time_warp($issue, "1 week"); cron(); $votingmode_required = $issue->quorum_votingmode_required(); ${'branch'.++$branch.'_array'} = array(0, $votingmode_required-1, $votingmode_required); $votingmode_demanders_count = ${'branch'.$branch.'_array'}[$bcase[$branch]]; for ( $i=1; $i<=$votingmode_demanders_count; $i++ ) { add_votingmode_demander($proposal2, "a".$i); } if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "issue with $votingmode_demanders_count offline voting demanders"; return; } $proposal2->read(); ${'branch'.++$branch.'_array'} = array(false, true); if ( ${'branch'.$branch.'_array'}[$bcase[$branch]] and $proposal2->state!="cancelled" ) { // remove all proponents from alternative proposal during debate foreach ($proponents as $proponent) { $proposal2->remove_proponent($proponent); } } // move on to state "preparation" time_warp($issue, "1 week"); cron(); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "issue in voting preparation state"; return; } // move on to state "voting" time_warp($issue, "1 week"); cron(); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "issue in voting state"; return; } // random votes random_votes($issue); // move on to state "counting" and then "finished" time_warp($issue, "1 week"); cron(); if (no_branch_skip($branch, $bcase) and $stopcase == ++$stop) { $casetitle = "issue in finished state"; return; } // move on to cleared time_warp($issue, CLEAR_INTERVAL); cron(); $casetitle = "issue finished and cleared"; } else { $casetitle = "no admitted proposal"; } } else { $casetitle = "proposal not submitted"; } // continue with next case if branches are still available for ($i=1; $i<=$branch; $i++) { if (isset(${'branch'.$i.'_array'}[++$bcase[$i]])) { for ($j=1; $j<$i; $j++) $bcase[$j]=0; return true; } } // end of last case return "end"; }
cron(); // move to preparation time_warp($issue1, "2 weeks", true); time_warp($issue2, "2 weeks"); time_warp($issue3, "2 weeks"); cron(); // move to voting time_warp($issue1, "3 days", true); time_warp($issue2, "3 days"); time_warp($issue3, "3 days"); cron(); /** @noinspection PhpUndefinedVariableInspection */ random_votes($issue1); /** @noinspection PhpUndefinedVariableInspection */ random_votes($issue2); // move to counting time_warp($issue1, "2 weeks", true); time_warp($issue2, "2 weeks"); time_warp($issue3, "2 weeks"); cron(); // period in voting state $period = create_period($ngroup); list($issue1, $issue2, $issue3) = create_vote_proposals($period); cron(); // move to preparation