diff --git a/poll.tokens.inc b/poll.tokens.inc
index 0c31e91..ae978e7 100644
--- a/poll.tokens.inc
+++ b/poll.tokens.inc
@@ -39,28 +39,24 @@ function poll_token_info() {
  * Implements hook_tokens().
  */
 function poll_tokens($type, $tokens, array $data = array(), array $options = array()) {
-  $sanitize = !empty($options['sanitize']);
-  if (isset($options['langcode'])) {
-    $url_options['language'] = \Drupal::languageManager()->getLanguage($options['langcode']);
-    $langcode = $options['langcode'];
-  }
-  else {
-    $langcode = NULL;
-  }
-
   $replacements = array();
 
-  if ($type == 'node' && !empty($data['node']) && $data['node']->type == 'poll') {
-    $node = $data['node'];
+  if ($type == 'node' && !empty($data['node']) && $data['node']->getEntityTypeId() == 'poll') {
+    /** @var \Drupal\poll\Entity\Poll $poll */
+    $poll = $data['node'];
 
     $total_votes = 0;
     $highest_votes = 0;
-    foreach ($node->choice as $choice) {
-      if ($choice['chvotes'] > $highest_votes) {
-        $winner = $choice;
-        $highest_votes = $choice['chvotes'];
+    foreach ($poll->votes as $vote) {
+      $total_votes += $vote;
+    }
+
+    $options = $poll->getOptions();
+    foreach ($poll->votes as $pid => $vote) {
+      if ($vote > $highest_votes) {
+        $winner = $options[$pid];
+        $highest_votes = $vote;
       }
-      $total_votes = $total_votes + $choice['chvotes'];
     }
     foreach ($tokens as $name => $original) {
       switch ($name) {
@@ -70,7 +66,7 @@ function poll_tokens($type, $tokens, array $data = array(), array $options = arr
 
         case 'poll-winner':
           if (isset($winner)) {
-            $replacements[$original] = $sanitize ? filter_xss($winner['chtext']) : $winner['chtext'];
+            $replacements[$original] = $winner;
           }
           else {
             $replacements[$original] = '';
@@ -79,7 +75,7 @@ function poll_tokens($type, $tokens, array $data = array(), array $options = arr
 
         case 'poll-winner-votes':
           if (isset($winner)) {
-            $replacements[$original] = $winner['chvotes'];
+            $replacements[$original] = $highest_votes;
           }
           else {
             $replacements[$original] = '';
@@ -88,7 +84,7 @@ function poll_tokens($type, $tokens, array $data = array(), array $options = arr
 
         case 'poll-winner-percent':
           if (isset($winner)) {
-            $percent = ($winner['chvotes'] / $total_votes) * 100;
+            $percent = ($highest_votes / $total_votes) * 100;
             $replacements[$original] = number_format($percent, 0);
           }
           else {
@@ -97,7 +93,7 @@ function poll_tokens($type, $tokens, array $data = array(), array $options = arr
           break;
 
         case 'poll-duration':
-          $replacements[$original] = format_interval($node->runtime, 1, $langcode);
+          $replacements[$original] = \Drupal::service('date.formatter')->formatInterval($poll->getRuntime());
           break;
       }
     }
diff --git a/src/Tests/PollTestBase.php b/src/Tests/PollTestBase.php
index f4dff33..049560b 100644
--- a/src/Tests/PollTestBase.php
+++ b/src/Tests/PollTestBase.php
@@ -68,8 +68,8 @@ abstract class PollTestBase extends WebTestBase {
     list($edit, $index) = $this->pollGenerateEdit($question, $choices);
 
     // Re-submit the form until all choices are filled in.
-    if (count($choices) > 1) {
-      while ($index < count($choices)) {
+    if (count($choices) > 0) {
+      for ($delta = 0; $delta <= count($choices); $delta++) {
         $this->drupalPostForm(NULL, $edit, t('Add another item'));
         list($edit, $index) = $this->pollGenerateEdit($question, $choices, $index);
       }
@@ -84,7 +84,9 @@ abstract class PollTestBase extends WebTestBase {
     $this->drupalPostForm(NULL, $edit, t('Save'));
 
     // Load the first node returned from the database.
-    $polls = entity_load_multiple_by_properties('poll', array('question' => $question));
+    $polls = \Drupal::entityManager()
+      ->getStorage('poll')
+      ->loadByProperties(array('question' => $question));
     $poll = reset($polls);
     $this->assertText(t('The poll @question has been added.', array('@question' => $question)), 'Poll has been created.');
     $this->assertTrue($poll->id, 'Poll has been found in the database.');
diff --git a/src/Tests/PollTokenReplaceTest.php b/src/Tests/PollTokenReplaceTest.php
index 14002a7..8af83f6 100644
--- a/src/Tests/PollTokenReplaceTest.php
+++ b/src/Tests/PollTokenReplaceTest.php
@@ -6,6 +6,9 @@
  */
 
 namespace Drupal\poll\Tests;
+use Drupal\Component\Utility\Xss;
+use Drupal\Core\Utility\Token;
+use Drupal\poll\Entity\Poll;
 
 /**
  * Tests poll token replacements in strings.
@@ -18,69 +21,72 @@ class PollTokenReplaceTest extends PollTestBase {
    * Creates a poll, then tests the tokens generated from it.
    */
   function testPollTokenReplacement() {
-//    $language_interface = language(LANGUAGE_TYPE_INTERFACE);
+    $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
 
     // Craete a poll with three choices.
     $poll = $this->pollCreate(3);
+    $poll->save();
     $poll_nid = $poll->id();
 
     // Create four users and have each of them vote.
-//    $vote_user1 = $this->drupalCreateUser(array('vote on polls', 'access content'));
-//    $this->drupalLogin($vote_user1);
-//    $edit = array(
-//      'choice' => '1',
-//    );
-//    $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
-//    $this->drupalLogout();
+    $vote_user1 = $this->drupalCreateUser(array('access polls', 'access content'));
+    $this->drupalLogin($vote_user1);
+    $edit = array(
+      'choice' => 1 + 7,
+    );
+    $this->drupalPostForm('poll/' . $poll_nid, $edit, t('Vote'));
+    $this->drupalLogout();
 
-//    $vote_user2 = $this->drupalCreateUser(array('vote on polls', 'access content'));
-//    $this->drupalLogin($vote_user2);
-//    $edit = array(
-//      'choice' => '1',
-//    );
-//    $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
-//    $this->drupalLogout();
+    $vote_user2 = $this->drupalCreateUser(array('access polls', 'access content'));
+    $this->drupalLogin($vote_user2);
+    $edit = array(
+      'choice' => 1 + 7,
+    );
+    $this->drupalPostForm('poll/' . $poll_nid, $edit, t('Vote'));
+    $this->drupalLogout();
 
-//    $vote_user3 = $this->drupalCreateUser(array('vote on polls', 'access content'));
-//    $this->drupalLogin($vote_user3);
-//    $edit = array(
-//      'choice' => '2',
-//    );
-//    $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
-//    $this->drupalLogout();
+    $vote_user3 = $this->drupalCreateUser(array('access polls', 'access content'));
+    $this->drupalLogin($vote_user3);
+    $edit = array(
+      'choice' => 2 + 7,
+    );
+    $this->drupalPostForm('poll/' . $poll_nid, $edit, t('Vote'));
+    $this->drupalLogout();
 
-//    $vote_user4 = $this->drupalCreateUser(array('vote on polls', 'access content'));
-//    $this->drupalLogin($vote_user4);
-//    $edit = array(
-//      'choice' => '3',
-//    );
-//    $this->drupalPost('node/' . $poll_nid, $edit, t('Vote'));
-//    $this->drupalLogout();
-//
-//    $poll = node_load($poll_nid, TRUE);
+    $vote_user4 = $this->drupalCreateUser(array('access polls', 'access content'));
+    $this->drupalLogin($vote_user4);
+    $edit = array(
+      'choice' => 3 + 7,
+    );
+    $this->drupalPostForm('poll/' . $poll_nid, $edit, t('Vote'));
+    $this->drupalLogout();
+
+    $poll = Poll::load($poll_nid);
 
     // Generate and test sanitized tokens.
-//    $tests = array();
-//    $tests['[node:poll-votes]'] = 4;
-//    $tests['[node:poll-winner]'] = filter_xss($poll->choice[1]['chtext']);
-//    $tests['[node:poll-winner-votes]'] = 2;
-//    $tests['[node:poll-winner-percent]'] = 50;
-//    $tests['[node:poll-duration]'] = format_interval($poll->runtime, 1, $language_interface->langcode);
+    $tests = array();
+    $tests['[node:poll-votes]'] = 4;
+    $tests['[node:poll-winner]'] = Xss::filter($poll->getOptions()[1 + 7]);
+    $tests['[node:poll-winner-votes]'] = 2;
+    $tests['[node:poll-winner-percent]'] = 50;
+    $tests['[node:poll-duration]'] = \Drupal::service('date.formatter')->formatInterval($poll->getRuntime());
 
     // Test to make sure that we generated something for each token.
-//    $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
+    $this->assertFalse(in_array(0, array_map('strlen', $tests)), 'No empty tokens generated.');
 
-//    foreach ($tests as $input => $expected) {
-//      $output = token_replace($input, array('node' => $poll), array('langcode' => $language_interface->langcode));
-//      $this->assertEqual($output, $expected, format_string('Sanitized poll token %token replaced.', array('%token' => $input)));
-//    }
+    /** @var Token token */
+    $token = \Drupal::service('token');
+    foreach ($tests as $input => $expected) {
+      $output = $token->replace($input, array('node' => $poll), array('langcode' => $langcode));
+      $this->assertEqual($output, $expected, format_string('Sanitized poll token %token replaced.', array('%token' => $input)));
+    }
 
     // Generate and test unsanitized tokens.
-//    $tests['[node:poll-winner]'] = $poll->choice[1]['chtext'];
+    $tests['[node:poll-winner]'] = $poll->getOptions()[1 + 7];
 
-//    foreach ($tests as $input => $expected) {
-//      $output = token_replace($input, array('node' => $poll), array('langcode' => $language_interface->langcode, 'sanitize' => FALSE));
-//      $this->assertEqual($output, $expected, format_string('Unsanitized poll token %token replaced.', array('%token' => $input)));
-//    }
+    foreach ($tests as $input => $expected) {
+      $output = $token->replace($input, array('node' => $poll), array('langcode' => $langcode, 'sanitize' => FALSE));
+      $this->assertEqual($output, $expected, format_string('Unsanitized poll token %token replaced.', array('%token' => $input)));
+    }
   }
 }
