permissions.test in Weather 6.5
File
tests/permissions.test
View source
<?php
class WeatherPermissionTestCase extends DrupalWebTestCase {
function getInfo() {
return array(
'name' => t('Permission'),
'description' => t('Tests permission and access settings for different users.'),
'group' => t('Weather'),
);
}
function setUp() {
parent::setUp('weather');
}
function testPermissions() {
$normal_user = $this
->drupalCreateUser(array(
'access content',
));
$weather_user_1 = $this
->drupalCreateUser(array(
'access content',
'administer custom weather block',
));
$weather_user_2 = $this
->drupalCreateUser(array(
'access content',
'administer custom weather block',
));
$weather_pages_user = $this
->drupalCreateUser(array(
'access content',
'access weather pages',
));
$admin_user = $this
->drupalCreateUser(array(
'access content',
'administer custom weather block',
'administer site configuration',
'administer blocks',
));
$this
->drupalLogin($admin_user);
$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'));
$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'));
$this
->drupalLogout();
$this
->drupalLogin($normal_user);
$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'));
$this
->drupalLogout();
$this
->drupalLogin($weather_user_1);
$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'));
$this
->drupalLogout();
$this
->drupalLogin($weather_user_2);
$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'));
$this
->drupalGet('user/' . $weather_user_1->uid . '/weather');
$this
->assertText(t('Access denied'));
$this
->drupalLogout();
$this
->drupalLogin($weather_pages_user);
$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.'));
$this
->drupalLogout();
}
}