You are here

public function VoteTokenTest::testVoteTokens in Voting API 8.3

Tests token replacements.

File

modules/votingapi_tokens/tests/src/Kernel/VoteTokenTest.php, line 75

Class

VoteTokenTest
Tests the Voting API basics.

Namespace

Drupal\Tests\votingapi_tokens\Kernel

Code

public function testVoteTokens() {
  $vote_type = 'vote';

  // First check for non-existing votes.
  $tokens = [
    'vote_count:' . $vote_type => NULL,
    'vote_average:' . $vote_type => NULL,
    'best_vote:' . $vote_type => NULL,
    'worst_vote:' . $vote_type => NULL,
  ];
  $this
    ->assertTokens('votingapi_node_token', [
    'node' => $this->node,
  ], $tokens);
  $vote = Vote::create([
    'type' => $vote_type,
    'entity_id' => $this->node
      ->id(),
    'entity_type' => 'node',
    'user_id' => 0,
    'value' => 1,
  ]);
  $vote
    ->save();
  $tokens = [
    'vote_count:' . $vote_type => '1',
    'vote_average:' . $vote_type => '1',
    'best_vote:' . $vote_type => '1',
    'worst_vote:' . $vote_type => '1',
  ];
  $this
    ->assertTokens('votingapi_node_token', [
    'node' => $this->node,
  ], $tokens);
  $vote = Vote::create([
    'type' => $vote_type,
    'entity_id' => $this->node
      ->id(),
    'entity_type' => 'node',
    'user_id' => 0,
    'value' => 5,
  ]);
  $vote
    ->save();
  $tokens = [
    'vote_count:' . $vote_type => '2',
    'vote_average:' . $vote_type => '3',
    'best_vote:' . $vote_type => '5',
    'worst_vote:' . $vote_type => '1',
  ];
  $this
    ->assertTokens('votingapi_node_token', [
    'node' => $this->node,
  ], $tokens);
}