Newer
Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
$list_themes = list_themes();
$this->assertFalse(isset($list_themes['seven']->info['regions']['test_region']), t('Altered theme info was not returned by list_themes().'));
}
/**
* Returns the info array as it is stored in {system}.
*
* @param $name
* The name of the record in {system}.
* @param $type
* The type of record in {system}.
*
* @return
* Array of info, or FALSE if the record is not found.
*/
function getSystemInfo($name, $type) {
$raw_info = db_query("SELECT info FROM {system} WHERE name = :name AND type = :type", array(':name' => $name, ':type' => $type))->fetchField();
return $raw_info ? unserialize($raw_info) : FALSE;
}
}
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
/**
* Tests for the update system functionality.
*/
class UpdateScriptFunctionalTest extends DrupalWebTestCase {
private $update_url;
private $update_user;
public static function getInfo() {
return array(
'name' => 'Update functionality',
'description' => 'Tests the update script access and functionality.',
'group' => 'System',
);
}
function setUp() {
parent::setUp();
$this->update_url = $GLOBALS['base_url'] . '/update.php';
$this->update_user = $this->drupalCreateUser(array('administer software updates'));
}
/**
* Tests access to the update script.
*/
function testUpdateAccess() {
// Try accessing update.php without the proper permission.
$regular_user = $this->drupalCreateUser();
$this->drupalLogin($regular_user);
$this->drupalGet($this->update_url, array('external' => TRUE));
$this->assertResponse(403);
// Try accessing update.php as an anonymous user.
$this->drupalLogout();
$this->drupalGet($this->update_url, array('external' => TRUE));
$this->assertResponse(403);
// Access the update page with the proper permission.
$this->drupalLogin($this->update_user);
$this->drupalGet($this->update_url, array('external' => TRUE));
$this->assertResponse(200);
// Access the update page as user 1.
$user1 = user_load(1);
$user1->pass_raw = user_password();
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$user1->pass = user_hash_password(trim($user1->pass_raw));
db_query("UPDATE {users} SET pass = :pass WHERE uid = :uid", array(':pass' => $user1->pass, ':uid' => $user1->uid));
$this->drupalLogin($user1);
$this->drupalGet($this->update_url, array('external' => TRUE));
$this->assertResponse(200);
}

Dries Buytaert
committed
/**
* Tests the effect of using the update script on the theme system.
*/
function testThemeSystem() {
// Since visiting update.php triggers a rebuild of the theme system from an
// unusual maintenance mode environment, we check that this rebuild did not
// put any incorrect information about the themes into the database.
$original_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
$this->drupalLogin($this->update_user);
$this->drupalGet($this->update_url, array('external' => TRUE));
$final_theme_data = db_query("SELECT * FROM {system} WHERE type = 'theme' ORDER BY name")->fetchAll();
$this->assertEqual($original_theme_data, $final_theme_data, t('Visiting update.php does not alter the information about themes stored in the database.'));

Dries Buytaert
committed
}
}

Dries Buytaert
committed
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
/**
* Functional tests for the flood control mechanism.
*/
class FloodFunctionalTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Flood control mechanism',
'description' => 'Functional tests for the flood control mechanism.',
'group' => 'System',
);
}
/**
* Test flood control mechanism clean-up.
*/
function testCleanUp() {
$threshold = 1;
$window_expired = -1;
$name = 'flood_test_cleanup';
// Register expired event.
flood_register_event($name, $window_expired);
// Verify event is not allowed.
$this->assertFalse(flood_is_allowed($name, $threshold));
// Run cron and verify event is now allowed.
$this->cronRun();
$this->assertTrue(flood_is_allowed($name, $threshold));
// Register unexpired event.
flood_register_event($name);
// Verify event is not allowed.
$this->assertFalse(flood_is_allowed($name, $threshold));
// Run cron and verify event is still not allowed.
$this->cronRun();
$this->assertFalse(flood_is_allowed($name, $threshold));
}
}

