summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2009-11-30 00:42:01 +0000
committerDries Buytaert <dries@buytaert.net>2009-11-30 00:42:01 +0000
commit49af6f98f84736098d67b33fbfcd18ee5e79589d (patch)
tree4b7b71e366d256c6aba4647a83f851e017a1b5ec
parent27128bc1483d083dd7db314fdb0982f572d23f11 (diff)
downloadbrdo-49af6f98f84736098d67b33fbfcd18ee5e79589d.tar.gz
brdo-49af6f98f84736098d67b33fbfcd18ee5e79589d.tar.bz2
- Patch #562932 by sun, dropcube, ugerhard: filter cache settings not saved properly.
-rw-r--r--modules/filter/filter.module45
-rw-r--r--modules/filter/filter.test31
-rw-r--r--modules/simpletest/tests/filter_test.module12
3 files changed, 83 insertions, 5 deletions
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 16a32fd35..2464361e7 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -182,6 +182,7 @@ function filter_format_load($format_id) {
*/
function filter_format_save(&$format) {
$format->name = trim($format->name);
+ $format->cache = _filter_format_is_cacheable($format);
// Add a new text format.
if (empty($format->format)) {
@@ -493,13 +494,47 @@ function _filter_list_cmp($a, $b) {
/**
* Check if text in a certain text format is allowed to be cached.
+ *
+ * This function can be used to check whether the result of the filtering
+ * process can be cached. A text format may allow caching depending on the
+ * filters enabled.
+ *
+ * @param $format_id
+ * The text format ID to check.
+ * @return
+ * TRUE if the given text format allows caching, FALSE otherwise.
*/
function filter_format_allowcache($format_id) {
- static $cache = array();
- if (!isset($cache[$format_id])) {
- $cache[$format_id] = db_query('SELECT cache FROM {filter_format} WHERE format = :format', array(':format' => $format_id))->fetchField();
+ $format = filter_format_load($format_id);
+ return !empty($format->cache);
+}
+
+/**
+ * Helper function to determine whether the output of a given text format can be cached.
+ *
+ * The output of a given text format can be cached when all enabled filters in
+ * the text format allow caching.
+ *
+ * @param $format
+ * The text format object to check.
+ * @return
+ * TRUE if all the filters enabled in the given text format allow caching,
+ * FALSE otherwise.
+ *
+ * @see filter_format_save()
+ */
+function _filter_format_is_cacheable($format) {
+ if (empty($format->filters)) {
+ return TRUE;
+ }
+ $filter_info = filter_get_filters();
+ foreach ($format->filters as $name => $filter) {
+ // By default, 'cache' is TRUE for all filters unless specified otherwise.
+ if (isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+ return FALSE;
+ }
}
- return $cache[$format_id];
+ return TRUE;
}
/**
@@ -578,7 +613,7 @@ function check_markup($text, $format_id = NULL, $langcode = '', $cache = FALSE)
$format = filter_format_load($format_id);
// Check for a cached version of this piece of text.
- $cache = $cache && filter_format_allowcache($format->format);
+ $cache = $cache && !empty($format->cache);
$cache_id = '';
if ($cache) {
$cache_id = $format->format . ':' . $langcode . ':' . md5($text);
diff --git a/modules/filter/filter.test b/modules/filter/filter.test
index 905d32d66..bcdf2d4f5 100644
--- a/modules/filter/filter.test
+++ b/modules/filter/filter.test
@@ -13,6 +13,10 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
);
}
+ function setUp() {
+ parent::setUp('filter_test');
+ }
+
/**
* Test CRUD operations for text formats and filters.
*/
@@ -47,6 +51,12 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$this->verifyTextFormat($format);
$this->verifyFilters($format);
+ // Add a uncacheable filter and save again.
+ $format->filters['filter_test_uncacheable']['status'] = 1;
+ filter_format_save($format);
+ $this->verifyTextFormat($format);
+ $this->verifyFilters($format);
+
// Delete the text format.
filter_format_delete($format);
$db_format = db_query("SELECT * FROM {filter_format} WHERE format = :format", array(':format' => $format->format))->fetchObject();
@@ -79,6 +89,19 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$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));
+
+ // 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.
+ if (isset($filter_info[$name]['cache']) && !$filter_info[$name]['cache']) {
+ $cacheable = FALSE;
+ }
+ }
+ $this->assertEqual($filter_format->cache, $cacheable, t('Text format contains proper cache property.'));
}
/**
@@ -90,10 +113,12 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$format_filters = $format->filters;
foreach ($filters as $name => $filter) {
$t_args = array('%format' => $format->name, '%filter' => $name);
+
// Check whether the filter is contained in the saved $format.
if (isset($format_filters[$name])) {
// Verify that filter status is properly stored.
$this->assertEqual($filter->status, $format_filters[$name]['status'], t('Database: Proper status for %filter in text format %format.', $t_args));
+
// Verify that filter settings were properly stored.
$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));
}
@@ -101,6 +126,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
else {
$this->assertTrue($filter->status == 0, t('Database: Proper status for disabled %filter in text format %format.', $t_args));
}
+
// Verify that each filter has a module name assigned.
$this->assertTrue(!empty($filter->module), t('Database: Proper module name for %filter in text format %format.', $t_args));
@@ -108,6 +134,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
// filters have been processed later.
unset($format_filters[$name]);
}
+ // Verify that all filters have been processed.
$this->assertTrue(empty($format_filters), t('Database contains values for all filters in the saved format.'));
// Verify filter_list_format().
@@ -115,10 +142,12 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
$format_filters = $format->filters;
foreach ($filters as $name => $filter) {
$t_args = array('%format' => $format->name, '%filter' => $name);
+
// Check whether the filter is contained in the saved $format.
if (isset($format_filters[$name])) {
// Verify that filter status is properly stored.
$this->assertEqual($filter->status, $format_filters[$name]['status'], t('filter_list_format: Proper status for %filter in text format %format.', $t_args));
+
// Verify that filter settings were properly stored.
$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));
}
@@ -126,6 +155,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
else {
$this->assertTrue($filter->status == 0, t('filter_list_format: Proper status for disabled %filter in text format %format.', $t_args));
}
+
// Verify that each filter has a module name assigned.
$this->assertTrue(!empty($filter->module), t('filter_list_format: Proper module name for %filter in text format %format.', $t_args));
@@ -133,6 +163,7 @@ class FilterCRUDTestCase extends DrupalWebTestCase {
// filters have been processed later.
unset($format_filters[$name]);
}
+ // Verify that all filters have been processed.
$this->assertTrue(empty($format_filters), t('filter_list_format: Loaded filters contain values for all filters in the saved format.'));
}
}
diff --git a/modules/simpletest/tests/filter_test.module b/modules/simpletest/tests/filter_test.module
index 649415432..dcdbf79ad 100644
--- a/modules/simpletest/tests/filter_test.module
+++ b/modules/simpletest/tests/filter_test.module
@@ -27,3 +27,15 @@ function filter_test_filter_format_delete($format, $default) {
drupal_set_message('hook_filter_format_delete invoked.');
}
+/**
+ * Implements hook_filter_info().
+ */
+function filter_test_filter_info() {
+ $filters['filter_test_uncacheable'] = array(
+ 'title' => 'Uncacheable filter',
+ 'description' => 'Does nothing, but makes a text format uncacheable.',
+ 'cache' => FALSE,
+ );
+ return $filters;
+}
+