function ip2countryTestCase::testUserAccess in IP-based Determination of a Visitor's Country 6
Same name and namespace in other branches
- 7 tests/ip2country.test \ip2countryTestCase::testUserAccess()
Tests module permissions / access to configuration page.
File
- ./
ip2country.test, line 181 - Tests suite for the ip2country module.
Class
- ip2countryTestCase
- Need 1 class for unit tests, 1 class for functional tests 1 function for DB tests because filling takes so long
Code
function testUserAccess() {
//
// Test as anonymous user
//
$this
->drupalGet('admin/settings');
$this
->assertText(t('Access denied'));
$this
->assertText(t('You are not authorized to access this page.'));
$this
->drupalGet('admin/settings/ip2country');
$this
->assertText(t('Access denied'));
$this
->assertText(t('You are not authorized to access this page.'));
// Try to trigger DB update as anonymous
$this
->drupalGet('admin/settings/ip2country/update/arin');
$this
->assertText(t('Access denied'));
$this
->assertText(t('You are not authorized to access this page.'));
//
// Test as authenticated but unprivileged user
//
$this
->drupalLogin($this->unpriv_user);
$this
->drupalGet('admin/settings');
$this
->assertText(t('Access denied'));
$this
->assertText(t('You are not authorized to access this page.'));
$this
->drupalGet('admin/settings/ip2country');
$this
->assertText(t('Access denied'));
$this
->assertText(t('You are not authorized to access this page.'));
$this
->drupalLogout();
//
// As admin user
//
$this
->drupalLogin($this->admin_user);
$this
->drupalGet('admin/settings');
$this
->assertText(t('IP to Country settings'));
$this
->assertText(t('Settings for determining user location from IP address.'));
$this
->drupalGet('admin/settings/ip2country');
$this
->assertText(t('IP to Country settings'));
$this
->assertText(t('Configuration settings for the ip2country module.'));
$this
->assertText(t('Database is empty.'));
$this
->assertFieldByName('ip2country_watchdog', 1, t('Database updates are being logged to watchdog.'));
$this
->assertFieldByName('ip2country_rir', 'arin', t('Database updates from arin.'));
// Update database via UI - choose a random RIR
// (Actually short-circuiting the UI here because of the Ajax call)
$rir = array_rand(array(
'afrinic' => 'AFRINIC',
'arin' => 'ARIN',
'apnic' => 'APNIC',
'lacnic' => 'LACNIC',
'ripe' => 'RIPE',
));
$this
->drupalGet('admin/settings/ip2country/update/' . $rir);
$this
->assertText(t('The IP to Country database has been updated from @rir.', array(
'@rir' => strtoupper($rir),
)));
// Check watchdog
$this
->drupalGet('admin/reports/dblog');
$this
->assertText(t('Recent log entries'));
$this
->assertText('ip2country');
$this
->assertLink(t('Manual database update from @rir server.', array(
'@rir' => strtoupper($rir),
)));
// Drill down
$this
->clickLink(t('Manual database update from @rir server.', array(
'@rir' => strtoupper($rir),
)));
$this
->assertText(t('Details'));
$this
->assertText('ip2country');
$this
->assertText(t('Manual database update from @rir server.', array(
'@rir' => strtoupper($rir),
)));
$this
->drupalLogout();
}