Dries Buytaert
committed
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
/**
* Test HTTP file downloading capability.
*/
class RetrieveFileTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'HTTP file retrieval',
'description' => 'Checks HTTP file fetching and error handling.',
'group' => 'System',
);
}
/**
* Invokes system_retrieve_file() in several scenarios.
*/
function testFileRetrieving() {
// Test 404 handling by trying to fetch a randomly named file.
drupal_mkdir($sourcedir = 'public://' . $this->randomName());
$filename = $this->randomName();
$url = file_create_url($sourcedir . '/' . $filename);
$retrieved_file = system_retrieve_file($url);
$this->assertFalse($retrieved_file, t('Non-existent file not fetched.'));

Dries Buytaert
committed
// Actually create that file, download it via HTTP and test the returned path.
file_put_contents($sourcedir . '/' . $filename, 'testing');
$retrieved_file = system_retrieve_file($url);
$this->assertEqual($retrieved_file, 'public://' . $filename, t('Sane path for downloaded file returned (public:// scheme).'));
$this->assertTrue(is_file($retrieved_file), t('Downloaded file does exist (public:// scheme).'));
$this->assertEqual(filesize($retrieved_file), 7, t('File size of downloaded file is correct (public:// scheme).'));

Dries Buytaert
committed
file_unmanaged_delete($retrieved_file);
// Test downloading file to a different location.
drupal_mkdir($targetdir = 'temporary://' . $this->randomName());
$retrieved_file = system_retrieve_file($url, $targetdir);
$this->assertEqual($retrieved_file, "$targetdir/$filename", t('Sane path for downloaded file returned (temporary:// scheme).'));
$this->assertTrue(is_file($retrieved_file), t('Downloaded file does exist (temporary:// scheme).'));
$this->assertEqual(filesize($retrieved_file), 7, t('File size of downloaded file is correct (temporary:// scheme).'));

Dries Buytaert
committed
file_unmanaged_delete($retrieved_file);
file_unmanaged_delete_recursive($sourcedir);
file_unmanaged_delete_recursive($targetdir);
}
}
/**
* Functional tests shutdown functions.
*/
class ShutdownFunctionsTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Shutdown functions',
'description' => 'Functional tests for shutdown functions',
'group' => 'System',
);
}
function setUp() {
parent::setUp('system_test');
}
/**

Dries Buytaert
committed
* Test shutdown functions.
*/
function testShutdownFunctions() {
$arg1 = $this->randomName();
$arg2 = $this->randomName();
$this->drupalGet('system-test/shutdown-functions/' . $arg1 . '/' . $arg2);
$this->assertText(t('First shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2)));
$this->assertText(t('Second shutdown function, arg1 : @arg1, arg2: @arg2', array('@arg1' => $arg1, '@arg2' => $arg2)));

Dries Buytaert
committed
// Make sure exceptions displayed through _drupal_render_exception_safe()
// are correctly escaped.
$this->assertRaw('Drupal is <blink>awesome</blink>.');
}

Dries Buytaert
committed
/**
* Tests administrative overview pages.

Dries Buytaert
committed
*/
class SystemAdminTestCase extends DrupalWebTestCase {

Dries Buytaert
committed
public static function getInfo() {
return array(
'name' => 'Administrative pages',
'description' => 'Tests output on administrative pages and compact mode functionality.',

Dries Buytaert
committed
'group' => 'System',
);
}
function setUp() {
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
// testAdminPages() requires Locale module.
parent::setUp(array('locale'));
// Create an administrator with all permissions, as well as a regular user
// who can only access administration pages and perform some Locale module
// administrative tasks, but not all of them.
$this->admin_user = $this->drupalCreateUser(array_keys(module_invoke_all('permission')));
$this->web_user = $this->drupalCreateUser(array(
'access administration pages',
'translate interface',
));
$this->drupalLogin($this->admin_user);
}
/**
* Tests output on administrative listing pages.
*/
function testAdminPages() {
// Go to Administration.
$this->drupalGet('admin');
// Verify that all visible, top-level administration links are listed on
// the main administration page.
foreach (menu_get_router() as $path => $item) {
if (strpos($path, 'admin/') === 0 && ($item['type'] & MENU_VISIBLE_IN_TREE) && $item['_number_parts'] == 2) {
$this->assertLink($item['title']);
$this->assertLinkByHref($path);
$this->assertText($item['description']);
}
}
// For each administrative listing page on which the Locale module appears,
// verify that there are links to the module's primary configuration pages,
// but no links to its individual sub-configuration pages. Also verify that
// a user with access to only some Locale module administration pages only
// sees links to the pages they have access to.
$admin_list_pages = array(
'admin/index',
'admin/config',
'admin/config/regional',
);
foreach ($admin_list_pages as $page) {
// For the administrator, verify that there are links to Locale's primary
// configuration pages, but no links to individual sub-configuration
// pages.
$this->drupalLogin($this->admin_user);
$this->drupalGet($page);
$this->assertLinkByHref('admin/config');
$this->assertLinkByHref('admin/config/regional/settings');
$this->assertLinkByHref('admin/config/regional/date-time');
$this->assertLinkByHref('admin/config/regional/language');
$this->assertNoLinkByHref('admin/config/regional/language/configure/session');
$this->assertNoLinkByHref('admin/config/regional/language/configure/url');
$this->assertLinkByHref('admin/config/regional/translate');
// On admin/index only, the administrator should also see a "Configure
// permissions" link for the Locale module.
if ($page == 'admin/index') {
$this->assertLinkByHref("admin/people/permissions#module-locale");
}
// For a less privileged user, verify that there are no links to Locale's
// primary configuration pages, but a link to the translate page exists.
$this->drupalLogin($this->web_user);
$this->drupalGet($page);
$this->assertLinkByHref('admin/config');
$this->assertNoLinkByHref('admin/config/regional/settings');
$this->assertNoLinkByHref('admin/config/regional/date-time');
$this->assertNoLinkByHref('admin/config/regional/language');
$this->assertNoLinkByHref('admin/config/regional/language/configure/session');
$this->assertNoLinkByHref('admin/config/regional/language/configure/url');
$this->assertLinkByHref('admin/config/regional/translate');
// This user cannot configure permissions, so even on admin/index should
// not see a "Configure permissions" link for the Locale module.
if ($page == 'admin/index') {
$this->assertNoLinkByHref("admin/people/permissions#module-locale");
}
}

Dries Buytaert
committed
}
/**
* Test compact mode.
*/
function testCompactMode() {
$this->drupalGet('admin/compact/on');
$this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode turns on.'));

Dries Buytaert
committed
$this->drupalGet('admin/compact/on');
$this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode remains on after a repeat call.'));

Dries Buytaert
committed
$this->drupalGet('');
$this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode persists on new requests.'));

Dries Buytaert
committed
$this->drupalGet('admin/compact/off');
$this->assertEqual($this->cookies['Drupal.visitor.admin_compact_mode']['value'], 'deleted', t('Compact mode turns off.'));

Dries Buytaert
committed
$this->drupalGet('admin/compact/off');
$this->assertEqual($this->cookies['Drupal.visitor.admin_compact_mode']['value'], 'deleted', t('Compact mode remains off after a repeat call.'));

Dries Buytaert
committed
$this->drupalGet('');
$this->assertTrue($this->cookies['Drupal.visitor.admin_compact_mode']['value'], t('Compact mode persists on new requests.'));

Dries Buytaert
committed
}
}
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
/**
* Tests authorize.php and related hooks.
*/
class SystemAuthorizeCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Authorize API',
'description' => 'Tests the authorize.php script and related API.',
'group' => 'System',
);
}
function setUp() {
parent::setUp(array('system_test'));
variable_set('allow_authorize_operations', TRUE);
// Create an administrator user.
$this->admin_user = $this->drupalCreateUser(array('administer software updates'));
$this->drupalLogin($this->admin_user);
}
/**
* Helper function to initialize authorize.php and load it via drupalGet().
*
* Initializing authorize.php needs to happen in the child Drupal
* installation, not the parent. So, we visit a menu callback provided by
* system_test.module which calls system_authorized_init() to initialize the
* $_SESSION inside the test site, not the framework site. This callback
* redirects to authorize.php when it's done initializing.
*
* @see system_authorized_init().
*/
function drupalGetAuthorizePHP($page_title = 'system-test-auth') {
$this->drupalGet('system-test/authorize-init/' . $page_title);
}
/**
* Tests the FileTransfer hooks
*/
function testFileTransferHooks() {
$page_title = $this->randomName(16);
$this->drupalGetAuthorizePHP($page_title);
$this->assertTitle(strtr('@title | Drupal', array('@title' => $page_title)), 'authorize.php page title is correct.');
$this->assertNoText('It appears you have reached this page in error.');
$this->assertText('To continue, provide your server connection details');
// Make sure we see the new connection method added by system_test.
$this->assertRaw('System Test FileTransfer');
// Make sure the settings form callback works.
$this->assertText('System Test Username');
}
}

Dries Buytaert
committed
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
/**
* Test the handling of requests containing 'index.php'.
*/
class SystemIndexPhpTest extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Index.php handling',
'description' => "Test the handling of requests containing 'index.php'.",
'group' => 'System',
);
}
function setUp() {
parent::setUp();
}
/**
* Test index.php handling.
*/
function testIndexPhpHandling() {
$index_php = $GLOBALS['base_url'] . '/index.php';
$this->drupalGet($index_php, array('external' => TRUE));
$this->assertResponse(200, t('Make sure index.php returns a valid page.'));
$this->drupalGet($index_php, array('external' => TRUE, 'query' => array('q' => 'user')));
$this->assertResponse(200, t('Make sure index.php?q=user returns a valid page.'));
$this->drupalGet($index_php .'/user', array('external' => TRUE));
$this->assertResponse(404, t("Make sure index.php/user returns a 'page not found'."));
}
}