- 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-10-09 16:14:16 +00:00
/**
* Tests for text format and filter CRUD operations.
*/
class FilterCRUDTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Filter CRUD operations',
'description' => 'Test creation, loading, updating, deleting of text formats and filters.',
'group' => 'Filter',
);
}
2009-11-30 00:42:01 +00:00
function setUp() {
parent::setUp('filter_test');
}
2009-10-09 16:14:16 +00:00
/**
* Test CRUD operations for text formats and filters.
*/
function testTextFormatCRUD() {
// Add a text format with minimum data only.
2010-06-17 13:16:57 +00:00
$format = new stdClass();
2010-10-20 01:15:58 +00:00
$format->format = 'empty_format';
2009-10-09 16:14:16 +00:00
$format->name = 'Empty format';
filter_format_save($format);
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Add another text format specifying all possible properties.
2010-06-17 13:16:57 +00:00
$format = new stdClass();
2010-10-20 01:15:58 +00:00
$format->format = 'custom_format';
2009-10-09 16:14:16 +00:00
$format->name = 'Custom format';
$format->filters = array(
'filter_url' => array(
'status' => 1,
'settings' => array(
'filter_url_length' => 30,
),
),
);
filter_format_save($format);
$this->verifyTextFormat($format);
$this->verifyFilters($format);
// Alter some text format properties and save again.
$format->name = 'Altered format';
$format->filters['filter_url']['status'] = 0;
$format->filters['filter_autop']['status'] = 1;
filter_format_save($format);
$this->verifyTextFormat($format);
$this->verifyFilters($format);
2009-11-30 00:42:01 +00:00
// Add a uncacheable filter and save again.
$format->filters['filter_test_uncacheable']['status'] = 1;
filter_format_save($format);
$this->verifyTextFormat($format);
$this->verifyFilters($format);
2010-09-18 02:18:35 +00:00
// Disable the text format.
filter_format_disable($format);
2009-10-09 16:14:16 +00:00
$db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
2010-09-18 02:18:35 +00:00
$this->assertFalse($db_format->status, t('Database: Disabled text format is marked as disabled.'));
2009-10-09 16:14:16 +00:00
$formats = filter_formats();
2010-09-18 02:18:35 +00:00
$this->assertTrue(!isset($formats[$format->format]), t('filter_formats: Disabled text format no longer exists.'));
2009-10-09 16:14:16 +00:00
}
/**
* Verify that a text format is properly stored.
*/
function verifyTextFormat($format) {
$t_args = array('%format' => $format->name);
// Verify text format database record.
$db_format = db_select('filter_format', 'ff')
->fields('ff')
->condition('format', $format->format)
->execute()
->fetchObject();
2010-08-05 23:53:39 +00:00
$this->assertEqual($db_format->format, $format->format, t('Database: Proper format id for text format %format.', $t_args));
$this->assertEqual($db_format->name, $format->name, t('Database: Proper title for text format %format.', $t_args));
$this->assertEqual($db_format->cache, $format->cache, t('Database: Proper cache indicator for text format %format.', $t_args));
$this->assertEqual($db_format->weight, $format->weight, t('Database: Proper weight for text format %format.', $t_args));
2009-10-09 16:14:16 +00:00
// Verify filter_format_load().
$filter_format = filter_format_load($format->format);
2010-08-05 23:53:39 +00:00
$this->assertEqual($filter_format->format, $format->format, t('filter_format_load: Proper format id for text format %format.', $t_args));
$this->assertEqual($filter_format->name, $format->name, t('filter_format_load: Proper title for text format %format.', $t_args));
$this->assertEqual($filter_format->cache, $format->cache, t('filter_format_load: Proper cache indicator for text format %format.', $t_args));
$this->assertEqual($filter_format->weight, $format->weight, t('filter_format_load: Proper weight for text format %format.', $t_args));
2009-11-30 00:42:01 +00:00
// Verify the 'cache' text format property according to enabled filters.
$filter_info = filter_get_filters();
$filters = filter_list_format($filter_format->format);
$cacheable = TRUE;
foreach ($filters as $name => $filter) {
// If this filter is not cacheable, update $cacheable accordingly, so we
// can verify $format->cache after iterating over all filters.
2009-12-03 15:33:42 +00:00
if ($filter->status && isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
2009-11-30 00:42:01 +00:00
$cacheable = FALSE;
2009-12-03 15:33:42 +00:00
break;
2009-11-30 00:42:01 +00:00
}
}
2010-08-05 23:53:39 +00:00
$this->assertEqual($filter_format->cache, $cacheable, t('Text format contains proper cache property.'));
2009-10-09 16:14:16 +00:00
}
/**
* Verify that filters are properly stored for a text format.
*/
function verifyFilters($format) {
// Verify filter database records.
$filters = db_query("SELECT * FROM {filter} WHERE format = :format", array(':format' => $format->format))->fetchAllAssoc('name');
$format_filters = $format->filters;
foreach ($filters as $name => $filter) {
$t_args = array('%format' => $format->name, '%filter' => $name);
2009-11-30 00:42:01 +00:00
2009-12-03 15:33:42 +00:00
// Verify that filter status is properly stored.
2010-08-05 23:53:39 +00:00
$this->assertEqual($filter->status, $format_filters[$name]['status'], t('Database: Proper status for %filter in text format %format.', $t_args));
2009-11-30 00:42:01 +00:00
2009-12-03 15:33:42 +00:00
// Verify that filter settings were properly stored.
2010-08-05 23:53:39 +00:00
$this->assertEqual(unserialize($filter->settings), isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('Database: Proper filter settings for %filter in text format %format.', $t_args));
2009-11-30 00:42:01 +00:00
2009-10-09 16:14:16 +00:00
// Verify that each filter has a module name assigned.
2010-08-05 23:53:39 +00:00
$this->assertTrue(!empty($filter->module), t('Database: Proper module name for %filter in text format %format.', $t_args));
2009-10-09 16:14:16 +00:00
// Remove the filter from the copy of saved $format to check whether all
// filters have been processed later.
unset($format_filters[$name]);
}
2009-11-30 00:42:01 +00:00
// Verify that all filters have been processed.
2010-08-05 23:53:39 +00:00
$this->assertTrue(empty($format_filters), t('Database contains values for all filters in the saved format.'));
2009-10-09 16:14:16 +00:00
// Verify filter_list_format().
2009-11-22 08:14:27 +00:00
$filters = filter_list_format($format->format);
2009-10-09 16:14:16 +00:00
$format_filters = $format->filters;
foreach ($filters as $name => $filter) {
$t_args = array('%format' => $format->name, '%filter' => $name);
2009-11-30 00:42:01 +00:00
2009-12-03 15:33:42 +00:00
// Verify that filter status is properly stored.
2010-08-05 23:53:39 +00:00
$this->assertEqual($filter->status, $format_filters[$name]['status'], t('filter_list_format: Proper status for %filter in text format %format.', $t_args));
2009-11-30 00:42:01 +00:00
2009-12-03 15:33:42 +00:00
// Verify that filter settings were properly stored.
2010-08-05 23:53:39 +00:00
$this->assertEqual($filter->settings, isset($format_filters[$name]['settings']) ? $format_filters[$name]['settings'] : array(), t('filter_list_format: Proper filter settings for %filter in text format %format.', $t_args));
2009-11-30 00:42:01 +00:00
2009-10-09 16:14:16 +00:00
// Verify that each filter has a module name assigned.
2010-08-05 23:53:39 +00:00
$this->assertTrue(!empty($filter->module), t('filter_list_format: Proper module name for %filter in text format %format.', $t_args));
2009-10-09 16:14:16 +00:00
// Remove the filter from the copy of saved $format to check whether all
// filters have been processed later.
unset($format_filters[$name]);
}
2009-11-30 00:42:01 +00:00
// Verify that all filters have been processed.
2010-08-05 23:53:39 +00:00
$this->assertTrue(empty($format_filters), t('filter_list_format: Loaded filters contain values for all filters in the saved format.'));
2009-10-09 16:14:16 +00:00
}
}
2008-05-05 20:42:08 +00:00
class FilterAdminTestCase extends DrupalWebTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
- 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
return array(
2009-07-13 21:51:42 +00:00
'name' => 'Filter administration functionality',
'description' => 'Thoroughly test the administrative interface of the filter module.',
'group' => 'Filter',
- 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-09-25 14:06:09 +00:00
function setUp() {
parent::setUp();
// Create users.
2010-03-06 19:40:21 +00:00
$filtered_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Filtered HTML'))->fetchObject();
$full_html_format = db_query_range('SELECT * FROM {filter_format} WHERE name = :name', 0, 1, array(':name' => 'Full HTML'))->fetchObject();
2010-03-05 13:32:10 +00:00
$this->admin_user = $this->drupalCreateUser(array(
'administer filters',
2010-03-06 19:40:21 +00:00
filter_permission_name($filtered_html_format),
filter_permission_name($full_html_format),
2010-03-05 13:32:10 +00:00
));
2009-09-25 14:06:09 +00:00
$this->web_user = $this->drupalCreateUser(array('create page content', 'edit own page content'));
$this->drupalLogin($this->admin_user);
}
function testFormatAdmin() {
// Add text format.
$this->drupalGet('admin/config/content/formats');
$this->clickLink('Add text format');
$edit = array(
2010-10-20 01:15:58 +00:00
'format' => drupal_strtolower($this->randomName()),
2009-09-25 14:06:09 +00:00
'name' => $this->randomName(),
);
$this->drupalPost(NULL, $edit, t('Save configuration'));
// Edit text format.
2009-10-13 15:39:41 +00:00
$format = $this->getFormat($edit['name']);
2009-09-25 14:06:09 +00:00
$this->drupalGet('admin/config/content/formats');
$this->assertRaw('admin/config/content/formats/' . $format->format);
$this->drupalGet('admin/config/content/formats/' . $format->format);
$this->drupalPost(NULL, array(), t('Save configuration'));
2010-09-18 02:18:35 +00:00
// Disable text format.
2009-09-25 14:06:09 +00:00
$this->drupalGet('admin/config/content/formats');
2010-09-18 02:18:35 +00:00
$this->assertRaw('admin/config/content/formats/' . $format->format . '/disable');
$this->drupalGet('admin/config/content/formats/' . $format->format . '/disable');
$this->drupalPost(NULL, array(), t('Disable'));
2009-09-25 14:06:09 +00:00
2010-09-18 02:18:35 +00:00
// Verify that disabled text format no longer exists.
2009-09-25 14:06:09 +00:00
$this->drupalGet('admin/config/content/formats/' . $format->format);
2010-09-18 02:18:35 +00:00
$this->assertResponse(404, t('Disabled text format no longer exists.'));
2009-09-25 14:06:09 +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
/**
* Test filter administration functionality.
*/
2008-05-05 20:42:08 +00:00
function testFilterAdmin() {
2009-06-28 18:03:56 +00:00
// URL filter.
2009-08-21 17:28:27 +00:00
$first_filter = 'filter_url';
2009-06-28 18:03:56 +00:00
// Line filter.
2009-08-27 21:18:20 +00:00
$second_filter = 'filter_autop';
- 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
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
list($filtered, $full, $plain) = $this->checkFilterFormats();
- 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
2010-09-18 02:18:35 +00:00
// Check that the fallback format exists and cannot be disabled.
2010-08-05 23:53:39 +00:00
$this->assertTrue(!empty($plain) && $plain == filter_fallback_format(), t('The fallback format is set to plain text.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$this->drupalGet('admin/config/content/formats');
2010-09-18 02:18:35 +00:00
$this->assertNoRaw('admin/config/content/formats/' . $plain . '/disable', t('Disable link for the fallback format not found.'));
$this->drupalGet('admin/config/content/formats/' . $plain . '/disable');
$this->assertResponse(403, t('The fallback format cannot be disabled.'));
2009-09-12 06:09:45 +00:00
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Verify access permissions to Full HTML format.
2010-08-05 23:53:39 +00:00
$this->assertTrue(filter_access(filter_format_load($full), $this->admin_user), t('Admin user may use Full HTML.'));
$this->assertFalse(filter_access(filter_format_load($full), $this->web_user), t('Web user may not use Full HTML.'));
- 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
// Add an additional tag.
$edit = array();
2009-12-14 13:32:53 +00:00
$edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <quote>';
$this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], t('Allowed HTML tag added.'));
- 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-04-25 18:01:10 +00:00
$result = db_query('SELECT * FROM {cache_filter}')->fetchObject();
2010-08-05 23:53:39 +00:00
$this->assertFalse($result, t('Cache cleared.'));
- 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
2010-03-31 20:05:06 +00:00
$elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
':first' => 'filters[' . $first_filter . '][weight]',
':second' => 'filters[' . $second_filter . '][weight]',
));
2010-08-05 23:53:39 +00:00
$this->assertTrue(!empty($elements), t('Order confirmed in admin interface.'));
2010-02-05 21:44:35 +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
// Reorder filters.
$edit = array();
2009-12-14 13:32:53 +00:00
$edit['filters[' . $second_filter . '][weight]'] = 1;
$edit['filters[' . $first_filter . '][weight]'] = 2;
$this->drupalPost(NULL, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('filters[' . $second_filter . '][weight]', 1, t('Order saved successfully.'));
$this->assertFieldByName('filters[' . $first_filter . '][weight]', 2, t('Order saved successfully.'));
- 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
2010-03-31 20:05:06 +00:00
$elements = $this->xpath('//select[@name=:first]/following::select[@name=:second]', array(
':first' => 'filters[' . $second_filter . '][weight]',
':second' => 'filters[' . $first_filter . '][weight]',
));
2010-08-05 23:53:39 +00:00
$this->assertTrue(!empty($elements), t('Reorder confirmed in admin interface.'));
2010-02-05 21:44:35 +00:00
2009-04-25 18:01:10 +00:00
$result = db_query('SELECT * FROM {filter} WHERE format = :format ORDER BY weight ASC', array(':format' => $filtered));
- 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
$filters = array();
2009-04-25 18:01:10 +00:00
foreach ($result as $filter) {
2009-08-21 17:28:27 +00:00
if ($filter->name == $second_filter || $filter->name == $first_filter) {
- 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
$filters[] = $filter;
}
}
2010-08-05 23:53:39 +00:00
$this->assertTrue(($filters[0]->name == $second_filter && $filters[1]->name == $first_filter), t('Order confirmed in database.'));
- 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-12-08 03:10:51 +00:00
// Add format.
- 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();
2010-10-20 01:15:58 +00:00
$edit['format'] = drupal_strtolower($this->randomName());
- 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['name'] = $this->randomName();
2009-08-27 21:18:20 +00:00
$edit['roles[2]'] = 1;
2009-09-11 15:39:48 +00:00
$edit['filters[' . $second_filter . '][status]'] = TRUE;
$edit['filters[' . $first_filter . '][status]'] = TRUE;
2009-08-28 16:23:05 +00:00
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('Added text format %format.', array('%format' => $edit['name'])), t('New filter created.'));
- 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-10-13 15:39:41 +00:00
$format = $this->getFormat($edit['name']);
2010-08-05 23:53:39 +00:00
$this->assertNotNull($format, t('Format found in database.'));
- 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
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('roles[2]', '', t('Role found.'));
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', t('Line break filter found.'));
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', t('Url filter found.'));
- 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
2010-09-18 02:18:35 +00:00
// Disable new filter.
$this->drupalPost('admin/config/content/formats/' . $format->format . '/disable', array(), t('Disable'));
$this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), t('Format successfully disabled.'));
- 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
// Allow authenticated users on full HTML.
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$format = filter_format_load($full);
- 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();
2009-08-27 21:18:20 +00:00
$edit['roles[1]'] = 0;
$edit['roles[2]'] = 1;
2009-08-28 16:23:05 +00:00
$this->drupalPost('admin/config/content/formats/' . $full, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->name)), t('Full HTML format successfully 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
// Switch user.
$this->drupalLogout();
2009-09-25 14:06:09 +00:00
$this->drupalLogin($this->web_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
$this->drupalGet('node/add/page');
2010-08-05 23:53:39 +00:00
$this->assertRaw('<option value="' . $full . '">Full HTML</option>', t('Full HTML filter accessible.'));
- 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-06-28 18:03:56 +00:00
// Use filtered HTML and see if it removes tags that are not allowed.
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$body = '<em>' . $this->randomName() . '</em>';
- 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
$extra_text = 'text';
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$text = $body . '<random>' . $extra_text . '</random>';
- 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();
2009-12-02 19:26:23 +00:00
$langcode = LANGUAGE_NONE;
2010-01-09 21:54:01 +00:00
$edit["title"] = $this->randomName();
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$edit["body[$langcode][0][value]"] = $text;
2010-03-07 23:14:20 +00:00
$edit["body[$langcode][0][format]"] = $filtered;
- 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('node/add/page', $edit, t('Save'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('Basic page %title has been created.', array('%title' => $edit["title"])), t('Filtered node created.'));
- 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
2010-01-09 21:54:01 +00:00
$node = $this->drupalGetNodeByTitle($edit["title"]);
2010-08-05 23:53:39 +00:00
$this->assertTrue($node, t('Node found in database.'));
- 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-05 20:42:08 +00:00
$this->drupalGet('node/' . $node->nid);
2010-08-05 23:53:39 +00:00
$this->assertRaw($body . $extra_text, t('Filter removed invalid tag.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Use plain text and see if it escapes all tags, whether allowed or not.
$edit = array();
2010-03-07 23:14:20 +00:00
$edit["body[$langcode][0][format]"] = $plain;
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->drupalGet('node/' . $node->nid);
2010-08-05 23:53:39 +00:00
$this->assertText(check_plain($text), t('The "Plain text" text format escapes all HTML tags.'));
- 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
// Switch user.
$this->drupalLogout();
2009-09-25 14:06:09 +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
// Clean up.
2008-04-25 18:26:02 +00:00
// Allowed tags.
- 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();
2009-12-14 13:32:53 +00:00
$edit['filters[filter_html][settings][allowed_html]'] = '<a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>';
$this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('filters[filter_html][settings][allowed_html]', $edit['filters[filter_html][settings][allowed_html]'], t('Changes reverted.'));
- 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-04-25 18:26:02 +00:00
// Full HTML.
- 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['roles[2]'] = FALSE;
2009-08-28 16:23:05 +00:00
$this->drupalPost('admin/config/content/formats/' . $full, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->name)), t('Full HTML format successfully reverted.'));
$this->assertFieldByName('roles[2]', $edit['roles[2]'], t('Changes reverted.'));
- 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-04-25 18:26:02 +00:00
// Filter order.
- 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();
2009-12-14 13:32:53 +00:00
$edit['filters[' . $second_filter . '][weight]'] = 2;
$edit['filters[' . $first_filter . '][weight]'] = 1;
$this->drupalPost('admin/config/content/formats/' . $filtered, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertFieldByName('filters[' . $second_filter . '][weight]', $edit['filters[' . $second_filter . '][weight]'], t('Changes reverted.'));
$this->assertFieldByName('filters[' . $first_filter . '][weight]', $edit['filters[' . $first_filter . '][weight]'], t('Changes reverted.'));
- 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
}
/**
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
* Query the database to get the three basic formats.
- 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-06-28 18:03:56 +00:00
* @return
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
* An array containing filtered, full, and plain text format ids.
- 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 checkFilterFormats() {
2008-12-03 16:32:22 +00:00
$result = db_query('SELECT format, name FROM {filter_format}');
- 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
$filtered = -1;
$full = -1;
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$plain = -1;
2009-04-25 18:01:10 +00:00
foreach ($result as $format) {
- 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
if ($format->name == 'Filtered HTML') {
$filtered = $format->format;
}
2008-10-12 04:30:09 +00:00
elseif ($format->name == 'Full HTML') {
- 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
$full = $format->format;
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
elseif ($format->name == 'Plain text') {
$plain = $format->format;
}
- 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
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
return array($filtered, $full, $plain);
- 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-10-13 15:39:41 +00:00
* Retrieve a text format object by name.
- 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-06-28 18:03:56 +00:00
* @param $name
2009-10-13 15:39:41 +00:00
* The name of a text format.
2009-06-28 18:03:56 +00:00
* @return
2009-10-13 15:39:41 +00:00
* A text format object.
- 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-10-13 15:39:41 +00:00
function getFormat($name) {
2009-04-25 18:01:10 +00:00
return db_query("SELECT * FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchObject();
- 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-05 20:42:08 +00:00
2010-04-10 11:11:46 +00:00
class FilterFormatAccessTestCase extends DrupalWebTestCase {
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
protected $admin_user;
2010-09-28 03:30:37 +00:00
protected $filter_admin_user;
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
protected $web_user;
protected $allowed_format;
protected $disallowed_format;
public static function getInfo() {
return array(
2010-04-10 11:11:46 +00:00
'name' => 'Filter format access',
'description' => 'Tests access to text formats.',
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
'group' => 'Filter',
);
}
function setUp() {
parent::setUp();
2010-09-28 03:30:37 +00:00
// Create a user who can administer text formats, but does not have
// specific permission to use any of them.
$this->filter_admin_user = $this->drupalCreateUser(array(
2010-04-10 11:11:46 +00:00
'administer filters',
'create page content',
'edit any page content',
));
2010-09-28 03:30:37 +00:00
// Create two text formats.
$this->drupalLogin($this->filter_admin_user);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$formats = array();
for ($i = 0; $i < 2; $i++) {
2010-10-20 01:15:58 +00:00
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$formats[] = filter_format_load($format_id);
}
list($this->allowed_format, $this->disallowed_format) = $formats;
2010-09-28 03:30:37 +00:00
$this->drupalLogout();
2010-04-10 11:11:46 +00:00
2010-09-28 03:30:37 +00:00
// Create a regular user with access to one of the formats.
2010-04-10 11:11:46 +00:00
$this->web_user = $this->drupalCreateUser(array(
'create page content',
2010-09-28 03:30:37 +00:00
'edit any page content',
2010-04-10 11:11:46 +00:00
filter_permission_name($this->allowed_format),
));
2010-09-28 03:30:37 +00:00
// Create an administrative user who has access to use both formats.
$this->admin_user = $this->drupalCreateUser(array(
'administer filters',
'create page content',
'edit any page content',
filter_permission_name($this->allowed_format),
filter_permission_name($this->disallowed_format),
));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
}
function testFormatPermissions() {
// Make sure that a regular user only has access to the text format they
// were granted access to, as well to the fallback format.
2010-08-05 23:53:39 +00:00
$this->assertTrue(filter_access($this->allowed_format, $this->web_user), t('A regular user has access to a text format they were granted access to.'));
$this->assertFalse(filter_access($this->disallowed_format, $this->web_user), t('A regular user does not have access to a text format they were not granted access to.'));
$this->assertTrue(filter_access(filter_format_load(filter_fallback_format()), $this->web_user), t('A regular user has access to the fallback format.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Perform similar checks as above, but now against the entire list of
// available formats for this user.
2010-08-05 23:53:39 +00:00
$this->assertTrue(in_array($this->allowed_format->format, array_keys(filter_formats($this->web_user))), t('The allowed format appears in the list of available formats for a regular user.'));
$this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_formats($this->web_user))), t('The disallowed format does not appear in the list of available formats for a regular user.'));
$this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_formats($this->web_user))), t('The fallback format appears in the list of available formats for a regular user.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Make sure that a regular user only has permission to use the format
// they were granted access to.
2010-08-05 23:53:39 +00:00
$this->assertTrue(user_access(filter_permission_name($this->allowed_format), $this->web_user), t('A regular user has permission to use the allowed text format.'));
$this->assertFalse(user_access(filter_permission_name($this->disallowed_format), $this->web_user), t('A regular user does not have permission to use the disallowed text format.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Make sure that the allowed format appears on the node form and that
// the disallowed format does not.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/add/page');
2010-08-05 23:53:39 +00:00
$this->assertRaw($this->formatSelectorHTML($this->allowed_format), t('The allowed text format appears as an option when adding a new node.'));
$this->assertNoRaw($this->formatSelectorHTML($this->disallowed_format), t('The disallowed text format does not appear as an option when adding a new node.'));
$this->assertRaw($this->formatSelectorHTML(filter_format_load(filter_fallback_format())), t('The fallback format appears as an option when adding a new node.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
}
function testFormatRoles() {
// Get the role ID assigned to the regular user; it must be the maximum.
$rid = max(array_keys($this->web_user->roles));
// Check that this role appears in the list of roles that have access to an
// allowed text format, but does not appear in the list of roles that have
// access to a disallowed text format.
2010-08-05 23:53:39 +00:00
$this->assertTrue(in_array($rid, array_keys(filter_get_roles_by_format($this->allowed_format))), t('A role which has access to a text format appears in the list of roles that have access to that format.'));
$this->assertFalse(in_array($rid, array_keys(filter_get_roles_by_format($this->disallowed_format))), t('A role which does not have access to a text format does not appear in the list of roles that have access to that format.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Check that the correct text format appears in the list of formats
// available to that role.
2010-08-05 23:53:39 +00:00
$this->assertTrue(in_array($this->allowed_format->format, array_keys(filter_get_formats_by_role($rid))), t('A text format which a role has access to appears in the list of formats available to that role.'));
$this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_get_formats_by_role($rid))), t('A text format which a role does not have access to does not appear in the list of formats available to that role.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Check that the fallback format is always allowed.
2010-08-05 23:53:39 +00:00
$this->assertEqual(filter_get_roles_by_format(filter_format_load(filter_fallback_format())), user_roles(), t('All roles have access to the fallback format.'));
$this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_get_formats_by_role($rid))), t('The fallback format appears in the list of allowed formats for any role.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
}
2010-04-10 11:11:46 +00:00
/**
* Test editing a page using a disallowed text format.
*
2010-09-28 03:30:37 +00:00
* Verifies that regular users and administrators are able to edit a page,
* but not allowed to change the fields which use an inaccessible text
* format. Also verifies that fields which use a text format that does not
* exist can be edited by administrators only, but that the administrator is
* forced to choose a new format before saving the page.
2010-04-10 11:11:46 +00:00
*/
function testFormatWidgetPermissions() {
$langcode = LANGUAGE_NONE;
$title_key = "title";
$body_value_key = "body[$langcode][0][value]";
$body_format_key = "body[$langcode][0][format]";
// Create node to edit.
$this->drupalLogin($this->admin_user);
$edit = array();
$edit['title'] = $this->randomName(8);
$edit[$body_value_key] = $this->randomName(16);
2010-09-28 03:30:37 +00:00
$edit[$body_format_key] = $this->disallowed_format->format;
2010-04-10 11:11:46 +00:00
$this->drupalPost('node/add/page', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title']);
// Try to edit with a less privileged user.
2010-09-28 03:30:37 +00:00
$this->drupalLogin($this->web_user);
2010-04-10 11:11:46 +00:00
$this->drupalGet('node/' . $node->nid);
$this->clickLink(t('Edit'));
// Verify that body field is read-only and contains replacement value.
2010-08-05 23:53:39 +00:00
$this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), t('Text format access denied message found.'));
2010-04-10 11:11:46 +00:00
// Verify that title can be changed, but preview displays original body.
$new_edit = array();
$new_edit['title'] = $this->randomName(8);
$this->drupalPost(NULL, $new_edit, t('Preview'));
2010-08-05 23:53:39 +00:00
$this->assertText($edit[$body_value_key], t('Old body found in preview.'));
2010-04-10 11:11:46 +00:00
// Save and verify that only the title was changed.
$this->drupalPost(NULL, $new_edit, t('Save'));
2010-08-05 23:53:39 +00:00
$this->assertNoText($edit['title'], t('Old title not found.'));
$this->assertText($new_edit['title'], t('New title found.'));
$this->assertText($edit[$body_value_key], t('Old body found.'));
2010-04-10 11:11:46 +00:00
2010-09-28 03:30:37 +00:00
// Check that even an administrator with "administer filters" permission
// cannot edit the body field if they do not have specific permission to
// use its stored format. (This must be disallowed so that the
// administrator is never forced to switch the text format to something
// else.)
$this->drupalLogin($this->filter_admin_user);
$this->drupalGet('node/' . $node->nid . '/edit');
$this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), t('Text format access denied message found.'));
// Disable the text format used above.
filter_format_disable($this->disallowed_format);
2010-04-10 11:11:46 +00:00
$this->resetFilterCaches();
2010-09-28 03:30:37 +00:00
// Log back in as the less privileged user and verify that the body field
// is still disabled, since the less privileged user should not be able to
// edit content that does not have an assigned format.
$this->drupalLogin($this->web_user);
$this->drupalGet('node/' . $node->nid . '/edit');
$this->assertFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", t('This field has been disabled because you do not have sufficient permissions to edit it.'), t('Text format access denied message found.'));
// Log back in as the filter administrator and verify that the body field
// can be edited.
$this->drupalLogin($this->filter_admin_user);
2010-04-10 11:11:46 +00:00
$this->drupalGet('node/' . $node->nid . '/edit');
2010-08-05 23:53:39 +00:00
$this->assertNoFieldByXPath("//textarea[@name='$body_value_key' and @disabled='disabled']", NULL, t('Text format access denied message not found.'));
$this->assertFieldByXPath("//select[@name='$body_format_key']", NULL, t('Text format selector found.'));
2010-09-28 03:30:37 +00:00
// Verify that trying to save the node without selecting a new text format
// produces an error message, and does not result in the node being saved.
$old_title = $new_edit['title'];
$new_title = $this->randomName(8);
$edit = array('title' => $new_title);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText(t('!name field is required.', array('!name' => t('Text format'))), t('Error message is displayed.'));
$this->drupalGet('node/' . $node->nid);
$this->assertText($old_title, t('Old title found.'));
$this->assertNoText($new_title, t('New title not found.'));
// Now select a new text format and make sure the node can be saved.
$edit[$body_format_key] = filter_fallback_format();
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertUrl('node/' . $node->nid);
$this->assertText($new_title, t('New title found.'));
$this->assertNoText($old_title, t('Old title not found.'));
// Switch the text format to a new one, then disable that format and all
// other formats on the site (leaving only the fallback format).
$this->drupalLogin($this->admin_user);
$edit = array($body_format_key => $this->allowed_format->format);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertUrl('node/' . $node->nid);
foreach (filter_formats() as $format) {
if ($format->format != filter_fallback_format()) {
filter_format_disable($format);
}
}
// Since there is now only one available text format, the widget for
// selecting a text format would normally not display when the content is
// edited. However, we need to verify that the filter administrator still
// is forced to make a conscious choice to reassign the text to a different
// format.
$this->drupalLogin($this->filter_admin_user);
$old_title = $new_title;
$new_title = $this->randomName(8);
$edit = array('title' => $new_title);
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertText(t('!name field is required.', array('!name' => t('Text format'))), t('Error message is displayed.'));
$this->drupalGet('node/' . $node->nid);
$this->assertText($old_title, t('Old title found.'));
$this->assertNoText($new_title, t('New title not found.'));
$edit[$body_format_key] = filter_fallback_format();
$this->drupalPost('node/' . $node->nid . '/edit', $edit, t('Save'));
$this->assertUrl('node/' . $node->nid);
$this->assertText($new_title, t('New title found.'));
$this->assertNoText($old_title, t('Old title not found.'));
2010-04-10 11:11:46 +00:00
}
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
/**
* Returns the expected HTML for a particular text format selector.
*
* @param $format
* An object representing the text format for which to return HTML.
* @return
* The expected HTML for that text format's selector.
*/
function formatSelectorHTML($format) {
return '<option value="' . $format->format . '">' . $format->name . '</option>';
}
/**
* Rebuild text format and permission caches in the thread running the tests.
*/
protected function resetFilterCaches() {
filter_formats_reset();
$this->checkPermissions(array(), TRUE);
}
}
class FilterDefaultFormatTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Default text format functionality',
'description' => 'Test the default text formats for different users.',
'group' => 'Filter',
);
}
2009-11-10 17:27:54 +00:00
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
function testDefaultTextFormats() {
// Create two text formats, and two users. The first user has access to
// both formats, but the second user only has access to the second one.
$admin_user = $this->drupalCreateUser(array('administer filters'));
$this->drupalLogin($admin_user);
$formats = array();
for ($i = 0; $i < 2; $i++) {
2010-10-20 01:15:58 +00:00
$edit = array(
'format' => drupal_strtolower($this->randomName()),
'name' => $this->randomName(),
);
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
$this->resetFilterCaches();
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $edit['name']))->fetchField();
$formats[] = filter_format_load($format_id);
}
list($first_format, $second_format) = $formats;
$first_user = $this->drupalCreateUser(array(filter_permission_name($first_format), filter_permission_name($second_format)));
$second_user = $this->drupalCreateUser(array(filter_permission_name($second_format)));
// Adjust the weights so that the first and second formats (in that order)
// are the two lowest weighted formats available to any user.
$minimum_weight = db_query("SELECT MIN(weight) FROM {filter_format}")->fetchField();
$edit = array();
$edit['formats[' . $first_format->format . '][weight]'] = $minimum_weight - 2;
$edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 1;
$this->drupalPost('admin/config/content/formats', $edit, t('Save changes'));
$this->resetFilterCaches();
// Check that each user's default format is the lowest weighted format that
// the user has access to.
2010-08-05 23:53:39 +00:00
$this->assertEqual(filter_default_format($first_user), $first_format->format, t("The first user's default format is the lowest weighted format that the user has access to."));
$this->assertEqual(filter_default_format($second_user), $second_format->format, t("The second user's default format is the lowest weighted format that the user has access to, and is different than the first user's."));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
// Reorder the two formats, and check that both users now have the same
// default.
$edit = array();
$edit['formats[' . $second_format->format . '][weight]'] = $minimum_weight - 3;
$this->drupalPost('admin/config/content/formats', $edit, t('Save changes'));
$this->resetFilterCaches();
2010-08-05 23:53:39 +00:00
$this->assertEqual(filter_default_format($first_user), filter_default_format($second_user), t('After the formats are reordered, both users have the same default format.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
}
/**
* Rebuild text format and permission caches in the thread running the tests.
*/
protected function resetFilterCaches() {
filter_formats_reset();
$this->checkPermissions(array(), TRUE);
}
}
class FilterNoFormatTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Unassigned text format functionality',
'description' => 'Test the behavior of check_markup() when it is called without a text format.',
'group' => 'Filter',
);
}
function testCheckMarkupNoFormat() {
// Create some text. Include some HTML and line breaks, so we get a good
// test of the filtering that is applied to it.
$text = "<strong>" . $this->randomName(32) . "</strong>\n\n<div>" . $this->randomName(32) . "</div>";
// Make sure that when this text is run through check_markup() with no text
// format, it is filtered as though it is in the fallback format.
2010-08-05 23:53:39 +00:00
$this->assertEqual(check_markup($text), check_markup($text, filter_fallback_format()), t('Text with no format is filtered the same as text in the fallback format.'));
- Patch #11218 by David_Rothstein, sun, quicksketch, duncf, awood456, dropcube, mgifford | pwolanin, dww, RobRoy, Crell, webchick, beginner, ray007, bjaspan, chx, Gábor Hojtsy, Steven, Dries, lutegrass, sym, guardian, matt2000, geerlingguy, SeanBannister, matt westgate, com2, praseodym: allow default text formats per role, and integrate text format permissions.
2009-09-20 07:32:19 +00:00
}
}
2010-08-22 12:55:04 +00:00
/**
* Security tests for missing/vanished text formats or filters.
*/
class FilterSecurityTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Security',
'description' => 'Test the behavior of check_markup() when a filter or text format vanishes.',
'group' => 'Filter',
);
}
function setUp() {
parent::setUp('php', 'filter_test');
$this->admin_user = $this->drupalCreateUser(array('administer modules', 'administer filters', 'administer site configuration'));
$this->drupalLogin($this->admin_user);
}
/**
* Test that filtered content is emptied when an actively used filter module is disabled.
*/
function testDisableFilterModule() {
// Create a new node.
$node = $this->drupalCreateNode(array('promote' => 1));
$body_raw = $node->body[LANGUAGE_NONE][0]['value'];
$format_id = $node->body[LANGUAGE_NONE][0]['format'];
$this->drupalGet('node/' . $node->nid);
$this->assertText($body_raw, t('Node body found.'));
// Enable the filter_test_replace filter.
$edit = array(
'filters[filter_test_replace][status]' => 1,
);
$this->drupalPost('admin/config/content/formats/' . $format_id, $edit, t('Save configuration'));
// Verify that filter_test_replace filter replaced the content.
$this->drupalGet('node/' . $node->nid);
$this->assertNoText($body_raw, t('Node body not found.'));
$this->assertText('Filter: Testing filter', t('Testing filter output found.'));
2010-09-18 02:18:35 +00:00
// Disable the text format entirely.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/disable', array(), t('Disable'));
2010-08-22 12:55:04 +00:00
// Verify that the content is empty, because the text format does not exist.
$this->drupalGet('node/' . $node->nid);
$this->assertNoText($body_raw, t('Node body not found.'));
}
}
2009-07-27 20:15:35 +00:00
/**
* Unit tests for core filters.
*/
2009-10-13 15:39:41 +00:00
class FilterUnitTestCase extends DrupalUnitTestCase {
2009-03-31 01:49:55 +00:00
public static function getInfo() {
2008-05-05 20:42:08 +00:00
return array(
2010-09-04 17:55:43 +00:00
'name' => 'Filter module filters',
'description' => 'Tests Filter module filters individually.',
2009-07-13 21:51:42 +00:00
'group' => 'Filter',
2008-05-05 20:42:08 +00:00
);
}
/**
2009-06-28 12:01:26 +00:00
* Test the line break filter.
2008-05-05 20:42:08 +00:00
*/
function testLineBreakFilter() {
2010-09-04 17:55:43 +00:00
// Setup dummy filter object.
$filter = new stdClass;
$filter->callback = '_filter_autop';
2008-12-28 19:30:36 +00:00
2010-09-04 17:55:43 +00:00
// Since the line break filter naturally needs plenty of newlines in test
// strings and expectations, we're using "\n" instead of regular newlines
// here.
$tests = array(
// Single line breaks should be changed to <br /> tags, while paragraphs
// separated with double line breaks should be enclosed with <p></p> tags.
"aaa\nbbb\n\nccc" => array(
"<p>aaa<br />\nbbb</p>\n<p>ccc</p>" => TRUE,
),
// Skip contents of certain block tags entirely.
"<script>aaa\nbbb\n\nccc</script>
<style>aaa\nbbb\n\nccc</style>
<pre>aaa\nbbb\n\nccc</pre>
<object>aaa\nbbb\n\nccc</object>
<iframe>aaa\nbbb\n\nccc</iframe>
" => array(
"<script>aaa\nbbb\n\nccc</script>" => TRUE,
"<style>aaa\nbbb\n\nccc</style>" => TRUE,
"<pre>aaa\nbbb\n\nccc</pre>" => TRUE,
"<object>aaa\nbbb\n\nccc</object>" => TRUE,
"<iframe>aaa\nbbb\n\nccc</iframe>" => TRUE,
),
// Skip comments entirely.
"One. <!-- comment --> Two.\n<!--\nThree.\n-->\n" => array(
'<!-- comment -->' => TRUE,
"<!--\nThree.\n-->" => TRUE,
),
// Resulting HTML should produce matching paragraph tags.
'<p><div> </div></p>' => array(
"<p>\n<div> </div>\n</p>" => TRUE,
),
'<div><p> </p></div>' => array(
"<div>\n</div>" => TRUE,
),
'<blockquote><pre>aaa</pre></blockquote>' => array(
"<blockquote><pre>aaa</pre></blockquote>" => TRUE,
),
);
$this->assertFilteredString($filter, $tests);
2009-05-24 19:12:12 +00:00
2010-09-04 17:55:43 +00:00
// Very long string hitting PCRE limits.
2009-05-24 19:12:12 +00:00
$limit = max(ini_get('pcre.backtrack_limit'), ini_get('pcre.recursion_limit'));
2010-09-04 17:55:43 +00:00
$source = $this->randomName($limit);
$result = _filter_autop($source);
$success = $this->assertEqual($result, '<p>' . $source . "</p>\n", t('Line break filter can process very long strings.'));
if (!$success) {
$this->verbose("\n" . $source . "\n<hr />\n" . $result);
}
2008-05-05 20:42:08 +00:00
}
/**
2010-09-04 17:55:43 +00:00
* Tests limiting allowed tags and XSS prevention.
2009-06-28 18:03:56 +00:00
*
2010-09-04 17:55:43 +00:00
* XSS tests assume that script is disallowed by default and src is allowed
* by default, but on* and style attributes are disallowed.
2009-06-28 12:01:26 +00:00
*
* Script injection vectors mostly adopted from http://ha.ckers.org/xss.html.
*
* Relevant CVEs:
2009-06-28 18:03:56 +00:00
* - CVE-2002-1806, ~CVE-2005-0682, ~CVE-2005-2106, CVE-2005-3973,
* CVE-2006-1226 (= rev. 1.112?), CVE-2008-0273, CVE-2008-3740.
2008-05-05 20:42:08 +00:00
*/
2010-09-04 17:55:43 +00:00
function testFilterXSS() {
2009-06-28 12:01:26 +00:00
// Tag stripping, different ways to work around removal of HTML tags.
$f = filter_xss('<script>alert(0)</script>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping -- simple script without special characters.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script src="http://www.example.com" />');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping -- empty script with source.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<ScRipt sRc=http://www.example.com/>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- varying case.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<script\nsrc\n=\nhttp://www.example.com/\n>");
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- multiline tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script/a src=http://www.example.com/a.js></script>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- non whitespace character after tag name.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script/src=http://www.example.com/a.js></script>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- no space between tag and attribute.'));
2009-06-28 12:01:26 +00:00
// Null between < and tag name works at least with IE6.
$f = filter_xss("<\0scr\0ipt>alert(0)</script>");
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'ipt', t('HTML tag stripping evasion -- breaking HTML with nulls.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<scrscriptipt src=http://www.example.com/a.js>");
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- filter just removing "script".'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<<script>alert(0);//<</script>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- double opening brackets.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script src=http://www.example.com/a.js?<b>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- no closing tag.'));
2009-06-28 12:01:26 +00:00
2009-06-28 18:03:56 +00:00
// DRUPAL-SA-2008-047: This doesn't seem exploitable, but the filter should
// work consistently.
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script>>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- double closing tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script src=//www.example.com/.a>');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- no scheme or ending slash.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script src=http://www.example.com/.a');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- no closing bracket.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<script src=http://www.example.com/ <');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- opening instead of closing bracket.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<nosuchtag attribute="newScriptInjectionVector">');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'nosuchtag', t('HTML tag stripping evasion -- unknown tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<?xml:namespace ns="urn:schemas-microsoft-com:time">');
2010-08-05 23:53:39 +00:00
$this->assertTrue(stripos($f, '<?xml') === FALSE, t('HTML tag stripping evasion -- starting with a question sign (processing instructions).'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<t:set attributeName="innerHTML" to="<script defer>alert(0)</script>">');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 't:set', t('HTML tag stripping evasion -- colon in the tag name (namespaces\' tricks).'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img """><script>alert(0)</script>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- a malformed image tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<blockquote><script>alert(0)</script></blockquote>', array('blockquote'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- script in a blockqoute.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<!--[if true]><script>alert(0)</script><![endif]-->");
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML tag stripping evasion -- script within a comment.'));
2009-06-28 12:01:26 +00:00
// Dangerous attributes removal.
$f = filter_xss('<p onmouseover="http://www.example.com/">', array('p'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'onmouseover', t('HTML filter attributes removal -- events, no evasion.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<li style="list-style-image: url(javascript:alert(0))">', array('li'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'style', t('HTML filter attributes removal -- style, no evasion.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img onerror =alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'onerror', t('HTML filter attributes removal evasion -- spaces before equals sign.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img onabort!#$%&()*~+-_.,:;?@[/|\]^`=alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'onabort', t('HTML filter attributes removal evasion -- non alphanumeric characters before equals sign.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img oNmediAError=alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'onmediaerror', t('HTML filter attributes removal evasion -- varying case.'));
2009-06-28 12:01:26 +00:00
// Works at least with IE6.
$f = filter_xss("<img o\0nfocus\0=alert(0)>", array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'focus', t('HTML filter attributes removal evasion -- breaking with nulls.'));
2009-06-28 12:01:26 +00:00
2009-06-28 18:03:56 +00:00
// Only whitelisted scheme names allowed in attributes.
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="javascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing -- no evasion.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src=javascript:alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- no quotes.'));
2009-06-28 12:01:26 +00:00
// A bit like CVE-2006-0070.
$f = filter_xss('<img src="javascript:confirm(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- no alert ;)'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src=`javascript:alert(0)`>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- grave accents.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img dynsrc="javascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing -- rare attribute.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<table background="javascript:alert(0)">', array('table'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing -- another tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<base href="javascript:alert(0);//">', array('base'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing -- one more attribute and tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="jaVaSCriPt:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- varying case.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src=javascript:alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- UTF-8 decimal encoding.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src=javascript:alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- long UTF-8 encoding.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src=javascript:alert(0)>', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- UTF-8 hex encoding.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<img src=\"jav\tascript:alert(0)\">", array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML scheme clearing evasion -- an embedded tab.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="jav	ascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML scheme clearing evasion -- an encoded, embedded tab.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="jav
ascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML scheme clearing evasion -- an encoded, embedded newline.'));
2009-06-28 12:01:26 +00:00
// With 
 this test would fail, but the entity gets turned into
// &#xD;, so it's OK.
$f = filter_xss('<img src="jav
ascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML scheme clearing evasion -- an encoded, embedded carriage return.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<img src=\"\n\n\nj\na\nva\ns\ncript:alert(0)\">", array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'cript', t('HTML scheme clearing evasion -- broken into many lines.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("<img src=\"jav\0a\0\0cript:alert(0)\">", array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'cript', t('HTML scheme clearing evasion -- embedded nulls.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="  javascript:alert(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'javascript', t('HTML scheme clearing evasion -- spaces and metacharacters before scheme.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="vbscript:msgbox(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'vbscript', t('HTML scheme clearing evasion -- another scheme.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss('<img src="nosuchscheme:notice(0)">', array('img'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'nosuchscheme', t('HTML scheme clearing evasion -- unknown scheme.'));
2009-06-28 12:01:26 +00:00
// Netscape 4.x javascript entities.
$f = filter_xss('<br size="&{alert(0)}">', array('br'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'alert', t('Netscape 4.x javascript entities.'));
2009-06-28 12:01:26 +00:00
2009-06-28 18:03:56 +00:00
// DRUPAL-SA-2008-006: Invalid UTF-8, these only work as reflected XSS with
// Internet Explorer 6.
$f = filter_xss("<p arg=\"\xe0\">\" style=\"background-image: url(javascript:alert(0));\"\xe0<p>", array('p'));
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'style', t('HTML filter -- invalid UTF-8.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss("\xc0aaa");
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '', t('HTML filter -- overlong UTF-8 sequences.'));
2009-07-03 18:26:35 +00:00
$f = filter_xss("Who's Online");
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, "who's online", t('HTML filter -- html entity number'));
2009-07-03 18:26:35 +00:00
$f = filter_xss("Who&#039;s Online");
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, "who's online", t('HTML filter -- encoded html entity number'));
2009-07-03 18:26:35 +00:00
$f = filter_xss("Who&amp;#039; Online");
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, "who&#039; online", t('HTML filter -- double encoded html entity number'));
2009-06-28 12:01:26 +00:00
}
/**
* Test filter settings, defaults, access restrictions and similar.
*
2009-06-28 18:03:56 +00:00
* @todo This is for functions like filter_filter and check_markup, whose
* functionality is not completely focused on filtering. Some ideas:
* restricting formats according to user permissions, proper cache
* handling, defaults -- allowed tags/attributes/protocols.
2009-06-28 12:01:26 +00:00
*
2009-06-28 18:03:56 +00:00
* @todo It is possible to add script, iframe etc. to allowed tags, but this
* makes HTML filter completely ineffective.
2009-06-28 12:01:26 +00:00
*
2009-06-28 18:03:56 +00:00
* @todo Class, id, name and xmlns should be added to disallowed attributes,
* or better a whitelist approach should be used for that too.
2009-06-28 12:01:26 +00:00
*/
2010-09-04 17:55:43 +00:00
function testHtmlFilter() {
2009-08-27 21:18:20 +00:00
// Setup dummy filter object.
2010-06-17 13:16:57 +00:00
$filter = new stdClass();
2009-08-27 21:18:20 +00:00
$filter->settings = array(
'allowed_html' => '<a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>',
'filter_html_help' => 1,
'filter_html_nofollow' => 0,
);
2009-06-28 12:01:26 +00:00
// HTML filter is not able to secure some tags, these should never be
// allowed.
2009-08-27 21:18:20 +00:00
$f = _filter_html('<script />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('HTML filter should always remove script tags.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<iframe />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'iframe', t('HTML filter should always remove iframe tags.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<object />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'object', t('HTML filter should always remove object tags.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<style />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'style', t('HTML filter should always remove style tags.'));
2009-06-28 12:01:26 +00:00
// Some tags make CSRF attacks easier, let the user take the risk herself.
2009-08-27 21:18:20 +00:00
$f = _filter_html('<img />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'img', t('HTML filter should remove img tags on default.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<input />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'img', t('HTML filter should remove input tags on default.'));
2008-05-05 20:42:08 +00:00
2009-06-28 12:01:26 +00:00
// Filtering content of some attributes is infeasible, these shouldn't be
// allowed too.
2009-08-27 21:18:20 +00:00
$f = _filter_html('<p style="display: none;" />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'style', t('HTML filter should remove style attribute on default.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<p onerror="alert(0);" />', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'onerror', t('HTML filter should remove on* attributes on default.'));
2010-07-01 19:41:18 +00:00
2010-08-05 23:53:39 +00:00
$f = _filter_html('<code onerror> </code>', $filter);
$this->assertNoNormalized($f, 'onerror', t('HTML filter should remove empty on* attributes on default.'));
2009-06-28 12:01:26 +00:00
}
/**
* Test the spam deterrent.
*/
function testNoFollowFilter() {
2009-08-27 21:18:20 +00:00
// Setup dummy filter object.
2010-06-17 13:16:57 +00:00
$filter = new stdClass();
2009-08-27 21:18:20 +00:00
$filter->settings = array(
'allowed_html' => '<a>',
'filter_html_help' => 1,
'filter_html_nofollow' => 1,
);
2009-06-28 12:01:26 +00:00
// Test if the rel="nofollow" attribute is added, even if we try to prevent
// it.
2009-08-27 21:18:20 +00:00
$f = _filter_html('<a href="http://www.example.com/">text</a>', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent -- no evasion.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<A href="http://www.example.com/">text</a>', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- capital A.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html("<a/href=\"http://www.example.com/\">text</a>", $filter);
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- non whitespace character after tag name.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html("<\0a\0 href=\"http://www.example.com/\">text</a>", $filter);
2010-08-05 23:53:39 +00:00
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- some nulls.'));
2009-06-28 12:01:26 +00:00
2009-08-27 21:18:20 +00:00
$f = _filter_html('<a href="http://www.example.com/" rel="follow">text</a>', $filter);
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'rel="follow"', t('Spam deterrent evasion -- with rel set - rel="follow" removed.'));
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- with rel set - rel="nofollow" added.'));
2009-06-28 12:01:26 +00:00
}
/**
* Test the loose, admin HTML filter.
*/
2010-09-04 17:55:43 +00:00
function testFilterXSSAdmin() {
2009-06-28 12:01:26 +00:00
// DRUPAL-SA-2008-044
$f = filter_xss_admin('<object />');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'object', t('Admin HTML filter -- should not allow object tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss_admin('<script />');
2010-08-05 23:53:39 +00:00
$this->assertNoNormalized($f, 'script', t('Admin HTML filter -- should not allow script tag.'));
2009-06-28 12:01:26 +00:00
$f = filter_xss_admin('<style /><iframe /><frame /><frameset /><meta /><link /><embed /><applet /><param /><layer />');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '', t('Admin HTML filter -- should never allow some tags.'));
2009-06-28 12:01:26 +00:00
}
/**
2010-09-04 17:55:43 +00:00
* Tests the HTML escaping filter.
*
* check_plain() is not tested here.
2009-06-28 12:01:26 +00:00
*/
2010-09-04 17:55:43 +00:00
function testHtmlEscapeFilter() {
// Setup dummy filter object.
$filter = new stdClass;
$filter->callback = '_filter_html_escape';
2009-06-28 12:01:26 +00:00
2010-09-04 17:55:43 +00:00
$tests = array(
" One. <!-- \"comment\" --> Two'.\n<p>Three.</p>\n " => array(
"One. <!-- "comment" --> Two'.\n<p>Three.</p>" => TRUE,
' One.' => FALSE,
"</p>\n " => FALSE,
),
);
$this->assertFilteredString($filter, $tests);
2009-06-28 12:01:26 +00:00
}
/**
2010-09-02 15:56:10 +00:00
* Tests the URL filter.
2009-06-28 12:01:26 +00:00
*/
function testUrlFilter() {
2009-08-27 21:18:20 +00:00
// Setup dummy filter object.
2010-09-02 15:56:10 +00:00
$filter = new stdClass;
2010-09-04 17:55:43 +00:00
$filter->callback = '_filter_url';
2009-08-27 21:18:20 +00:00
$filter->settings = array(
'filter_url_length' => 496,
);
2010-09-02 15:56:10 +00:00
// @todo Possible categories:
// - absolute, mail, partial
// - characters/encoding, surrounding markup, security
// Filter selection/pattern matching.
$tests = array(
// HTTP URLs.
'
http://example.com or www.example.com
' => array(
'<a href="http://example.com">http://example.com</a>' => TRUE,
'<a href="http://www.example.com">www.example.com</a>' => TRUE,
),
// MAILTO URLs.
'
person@example.com or mailto:person2@example.com
' => array(
'<a href="mailto:person@example.com">person@example.com</a>' => TRUE,
'<a href="mailto:person2@example.com">mailto:person2@example.com</a>' => TRUE,
),
// URI parts.
'
http://trailingslash.com/ or www.trailingslash.com/
http://host.com/some/path?query=foo&bar[baz]=beer#fragment or www.host.com/some/path?query=foo&bar[baz]=beer#fragment
ftp://user:pass@ftp.example.com/~home/dir1
sftp://user@nonstandardport:222/dir
ssh://192.168.0.100/srv/git/drupal.git
' => array(
'<a href="http://trailingslash.com/">http://trailingslash.com/</a>' => TRUE,
'<a href="http://www.trailingslash.com/">www.trailingslash.com/</a>' => TRUE,
'<a href="http://host.com/some/path?query=foo&bar[baz]=beer#fragment">http://host.com/some/path?query=foo&bar[baz]=beer#fragment</a>' => TRUE,
'<a href="http://www.host.com/some/path?query=foo&bar[baz]=beer#fragment">www.host.com/some/path?query=foo&bar[baz]=beer#fragment</a>' => TRUE,
'<a href="ftp://user:pass@ftp.example.com/~home/dir1">ftp://user:pass@ftp.example.com/~home/dir1</a>' => TRUE,
'<a href="sftp://user@nonstandardport:222/dir">sftp://user@nonstandardport:222/dir</a>' => TRUE,
'<a href="ssh://192.168.0.100/srv/git/drupal.git">ssh://192.168.0.100/srv/git/drupal.git</a>' => TRUE,
),
// Encoding.
'
http://ampersand.com/?a=1&b=2
http://encoded.com/?a=1&b=2
' => array(
'<a href="http://ampersand.com/?a=1&b=2">http://ampersand.com/?a=1&b=2</a>' => TRUE,
'<a href="http://encoded.com/?a=1&b=2">http://encoded.com/?a=1&b=2</a>' => TRUE,
),
// Domain name length.
'
www.ex.ex or www.example.example or www.toolongdomainexampledomainexampledomainexampledomainexampledomain or
me@me.tv
' => array(
'<a href="http://www.ex.ex">www.ex.ex</a>' => TRUE,
'<a href="http://www.example.example">www.example.example</a>' => TRUE,
'http://www.toolong' => FALSE,
'<a href="mailto:me@me.tv">me@me.tv</a>' => TRUE,
),
// Absolute URL protocols.
// The list to test is found in the beginning of _filter_url() at
// $protocols = variable_get('filter_allowed_protocols'... (approx line 1325).
'
https://example.com,
ftp://ftp.example.com,
news://example.net,
telnet://example,
irc://example.host,
ssh://odd.geek,
sftp://secure.host?,
webcal://calendar,
rtsp://127.0.0.1,
not foo://disallowed.com.
' => array(
'href="https://example.com"' => TRUE,
'href="ftp://ftp.example.com"' => TRUE,
'href="news://example.net"' => TRUE,
'href="telnet://example"' => TRUE,
'href="irc://example.host"' => TRUE,
'href="ssh://odd.geek"' => TRUE,
'href="sftp://secure.host"' => TRUE,
'href="webcal://calendar"' => TRUE,
'href="rtsp://127.0.0.1"' => TRUE,
'href="foo://disallowed.com"' => FALSE,
'not foo://disallowed.com.' => TRUE,
),
);
$this->assertFilteredString($filter, $tests);
// Surrounding text/punctuation.
$tests = array(
'
Partial URL with trailing period www.partial.com.
E-mail with trailing comma person@example.com,
Absolute URL with trailing question http://www.absolute.com?
Query string with trailing exclamation www.query.com/index.php?a=!
Partial URL with 3 trailing www.partial.periods...
E-mail with 3 trailing exclamations@example.com!!!
Absolute URL and query string with 2 different punctuation characters (http://www.example.com/q=abc).
' => array(
'period <a href="http://www.partial.com">www.partial.com</a>.' => TRUE,
'comma <a href="mailto:person@example.com">person@example.com</a>,' => TRUE,
'question <a href="http://www.absolute.com">http://www.absolute.com</a>?' => TRUE,
'exclamation <a href="http://www.query.com/index.php?a=">www.query.com/index.php?a=</a>!' => TRUE,
'trailing <a href="http://www.partial.periods">www.partial.periods</a>...' => TRUE,
'trailing <a href="mailto:exclamations@example.com">exclamations@example.com</a>!!!' => TRUE,
'characters (<a href="http://www.example.com/q=abc">http://www.example.com/q=abc</a>).' => TRUE,
),
'
(www.parenthesis.com/dir?a=1&b=2#a)
' => array(
'(<a href="http://www.parenthesis.com/dir?a=1&b=2#a">www.parenthesis.com/dir?a=1&b=2#a</a>)' => TRUE,
),
);
$this->assertFilteredString($filter, $tests);
// Surrounding markup.
$tests = array(
'
<p xmlns="www.namespace.com" />
<p xmlns="http://namespace.com">
An <a href="http://example.com" title="Read more at www.example.info...">anchor</a>.
</p>
' => array(
'<p xmlns="www.namespace.com" />' => TRUE,
'<p xmlns="http://namespace.com">' => TRUE,
'href="http://www.namespace.com"' => FALSE,
'href="http://namespace.com"' => FALSE,
'An <a href="http://example.com" title="Read more at www.example.info...">anchor</a>.' => TRUE,
),
'
Not <a href="foo">www.relative.com</a> or <a href="http://absolute.com">www.absolute.com</a>
but <strong>http://www.strong.net</strong> or <em>www.emphasis.info</em>
' => array(
'<a href="foo">www.relative.com</a>' => TRUE,
'href="http://www.relative.com"' => FALSE,
'<a href="http://absolute.com">www.absolute.com</a>' => TRUE,
'<strong><a href="http://www.strong.net">http://www.strong.net</a></strong>' => TRUE,
'<em><a href="http://www.emphasis.info">www.emphasis.info</a></em>' => TRUE,
),
'
Test <code>using www.example.com the code tag</code>.
' => array(
'href' => FALSE,
'http' => FALSE,
),
'
Intro.
<blockquote>
Quoted text linking to www.example.com, written by person@example.com, originating from http://origin.example.com. <code>@see www.usage.example.com or <em>www.example.info</em> bla bla</code>.
</blockquote>
Outro.
' => array(
'href="http://www.example.com"' => TRUE,
'href="mailto:person@example.com"' => TRUE,
'href="http://origin.example.com"' => TRUE,
'http://www.usage.example.com' => FALSE,
'http://www.example.info' => FALSE,
'Intro.' => TRUE,
'Outro.' => TRUE,
),
'
Unknown tag <x>containing x and www.example.com</x>? And a tag <pooh>beginning with p and containing www.example.pooh with p?</pooh>
' => array(
'href="http://www.example.com"' => TRUE,
'href="http://www.example.pooh"' => TRUE,
),
'
<p>Test <br/>: This is a www.example17.com example <strong>with</strong> various http://www.example18.com tags. *<br/>
It is important www.example19.com to *<br/>test different URLs and http://www.example20.com in the same paragraph. *<br>
HTML www.example21.com soup by person@example22.com can litererally http://www.example23.com contain *img*<img> anything. Just a www.example24.com with http://www.example25.com thrown in. www.example26.com from person@example27.com with extra http://www.example28.com.
' => array(
'href="http://www.example17.com"' => TRUE,
'href="http://www.example18.com"' => TRUE,
'href="http://www.example19.com"' => TRUE,
'href="http://www.example20.com"' => TRUE,
'href="http://www.example21.com"' => TRUE,
'href="mailto:person@example22.com"' => TRUE,
'href="http://www.example23.com"' => TRUE,
'href="http://www.example24.com"' => TRUE,
'href="http://www.example25.com"' => TRUE,
'href="http://www.example26.com"' => TRUE,
'href="mailto:person@example27.com"' => TRUE,
'href="http://www.example28.com"' => TRUE,
),
'
<script>
<!--
// @see www.example.com
var exampleurl = "http://example.net";
-->
<!--//--><![CDATA[//><!--
// @see www.example.com
var exampleurl = "http://example.net";
//--><!]]>
</script>
' => array(
'href="http://www.example.com"' => FALSE,
'href="http://example.net"' => FALSE,
),
'
<style>body {
background: url(http://example.com/pixel.gif);
}</style>
' => array(
'href' => FALSE,
),
'
<!-- Skip any URLs like www.example.com in comments -->
' => array(
'href' => FALSE,
),
'
<!-- Skip any URLs like
www.example.com with a newline in comments -->
' => array(
'href' => FALSE,
),
'
<!-- Skip any URLs like www.comment.com in comments. <p>Also ignore http://commented.out/markup.</p> -->
' => array(
'href' => FALSE,
),
'
<dl>
<dt>www.example.com</dt>
<dd>http://example.com</dd>
<dd>person@example.com</dd>
<dt>Check www.example.net</dt>
<dd>Some text around http://www.example.info by person@example.info?</dd>
</dl>
' => array(
'href="http://www.example.com"' => TRUE,
'href="http://example.com"' => TRUE,
'href="mailto:person@example.com"' => TRUE,
'href="http://www.example.net"' => TRUE,
'href="http://www.example.info"' => TRUE,
'href="mailto:person@example.info"' => TRUE,
),
2010-09-02 21:01:15 +00:00
'
<div>www.div.com</div>
<ul>
<li>http://listitem.com</li>
<li class="odd">www.class.listitem.com</li>
</ul>
' => array(
'<div><a href="http://www.div.com">www.div.com</a></div>' => TRUE,
'<li><a href="http://listitem.com">http://listitem.com</a></li>' => TRUE,
'<li class="odd"><a href="http://www.class.listitem.com">www.class.listitem.com</a></li>' => TRUE,
),
2010-09-02 15:56:10 +00:00
);
$this->assertFilteredString($filter, $tests);
2009-06-28 12:01:26 +00:00
// URL trimming.
2010-09-02 15:56:10 +00:00
$filter->settings['filter_url_length'] = 20;
$tests = array(
'www.trimmed.com/d/ff.ext?a=1&b=2#a1' => array(
'<a href="http://www.trimmed.com/d/ff.ext?a=1&b=2#a1">www.trimmed.com/d/ff...</a>' => TRUE,
),
);
$this->assertFilteredString($filter, $tests);
}
2009-06-28 12:01:26 +00:00
2010-09-02 15:56:10 +00:00
/**
* Asserts multiple filter output expectations for multiple input strings.
*
* @param $filter
* A input filter object.
* @param $tests
* An associative array, whereas each key is an arbitrary input string and
* each value is again an associative array whose keys are filter output
* strings and whose values are Booleans indicating whether the output is
* expected or not.
*
* For example:
* @code
* $tests = array(
* 'Input string' => array(
* '<p>Input string</p>' => TRUE,
* 'Input string<br' => FALSE,
* ),
* );
* @endcode
*/
2010-09-04 17:55:43 +00:00
function assertFilteredString($filter, $tests) {
foreach ($tests as $source => $tasks) {
$function = $filter->callback;
$result = $function($source, $filter);
foreach ($tasks as $value => $is_expected) {
2010-09-02 15:56:10 +00:00
// Not using assertIdentical, since combination with strpos() is hard to grok.
2010-09-04 17:55:43 +00:00
if ($is_expected) {
$success = $this->assertTrue(strpos($result, $value) !== FALSE, t('@source: @value found.', array(
'@source' => var_export($source, TRUE),
2010-09-02 15:56:10 +00:00
'@value' => var_export($value, TRUE),
)));
}
else {
2010-09-04 17:55:43 +00:00
$success = $this->assertTrue(strpos($result, $value) === FALSE, t('@source: @value not found.', array(
'@source' => var_export($source, TRUE),
2010-09-02 15:56:10 +00:00
'@value' => var_export($value, TRUE),
)));
}
2010-09-04 17:55:43 +00:00
if (!$success) {
$this->verbose('Source:<pre>' . check_plain(var_export($source, TRUE)) . '</pre>'
. '<hr />' . 'Result:<pre>' . check_plain(var_export($result, TRUE)) . '</pre>'
. '<hr />' . ($is_expected ? 'Found:' : 'Not found:')
. '<pre>' . check_plain(var_export($value, TRUE)) . '</pre>'
);
}
2010-09-02 15:56:10 +00:00
}
}
}
2009-06-28 12:01:26 +00:00
2010-09-02 15:56:10 +00:00
/**
* Tests URL filter on longer content.
*
* Filters based on regular expressions should also be tested with a more
* complex content than just isolated test lines.
* The most common errors are:
* - accidental '*' (greedy) match instead of '*?' (minimal) match.
* - only matching first occurrence instead of all.
* - newlines not matching '.*'.
*
* This test covers:
* - Document with multiple newlines and paragraphs (two newlines).
* - Mix of several HTML tags, invalid non-HTML tags, tags to ignore and HTML
* comments.
* - Empty HTML tags (BR, IMG).
* - Mix of absolute and partial URLs, and e-mail addresses in one content.
*/
function testUrlFilterContent() {
// Setup dummy filter object.
$filter = new stdClass;
$filter->settings = array(
'filter_url_length' => 496,
);
$path = drupal_get_path('module', 'filter') . '/tests';
2009-06-28 12:01:26 +00:00
2010-09-02 15:56:10 +00:00
$input = file_get_contents($path . '/filter.url-input.txt');
$expected = file_get_contents($path . '/filter.url-output.txt');
$result = _filter_url($input, $filter);
$this->assertIdentical($result, $expected, 'Complex HTML document was correctly processed.');
2009-06-28 12:01:26 +00:00
}
/**
2009-07-27 20:15:35 +00:00
* Test the HTML corrector filter.
2009-06-28 12:01:26 +00:00
*
2009-06-28 18:03:56 +00:00
* @todo This test could really use some validity checking function.
2009-06-28 12:01:26 +00:00
*/
2009-07-27 20:15:35 +00:00
function testHtmlCorrectorFilter() {
2009-06-28 12:01:26 +00:00
// Tag closing.
$f = _filter_htmlcorrector('<p>text');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>text</p>', t('HTML corrector -- tag closing at the end of input.'));
2009-06-28 12:01:26 +00:00
$f = _filter_htmlcorrector('<p>text<p><p>text');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>text</p><p></p><p>text</p>', t('HTML corrector -- tag closing.'));
2009-06-28 12:01:26 +00:00
$f = _filter_htmlcorrector("<ul><li>e1<li>e2");
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, "<ul><li>e1</li><li>e2</li></ul>", t('HTML corrector -- unclosed list tags.'));
2009-06-28 12:01:26 +00:00
$f = _filter_htmlcorrector('<div id="d">content');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<div id="d">content</div>', t('HTML corrector -- unclosed tag with attribute.'));
2009-06-28 12:01:26 +00:00
// XHTML slash for empty elements.
$f = _filter_htmlcorrector('<hr><br>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<hr /><br />', t('HTML corrector -- XHTML closing slash.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<P>test</P>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>test</p>', t('HTML corrector -- Convert uppercased tags to proper lowercased ones.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<P>test</p>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>test</p>', t('HTML corrector -- Convert uppercased tags to proper lowercased ones.'));
2009-07-27 20:15:35 +00:00
2010-04-10 10:01:15 +00:00
$f = _filter_htmlcorrector('test<hr />');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through.'));
2010-04-10 10:01:15 +00:00
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test<hr/>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through, but ensure there is a single space before the closing slash.'));
2009-07-27 20:15:35 +00:00
2010-04-10 10:01:15 +00:00
$f = _filter_htmlcorrector('test<hr />');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test<hr />', t('HTML corrector -- Let proper XHTML pass through, but ensure there are not too many spaces before the closing slash.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<span class="test" />');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<span class="test"></span>', t('HTML corrector -- Convert XHTML that is properly formed but that would not be compatible with typical HTML user agents.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test1<br class="test">test2');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test1<br class="test" />test2', t('HTML corrector -- Automatically close single tags.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('line1<hr>line2');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'line1<hr />line2', t('HTML corrector -- Automatically close single tags.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('line1<HR>line2');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'line1<hr />line2', t('HTML corrector -- Automatically close single tags.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<img src="http://example.com/test.jpg">test</img>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<img src="http://example.com/test.jpg" />test', t('HTML corrector -- Automatically close single tags.'));
2009-07-27 20:15:35 +00:00
2010-04-10 10:01:15 +00:00
$f = _filter_htmlcorrector('<br></br>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<br />', t("HTML corrector -- Transform empty tags to a single closed tag if the tag's content model is EMPTY."));
2010-04-10 10:01:15 +00:00
$f = _filter_htmlcorrector('<div></div>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<div></div>', t("HTML corrector -- Do not transform empty tags to a single closed tag if the tag's content model is not EMPTY."));
2010-04-10 10:01:15 +00:00
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>line1<br/><hr/>line2</p>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>line1<br /></p><hr />line2', t('HTML corrector -- Move non-inline elements outside of inline containers.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>line1<div>line2</div></p>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>line1</p><div>line2</div>', t('HTML corrector -- Move non-inline elements outside of inline containers.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>test<p>test</p>\n');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>test</p><p>test</p>\n', t('HTML corrector -- Auto-close improperly nested tags.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>Line1<br><STRONG>bold stuff</b>');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>Line1<br /><strong>bold stuff</strong></p>', t('HTML corrector -- Properly close unclosed tags, and remove useless closing tags.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test <!-- this is a comment -->');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test <!-- this is a comment -->', t('HTML corrector -- Do not touch HTML comments.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test <!--this is a comment-->');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test <!--this is a comment-->', t('HTML corrector -- Do not touch HTML comments.'));
2009-07-27 20:15:35 +00:00
2009-11-10 17:27:54 +00:00
$f = _filter_htmlcorrector('test <!-- comment <p>another
<strong>multiple</strong> line
2009-07-27 20:15:35 +00:00
comment</p> -->');
2009-11-10 17:27:54 +00:00
$this->assertEqual($f, 'test <!-- comment <p>another
<strong>multiple</strong> line
2010-08-05 23:53:39 +00:00
comment</p> -->', t('HTML corrector -- Do not touch HTML comments.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test <!-- comment <p>another comment</p> -->');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test <!-- comment <p>another comment</p> -->', t('HTML corrector -- Do not touch HTML comments.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('test <!--break-->');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, 'test <!--break-->', t('HTML corrector -- Do not touch HTML comments.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>test\n</p>\n');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>test\n</p>\n', t('HTML corrector -- New-lines are accepted and kept as-is.'));
2009-07-27 20:15:35 +00:00
$f = _filter_htmlcorrector('<p>دروبال');
2010-08-05 23:53:39 +00:00
$this->assertEqual($f, '<p>دروبال</p>', t('HTML corrector -- Encoding is correctly kept.'));
2010-02-25 08:58:31 +00:00
$f = _filter_htmlcorrector('<script type="text/javascript">alert("test")</script>');
$this->assertEqual($f, '<script type="text/javascript">
<!--//--><![CDATA[// ><!--
alert("test")
//--><!]]>
2010-08-05 23:53:39 +00:00
</script>', t('HTML corrector -- CDATA added to script element'));
2010-02-25 08:58:31 +00:00
$f = _filter_htmlcorrector('<p><script type="text/javascript">alert("test")</script></p>');
$this->assertEqual($f, '<p><script type="text/javascript">
<!--//--><![CDATA[// ><!--
alert("test")
//--><!]]>
2010-08-05 23:53:39 +00:00
</script></p>', t('HTML corrector -- CDATA added to a nested script element'));
2010-02-25 08:58:31 +00:00
2010-03-06 06:39:01 +00:00
$f = _filter_htmlcorrector('<p><style> /* Styling */ body {color:red}</style></p>');
2010-02-25 08:58:31 +00:00
$this->assertEqual($f, '<p><style>
<!--/*--><![CDATA[/* ><!--*/
2010-03-06 06:39:01 +00:00
/* Styling */ body {color:red}
2010-02-25 08:58:31 +00:00
/*--><!]]>*/
2010-08-05 23:53:39 +00:00
</style></p>', t('HTML corrector -- CDATA added to a style element.'));
2008-05-05 20:42:08 +00:00
}
2009-06-28 12:01:26 +00:00
/**
2009-06-28 18:03:56 +00:00
* Asserts that a text transformed to lowercase with HTML entities decoded does contains a given string.
2009-06-28 12:01:26 +00:00
*
* Otherwise fails the test with a given message, similar to all the
* SimpleTest assert* functions.
*
* Note that this does not remove nulls, new lines and other characters that
* could be used to obscure a tag or an attribute name.
*
* @param $haystack
* Text to look in.
* @param $needle
* Lowercase, plain text to look for.
* @param $message
* Message to display if failed.
* @param $group
* The group this message belongs to, defaults to 'Other'.
* @return
* TRUE on pass, FALSE on fail.
*/
function assertNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos(strtolower(decode_entities($haystack)), $needle) !== FALSE, $message, $group);
}
/**
2009-06-28 18:03:56 +00:00
* Asserts that text transformed to lowercase with HTML entities decoded does not contain a given string.
2009-06-28 12:01:26 +00:00
*
* Otherwise fails the test with a given message, similar to all the
* SimpleTest assert* functions.
*
* Note that this does not remove nulls, new lines, and other character that
* could be used to obscure a tag or an attribute name.
*
* @param $haystack
* Text to look in.
* @param $needle
* Lowercase, plain text to look for.
* @param $message
* Message to display if failed.
* @param $group
* The group this message belongs to, defaults to 'Other'.
* @return
* TRUE on pass, FALSE on fail.
*/
function assertNoNormalized($haystack, $needle, $message = '', $group = 'Other') {
return $this->assertTrue(strpos(strtolower(decode_entities($haystack)), $needle) === FALSE, $message, $group);
}
2008-05-05 20:42:08 +00:00
}
2009-08-26 10:29:26 +00:00
/**
* Tests for filter hook invocation.
*/
class FilterHooksTestCase extends DrupalWebTestCase {
2009-08-27 21:18:20 +00:00
public static function getInfo() {
2009-08-26 10:29:26 +00:00
return array(
'name' => 'Filter format hooks',
2010-09-18 02:18:35 +00:00
'description' => 'Test hooks for text formats insert/update/disable.',
2009-08-26 10:29:26 +00:00
'group' => 'Filter',
);
}
function setUp() {
parent::setUp('block', 'filter_test');
$admin_user = $this->drupalCreateUser(array('administer filters', 'administer blocks'));
$this->drupalLogin($admin_user);
}
/**
* Test that hooks run correctly on creating, editing, and deleting a text format.
*/
function testFilterHooks() {
// Add a text format.
$name = $this->randomName();
$edit = array();
2010-10-20 01:15:58 +00:00
$edit['format'] = drupal_strtolower($this->randomName());
2009-08-26 10:29:26 +00:00
$edit['name'] = $name;
$edit['roles[1]'] = 1;
2009-08-28 16:23:05 +00:00
$this->drupalPost('admin/config/content/formats/add', $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('Added text format %format.', array('%format' => $name)), t('New format created.'));
$this->assertText('hook_filter_format_insert invoked.', t('hook_filter_format_insert was invoked.'));
2009-08-26 10:29:26 +00:00
2009-10-13 15:39:41 +00:00
$format_id = db_query("SELECT format FROM {filter_format} WHERE name = :name", array(':name' => $name))->fetchField();
2009-08-26 10:29:26 +00:00
// Update text format.
$edit = array();
$edit['roles[2]'] = 1;
2009-10-13 15:39:41 +00:00
$this->drupalPost('admin/config/content/formats/' . $format_id, $edit, t('Save configuration'));
2010-08-05 23:53:39 +00:00
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $name)), t('Format successfully updated.'));
$this->assertText('hook_filter_format_update invoked.', t('hook_filter_format_update() was invoked.'));
2009-08-26 10:29:26 +00:00
// Add a new custom block.
2009-08-28 19:44:05 +00:00
$custom_block = array();
$custom_block['info'] = $this->randomName(8);
$custom_block['title'] = $this->randomName(8);
2010-03-07 23:14:20 +00:00
$custom_block['body[value]'] = $this->randomName(32);
2009-08-26 10:29:26 +00:00
// Use the format created.
2010-03-07 23:14:20 +00:00
$custom_block['body[format]'] = $format_id;
2009-08-28 19:44:05 +00:00
$this->drupalPost('admin/structure/block/add', $custom_block, t('Save block'));
2010-08-05 23:53:39 +00:00
$this->assertText(t('The block has been created.'), t('New block successfully created.'));
2009-08-26 10:29:26 +00:00
// Verify the new block is in the database.
2009-08-28 19:44:05 +00:00
$bid = db_query("SELECT bid FROM {block_custom} WHERE info = :info", array(':info' => $custom_block['info']))->fetchField();
2010-08-05 23:53:39 +00:00
$this->assertNotNull($bid, t('New block found in database'));
2009-08-26 10:29:26 +00:00
2010-09-18 02:18:35 +00:00
// Disable the text format.
$this->drupalPost('admin/config/content/formats/' . $format_id . '/disable', array(), t('Disable'));
$this->assertRaw(t('Disabled text format %format.', array('%format' => $name)), t('Format successfully disabled.'));
$this->assertText('hook_filter_format_disable invoked.', t('hook_filter_format_disable() was invoked.'));
2009-08-26 10:29:26 +00:00
}
}