Fix tests

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2018-04-12 15:05:50 +02:00
parent b9528b1b39
commit 69648b4428
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
5 changed files with 41 additions and 19 deletions

View file

@ -39,6 +39,9 @@ class ChoiceRepository extends AbstractRepository
foreach ($choices as $choice) {
if ($choice instanceof DateChoice) {
if ($choice->getDate() === null) {
continue;
}
/** @var DateChoice $choice */
// We prepared the choices (joined by comas)
$prepared->execute([$poll_id, $choice->getDate()->getTimestamp(), $this->joinMoments($choice->getMoments())]);

View file

@ -253,22 +253,22 @@ class PollService
if (0 === count($votes)) {
// if there is no votes, calculates the number of slot
$slots = $this->allChoicesByPoll($poll);
$choices = $this->allChoicesByPoll($poll);
if ($poll->getFormat() === 'A') {
if (!$poll->isDate()) {
// poll format classic
foreach ($slots as $slot) {
foreach ($choices as $choice) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
} else {
// poll format date
$slots = $this->splitVotes($slots);
$choices = $this->splitChoices($choices);
foreach ($slots as $slot) {
foreach ($slot->moments as $_) {
foreach ($choices as $choice) {
foreach ($choice->moments as $_) {
$result['y'][] = 0;
$result['inb'][] = 0;
}
@ -313,18 +313,19 @@ class PollService
}
/**
* @param array $votes
* @param Vote[] $votes
* @return array
*/
public function splitVotes(array $votes)
{
$splitted = [];
foreach ($votes as $vote) {
/** @var Vote $vote */
$obj = new \stdClass();
$obj->id = $vote['id'];
$obj->name = $vote['name'];
$obj->uniqId = $vote['uniqId'];
$obj->choices = str_split($vote['choices']);
$obj->id = $vote->getId();
$obj->name = $vote->getName();
$obj->uniqId = $vote->getUniqId();
$obj->choices = str_split($vote->getChoices());
$splitted[] = $obj;
}
@ -332,6 +333,22 @@ class PollService
return $splitted;
}
function splitChoices($choices)
{
$splitted = [];
foreach ($choices as $choice) {
/** @var DateChoice $choice */
$obj = new \stdClass();
$obj->day = $choice->getName();
$obj->moments = $choice->getMoments();
$splitted[] = $obj;
}
return $splitted;
}
/**
* @return \DateTime The max timestamp allowed for expiry date
*/
@ -413,13 +430,15 @@ class PollService
/**
* @param $choices
* @param $poll_id
* @param $slots_hash
* @param $choices_hash
* @param $name
* @param string|bool $vote_id
* @throws AlreadyExistsException
* @throws ConcurrentEditionException
* @throws ConcurrentVoteException
* @throws DBALException
*/
private function checkVoteConstraints($choices, $poll_id, $slots_hash, $name, $vote_id = false)
private function checkVoteConstraints($choices, $poll_id, $choices_hash, $name, $vote_id = false)
{
// Check if vote already exists with the same name
if (false !== $vote_id) {
@ -437,7 +456,7 @@ class PollService
// Check that no-one voted in the meantime and it conflicts the maximum votes constraint
$this->checkMaxVotes($choices, $poll, $poll_id);
// Check if slots are still the same
$this->checkThatChoicesDidntChanged($poll, $slots_hash);
// Check if choices are still the same
$this->checkThatChoicesDidntChanged($poll, $choices_hash);
}
}

View file

@ -18,7 +18,7 @@
<td class="bg-info" headers="M{{ headersM[i] }} D{{ headersD[i] }} H{{ headersH[i] }}">
<ul class="list-unstyled choice">
{% if poll.ValueMax is null or best_choices['y'][0] > poll.ValueMax %}
{% if poll.ValueMax is null or poll.ValueMax is same as(0) or best_choices['y'][0] > poll.ValueMax %}
<li class="yes">
<input type="radio" id="y-choice-{{ i }}" name="choices[{{ i }}]"
value="2"/>

View file

@ -106,7 +106,7 @@
poll.editable == constant('Framadate\Editable::EDITABLE_BY_ALL')
or admin
or (poll.editable == constant('Framadate\Editable::EDITABLE_BY_OWN') and editedVoteUniqueId == vote.uniqId)
)
) and
poll.choices > 4 %}
<span class="edit-username-left">
<a href="{% if admin %}{{ poll_url(poll.admin_id, vote.uniqId, true) }}{% else %}{{ poll_url(poll.id, vote.uniqId) }}{% endif %}" class="btn btn-default btn-sm" title="{{__('Poll results', 'Edit the line: %s', vote.name)|raw}}">
@ -185,7 +185,7 @@
{% for id, choice in poll.choices %}
<td class="bg-info" headers="C{{ id }}">
<ul class="list-unstyled choice">
{% if poll.ValueMax is null or best_choices.y | first < poll.ValueMax %}
{% if poll.ValueMax is null or poll.ValueMax is same as(0) or best_choices.y | first < poll.ValueMax %}
<li class="yes">
<input type="radio" id="y-choice-{{ id }}" name="choices[{{ id }}]" value="2" />
<label class="btn btn-default btn-xs" for="y-choice-{{ id }}" title="{{__('Poll results', 'Vote yes for')|raw}} {{choice.name | raw}}">

View file

@ -5,7 +5,7 @@
{% endblock %}
{% block main %}
{% if not accessGranted and not resultPubliclyVisible %}
{% include 'part/password_request.twig' with {active: poll.active} %}