t('Module list functionality'), 'description' => t('Enable/disable core module and confirm table creation/deletion. Enable module without dependency enabled. Attempt disabling of required modules.'), 'group' => t('System') ); } /** * Implementation of setUp(). */ function setUp() { parent::setUp('system_test'); $this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer site configuration')); $this->drupalLogin($this->admin_user); } /** * Enable a module, check the database for related tables, disable module, * check for related tables, unistall module, check for related tables. * Also check for invocation of the hook_module_action hook. */ function testEnableDisable() { // Enable aggregator, and check tables. $this->assertModules(array('aggregator'), FALSE); $this->assertTableCount('aggregator', FALSE); // Install (and enable) aggregator module. $edit = array(); $edit['modules[Core][aggregator][enable]'] = 'aggregator'; $this->drupalPost('admin/build/modules', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); // Check that hook_modules_installed and hook_modules_enabled hooks were invoked and check tables. $this->assertText(t('hook_modules_installed fired for aggregator'), t('hook_modules_installed fired.')); $this->assertText(t('hook_modules_enabled fired for aggregator'), t('hook_modules_enabled fired.')); $this->assertModules(array('aggregator'), TRUE); $this->assertTableCount('aggregator', TRUE); // Disable aggregator, check tables, uninstall aggregator, check tables. $edit = array(); $edit['modules[Core][aggregator][enable]'] = FALSE; $this->drupalPost('admin/build/modules', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); // Check that hook_modules_disabled hook was invoked and check tables. $this->assertText(t('hook_modules_disabled fired for aggregator'), t('hook_modules_disabled fired.')); $this->assertModules(array('aggregator'), FALSE); $this->assertTableCount('aggregator', TRUE); // Uninstall the module. $edit = array(); $edit['uninstall[aggregator]'] = 'aggregator'; $this->drupalPost('admin/build/modules/uninstall', $edit, t('Uninstall')); $this->drupalPost(NULL, NULL, t('Uninstall')); $this->assertText(t('The selected modules have been uninstalled.'), t('Modules status has been updated.')); // Check that hook_modules_uninstalled hook was invoked and check tables. $this->assertText(t('hook_modules_uninstalled fired for aggregator'), t('hook_modules_uninstalled fired.')); $this->assertModules(array('aggregator'), FALSE); $this->assertTableCount('aggregator', FALSE); } /** * Attempt to enable translation module without locale enabled. */ function testEnableWithoutDependency () { // Attempt to enable content translation without locale enabled. $edit = array(); $edit['modules[Core][translation][enable]'] = 'translation'; $this->drupalPost('admin/build/modules', $edit, t('Save configuration')); $this->assertText(t('Some required modules must be enabled'), t('Dependecy required.')); $this->assertModules(array('translation', 'locale'), FALSE); // Assert that the locale tables weren't enabled. $this->assertTableCount('languages', FALSE); $this->assertTableCount('locale', FALSE); $this->drupalPost(NULL, NULL, t('Continue')); $this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.')); $this->assertModules(array('translation', 'locale'), TRUE); // Assert that the locale tables were enabled. $this->assertTableCount('languages', TRUE); $this->assertTableCount('locale', TRUE); } /** * Assert that core required modules cannot be disabled. */ function testDisableRequired() { $required_modules = drupal_required_modules(); $this->drupalGet('admin/build/modules'); foreach($required_modules as $module) { // Check to make sure the checkbox for required module is not found. $this->assertNoFieldByName('modules[Core][' . $module . '][enable]'); } } /** * Assert tables that begin with the specified base table name. * * @param string $base_table Begginning of table name to look for. * @param boolean $count Assert tables that match specified base table. * @return boolean Tables with specified base table. */ function assertTableCount($base_table, $count) { $tables = db_find_tables(Database::getActiveConnection()->prefixTables('{' . $base_table . '}') . '%'); if ($count) { return $this->assertTrue($tables, t('Tables matching "@base_table" found.', array('@base_table' => $base_table))); } return $this->assertFalse($tables, t('Tables matching "@base_table" not found.', array('@base_table' => $base_table))); } /** * Assert the list of modules are enabled or disabled. * * @param array $modules Modules to check. * @param boolean $enabled Module state. */ function assertModules(array $modules, $enabled) { module_list(TRUE); foreach ($modules as $module) { if ($enabled) { $message = 'Module "@module" is enabled.'; } else { $message = 'Module "@module" is not enabled.'; } $this->assertEqual(module_exists($module), $enabled, t($message, array('@module' => $module))); } } } class IPAddressBlockingTestCase extends DrupalWebTestCase { protected $blocking_user; /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('IP address blocking'), 'description' => t('Test IP address blocking.'), 'group' => t('System') ); } /** * Implementation of setUp(). */ function setUp() { parent::setUp(); // Create user. $this->blocking_user = $this->drupalCreateUser(array('block IP addresses')); $this->drupalLogin($this->blocking_user); } /** * Test a variety of user input to confirm correct validation and saving of data. */ function testIPAddressValidation() { $this->drupalGet('admin/settings/ip-blocking'); // Block a valid IP address. $edit = array(); $edit['ip'] = '192.168.1.1'; $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); $ip = db_result(db_query("SELECT iid from {blocked_ips} WHERE ip = '%s'", $edit['ip'])); $this->assertNotNull($ip, t('IP address found in database')); $this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $edit['ip'])), t('IP address was blocked.')); // Try to block an IP address that's already blocked. $edit = array(); $edit['ip'] = '192.168.1.1'; $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); $this->assertText(t('This IP address is already blocked.')); // Try to block a reserved IP address. $edit = array(); $edit['ip'] = '255.255.255.255'; $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); $this->assertText(t('Please enter a valid IP address.')); // Try to block a reserved IP address. $edit = array(); $edit['ip'] = 'test.example.com'; $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); $this->assertText(t('Please enter a valid IP address.')); // Submit an empty form. $edit = array(); $edit['ip'] = ''; $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); $this->assertText(t('Please enter a valid IP address.')); // Submit your own IP address. This fails, although it works when testing manually. // TODO: on some systems this test fails due to a bug or inconsistency in cURL. // $edit = array(); // $edit['ip'] = ip_address(); // $this->drupalPost('admin/settings/ip-blocking', $edit, t('Save')); // $this->assertText(t('You may not block your own IP address.')); } } class CronRunTestCase extends DrupalWebTestCase { /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('Cron run'), 'description' => t('Test cron run.'), 'group' => t('System') ); } /** * Test cron runs. */ function testCronRun() { global $base_url; // Run cron anonymously without any cron key. $this->drupalGet($base_url . '/cron.php', array('external' => TRUE)); $this->assertResponse(403); // Run cron anonymously with a random cron key. $key = $this->randomName(16); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => 'cron_key=' . $key)); $this->assertResponse(403); // Run cron anonymously with the valid cron key. $key = variable_get('cron_key', 'drupal'); $this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => 'cron_key=' . $key)); $this->assertResponse(200); // Execute cron directly. $this->assertTrue(drupal_cron_run(), t('Cron ran successfully.')); } } class AdminOverviewTestCase extends DrupalWebTestCase { /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('Admin overview'), 'description' => t('Confirm that the admin overview page appears as expected.'), 'group' => t('System') ); } /** * Test the overview page by task. */ function testAdminOverview() { $admin_user1 = $this->drupalCreateUser(array('access administration pages')); $this->drupalLogin($admin_user1); $this->drupalGet('admin'); $this->checkOverview(); $this->drupalGet('admin/by-module'); $this->checkOverview(); // Comments on permissions follow the format: [task], [module] that the permission relates to. $permissions = array(); $permissions[] = 'access administration pages'; $permissions[] = 'administer comments'; // Content management, Comment. $permissions[] = 'administer blocks'; // Site building, Block. $permissions[] = 'administer filters'; // Site configuration, Filter. $permissions[] = 'administer users'; // User management, User. $permissions[] = 'access site reports'; // Reports, Database logging. $admin_user2 = $this->drupalCreateUser($permissions); $this->drupalLogin($admin_user2); $this->drupalGet('admin'); $this->checkOverview(array(t('Content management'), t('User management'), t('Reports'), t('Site building'), t('Site configuration'))); $this->drupalGet('admin/by-module'); $this->checkOverview(array(t('Comment'), t('Block'), t('Filter'), t('User'), t('Database logging'))); } /** * Check the overview page panels. * * @param array $panels List of panels to be found. */ function checkOverview(array $panels = array()) { if ($this->parse()) { $found = 0; $extra = 0; $divs = $this->xpath("//div[@class='admin-panel']"); foreach ($divs as $panel) { if (in_array(trim($panel->h3), $panels)) { $found++; } else { $extra++; } } $this->assertTrue(count($panels) == $found, t('Required panels found.')); $this->assertFalse($extra, t('No extra panels found.')); } } } class AdminMetaTagTestCase extends DrupalWebTestCase { /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('Fingerprinting meta tag'), 'description' => t('Confirm that the fingerprinting meta tag appears as expected.'), 'group' => t('System') ); } /** * Verify that the meta tag HTML is generated correctly. */ public function testMetaTag() { list($version,) = explode('.', VERSION); $string = ''; $this->drupalGet('node'); $this->assertRaw($string, t('Fingerprinting meta tag generated correctly.'), t('System')); } } /** * Tests custom access denied functionality. */ class AccessDeniedTestCase extends DrupalWebTestCase { protected $admin_user; /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('403 functionality'), 'description' => t("Tests page access denied functionality, including custom 403 pages."), 'group' => t('System') ); } /** * Implementation of setUp(). */ function setUp() { parent::setUp(); // Create an administrative user. $this->admin_user = $this->drupalCreateUser(array('administer site configuration')); $this->drupalLogin($this->admin_user); } function testAccessDenied() { $this->drupalGet('admin'); $this->assertText(t('Access denied'), t('Found the default 403 page')); $edit = array( 'title' => $this->randomName(10), 'body' => $this->randomName(100) ); $node = $this->drupalCreateNode($edit); // Use a custom 403 page. $this->drupalPost('admin/settings/error-reporting', array('site_403' => 'node/' . $node->nid), t('Save configuration')); $this->drupalGet('admin'); $this->assertText($node->title, t('Found the custom 403 page')); // Logout and check that the user login block is shown on custom 403 pages. $this->drupalLogout(); $this->drupalGet('admin'); $this->assertText($node->title, t('Found the custom 403 page')); $this->assertText(t('User login'), t('Blocks are shown on the custom 403 page')); // Log back in and remove the custom 403 page. $this->drupalLogin($this->admin_user); $this->drupalPost('admin/settings/error-reporting', array(), t('Reset to defaults')); // Logout and check that the user login block is shown on default 403 pages. $this->drupalLogout(); $this->drupalGet('admin'); $this->assertText(t('Access denied'), t('Found the default 403 page')); $this->assertText(t('User login'), t('Blocks are shown on the default 403 page')); } } class PageNotFoundTestCase extends DrupalWebTestCase { protected $admin_user; /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('404 functionality'), 'description' => t("Tests page not found functionality, including custom 404 pages."), 'group' => t('System') ); } /** * Implementation of setUp(). */ function setUp() { parent::setUp(); // Create an administrative user. $this->admin_user = $this->drupalCreateUser(array('administer site configuration')); $this->drupalLogin($this->admin_user); } function testPageNotFound() { $this->drupalGet($this->randomName(10)); $this->assertText(t('Page not found'), t('Found the default 404 page')); $edit = array( 'title' => $this->randomName(10), 'body' => $this->randomName(100) ); $node = $this->drupalCreateNode($edit); // Use a custom 404 page. $this->drupalPost('admin/settings/error-reporting', array('site_404' => 'node/' . $node->nid), t('Save configuration')); $this->drupalGet($this->randomName(10)); $this->assertText($node->title, t('Found the custom 404 page')); // Logout and check that the user login block is not shown on custom 404 pages. $this->drupalLogout(); $this->drupalGet($this->randomName(10)); $this->assertText($node->title, t('Found the custom 404 page')); $this->assertNoText(t('User login'), t('Blocks are not shown on the custom 404 page')); // Log back in and remove the custom 404 page. $this->drupalLogin($this->admin_user); $this->drupalPost('admin/settings/error-reporting', array(), t('Reset to defaults')); // Logout and check that the user login block is not shown on default 404 pages. $this->drupalLogout(); $this->drupalGet($this->randomName(10)); $this->assertText(t('Page not found'), t('Found the default 404 page')); $this->assertNoText(t('User login'), t('Blocks are not shown on the default 404 page')); } } /** * Tests generic date and time handling capabilities of Drupal. */ class DateTimeFunctionalTest extends DrupalWebTestCase { function getInfo() { return array( 'name' => t('Date and time'), 'description' => t('Configure date and time settings. Test date formatting and time zone handling, including daylight saving time.'), 'group' => t('System'), ); } /** * Test time zones and DST handling. */ function testTimeZoneHandling() { // Setup date/time settings for Honolulu time. variable_set('date_default_timezone', 'Pacific/Honolulu'); variable_set('configurable_timezones', 0); variable_set('date_format_medium', 'Y-m-d H:i:s O'); // Create some nodes with different authored-on dates. $date1 = '2007-01-31 21:00:00 -1000'; $date2 = '2007-07-31 21:00:00 -1000'; $node1 = $this->drupalCreateNode(array('created' => strtotime($date1), 'type' => 'article')); $node2 = $this->drupalCreateNode(array('created' => strtotime($date2), 'type' => 'article')); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); $this->assertText('2007-01-31 21:00:00 -1000', t('Date should be identical, with GMT offset of -10 hours.')); $this->drupalGet("node/$node2->nid"); $this->assertText('2007-07-31 21:00:00 -1000', t('Date should be identical, with GMT offset of -10 hours.')); // Set time zone to Los Angeles time. variable_set('date_default_timezone', 'America/Los_Angeles'); // Confirm date format and time zone. $this->drupalGet("node/$node1->nid"); $this->assertText('2007-01-31 23:00:00 -0800', t('Date should be two hours ahead, with GMT offset of -8 hours.')); $this->drupalGet("node/$node2->nid"); $this->assertText('2007-08-01 00:00:00 -0700', t('Date should be three hours ahead, with GMT offset of -7 hours.')); } } class PageTitleFiltering extends DrupalWebTestCase { protected $content_user; protected $saved_title; /** * Implementation of getInfo(). */ function getInfo() { return array( 'name' => t('HTML in page titles'), 'description' => t('Tests correct handling or conversion by drupal_set_title() and drupal_get_title().'), 'group' => t('System') ); } /** * Implementation of setUp(). */ function setUp() { parent::setUp(); $this->content_user = $this->drupalCreateUser(array('create page content', 'access content')); $this->drupalLogin($this->content_user); $this->saved_title = drupal_get_title(); } /** * Reset page title. */ function tearDown() { // Restore the page title. drupal_set_title($this->saved_title, PASS_THROUGH); parent::tearDown(); } /** * Tests the handling of HTML by drupal_set_title() and drupal_get_title() */ function testTitleTags() { $title = "string with HTML"; // drupal_set_title's $filter is CHECK_PLAIN by default, so the title should be // returned with check_plain(). drupal_set_title($title, CHECK_PLAIN); $this->assertTrue(strpos(drupal_get_title(), '') === FALSE, t('Tags in title converted to entities when $output is CHECK_PLAIN.')); // drupal_set_title's $filter is passed as PASS_THROUGH, so the title should be // returned with HTML. drupal_set_title($title, PASS_THROUGH); $this->assertTrue(strpos(drupal_get_title(), '') !== FALSE, t('Tags in title are not converted to entities when $output is PASS_THROUGH.')); // Generate node content. $edit = array( 'title' => '!SimpleTest! ' . $title . $this->randomName(20), 'body' => '!SimpleTest! test body' . $this->randomName(200), ); // Create the node with HTML in the title. $this->drupalPost('node/add/page', $edit, t('Save')); $node = $this->drupalGetNodeByTitle($edit['title']); $this->assertNotNull($node, 'Node created and found in database'); $this->drupalGet("node/" . $node->nid); $this->assertText(check_plain($edit['title']), 'Check to make sure tags in the node title are converted.'); } } /** * Test front page functionality and administration. */ class FrontPageTestCase extends DrupalWebTestCase { function getInfo() { return array( 'name' => t('Front page'), 'description' => t('Tests front page functionality and administration.'), 'group' => t('System'), ); } function setUp() { parent::setUp('system_test'); // Create admin user, log in admin user, and create one node. $this->admin_user = $this->drupalCreateUser(array('access content', 'administer site configuration')); $this->drupalLogin($this->admin_user); $this->node_path = "node/" . $this->drupalCreateNode(array('promote' => 1))->nid; // Enable front page logging in system_test.module. variable_set('front_page_output', 1); } /** * Test front page functionality. */ function testDrupalIsFrontPage() { $this->drupalGet(''); $this->assertText(t('On front page.'), t('Path is the front page.')); $this->drupalGet('node'); $this->assertText(t('On front page.'), t('Path is the front page.')); $this->drupalGet($this->node_path); $this->assertNoText(t('On front page.'), t('Path is not the front page.')); // Change the front page to an invalid path. $edit = array('site_frontpage' => 'kittens'); $this->drupalPost('admin/settings/site-information', $edit, t('Save configuration')); $this->assertText(t("The path '@path' is either invalid or you do not have access to it.", array('@path' => $edit['site_frontpage']))); // Change the front page to a valid path. $edit['site_frontpage'] = $this->node_path; $this->drupalPost('admin/settings/site-information', $edit, t('Save configuration')); $this->assertText(t('The configuration options have been saved.'), t('The front page path has been saved.')); $this->drupalGet(''); $this->assertText(t('On front page.'), t('Path is the front page.')); $this->drupalGet('node'); $this->assertNoText(t('On front page.'), t('Path is not the front page.')); $this->drupalGet($this->node_path); $this->assertText(t('On front page.'), t('Path is the front page.')); } } class SystemBlockTestCase extends DrupalWebTestCase { function getInfo() { return array( 'name' => t('Block functionality'), 'description' => t('Configure and move powered-by block.'), 'group' => t('System'), ); } function setUp() { parent::setUp(); // Create and login user $admin_user = $this->drupalCreateUser(array('administer blocks')); $this->drupalLogin($admin_user); } /** * Test displaying and hiding the powered-by block. */ function testPoweredByBlock() { // Set block title and some settings to confirm that the interface is availble. $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => $this->randomName(8), 'color' => 'powered-black', 'size' => '135x42'), t('Save block')); $this->assertText(t('The block configuration has been saved.'), t('Block configuration set.')); // Set the powered-by block to the footer region. $edit = array(); $edit['system_powered-by[region]'] = 'footer'; $this->drupalPost('admin/build/block', $edit, t('Save blocks')); $this->assertText(t('The block settings have been updated.'), t('Block successfully move to footer region.')); // Confirm that the block is being displayed. $this->assertRaw('id="block-system-powered-by"', t('Block successfully being displayed on the page.')); // Set the block to the disabled region. $edit = array(); $edit['system_powered-by[region]'] = '-1'; $this->drupalPost('admin/build/block', $edit, t('Save blocks')); // Confirm that the block is hidden. $this->assertNoRaw('id="block-system-powered-by"', t('Block no longer appears on page.')); // For convenience of developers, set the block to it's default settings. $edit = array(); $edit['system_powered-by[region]'] = 'footer'; $this->drupalPost('admin/build/block', $edit, t('Save blocks')); $this->drupalPost('admin/build/block/configure/system/powered-by', array('title' => '', 'color' => 'powered-blue', 'size' => '80x15'), t('Save block')); } }