Example #1
0
/**
 * 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";
}
/**
 * create one test case
 *
 * @param integer $case
 * @param integer $stopcase
 * @return boolean true after last case
 */
function create_case($case, $stopcase) {
	global $date, $login, $ngroup;

	$stop = 0;
	$branch = 0;
	static $branch1 = 0;
	$casedesc = $case." (".$stopcase."/".$branch1.")";
	echo "Test case ".$casedesc."\n";

	Login::$member = $login;

	// create period
	if ($stopcase == ++$stop) {
		// period without ballot voting
		$sql = "INSERT INTO period (debate, preparation, voting, ballot_assignment, ballot_preparation, counting, ballot_voting, ngroup)
		VALUES (
			now(),
			now() + interval '1 week',
			now() + interval '2 weeks',
			NULL,
			NULL,
			now() + interval '4 weeks',
			false,
			".$ngroup->id."
		)";
		DB::query($sql);
		return;
	} else {
		// period with ballot voting
		$sql = "INSERT INTO period (debate, preparation, voting, ballot_assignment, ballot_preparation, counting, ballot_voting, ngroup, postage)
		VALUES (
			now(),
			now() + interval '1 week',
			now() + interval '2 weeks',
			now() + interval '1 week',
			now() + interval '3 weeks',
			now() + interval '4 weeks',
			true,
			".$ngroup->id.",
			true
		) RETURNING id";
		$result = DB::query($sql);
		$row = DB::fetch_row($result);
		$period = new Period($row[0]);
	}

	${'branch'.++$branch.'_array'} = array(0, 5, 15);
	$ballot_count = ${'branch'.$branch.'_array'}[${'branch'.$branch}];

	for ( $i=1; $i<=$ballot_count; $i++ ) {
		// create a ballot
		$ballot = new Ballot;
		$ballot->ngroup = $ngroup->id;
		$ballot->name = "Test ballot ".$casedesc;
		$ballot->agents = "Test agents";
		$ballot->period = $period->id;
		$ballot->opening = "8:00";
		$ballot->create();
		// add participants
		for ( $j=1; $j<=$i-1; $j++ ) {
			add_participant($period, $ballot, $case, "a".$ballot_count."i".$i."j".$j);
		}
	}

	// add postal voters
	for ( $j=1; $j<=10; $j++ ) {
		add_participant($period, true, $case, "a".$ballot_count."i0j".$j);
	}

	if ($stopcase == ++$stop) return;

	// approve ballots with 10 or more participants
	$sql = "SELECT * FROM ballot WHERE period=".intval($period->id);
	$result = DB::query($sql);
	while ( $ballot = DB::fetch_object($result, "Ballot") ) {
		if ($ballot->voters < 10) continue;
		$ballot->approved = true;
		$ballot->update(["approved"]);
	}

	if ($stopcase == ++$stop) return;

	// add further participants without assigning them to ballots
	for ($i=1; $i<=100; $i++) {
		add_participant($period, null, $case, "t".$date."c".$case."i".$i);
	}

	// move to phase "ballot_assignment"
	time_warp($period, "1 week");
	cron();

	if ($stopcase == ++$stop) return;

	// move to phase "ballot_preparation"
	time_warp($period, "2 weeks");
	cron();

	// continue with next case if branches are still available
	for ($i=1; $i<=$branch; $i++) {
		if (isset(${'branch'.$i.'_array'}[++${'branch'.$i}])) {
			for ($j=1; $j<$i; $j++) ${'branch'.$j}=0;
			return true;
		}
	}

	// end of last case
	return "end";
}
Example #3
0
/**
 *
 * @param integer $period
 * @return array
 */
