You are here

public function WeatherPermissionTestCase::testPermissions in Weather 7

Same name and namespace in other branches
  1. 6.5 tests/permissions.test \WeatherPermissionTestCase::testPermissions()
  2. 7.3 tests/permissions.test \WeatherPermissionTestCase::testPermissions()
  3. 7.2 tests/permissions.test \WeatherPermissionTestCase::testPermissions()

Permissions of weather block

This test requires that at least one system wide block is enabled.

File

tests/permissions.test, line 52
Tests permission and access settings for different users.

Class

WeatherPermissionTestCase
Test class for permissions.

Code

public function testPermissions() {

  // This user is allowed to view the system block
  $normal_user = $this
    ->drupalCreateUser(array(
    'access content',
  ));

  // This user is allowed to administer a custom weather block
  $weather_user_1 = $this
    ->drupalCreateUser(array(
    'access content',
    'administer custom weather block',
  ));

  // This user is also allowed to administer a custom weather block,
  // like weather_user_1. However, he's not allowed to edit the
  // custom block of weather_user_1. This catches bug #244087
  // (Only one permission for everyone)
  $weather_user_2 = $this
    ->drupalCreateUser(array(
    'access content',
    'administer custom weather block',
  ));

  // This user is allowed to access the weather pages
  $weather_pages_user = $this
    ->drupalCreateUser(array(
    'access content',
    'access weather pages',
  ));

  // This user may setup a system-wide weather block.
  $admin_user = $this
    ->drupalCreateUser(array(
    'access content',
    'administer custom weather block',
    'administer site configuration',
    'administer blocks',
  ));

  // Test with admin user
  $this
    ->drupalLogin($admin_user);

  // Get different pages
  $this
    ->drupalGet('node');
  $this
    ->drupalGet('user/' . $admin_user->uid . '/weather');
  $this
    ->assertText(t('Weather'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText(t('Add display'));

  // Enable a system-wide weather block
  $this
    ->drupalPost('admin/config/user-interface/weather/system-wide/add', array(), t('Save'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText('Add location to this display');
  $edit = array(
    'blocks[weather_system_1][region]' => 'sidebar_second',
  );
  $this
    ->drupalPost('admin/structure/block', $edit, t('Save blocks'));
  $this
    ->drupalGet('node');
  $this
    ->assertText(t('Current weather'));

  // Logout current user
  $this
    ->drupalLogout();

  // Test with normal user
  $this
    ->drupalLogin($normal_user);

  // Get different pages
  $this
    ->drupalGet('node');
  $this
    ->assertText(t('Current weather'));
  $this
    ->drupalGet('user/' . $normal_user->uid);
  $this
    ->assertNoText(t('Weather'));
  $this
    ->drupalGet('user/' . $normal_user->uid . '/weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('weather/EDDH');
  $this
    ->assertText(t('Access denied'));

  // Logout current user
  $this
    ->drupalLogout();

  // Test with weather user
  $this
    ->drupalLogin($weather_user_1);

  // Get different pages
  $this
    ->drupalGet('node');
  $this
    ->assertText(t('Current weather'));
  $this
    ->drupalGet('user/' . $weather_user_1->uid);
  $this
    ->assertText(t('Weather'));
  $this
    ->drupalGet('user/' . $weather_user_1->uid . '/weather');
  $this
    ->assertText(t('Weather'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('weather/EDDH');
  $this
    ->assertText(t('Access denied'));

  // Logout current user
  $this
    ->drupalLogout();

  // Test with weather user 2
  $this
    ->drupalLogin($weather_user_2);

  // Get different pages
  $this
    ->drupalGet('node');
  $this
    ->assertText(t('Current weather'));
  $this
    ->drupalGet('user/' . $weather_user_2->uid);
  $this
    ->assertText(t('Weather'));
  $this
    ->drupalGet('user/' . $weather_user_2->uid . '/weather');
  $this
    ->assertText(t('Weather'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText(t('Access denied'));

  // Do not allow editing another user's settings, see #244087
  $this
    ->drupalGet('user/' . $weather_user_1->uid . '/weather');
  $this
    ->assertText(t('Access denied'));

  // Logout current user
  $this
    ->drupalLogout();

  // Test with weather pages
  $this
    ->drupalLogin($weather_pages_user);

  // Get different pages
  $this
    ->drupalGet('node');
  $this
    ->assertText(t('Current weather'));
  $this
    ->drupalGet('user/' . $weather_pages_user->uid . '/weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('admin/config/user-interface/weather');
  $this
    ->assertText(t('Access denied'));
  $this
    ->drupalGet('weather');
  $this
    ->assertText(t('Search for a location'));
  $this
    ->drupalGet('weather/EDDV');
  $this
    ->assertText(t('Hannover'));
  $this
    ->drupalGet('weather/hannover');
  $this
    ->assertText(t('Hannover'));
  $this
    ->drupalGet('weather/toddy');
  $this
    ->assertText(t('Your search did not return any results.'));

  // Logout current user
  $this
    ->drupalLogout();
}