PollVoteStorageTest.php in Poll 8
File
tests/src/Kernel/PollVoteStorageTest.php
View source
<?php
namespace Drupal\Tests\poll\Kernel;
use Drupal\Tests\user\Traits\UserCreationTrait;
class PollVoteStorageTest extends PollKernelTestBase {
use UserCreationTrait;
public static $modules = [
'system',
];
public function testGetUserVote() {
$poll = $this
->createPoll();
$choice_id = $poll
->get('choice')
->first()
->getValue()['target_id'];
$this
->saveVote($poll, $choice_id);
$poll_vote_storage = $this->container
->get('poll_vote.storage');
$this
->assertEquals($choice_id, $poll_vote_storage
->getUserVote($poll)['chid']);
$second_poll = $this
->createPoll();
$another_choice_id = $second_poll
->get('choice')
->first()
->getValue()['target_id'];
$this
->saveVote($second_poll, $another_choice_id);
$this
->assertEquals($another_choice_id, $poll_vote_storage
->getUserVote($second_poll)['chid']);
$not_anonymous_poll = $this
->createPoll();
$not_anonymous_poll
->setAnonymousVoteAllow(FALSE);
$poll
->save();
$this
->assertFalse($poll_vote_storage
->getUserVote($not_anonymous_poll));
$this
->setUpCurrentUser([
'uid' => 2,
]);
$choice_id = $poll
->get('choice')
->get(1)->target_id;
$this
->saveVote($poll, $choice_id);
$this
->assertEquals($choice_id, $poll_vote_storage
->getUserVote($poll)['chid']);
$connection = $this->container
->get('database');
$connection
->delete('poll_vote')
->execute();
$this
->assertEquals($choice_id, $poll_vote_storage
->getUserVote($poll)['chid']);
}
}