function WeatherPermissionTestCase::testPermissions in Weather 6.5
Same name and namespace in other branches
- 7.3 tests/permissions.test \WeatherPermissionTestCase::testPermissions()
- 7 tests/permissions.test \WeatherPermissionTestCase::testPermissions()
- 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 50
Class
Code
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('My weather'));
$this
->drupalGet('admin/settings/weather');
$this
->assertText(t('Create new system-wide block'));
// Enable a system-wide weather block
$this
->drupalPost('admin/settings/weather/edit/-1/1', array(), t('Save configuration'));
$this
->drupalGet('admin/settings/weather');
$this
->assertText('Create new location in block 1');
$edit = array(
'weather_3[region]' => 'right',
);
$this
->drupalPost('admin/build/block', $edit, t('Save blocks'));
$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('My weather'));
$this
->drupalGet('user/' . $normal_user->uid . '/weather');
$this
->assertText(t('Access denied'));
$this
->drupalGet('admin/settings/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('My weather'));
$this
->drupalGet('user/' . $weather_user_1->uid . '/weather');
$this
->assertText(t('My weather'));
$this
->drupalGet('admin/settings/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('My weather'));
$this
->drupalGet('user/' . $weather_user_2->uid . '/weather');
$this
->assertText(t('My weather'));
$this
->drupalGet('admin/settings/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
->assertNoText(t('My weather'));
$this
->drupalGet('user/' . $weather_pages_user->uid . '/weather');
$this
->assertText(t('Access denied'));
$this
->drupalGet('admin/settings/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();
}