t('Troll unit tests'), 'desc' => t("Tests the expected return values of functions."), 'group' => 'Troll' ); } function setUp() { $this->drupalModuleEnable('troll'); } function tearDown() { parent::tearDown(); } function testTrollLongIP() { $test_urls = array( '127.0.0.1' => 2130706433, ); foreach ($test_urls as $ip => $result) { $this->assertTrue(_troll_longip($ip) == $result, t('!original was converted to !new', array('!original' => $ip, '!new' => $result))); } } function testTrollPerms() { $perms = troll_perm(); $this->assertTrue(is_array($perms) && sizeof($perms) > 0, t('Troll has special permissions.')); } } class TrollWebTestCase extends DrupalTestCase { function get_info() { return array( 'name' => t('Troll interface'), 'description' => t("Test the Troll interface."), 'group' => 'Troll' ); } function setUp() { $this->drupalModuleEnable('troll'); } function tearDown() { parent::tearDown(); } function testTrollNonPrivInterfaceGrants() { $permissions = array('access content'); $priv_user = $this->drupalCreateUserRolePerm($permissions); $this->drupalLoginUser($priv_user); $this->get(url('admin/user/troll', array('absolute' => TRUE))); $this->assertNoLink('Search Users'); $this->assertNoLink('IP Banning'); $this->assertNoLink('Blacklists'); $this->assertNoLink('Settings'); $this->get(url('admin/user/troll/ip_blacklist', array('absolute' => TRUE))); $this->assertNoLink('Summary'); $this->assertNoLink('Visitor Punishment'); $this->assertNoLink('Import Blacklist'); $this->assertNoLink('Search Blacklisted IPs'); $this->assertNoLink('Whitelist'); $this->get(url('user', array('absolute' => TRUE))); $this->assertNoLink('Troll Track'); $this->get(url('logout', array('absolute' => TRUE))); } function testTrollPrivInterfaceGrants() { $permissions = array('administer troll', 'administer site configuration'); $priv_user = $this->drupalCreateUserRolePerm($permissions); $this->drupalLoginUser($priv_user); $this->get(url('admin/user/troll', array('absolute' => TRUE))); $this->assertLink('Search Users'); $this->assertLink('IP Banning'); $this->assertLink('Blacklists'); $this->assertLink('Settings'); $this->assertText('Search Users', t('Fieldset found')); $this->assertFieldByName('username', ''); $this->assertFieldByName('mail', ''); $this->assertFieldByName('ip_address', ''); $this->assertFieldByName('date_created', ''); $this->get(url('admin/user/troll/ip_ban', array('absolute' => TRUE))); $this->assertText('Add IP Ban', t('Fieldset found')); $this->assertFieldByName('ip_address', ''); $this->assertFieldByName('domain_name', ''); $this->assertField('expires'); $this->assertField('month'); $this->assertField('day'); $this->assertField('year'); $this->assertText('Banned IPs', t('Fieldset found')); $this->get(url('admin/user/troll/ip_blacklist', array('absolute' => TRUE))); $this->assertLink('Summary'); $this->assertLink('Visitor Punishment'); $this->assertLink('Import Blacklist'); $this->assertLink('Search Blacklisted IPs'); $this->assertLink('Whitelist'); $this->assertText('address blocks filtered'); $this->get(url('admin/user/troll/ip_blacklist/punishment', array('absolute' => TRUE))); $this->assertField('stutter'); $this->assertField('mod_requests'); $this->assertField('alt_page'); $this->assertField('alt_url'); $this->get(url('admin/user/troll/ip_blacklist/import', array('absolute' => TRUE))); $this->assertField('truncate_list'); $this->assertField('select_list'); $this->assertField('custom_list'); $this->get(url('admin/user/troll/ip_blacklist/search', array('absolute' => TRUE))); $this->assertField('ip_address'); $this->get(url('admin/user/troll/ip_blacklist/whitelist', array('absolute' => TRUE))); $this->assertField('whitelist_addr1'); $this->assertField('whitelist_addr2'); $this->get(url('admin/user/troll/settings', array('absolute' => TRUE))); $this->assertField('troll_enable_ip_ban'); $this->assertField('troll_ip_ban_redirect'); $this->assertField('troll_block_role'); $this->get(url('user', array('absolute' => TRUE))); $this->assertLink('Troll Track'); $this->clickLink('Troll Track'); $this->assertText("Account Details for $priv_user->name"); $this->assertLink('Block User'); $this->assertLink('Ban IP'); $this->assertText($priv_user->mail); $this->assertLink($priv_user->name); $this->assertText('IP History'); $this->assertText('Status'); $this->assertText('Last Access'); $this->assertText('First Access'); $this->assertText('Host Information'); $this->assertText('Recent Posts'); $this->get(url('logout', array('absolute' => TRUE))); } }