You are here

PollBlockTest.php in Poll 8

File

tests/src/Functional/PollBlockTest.php
View source
<?php

namespace Drupal\Tests\poll\Functional;


/**
 * Tests the recent poll block.
 *
 * @group poll
 */
class PollBlockTest extends PollTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array(
    'block',
  );
  function setUp() {
    parent::setUp();

    // Enable the recent poll block.
    $this
      ->drupalPlaceBlock('poll_recent_block');
  }

  /**
   * Tests creating, viewing, voting on recent poll block.
   */
  function testRecentBlock() {
    $poll = $this->poll;
    $user = $this->web_user;

    // Verify poll appears in a block.
    $this
      ->drupalLogin($user);
    $this
      ->drupalGet('user');

    // If a 'block' view not generated, this title would not appear even though
    // the choices might.
    $this
      ->assertText($poll
      ->label());
    $options = $poll
      ->getOptions();
    foreach ($options as $option) {
      $this
        ->assertText($option);
    }

    // Verify we can vote via the block.
    $edit = array(
      'choice' => '1',
    );
    $this
      ->drupalPostForm('user/' . $this->web_user
      ->id(), $edit, t('Vote'));
    $this
      ->assertText('Your vote has been recorded.');
    $this
      ->assertText('Total votes: 1');

    // Close the poll and verify block doesn't appear.
    $poll
      ->close();
    $poll
      ->save();
    $this
      ->drupalGet('user/' . $user
      ->id());
    $this
      ->assertNoText($poll
      ->label());
  }

}

Classes

Namesort descending Description
PollBlockTest Tests the recent poll block.