You are here

public function OpignoPollAppWebTestCase::testDisplays in Opigno Poll App 7

Test default views and displays.

Opigno Poll App ships with a view that lists all the polls for the current course (node/%/polls). Test the displays work as planned. The View requires OG Access and OG Context to work, so enable these at setup.

File

tests/OpignoPollAppWebTestCase.test, line 40
Defines the unit tests for Opigno Poll.

Class

OpignoPollAppWebTestCase
@file Defines the unit tests for Opigno Poll.

Code

public function testDisplays() {

  // Create a course manager. Create a course in her name.
  $course_manager = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $course = $this
    ->createCourse('Course 1', $course_manager, 1);

  // Create one global poll, and 2 inside the course.
  $this
    ->createPoll('Global poll 1');
  $this
    ->createPoll('Course poll 1', $course->nid);
  $this
    ->createPoll('Course poll 2', $course->nid);

  // Login the course manager.
  // She should see the 2 polls on the course poll page, but not the global
  // one. She should also see a link to create a new poll.
  $this
    ->drupalLogin($course_manager);
  $this
    ->drupalGet('node/' . $course->nid . '/polls');
  $this
    ->assertLink('Add a new poll', 0, "Found the local action for adding a new poll.");
  $this
    ->assertNoText('Global poll 1', "The global poll is not listed.");
  $this
    ->assertText('Course poll 1', "The first course poll is listed.");
  $this
    ->assertText('Course poll 2', "The second course poll is listed.");

  // Create a member and log her in.
  // She should see the 2 polls, but not the global one. She should not see
  // the "Add poll" link.
  $member = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->addMemberToCourse($course, $member->uid, array(
    'member',
    'can vote',
  ));
  $this
    ->drupalLogin($member);
  $this
    ->drupalGet('node/' . $course->nid . '/polls');
  $this
    ->assertNoLink('Add a new poll', 0, "Did not find the local action for adding a new poll.");
  $this
    ->assertNoText('Global poll 1', "The global poll is not listed.");
  $this
    ->assertText('Course poll 1', "The first course poll is listed.");
  $this
    ->assertText('Course poll 2', "The second course poll is listed.");

  // Create a non-member and log her in.
  // She should have an "Access denied" page and not see anything.
  $non_member = $this
    ->drupalCreateUser(array(
    'access content',
  ));
  $this
    ->drupalLogin($non_member);
  $this
    ->drupalGet('node/' . $course->nid . '/polls');
  $this
    ->assertNoLink('Add a new poll', 0, "Did not find the local action for adding a new poll.");
  $this
    ->assertText('Access denied', "Correctly denied access to the page.");
  $this
    ->assertNoText('Global poll 1', "The global poll is not listed.");
  $this
    ->assertNoText('Course poll 1', "The first course poll is not listed.");
  $this
    ->assertNoText('Course poll 2', "The second course poll is not listed.");
}