You are here

function NotificationsContentTests::testNotificationsUserPages in Notifications 6

Same name and namespace in other branches
  1. 6.4 tests/notifications_content.test \NotificationsContentTests::testNotificationsUserPages()
  2. 6.2 tests/notifications_content.test \NotificationsContentTests::testNotificationsUserPages()
  3. 6.3 tests/notifications_content.test \NotificationsContentTests::testNotificationsUserPages()
  4. 7 tests/notifications_content.test \NotificationsContentTests::testNotificationsUserPages()

Check all user pages before and after enabling permissions

File

tests/notifications_content.test, line 41

Class

NotificationsContentTests
Class for testing notifications module. Tests basic API functions

Code

function testNotificationsUserPages() {
  $this
    ->enableSubscriptionTypes();
  $this
    ->enableUIPages(0);
  $user = $this
    ->drupalCreateUser($this
    ->listPermissions());
  $this
    ->drupalLogin($user);
  $prefix = 'user/' . $user->uid . '/notifications';
  $test_pages = array(
    "{$prefix}/thread" => 'Thread overview page',
    "{$prefix}/add/thread" => 'Add thread subscription',
    "{$prefix}/nodetype" => 'Node type overview',
    "{$prefix}/add/nodetype" => 'Add node type subscription',
    "{$prefix}/author" => 'Author overview page',
    "{$prefix}/add/author" => 'Add author subscription',
  );

  // Test UI api function
  foreach (array(
    'thread',
    'nodetype',
    'author',
  ) as $type) {
    $this
      ->assertFalse(notifications_ui_access_page($type, $user), 'No permission for account page: ' . $type);
    $this
      ->assertFalse(notifications_ui_access_user_add($user, $type), 'No permission for adding type: ' . $type);
  }

  // First we shouldn't be able to access any of them
  foreach ($test_pages as $path => $name) {
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(403, 'User cannot access the page: ' . $name);
  }
  $this
    ->enableUIPages();

  // Now we should be able to access all of them
  // Test UI api function
  foreach (array(
    'page',
    'create',
  ) as $type) {
    $this
      ->assertTrue(notifications_ui_user_options($type), 'Enabled user page: ' . $type);
  }
  foreach (array(
    'thread',
    'nodetype',
    'author',
  ) as $type) {
    $this
      ->assertTrue(notifications_ui_subscription_type($type), 'Enabled subscription type: ' . $type);
    $this
      ->assertTrue(notifications_ui_access_page($type, $user), 'Permission for account page: ' . $type);
    $this
      ->assertTrue(notifications_ui_access_user_add($user, $type), 'Permission for adding type: ' . $type);
  }
  foreach ($test_pages as $path => $name) {
    $this
      ->drupalGet($path);
    $this
      ->assertResponse(200, 'User can access the page: ' . $name);
  }
}