- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
<?php
// $Id$
2009-01-14 12:18:37 +00:00
/**
* Helper class for module test cases.
*/
class ModuleTestCase extends DrupalWebTestCase {
2008-05-19 19:28:39 +00:00
protected $admin_user;
2009-01-14 12:18:37 +00:00
function setUp() {
parent::setUp('system_test');
2009-12-01 22:30:31 +00:00
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer modules'));
2009-01-14 12:18:37 +00:00
$this->drupalLogin($this->admin_user);
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
2009-01-14 12:18:37 +00:00
* Assert there are tables that begin with the specified base table name.
*
* @param $base_table
* Beginning of table name to look for.
* @param $count
* (optional) Whether or not to assert that there are tables that match the
* specified base table. Defaults to TRUE.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2009-01-14 12:18:37 +00:00
function assertTableCount($base_table, $count = TRUE) {
2009-01-25 12:19:32 +00:00
$tables = db_find_tables(Database::getConnection()->prefixTables('{' . $base_table . '}') . '%');
2009-01-14 12:18:37 +00:00
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)));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
2009-01-14 12:18:37 +00:00
* Assert the list of modules are enabled or disabled.
*
* @param $modules
* Module list to check.
* @param $enabled
* Expected module state.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
2009-01-14 12:18:37 +00:00
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)));
}
}
2009-05-12 18:08:43 +00:00
/**
* Verify a log entry was entered for a module's status change.
* Called in the same way of the expected original watchdog() execution.
*
* @param $type
* The category to which this message belongs.
* @param $message
* The message to store in the log. Keep $message translatable
* by not concatenating dynamic values into it! Variables in the
* message should be added by using placeholder strings alongside
* the variables argument to declare the value of the placeholders.
* See t() for documentation on how $message and $variables interact.
* @param $variables
* Array of variables to replace in the message on display or
* NULL if message is already translated or not possible to
* translate.
* @param $severity
* The severity of the message, as per RFC 3164.
* @param $link
* A link to associate with the message.
*/
function assertLogMessage($type, $message, $variables = array(), $severity = WATCHDOG_NOTICE, $link = '') {
$count = db_select('watchdog', 'w')
->condition('type', $type)
->condition('message', $message)
->condition('variables', serialize($variables))
->condition('severity', $severity)
->condition('link', $link)
->countQuery()
->execute()
->fetchField();
$this->assertTrue($count > 0, t('watchdog table contains @count rows for @message', array('@count' => $count, '@message' => $message)));
}
2009-01-14 12:18:37 +00:00
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2009-01-14 12:18:37 +00:00
/**
* Test module enabling/disabling functionality.
*/
class EnableDisableTestCase extends ModuleTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-14 12:18:37 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Enable/disable modules',
'description' => 'Enable/disable core module and confirm table creation/deletion.',
'group' => 'Module',
2009-01-14 12:18:37 +00:00
);
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
/**
* Enable a module, check the database for related tables, disable module,
2008-12-30 16:43:20 +00:00
* check for related tables, uninstall module, check for related tables.
2008-10-11 22:46:22 +00:00
* Also check for invocation of the hook_module_action hook.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
*/
function testEnableDisable() {
// Enable aggregator, and check tables.
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', FALSE);
2008-10-11 22:46:22 +00:00
// Install (and enable) aggregator module.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$edit = array();
2008-10-11 02:33:14 +00:00
$edit['modules[Core][aggregator][enable]'] = 'aggregator';
2009-06-28 03:56:43 +00:00
$edit['modules[Core][forum][enable]'] = 'forum';
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
2008-10-11 22:46:22 +00:00
// 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.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertModules(array('aggregator'), TRUE);
$this->assertTableCount('aggregator', TRUE);
2009-05-12 18:08:43 +00:00
$this->assertLogMessage('system', "%module module enabled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Disable aggregator, check tables, uninstall aggregator, check tables.
$edit = array();
2008-10-11 02:33:14 +00:00
$edit['modules[Core][aggregator][enable]'] = FALSE;
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
2008-10-11 22:46:22 +00:00
// 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.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', TRUE);
2009-05-12 18:08:43 +00:00
$this->assertLogMessage('system', "%module module disabled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-10-11 22:46:22 +00:00
// Uninstall the module.
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$edit = array();
$edit['uninstall[aggregator]'] = 'aggregator';
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->drupalPost(NULL, NULL, t('Uninstall'));
$this->assertText(t('The selected modules have been uninstalled.'), t('Modules status has been updated.'));
2008-10-11 22:46:22 +00:00
// 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.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$this->assertModules(array('aggregator'), FALSE);
$this->assertTableCount('aggregator', FALSE);
2009-05-12 18:08:43 +00:00
$this->assertLogMessage('system', "%module module uninstalled.", array('%module' => 'aggregator'), WATCHDOG_INFO);
2009-07-01 08:39:56 +00:00
// Reinstall (and enable) aggregator module.
$edit = array();
$edit['modules[Core][aggregator][enable]'] = 'aggregator';
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2009-07-01 08:39:56 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2009-01-14 12:18:37 +00:00
}
/**
* Test module dependency functionality.
*/
class ModuleDependencyTestCase extends ModuleTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-14 12:18:37 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Module dependencies',
'description' => 'Enable module without dependency enabled.',
'group' => 'Module',
2009-01-14 12:18:37 +00:00
);
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
/**
* Attempt to enable translation module without locale enabled.
*/
2009-05-24 17:39:35 +00:00
function testEnableWithoutDependency() {
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
// Attempt to enable content translation without locale enabled.
$edit = array();
2008-10-11 02:33:14 +00:00
$edit['modules[Core][translation][enable]'] = 'translation';
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
$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);
}
2009-12-08 06:39:34 +00:00
/**
* Attempt to enable a module with a missing dependency.
*/
function testMissingModules() {
// Test that the system_dependencies_test module is marked
// as missing a dependency.
2010-01-04 21:31:52 +00:00
$this->drupalGet('admin/modules');
2009-12-08 06:39:34 +00:00
$this->assertRaw(t('@module (<span class="admin-missing">missing</span>)', array('@module' => drupal_ucfirst('_missing_dependency'))), t('A module with missing dependencies is marked as such.'));
$checkbox = $this->xpath('//input[@type="checkbox" and @disabled="disabled" and @name="modules[Testing][system_dependencies_test][enable]"]');
$this->assert(count($checkbox) == 1, t('Checkbox for the module is disabled.'));
// Force enable the system_dependencies_test module.
2010-01-13 05:08:29 +00:00
module_enable(array('system_dependencies_test'), FALSE);
2009-12-08 06:39:34 +00:00
// Verify that the module is forced to be disabled when submitting
// the module page.
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', array(), t('Save configuration'));
2009-12-08 06:39:34 +00:00
$this->assertText(t('The @module module is missing, so the following module will be disabled: @depends.', array('@module' => '_missing_dependency', '@depends' => 'system_dependencies_test')), t('The module missing dependencies will be disabled.'));
// Confirm.
$this->drupalPost(NULL, NULL, t('Continue'));
// Verify that the module has been disabled.
$this->assertModules(array('system_dependencies_test'), FALSE);
}
2009-01-14 12:18:37 +00:00
}
2009-07-28 19:06:16 +00:00
/**
* Test module dependency on specific versions.
*/
class ModuleVersionTestCase extends ModuleTestCase {
public static function getInfo() {
return array(
'name' => 'Module versions',
'description' => 'Check module version dependencies.',
'group' => 'Module',
);
}
2009-08-05 16:16:41 +00:00
2009-12-10 15:39:43 +00:00
function setUp() {
2009-07-28 19:06:16 +00:00
parent::setUp('module_test');
}
/**
* Test version dependencies.
*/
function testModuleVersions() {
$dependencies = array(
2009-08-05 16:16:41 +00:00
// Alternating between being compatible and incompatible with 7.x-2.4-beta3.
2009-07-28 19:06:16 +00:00
// The first is always a compatible.
'common_test',
// Branch incompatibility.
'common_test (1.x)',
// Branch compatibility.
'common_test (2.x)',
// Another branch incompatibility.
'common_test (>2.x)',
// Another branch compatibility.
'common_test (<=2.x)',
// Another branch incompatibility.
'common_test (<2.x)',
// Another branch compatibility.
'common_test (>=2.x)',
// Nonsense, misses a dash. Incompatible with everything.
'common_test (=7.x2.x, >=2.4)',
// Core version is optional. Compatible.
2009-08-05 16:16:41 +00:00
'common_test (=7.x-2.x, >=2.4-alpha2)',
2009-07-28 19:06:16 +00:00
// Test !=, explicitly incompatible.
2009-08-05 16:16:41 +00:00
'common_test (=2.x, !=2.4-beta3)',
2009-07-28 19:06:16 +00:00
// Three operations. Compatible.
'common_test (=2.x, !=2.3, <2.5)',
2009-08-05 16:16:41 +00:00
// Testing extra version. Incompatible.
'common_test (<=2.4-beta2)',
// Testing extra version. Compatible.
'common_test (>2.4-beta2)',
// Testing extra version. Incompatible.
'common_test (>2.4-rc0)',
2009-07-28 19:06:16 +00:00
);
variable_set('dependencies', $dependencies);
$n = count($dependencies);
for ($i = 0; $i < $n; $i++) {
2010-01-04 21:31:52 +00:00
$this->drupalGet('admin/modules');
2009-10-03 19:16:04 +00:00
$checkbox = $this->xpath('//input[@id="edit-modules-testing-module-test-enable"]');
2009-07-28 19:06:16 +00:00
$this->assertEqual(!empty($checkbox[0]['disabled']), $i % 2, $dependencies[$i]);
}
}
}
2009-01-14 12:18:37 +00:00
/**
* Test required modules functionality.
*/
class ModuleRequiredTestCase extends ModuleTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-14 12:18:37 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Required modules',
'description' => 'Attempt disabling of required modules.',
'group' => 'Module',
2009-01-14 12:18:37 +00:00
);
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
2008-10-11 03:25:36 +00:00
/**
* Assert that core required modules cannot be disabled.
*/
function testDisableRequired() {
$required_modules = drupal_required_modules();
2010-01-04 21:31:52 +00:00
$this->drupalGet('admin/modules');
2009-05-24 17:39:35 +00:00
foreach ($required_modules as $module) {
2008-10-11 03:25:36 +00:00
// Check to make sure the checkbox for required module is not found.
$this->assertNoFieldByName('modules[Core][' . $module . '][enable]');
}
}
- Added a test framework to Drupal along with a first batch of tests for
Drupal core! This is an important milestone for the project so enable
the module and check it out ... :)
Thanks to Rok Žlender, Károly Négyesi, Jimmy Berry, Kevin Bridges, Charlie
Gordon, Douglas Hubler, Miglius Alaburda, Andy Kirkham, Dimitri13, Kieran
Lal, Moshe Weitzman, and the many other people that helped with testing
over the past years and that drove this home.
It all works but it is still rough around the edges (i.e. documentation
is still being written, the coding style is not 100% yet, a number of
tests still fail) but we spent the entire weekend working on it in Paris
and made a ton of progress. The best way to help and to get up to speed,
is to start writing and contributing some tests ... as well as fixing
some of the failures.
For those willing to help with improving the test framework, here are
some next steps and issues to resolve:
- How to best approach unit tests and mock functions?
- How to test drupal_mail() and drupal_http_request()?
- How to improve the admin UI so we have a nice progress bar?
- How best to do code coverage?
- See http://g.d.o/node/10099 for more ...
2008-04-20 18:24:07 +00:00
}
2008-05-10 07:32:02 +00:00
2008-06-02 17:32:19 +00:00
class IPAddressBlockingTestCase extends DrupalWebTestCase {
2008-05-19 19:28:39 +00:00
protected $blocking_user;
2008-05-10 07:32:02 +00:00
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2008-05-10 07:32:02 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-10 07:32:02 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'IP address blocking',
'description' => 'Test IP address blocking.',
'group' => 'System'
2008-05-10 07:32:02 +00:00
);
}
/**
2009-05-27 18:34:03 +00:00
* Implement setUp().
2008-05-10 07:32:02 +00:00
*/
function setUp() {
parent::setUp();
// Create user.
2008-06-09 16:33:20 +00:00
$this->blocking_user = $this->drupalCreateUser(array('block IP addresses'));
2008-05-19 19:28:39 +00:00
$this->drupalLogin($this->blocking_user);
2008-05-10 07:32:02 +00:00
}
/**
2008-05-30 07:27:14 +00:00
* Test a variety of user input to confirm correct validation and saving of data.
2008-05-10 07:32:02 +00:00
*/
function testIPAddressValidation() {
2009-08-24 12:32:10 +00:00
$this->drupalGet('admin/config/people/ip-blocking');
2008-05-10 07:32:02 +00:00
// Block a valid IP address.
$edit = array();
$edit['ip'] = '192.168.1.1';
2009-08-24 12:32:10 +00:00
$this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2009-05-16 18:34:23 +00:00
$ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $edit['ip']))->fetchField();
2010-01-18 17:05:35 +00:00
$this->assertTrue($ip, t('IP address found in database.'));
2008-05-10 07:32:02 +00:00
$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';
2009-08-24 12:32:10 +00:00
$this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2008-05-10 07:32:02 +00:00
$this->assertText(t('This IP address is already blocked.'));
// Try to block a reserved IP address.
$edit = array();
$edit['ip'] = '255.255.255.255';
2009-08-24 12:32:10 +00:00
$this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2010-01-09 23:03:22 +00:00
$this->assertText(t('Enter a valid IP address.'));
2008-05-10 07:32:02 +00:00
// Try to block a reserved IP address.
$edit = array();
$edit['ip'] = 'test.example.com';
2009-08-24 12:32:10 +00:00
$this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2010-01-09 23:03:22 +00:00
$this->assertText(t('Enter a valid IP address.'));
2008-05-10 07:32:02 +00:00
// Submit an empty form.
$edit = array();
$edit['ip'] = '';
2009-08-24 12:32:10 +00:00
$this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2010-01-09 23:03:22 +00:00
$this->assertText(t('Enter a valid IP address.'));
2008-05-10 07:32:02 +00:00
2010-01-18 17:08:20 +00:00
// Pass an IP address as a URL parameter and submit it.
$submit_ip = '1.2.3.4';
$this->drupalPost('admin/config/people/ip-blocking/' . $submit_ip, NULL, t('Save'));
$ip = db_query("SELECT iid from {blocked_ips} WHERE ip = :ip", array(':ip' => $submit_ip))->fetchField();
$this->assertTrue($ip, t('IP address found in database'));
$this->assertRaw(t('The IP address %ip has been blocked.', array('%ip' => $submit_ip)), t('IP address was blocked.'));
2008-05-10 07:32:02 +00:00
// Submit your own IP address. This fails, although it works when testing manually.
2008-06-29 11:39:38 +00:00
// TODO: on some systems this test fails due to a bug or inconsistency in cURL.
// $edit = array();
// $edit['ip'] = ip_address();
2009-08-24 12:32:10 +00:00
// $this->drupalPost('admin/config/people/ip-blocking', $edit, t('Save'));
2008-06-29 11:39:38 +00:00
// $this->assertText(t('You may not block your own IP address.'));
2008-05-10 07:32:02 +00:00
}
}
2008-05-30 07:27:14 +00:00
2008-06-02 17:32:19 +00:00
class CronRunTestCase extends DrupalWebTestCase {
2008-05-30 07:27:14 +00:00
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2008-05-30 07:27:14 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-30 07:27:14 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Cron run',
'description' => 'Test cron run.',
'group' => 'System'
2008-05-30 07:27:14 +00:00
);
}
/**
* Test cron runs.
*/
function testCronRun() {
2008-10-13 20:29:42 +00:00
global $base_url;
2009-08-22 16:01:10 +00:00
2008-05-30 07:27:14 +00:00
// Run cron anonymously without any cron key.
2008-10-13 20:29:42 +00:00
$this->drupalGet($base_url . '/cron.php', array('external' => TRUE));
2008-05-30 07:27:14 +00:00
$this->assertResponse(403);
// Run cron anonymously with a random cron key.
$key = $this->randomName(16);
2009-09-29 15:31:17 +00:00
$this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key)));
2008-05-30 07:27:14 +00:00
$this->assertResponse(403);
// Run cron anonymously with the valid cron key.
$key = variable_get('cron_key', 'drupal');
2009-09-29 15:31:17 +00:00
$this->drupalGet($base_url . '/cron.php', array('external' => TRUE, 'query' => array('cron_key' => $key)));
2008-05-30 07:27:14 +00:00
$this->assertResponse(200);
}
2008-12-28 19:11:31 +00:00
2009-08-22 16:01:10 +00:00
/**
2009-12-15 08:45:32 +00:00
* Ensure that the automatic cron run callback is working.
2009-08-22 16:01:10 +00:00
*
* In these tests we do not use REQUEST_TIME to track start time, because we
* need the exact time when cron is triggered.
*/
2009-12-15 08:45:32 +00:00
function testAutomaticCron() {
2009-08-22 16:01:10 +00:00
// Ensure cron does not run when the cron threshold is enabled and was
// not passed.
2009-12-15 08:45:32 +00:00
$cron_last = time();
$cron_safe_threshold = 100;
variable_set('cron_last', $cron_last);
variable_set('cron_safe_threshold', $cron_safe_threshold);
2009-08-22 16:01:10 +00:00
$this->drupalGet('');
2009-12-15 08:45:32 +00:00
$this->assertRaw('"cronCheck":' . ($cron_last + $cron_safe_threshold));
$this->drupalGet('system/run-cron-check');
$this->assertExpiresHeader($cron_last + $cron_safe_threshold);
$this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is not passed.'));
2009-08-22 16:01:10 +00:00
// Test if cron runs when the cron threshold was passed.
2009-12-15 08:45:32 +00:00
$cron_last = time() - 200;
variable_set('cron_last', $cron_last);
2009-08-22 16:01:10 +00:00
$this->drupalGet('');
2009-12-15 08:45:32 +00:00
$this->assertRaw('"cronCheck":' . ($cron_last + $cron_safe_threshold));
sleep(1);
$this->drupalGet('system/run-cron-check');
$this->assertExpiresHeader(variable_get('cron_last', NULL) + $cron_safe_threshold);
$this->assertTrue($cron_last < variable_get('cron_last', NULL), t('Cron runs when the cron threshold is passed.'));
// Disable the cron threshold through the interface.
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($admin_user);
$this->drupalPost('admin/config/system/site-information', array('cron_safe_threshold' => 0), t('Save configuration'));
$this->assertText(t('The configuration options have been saved.'));
$this->drupalLogout();
// Test if cron does not run when the cron threshold is disabled.
$cron_last = time() - 200;
variable_set('cron_last', $cron_last);
2009-08-22 16:01:10 +00:00
$this->drupalGet('');
2009-12-15 08:45:32 +00:00
$this->assertNoRaw('cronCheck');
$this->drupalGet('system/run-cron-check');
$this->assertResponse(403);
$this->assertTrue($cron_last == variable_get('cron_last', NULL), t('Cron does not run when the cron threshold is disabled.'));
}
/**
* Assert that the Expires header is a specific timestamp.
*
* @param $timestamp
* The timestamp value to match against the header.
*/
private function assertExpiresHeader($timestamp) {
$expires = $this->drupalGetHeader('Expires');
$expires = strtotime($expires);
$this->assertEqual($expires, $timestamp, t('Expires header expected @expected got @actual.', array('@expected' => $timestamp, '@actual' => $expires)));
2009-08-22 16:01:10 +00:00
}
2008-12-28 19:11:31 +00:00
/**
* Ensure that temporary files are removed.
2009-08-22 16:01:10 +00:00
*
* Create files for all the possible combinations of age and status. We are
2010-01-25 10:38:35 +00:00
* using UPDATE statements rather than file_save() because it would set the
2009-08-22 16:01:10 +00:00
* timestamp.
2008-12-28 19:11:31 +00:00
*/
function testTempFileCleanup() {
// Temporary file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$temp_old = file_save_data('');
2009-08-17 19:14:42 +00:00
db_update('file')
2009-05-16 18:34:23 +00:00
->fields(array(
'status' => 0,
'timestamp' => 1,
))
->condition('fid', $temp_old->fid)
->execute();
2009-08-17 19:14:42 +00:00
$this->assertTrue(file_exists($temp_old->uri), t('Old temp file was created correctly.'));
2008-12-28 19:11:31 +00:00
// Temporary file that is less than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$temp_new = file_save_data('');
2009-08-17 19:14:42 +00:00
db_update('file')
2009-05-16 18:34:23 +00:00
->fields(array('status' => 0))
->condition('fid', $temp_new->fid)
->execute();
2009-08-17 19:14:42 +00:00
$this->assertTrue(file_exists($temp_new->uri), t('New temp file was created correctly.'));
2008-12-28 19:11:31 +00:00
// Permanent file that is older than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$perm_old = file_save_data('');
2009-08-17 19:14:42 +00:00
db_update('file')
2009-05-16 18:34:23 +00:00
->fields(array('timestamp' => 1))
->condition('fid', $temp_old->fid)
->execute();
2009-08-17 19:14:42 +00:00
$this->assertTrue(file_exists($perm_old->uri), t('Old permanent file was created correctly.'));
2008-12-28 19:11:31 +00:00
// Permanent file that is newer than DRUPAL_MAXIMUM_TEMP_FILE_AGE.
$perm_new = file_save_data('');
2009-08-17 19:14:42 +00:00
$this->assertTrue(file_exists($perm_new->uri), t('New permanent file was created correctly.'));
2008-12-28 19:11:31 +00:00
// Run cron and then ensure that only the old, temp file was deleted.
2009-10-13 05:37:46 +00:00
$this->cronRun();
2009-08-17 19:14:42 +00:00
$this->assertFalse(file_exists($temp_old->uri), t('Old temp file was correctly removed.'));
$this->assertTrue(file_exists($temp_new->uri), t('New temp file was correctly ignored.'));
$this->assertTrue(file_exists($perm_old->uri), t('Old permanent file was correctly ignored.'));
$this->assertTrue(file_exists($perm_new->uri), t('New permanent file was correctly ignored.'));
2008-12-28 19:11:31 +00:00
}
2008-06-02 17:32:19 +00:00
}
2008-06-28 19:19:08 +00:00
class AdminMetaTagTestCase extends DrupalWebTestCase {
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2008-06-28 19:19:08 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-06-28 19:19:08 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Fingerprinting meta tag',
'description' => 'Confirm that the fingerprinting meta tag appears as expected.',
'group' => 'System'
2008-06-28 19:19:08 +00:00
);
}
/**
* Verify that the meta tag HTML is generated correctly.
*/
public function testMetaTag() {
2009-05-24 17:39:35 +00:00
list($version, ) = explode('.', VERSION);
$string = '<meta name="Generator" content="Drupal ' . $version . ' (http://drupal.org)" />';
2008-06-28 19:19:08 +00:00
$this->drupalGet('node');
$this->assertRaw($string, t('Fingerprinting meta tag generated correctly.'), t('System'));
}
}
2008-08-28 08:37:46 +00:00
2008-10-11 18:17:02 +00:00
/**
* Tests custom access denied functionality.
*/
class AccessDeniedTestCase extends DrupalWebTestCase {
protected $admin_user;
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-10-11 18:17:02 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => '403 functionality',
2009-09-21 06:44:14 +00:00
'description' => 'Tests page access denied functionality, including custom 403 pages.',
2009-07-13 21:51:42 +00:00
'group' => 'System'
2008-10-11 18:17:02 +00:00
);
}
function setUp() {
parent::setUp();
// Create an administrative user.
2009-07-23 20:58:26 +00:00
$this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer blocks'));
2008-10-11 18:17:02 +00:00
$this->drupalLogin($this->admin_user);
}
function testAccessDenied() {
$this->drupalGet('admin');
$this->assertText(t('Access denied'), t('Found the default 403 page'));
2009-12-10 17:22:35 +00:00
$this->assertResponse(403);
2008-10-11 18:17:02 +00:00
$edit = array(
2010-01-09 21:54:01 +00:00
'title' => $this->randomName(10),
2009-12-02 19:26:23 +00:00
'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(100)))),
2008-10-11 18:17:02 +00:00
);
$node = $this->drupalCreateNode($edit);
// Use a custom 403 page.
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', array('site_403' => 'node/' . $node->nid), t('Save configuration'));
2008-10-11 18:17:02 +00:00
$this->drupalGet('admin');
2010-01-09 21:54:01 +00:00
$this->assertText($node->title, t('Found the custom 403 page'));
2008-10-11 18:17:02 +00:00
// Logout and check that the user login block is shown on custom 403 pages.
$this->drupalLogout();
$this->drupalGet('admin');
2010-01-09 21:54:01 +00:00
$this->assertText($node->title, t('Found the custom 403 page'));
2008-10-11 18:17:02 +00:00
$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);
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', array('site_403' => ''), t('Save configuration'));
2008-10-11 18:17:02 +00:00
// 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'));
2009-12-10 17:22:35 +00:00
$this->assertResponse(403);
2008-10-11 18:17:02 +00:00
$this->assertText(t('User login'), t('Blocks are shown on the default 403 page'));
2009-07-23 20:58:26 +00:00
// Log back in, set the custom 403 page to /user and remove the block
$this->drupalLogin($this->admin_user);
variable_set('site_403', 'user');
$this->drupalPost('admin/structure/block', array('user_login[region]' => '-1'), t('Save blocks'));
// Check that we can log in from the 403 page.
$this->drupalLogout();
$edit = array(
'name' => $this->admin_user->name,
'pass' => $this->admin_user->pass_raw,
);
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', $edit, t('Log in'));
2009-07-23 20:58:26 +00:00
// Check that we're still on the same page.
$this->assertText(t('Site information'));
2008-10-11 18:17:02 +00:00
}
}
2008-08-28 08:37:46 +00:00
class PageNotFoundTestCase extends DrupalWebTestCase {
protected $admin_user;
2008-09-15 20:48:10 +00:00
2008-08-28 08:37:46 +00:00
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2008-08-28 08:37:46 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-08-28 08:37:46 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => '404 functionality',
'description' => "Tests page not found functionality, including custom 404 pages.",
'group' => 'System'
2008-08-28 08:37:46 +00:00
);
}
2008-09-15 20:48:10 +00:00
2008-08-28 08:37:46 +00:00
/**
2009-05-27 18:34:03 +00:00
* Implement setUp().
2008-08-28 08:37:46 +00:00
*/
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'));
2008-09-15 20:48:10 +00:00
2008-08-28 08:37:46 +00:00
$edit = array(
2010-01-09 21:54:01 +00:00
'title' => $this->randomName(10),
2009-12-02 19:26:23 +00:00
'body' => array(LANGUAGE_NONE => array(array('value' => $this->randomName(100)))),
2008-08-28 08:37:46 +00:00
);
$node = $this->drupalCreateNode($edit);
// Use a custom 404 page.
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', array('site_404' => 'node/' . $node->nid), t('Save configuration'));
2008-09-15 20:48:10 +00:00
2008-08-28 08:37:46 +00:00
$this->drupalGet($this->randomName(10));
2010-01-09 21:54:01 +00:00
$this->assertText($node->title, t('Found the custom 404 page'));
2008-08-28 08:37:46 +00:00
}
}
2008-10-13 00:33:05 +00:00
2009-08-22 18:24:14 +00:00
/**
* Tests site maintenance functionality.
*/
class SiteMaintenanceTestCase extends DrupalWebTestCase {
protected $admin_user;
public static function getInfo() {
return array(
'name' => 'Site maintenance mode functionality',
'description' => 'Test access to site while in maintenance mode.',
'group' => 'System',
);
}
function setUp() {
parent::setUp();
// Create a user allowed to access site in maintenance mode.
$this->user = $this->drupalCreateUser(array('access site in maintenance mode'));
// Create an administrative user.
$this->admin_user = $this->drupalCreateUser(array('administer site configuration', 'access site in maintenance mode'));
$this->drupalLogin($this->admin_user);
}
/**
* Verify site maintenance mode functionality.
*/
function testSiteMaintenance() {
// Turn on maintenance mode.
$edit = array(
'maintenance_mode' => 1,
);
$this->drupalPost('admin/config/development/maintenance', $edit, t('Save configuration'));
$admin_message = t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance')));
$user_message = t('Operating in maintenance mode.');
$offline_message = t('@site is currently under maintenance. We should be back shortly. Thank you for your patience.', array('@site' => variable_get('site_name', 'Drupal')));
$this->drupalGet('');
$this->assertRaw($admin_message, t('Found the site maintenance mode message.'));
// Logout and verify that offline message is displayed.
$this->drupalLogout();
$this->drupalGet('');
$this->assertText($offline_message);
$this->drupalGet('node');
$this->assertText($offline_message);
$this->drupalGet('user/register');
$this->assertText($offline_message);
$this->drupalGet('user/password');
$this->assertText($offline_message);
// Verify that user is able to log in.
$this->drupalGet('user');
$this->assertNoText($offline_message);
$this->drupalGet('user/login');
$this->assertNoText($offline_message);
// Log in user and verify that maintenance mode message is displayed
// directly after login.
$edit = array(
'name' => $this->user->name,
'pass' => $this->user->pass_raw,
);
$this->drupalPost(NULL, $edit, t('Log in'));
$this->assertText($user_message);
// Log in administrative user and configure a custom site offline message.
$this->drupalLogout();
$this->drupalLogin($this->admin_user);
$this->drupalGet('admin/config/development/maintenance');
$this->assertNoRaw($admin_message, t('Site maintenance mode message not displayed.'));
$offline_message = 'Sorry, not online.';
$edit = array(
'maintenance_mode_message' => $offline_message,
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
// Logout and verify that custom site offline message is displayed.
$this->drupalLogout();
$this->drupalGet('');
$this->assertRaw($offline_message, t('Found the site offline message.'));
}
}
2008-11-20 06:56:17 +00:00
/**
* Tests generic date and time handling capabilities of Drupal.
*/
class DateTimeFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-11-20 06:56:17 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Date and time',
'description' => 'Configure date and time settings. Test date formatting and time zone handling, including daylight saving time.',
'group' => 'System',
2008-11-20 06:56:17 +00:00
);
}
2009-10-13 21:34:15 +00:00
function setUp() {
parent::setUp();
// Create admin user and log in admin user.
$this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
$this->drupalLogin($this->admin_user);
}
2008-11-20 06:56:17 +00:00
/**
* 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.'));
}
2009-10-13 21:34:15 +00:00
/**
* Test date type configuration.
*/
function testDateTypeConfiguration() {
// Confirm system date types appear.
$this->drupalGet('admin/config/regional/date-time');
$this->assertText(t('Medium'), 'System date types appear in date type list.');
$this->assertNoRaw('href="/admin/config/regional/date-time/types/medium/delete"', 'No delete link appear for system date types.');
// Add custom date type.
$this->clickLink(t('Add date type'));
$date_type = $this->randomName(8);
$machine_name = 'machine_' . $date_type;
$date_format = 'd.m.Y - H:i';
$edit = array(
'date_type' => $date_type,
'machine_name' => $machine_name,
'date_format' => $date_format,
);
$this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('New date type added successfully.'), 'Date type added confirmation message appears.');
$this->assertText($date_type, 'Custom date type appears in the date type list.');
$this->assertText(t('delete'), 'Delete link for custom date type appears.');
// Delete custom date type.
$this->clickLink(t('delete'));
$this->drupalPost('admin/config/regional/date-time/types/' . $machine_name . '/delete', array(), t('Remove'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('Removed date type ' . $date_type), 'Custom date type removed.');
}
/**
* Test date format configuration.
*/
function testDateFormatConfiguration() {
// Confirm 'no custom date formats available' message appears.
$this->drupalGet('admin/config/regional/date-time/formats');
$this->assertText(t('No custom date formats available.'), 'No custom date formats message appears.');
// Add custom date format.
$this->clickLink(t('Add format'));
$edit = array(
'date_format' => 'Y',
);
$this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertNoText(t('No custom date formats available.'), 'No custom date formats message does not appear.');
$this->assertText(t('Custom date format added.'), 'Custom date format added.');
// Ensure custom date format appears in date type configuration options.
$this->drupalGet('admin/config/regional/date-time');
$this->assertRaw('<option value="Y">', 'Custom date format appears in options.');
// Edit custom date format.
$this->drupalGet('admin/config/regional/date-time/formats');
$this->clickLink(t('edit'));
$edit = array(
'date_format' => 'Y m',
);
$this->drupalPost($this->getUrl(), $edit, t('Save format'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('Custom date format updated.'), 'Custom date format successfully updated.');
// Delete custom date format.
$this->clickLink(t('delete'));
$this->drupalPost($this->getUrl(), array(), t('Remove'));
$this->assertEqual($this->getUrl(), url('admin/config/regional/date-time/formats', array('absolute' => TRUE)), t('Correct page redirection.'));
$this->assertText(t('Removed date format'), 'Custom date format removed successfully.');
}
2008-11-20 06:56:17 +00:00
}
2008-10-13 00:33:05 +00:00
class PageTitleFiltering extends DrupalWebTestCase {
protected $content_user;
protected $saved_title;
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2008-10-13 00:33:05 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-10-13 00:33:05 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'HTML in page titles',
'description' => 'Tests correct handling or conversion by drupal_set_title() and drupal_get_title().',
'group' => 'System'
2008-10-13 00:33:05 +00:00
);
}
/**
2009-05-27 18:34:03 +00:00
* Implement setUp().
2008-10-13 00:33:05 +00:00
*/
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 <em>HTML</em>";
// 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(), '<em>') === 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(), '<em>') !== FALSE, t('Tags in title are not converted to entities when $output is PASS_THROUGH.'));
// Generate node content.
2009-12-02 19:26:23 +00:00
$langcode = LANGUAGE_NONE;
2008-10-13 00:33:05 +00:00
$edit = array(
2010-01-09 21:54:01 +00:00
"title" => '!SimpleTest! ' . $title . $this->randomName(20),
2009-08-22 00:58:55 +00:00
"body[$langcode][0][value]" => '!SimpleTest! test body' . $this->randomName(200),
2008-10-13 00:33:05 +00:00
);
// Create the node with HTML in the title.
$this->drupalPost('node/add/page', $edit, t('Save'));
2010-01-09 21:54:01 +00:00
$node = $this->drupalGetNodeByTitle($edit["title"]);
2008-10-13 00:33:05 +00:00
$this->assertNotNull($node, 'Node created and found in database');
$this->drupalGet("node/" . $node->nid);
2010-01-09 21:54:01 +00:00
$this->assertText(check_plain($edit["title"]), 'Check to make sure tags in the node title are converted.');
2008-10-13 00:33:05 +00:00
}
}
2008-12-09 07:16:10 +00:00
/**
* Test front page functionality and administration.
*/
class FrontPageTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-12-09 07:16:10 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Front page',
'description' => 'Tests front page functionality and administration.',
'group' => 'System',
2008-12-09 07:16:10 +00:00
);
}
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');
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', $edit, t('Save configuration'));
2008-12-09 07:16:10 +00:00
$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;
2009-09-01 16:50:12 +00:00
$this->drupalPost('admin/config/system/site-information', $edit, t('Save configuration'));
2008-12-09 07:16:10 +00:00
$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.'));
}
}
2008-12-16 23:57:33 +00:00
class SystemBlockTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-12-16 23:57:33 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Block functionality',
'description' => 'Configure and move powered-by block.',
'group' => 'System',
2008-12-16 23:57:33 +00:00
);
}
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() {
2010-01-25 10:38:35 +00:00
// Set block title and some settings to confirm that the interface is available.
2009-10-23 00:45:51 +00:00
$this->drupalPost('admin/structure/block/manage/system/powered-by/configure', array('title' => $this->randomName(8)), t('Save block'));
2008-12-16 23:57:33 +00:00
$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';
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
2009-10-14 02:13:15 +00:00
$this->assertText(t('The block settings have been updated.'), t('Block successfully moved to footer region.'));
2008-12-16 23:57:33 +00:00
// Confirm that the block is being displayed.
2009-10-14 02:13:15 +00:00
$this->drupalGet('node');
2008-12-16 23:57:33 +00:00
$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';
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
2008-12-16 23:57:33 +00:00
// 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';
2009-07-20 18:51:36 +00:00
$this->drupalPost('admin/structure/block', $edit, t('Save blocks'));
2009-10-23 00:45:51 +00:00
$this->drupalPost('admin/structure/block/manage/system/powered-by/configure', array('title' => ''), t('Save block'));
2008-12-16 23:57:33 +00:00
}
2009-10-18 05:28:43 +00:00
}
/**
* Test main content rendering fallback provided by system module.
*/
class SystemMainContentFallback extends DrupalWebTestCase {
protected $admin_user;
protected $web_user;
public static function getInfo() {
return array(
'name' => 'Main content rendering fallback',
'description' => ' Test system module main content rendering fallback.',
'group' => 'System',
);
}
function setUp() {
parent::setUp('system_test');
// Create and login admin user.
$this->admin_user = $this->drupalCreateUser(array(
'access administration pages',
'administer site configuration',
2009-12-01 22:30:31 +00:00
'administer modules',
2009-10-18 05:28:43 +00:00
'administer blocks',
'administer nodes',
));
$this->drupalLogin($this->admin_user);
2008-12-16 23:57:33 +00:00
2009-10-18 05:28:43 +00:00
// Create a web user.
$this->web_user = $this->drupalCreateUser(array('access user profiles', 'access content'));
}
/**
* Test availability of main content.
*/
function testMainContentFallback() {
$edit = array();
// Disable the dashboard module, which depends on the block module.
$edit['modules[Core][dashboard][enable]'] = FALSE;
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2009-10-18 05:28:43 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
// Disable the block module.
$edit['modules[Core][block][enable]'] = FALSE;
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2009-10-18 05:28:43 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
module_list(TRUE);
$this->assertFalse(module_exists('block'), t('Block module disabled.'));
// At this point, no region is filled and fallback should be triggered.
$this->drupalGet('admin/config/system/site-information');
2009-12-01 22:30:31 +00:00
$this->assertField('site_name', t('Admin interface still available.'));
2009-10-18 05:28:43 +00:00
// Fallback should not trigger when another module is handling content.
$this->drupalGet('system-test/main-content-handling');
$this->assertRaw('id="system-test-content"', t('Content handled by another module'));
$this->assertText(t('Content to test main content fallback'), t('Main content still displayed.'));
// Fallback should trigger when another module
// indicates that it is not handling the content.
$this->drupalGet('system-test/main-content-fallback');
$this->assertText(t('Content to test main content fallback'), t('Main content fallback properly triggers.'));
// Fallback should not trigger when another module is handling content.
// Note that this test ensures that no duplicate
// content gets created by the fallback.
$this->drupalGet('system-test/main-content-duplication');
$this->assertNoText(t('Content to test main content fallback'), t('Main content not duplicated.'));
// Request a user* page and see if it is displayed.
$this->drupalLogin($this->web_user);
$this->drupalGet('user/' . $this->web_user->uid . '/edit');
2009-12-01 22:30:31 +00:00
$this->assertField('mail', t('User interface still available.'));
2009-10-18 05:28:43 +00:00
// Enable the block module again.
$this->drupalLogin($this->admin_user);
$edit = array();
$edit['modules[Core][block][enable]'] = 'block';
2010-01-04 21:31:52 +00:00
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
2009-10-18 05:28:43 +00:00
$this->assertText(t('The configuration options have been saved.'), t('Modules status has been updated.'));
module_list(TRUE);
$this->assertTrue(module_exists('block'), t('Block module re-enabled.'));
}
2008-12-16 23:57:33 +00:00
}
2009-01-11 21:19:19 +00:00
class SystemSettingsForm extends DrupalWebTestCase {
/**
2009-05-27 18:34:03 +00:00
* Implement getInfo().
2009-01-11 21:19:19 +00:00
*/
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-01-11 21:19:19 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'System setting forms',
'description' => 'Tests correctness of system_settings_form() processing.',
'group' => 'System'
2009-01-11 21:19:19 +00:00
);
}
/**
2009-05-27 18:34:03 +00:00
* Implement setUp().
2009-01-11 21:19:19 +00:00
*/
function setUp() {
parent::setUp();
variable_set('system_settings_form_test', TRUE);
variable_set('system_settings_form_test_4', TRUE);
}
/**
* Reset page title.
*/
function tearDown() {
variable_del('system_settings_form_test');
variable_del('system_settings_form_test_4');
2009-01-21 14:22:33 +00:00
2009-01-11 21:19:19 +00:00
parent::tearDown();
}
2009-01-21 14:22:33 +00:00
2009-01-11 21:19:19 +00:00
/**
* Tests the handling of automatic defaults in systems_settings_form().
*/
function testAutomaticDefaults() {
$form['system_settings_form_test'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['system_settings_form_test_2'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['system_settings_form_test_3'] = array(
'#type' => 'checkbox',
'#default_value' => TRUE,
);
$form['has_children']['system_settings_form_test_4'] = array(
'#type' => 'checkbox',
'#default_value' => FALSE,
);
$form['has_children']['system_settings_form_test_5'] = array(
'#type' => 'checkbox',
'#default_value' => TRUE,
);
$automatic = system_settings_form($form, FALSE);
$this->assertFalse($automatic['system_settings_form_test']['#default_value']);
$this->assertFalse($automatic['system_settings_form_test_2']['#default_value']);
$this->assertTrue($automatic['system_settings_form_test_3']['#default_value']);
$this->assertFalse($automatic['has_children']['system_settings_form_test_4']['#default_value']);
$this->assertTrue($automatic['has_children']['system_settings_form_test_5']['#default_value']);
$no_automatic = system_settings_form($form);
$this->assertTrue($no_automatic['system_settings_form_test']['#default_value']);
$this->assertFalse($no_automatic['system_settings_form_test_2']['#default_value']);
$this->assertTrue($no_automatic['system_settings_form_test_3']['#default_value']);
$this->assertTrue($no_automatic['has_children']['system_settings_form_test_4']['#default_value']);
$this->assertTrue($no_automatic['has_children']['system_settings_form_test_5']['#default_value']);
}
}
2009-02-11 05:33:18 +00:00
/**
* Tests for the theme interface functionality.
*/
class SystemThemeFunctionalTest extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2009-02-11 05:33:18 +00:00
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Theme interface functionality',
'description' => 'Tests the theme interface functionality by enabling and switching themes, and using an administration theme.',
'group' => 'System',
2009-02-11 05:33:18 +00:00
);
}
function setUp() {
parent::setUp();
2009-12-01 22:30:31 +00:00
$this->admin_user = $this->drupalCreateUser(array('access administration pages', 'administer themes', 'bypass node access'));
2009-02-11 05:33:18 +00:00
$this->drupalLogin($this->admin_user);
$this->node = $this->drupalCreateNode();
}
2009-12-24 16:54:56 +00:00
/**
* Test the theme settings form.
*/
function testThemeSettings() {
// Specify a filesystem path to be used for the logo.
$file = current($this->drupalGetTestFiles('image'));
$edit = array(
'default_logo' => FALSE,
'logo_path' => $file->uri,
);
$this->drupalPost('admin/appearance/settings', $edit, t('Save configuration'));
$this->drupalGet('node');
$this->assertRaw($file->uri, t('Logo path successfully changed.'));
// Upload a file to use for the logo.
$file = current($this->drupalGetTestFiles('image'));
$edit = array(
'default_logo' => FALSE,
'logo_path' => '',
'files[logo_upload]' => drupal_realpath($file->uri),
);
$options = array();
$this->drupalPost('admin/appearance/settings', $edit, t('Save configuration'), $options);
$this->drupalGet('node');
$this->assertRaw($file->name, t('Logo file successfully uploaded.'));
}
2009-02-11 05:33:18 +00:00
/**
* Test the administration theme functionality.
*/
function testAdministrationTheme() {
2009-12-01 00:39:35 +00:00
theme_enable(array('stark'));
variable_set('theme_default', 'stark');
2009-02-11 05:33:18 +00:00
// Enable an administration theme and show it on the node admin pages.
$edit = array(
'admin_theme' => 'garland',
'node_admin_theme' => TRUE,
);
2009-07-31 11:20:43 +00:00
$this->drupalPost('admin/appearance', $edit, t('Save configuration'));
2009-02-11 05:33:18 +00:00
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Administration theme used on an administration page.'));
$this->drupalGet('node/' . $this->node->nid);
$this->assertRaw('themes/stark', t('Site default theme used on node page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/garland', t('Administration theme used on the add content page.'));
$this->drupalGet('node/' . $this->node->nid . '/edit');
$this->assertRaw('themes/garland', t('Administration theme used on the edit content page.'));
// Disable the admin theme on the node admin pages.
$edit = array(
'node_admin_theme' => FALSE,
);
2009-07-31 11:20:43 +00:00
$this->drupalPost('admin/appearance', $edit, t('Save configuration'));
2009-05-24 17:39:35 +00:00
2009-02-11 05:33:18 +00:00
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Administration theme used on an administration page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/stark', t('Site default theme used on the add content page.'));
// Reset to the default theme settings.
2009-12-01 00:39:35 +00:00
variable_set('theme_default', 'garland');
2009-07-16 10:44:21 +00:00
$edit = array(
'admin_theme' => '0',
'node_admin_theme' => FALSE,
);
2009-07-31 11:20:43 +00:00
$this->drupalPost('admin/appearance', $edit, t('Save configuration'));
2009-05-24 17:39:35 +00:00
2009-02-11 05:33:18 +00:00
$this->drupalGet('admin');
$this->assertRaw('themes/garland', t('Site default theme used on administration page.'));
$this->drupalGet('node/add');
$this->assertRaw('themes/garland', t('Site default theme used on the add content page.'));
}
}
- Patch #391340 by chx, dww, neclimdul, Crell, alex_b, et al: job queue API.
The queue system allows placing items in a queue and processing them later. The system tries to ensure that only one consumer can process an item.
Before a queue can be used it needs to be created by DrupalQueueInterface::createQueue().
Items can be added to the queue by passing an arbitrary data object to DrupalQueueInterface::createItem().
To process an item, call DrupalQueueInterface::claimItem() and specify how long you want to have a lease for working on that item. When finished processing, the item needs to be deleted by calling DrupalQueueInterface::deleteItem(). If the consumer dies, the item will be made available again by the DrapalQueueInterface implementation once the lease expires. Another consumer will then be able to receive it when calling DrupalQueueInterface::claimItem().
The $item object used by the DrupalQueueInterface can contain arbitrary metadata depending on the implementation. Systems using the interface should only rely on the data property which will contain the information passed to DrupalQueueInterface::createItem(). The full queue item returned by DrupalQueueInterface::createItem() needs to be passed to DrupalQueueInterface::deleteItem() once processing is completed.
While the queue system makes a best effort to preserve order in messages, due to the pluggable nature of the queue, there is no guarantee that items will be delivered on claim in the order they were sent. For example, some implementations like beanstalkd or others with distributed back-ends like Amazon SQS will be managing jobs for a large set of producers and consumers where a strict FIFO ordering will likely not be preserved.
The system also makes no guarantees about a task only being executed once: callers that have non-idempotent tasks either need to live with the possiblity of the task being invoked multiple times in cases where a claim lease expires, or need to implement their own transactions to make their tasks idempotent.
2009-05-06 10:37:28 +00:00
/**
* Test the basic queue functionality.
*/
class QueueTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Queue functionality',
'description' => 'Queues and dequeues a set of items to check the basic queue functionality.',
'group' => 'System',
- Patch #391340 by chx, dww, neclimdul, Crell, alex_b, et al: job queue API.
The queue system allows placing items in a queue and processing them later. The system tries to ensure that only one consumer can process an item.
Before a queue can be used it needs to be created by DrupalQueueInterface::createQueue().
Items can be added to the queue by passing an arbitrary data object to DrupalQueueInterface::createItem().
To process an item, call DrupalQueueInterface::claimItem() and specify how long you want to have a lease for working on that item. When finished processing, the item needs to be deleted by calling DrupalQueueInterface::deleteItem(). If the consumer dies, the item will be made available again by the DrapalQueueInterface implementation once the lease expires. Another consumer will then be able to receive it when calling DrupalQueueInterface::claimItem().
The $item object used by the DrupalQueueInterface can contain arbitrary metadata depending on the implementation. Systems using the interface should only rely on the data property which will contain the information passed to DrupalQueueInterface::createItem(). The full queue item returned by DrupalQueueInterface::createItem() needs to be passed to DrupalQueueInterface::deleteItem() once processing is completed.
While the queue system makes a best effort to preserve order in messages, due to the pluggable nature of the queue, there is no guarantee that items will be delivered on claim in the order they were sent. For example, some implementations like beanstalkd or others with distributed back-ends like Amazon SQS will be managing jobs for a large set of producers and consumers where a strict FIFO ordering will likely not be preserved.
The system also makes no guarantees about a task only being executed once: callers that have non-idempotent tasks either need to live with the possiblity of the task being invoked multiple times in cases where a claim lease expires, or need to implement their own transactions to make their tasks idempotent.
2009-05-06 10:37:28 +00:00
);
}
/**
* Queues and dequeues a set of items to check the basic queue functionality.
*/
function testQueue() {
// Create two queues.
$queue1 = DrupalQueue::get($this->randomName());
$queue1->createQueue();
$queue2 = DrupalQueue::get($this->randomName());
$queue2->createQueue();
// Create four items.
$data = array();
for ($i = 0; $i < 4; $i++) {
$data[] = array($this->randomName() => $this->randomName());
}
// Queue items 1 and 2 in the queue1.
$queue1->createItem($data[0]);
$queue1->createItem($data[1]);
// Retrieve two items from queue1.
$items = array();
$new_items = array();
$items[] = $item = $queue1->claimItem();
$new_items[] = $item->data;
$items[] = $item = $queue1->claimItem();
$new_items[] = $item->data;
// First two dequeued items should match the first two items we queued.
$this->assertEqual($this->queueScore($data, $new_items), 2, t('Two items matched'));
// Add two more items.
$queue1->createItem($data[2]);
$queue1->createItem($data[3]);
$this->assertTrue($queue1->numberOfItems(), t('Queue 1 is not empty after adding items.'));
$this->assertFalse($queue2->numberOfItems(), t('Queue 2 is empty while Queue 1 has items'));
$items[] = $item = $queue1->claimItem();
$new_items[] = $item->data;
$items[] = $item = $queue1->claimItem();
$new_items[] = $item->data;
// All dequeued items should match the items we queued exactly once,
// therefore the score must be exactly 4.
$this->assertEqual($this->queueScore($data, $new_items), 4, t('Four items matched'));
// There should be no duplicate items.
$this->assertEqual($this->queueScore($new_items, $new_items), 4, t('Four items matched'));
// Delete all items from queue1.
foreach ($items as $item) {
$queue1->deleteItem($item);
}
// Check that both queues are empty.
$this->assertFalse($queue1->numberOfItems(), t('Queue 1 is empty'));
$this->assertFalse($queue2->numberOfItems(), t('Queue 2 is empty'));
}
/**
* This function returns the number of equal items in two arrays.
*/
function queueScore($items, $new_items) {
$score = 0;
foreach ($items as $item) {
foreach ($new_items as $new_item) {
if ($item === $new_item) {
$score++;
}
}
}
return $score;
}
}
2009-08-19 20:19:37 +00:00
/**
* Test token replacement in strings.
*/
class TokenReplaceTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Token replacement',
'description' => 'Generates text using placeholders for dummy content to check token replacement.',
'group' => 'System',
);
}
/**
* Creates a user and a node, then tests the tokens generated from them.
*/
function testTokenReplacement() {
// Create the initial objects.
$account = $this->drupalCreateUser();
$node = $this->drupalCreateNode(array('uid' => $account->uid));
2010-01-09 21:54:01 +00:00
$node->title = '<blink>Blinking Text</blink>';
2009-09-30 18:37:30 +00:00
global $user, $language;
2009-08-19 20:19:37 +00:00
$source = '[node:title]'; // Title of the node we passed in
$source .= '[node:author:name]'; // Node author's name
$source .= '[node:created:since]'; // Time since the node was created
$source .= '[current-user:name]'; // Current user's name
$source .= '[user:name]'; // No user passed in, should be untouched
2009-08-25 10:27:15 +00:00
$source .= '[date:short]'; // Short date format of REQUEST_TIME
2009-08-19 20:19:37 +00:00
$source .= '[bogus:token]'; // Nonexistent token, should be untouched
2010-01-09 21:54:01 +00:00
$target = check_plain($node->title);
2009-08-19 20:19:37 +00:00
$target .= check_plain($account->name);
2009-09-30 18:37:30 +00:00
$target .= format_interval(REQUEST_TIME - $node->created, 2, $language->language);
2009-08-19 20:19:37 +00:00
$target .= check_plain($user->name);
$target .= '[user:name]';
2009-09-30 18:37:30 +00:00
$target .= format_date(REQUEST_TIME, 'short', '', NULL, $language->language);
2009-08-19 20:19:37 +00:00
$target .= '[bogus:token]';
2009-09-30 18:37:30 +00:00
$result = token_replace($source, array('node' => $node), array('language' => $language));
2009-08-19 20:19:37 +00:00
// Check that the results of token_generate are sanitized properly. This does NOT
// test the cleanliness of every token -- just that the $sanitize flag is being
// passed properly through the call stack and being handled correctly by a 'known'
// token, [node:title].
$this->assertFalse(strcmp($target, $result), t('Basic placeholder tokens replaced.'));
2009-10-09 07:48:07 +00:00
2009-08-23 13:02:38 +00:00
$raw_tokens = array('title' => '[node:title]');
$generated = token_generate('node', $raw_tokens, array('node' => $node));
2010-01-09 21:54:01 +00:00
$this->assertFalse(strcmp($generated['[node:title]'], check_plain($node->title)), t('Token sanitized.'));
2009-08-19 20:19:37 +00:00
2009-08-23 13:02:38 +00:00
$generated = token_generate('node', $raw_tokens, array('node' => $node), array('sanitize' => FALSE));
2010-01-09 21:54:01 +00:00
$this->assertFalse(strcmp($generated['[node:title]'], $node->title), t('Unsanitized token generated properly.'));
2009-08-19 20:19:37 +00:00
}
}
2009-10-02 00:50:45 +00:00
class InfoFileParserTestCase extends DrupalUnitTestCase {
public static function getInfo() {
return array(
'name' => 'Info file format parser',
'description' => 'Tests proper parsing of a .info file formatted string.',
'group' => 'System',
);
}
/**
* Test drupal_parse_info_format().
*/
function testDrupalParseInfoFormat() {
$config = '
simple = Value
quoted = " Value"
multiline = "Value
Value"
array[] = Value1
array[] = Value2
array_assoc[a] = Value1
array_assoc[b] = Value2
array_deep[][][] = Value
array_deep_assoc[a][b][c] = Value
array_space[a b] = Value';
$expected = array(
'simple' => 'Value',
'quoted' => ' Value',
'multiline' => "Value\n Value",
'array' => array(
0 => 'Value1',
1 => 'Value2',
),
'array_assoc' => array(
'a' => 'Value1',
'b' => 'Value2',
),
'array_deep' => array(
0 => array(
0 => array(
0 => 'Value',
),
),
),
'array_deep_assoc' => array(
'a' => array(
'b' => array(
'c' => 'Value',
),
),
),
'array_space' => array(
'a b' => 'Value',
),
);
$parsed = drupal_parse_info_format($config);
$this->assertEqual($parsed['simple'], $expected['simple'], t('Set a simple value.'));
$this->assertEqual($parsed['quoted'], $expected['quoted'], t('Set a simple value in quotes.'));
$this->assertEqual($parsed['multiline'], $expected['multiline'], t('Set a multiline value.'));
$this->assertEqual($parsed['array'], $expected['array'], t('Set a simple array.'));
$this->assertEqual($parsed['array_assoc'], $expected['array_assoc'], t('Set an associative array.'));
$this->assertEqual($parsed['array_deep'], $expected['array_deep'], t('Set a nested array.'));
$this->assertEqual($parsed['array_deep_assoc'], $expected['array_deep_assoc'], t('Set a nested associative array.'));
$this->assertEqual($parsed['array_space'], $expected['array_space'], t('Set an array with a whitespace in the key.'));
$this->assertEqual($parsed, $expected, t('Entire parsed .info string and expected array are identical.'));
}
}
2009-10-09 07:48:07 +00:00
/**
* 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);
}
}
2009-10-18 11:34:45 +00:00
/**
* 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));
}
}