function create_vote_proposals($period) {
	global $area, $lorem_ipsum;


	// single proposal
	login(1);
	$proposal1 = new Proposal;
	$proposal1->title = "einzelner Beispielantrag";
	$proposal1->content = $lorem_ipsum;
	$proposal1->reason = $lorem_ipsum;
	$proposal1->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal1->add_proponent(Login::$member->username, true);
	}

	$issue1 = $proposal1->issue();
	// assign issue to period
	$issue1->period = $period;
	/** @var $issue Issue */
	$issue1->update(['period']);

	time_warp($issue1);
	$proposal1->submit();
	time_warp($issue1);
	$proposal1->read();
	for ( $i=6; $i<=23; $i++ ) {
		login($i);
		$proposal1->add_support();
	}
	time_warp($issue1);


	// 4 proposals
	login(1);
	$proposal2 = new Proposal;
	$proposal2->title = "Beispielantrag";
	$proposal2->content = $lorem_ipsum;
	$proposal2->reason = $lorem_ipsum;
	$proposal2->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal2->add_proponent(Login::$member->username, true);
	}

	$issue2 = $proposal2->issue();
	// assign issue to period
	$issue2->period = $period;
	/** @var $issue Issue */
	$issue2->update(['period']);

	login(1);
	$proposal3 = new Proposal;
	$proposal3->title = "Alternativantrag";
	$proposal3->content = $lorem_ipsum;
	$proposal3->reason = $lorem_ipsum;
	$proposal3->issue = $proposal2->issue;
	$proposal3->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal3->add_proponent(Login::$member->username, true);
	}

	login(1);
	$proposal4 = new Proposal;
	$proposal4->title = "nicht zugelassener Alternativantrag";
	$proposal4->content = $lorem_ipsum;
	$proposal4->reason = $lorem_ipsum;
	$proposal4->issue = $proposal2->issue;
	$proposal4->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal4->add_proponent(Login::$member->username, true);
	}

	login(1);
	$proposal5 = new Proposal;
	$proposal5->title = "zurückgezogener Antrag";
	$proposal5->content = $lorem_ipsum;
	$proposal5->reason = $lorem_ipsum;
	$proposal5->issue = $proposal2->issue;
	$proposal5->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal5->add_proponent(Login::$member->username, true);
	}

	time_warp($issue2);

	login(1);
	$proposal2->submit();
	$proposal3->submit();
	$proposal4->submit();
	$proposal5->submit();

	time_warp($issue2);

	$proposal2->read();
	for ( $i=6; $i<=24; $i++ ) {
		login($i);
		$proposal2->add_support();
	}

	$proposal3->read();
	for ( $i=6; $i<=15; $i++ ) {
		login($i);
		$proposal3->add_support();
	}

	$proposal4->read();
	for ( $i=6; $i<=8; $i++ ) {
		login($i);
		$proposal4->add_support();
	}

	$proposal5->read();
	for ( $i=6; $i<=15; $i++ ) {
		login($i);
		$proposal5->add_support();
	}
	// revoke by removing all proponents
	for ( $i=1; $i<=5; $i++ ) {
		login($i);
		$proposal5->remove_proponent(Login::$member);
	}

	time_warp($issue2);


	// single proposal for offline voting
	login(1);
	$proposal6 = new Proposal;
	$proposal6->title = "einzelner Beispielantrag";
	$proposal6->content = $lorem_ipsum;
	$proposal6->reason = $lorem_ipsum;
	$proposal6->create(Login::$member->username, $area->id);
	for ( $i=2; $i<=5; $i++ ) {
		login($i);
		$proposal6->add_proponent(Login::$member->username, true);
	}

	$issue3 = $proposal6->issue();
	// assign issue to period
	$issue3->period = $period;
	/** @var $issue Issue */
	$issue3->update(['period']);

	time_warp($issue3);
	$proposal6->submit();
	time_warp($issue3);
	$proposal6->read();
	for ( $i=6; $i<=23; $i++ ) {
		login($i);
		$proposal6->add_support();
	}

	for ( $i=1; $i<=23; $i++ ) {
		login($i);
		$issue3->demand_votingmode();
	}

	time_warp($issue3);


	return [$issue1, $issue2, $issue3];
}