]> git.mjollnir.org Git - moodle.git/commitdiff
filters: MDL-7336 rename get_active_filters -> filter_get_active_in_context and impro...
authortjhunt <tjhunt>
Mon, 13 Apr 2009 06:54:34 +0000 (06:54 +0000)
committertjhunt <tjhunt>
Mon, 13 Apr 2009 06:54:34 +0000 (06:54 +0000)
lib/filterlib.php
lib/simpletest/testfilterconfig.php

index 19aef380a342494409d9206fb38c2dfa1e1a6503..def5d451065faf745cbb380724c21c222cf6fdd9 100644 (file)
@@ -167,8 +167,9 @@ function filter_get_all_installed() {
  * @param integer $sortorder (optional) a position in the sortorder to place this filter.
  *      If not given defaults to:
  *      No change in order if we are updating an exsiting record, and not changing to or from TEXTFILTER_DISABLED.
- *      Just after the last currently active filter for a change to TEXTFILTER_ON or TEXTFILTER_OFF
- *      Just after the very last filter for a change to TEXTFILTER_DISABLED
+ *      Just after the last currently active filter when adding an unknown filter
+ *          in state TEXTFILTER_ON or TEXTFILTER_OFF, or enabling/diabling an exsisting filter.
+ *      Just after the very last filter when adding an unknown filter in state TEXTFILTER_DISABLED
  */
 function filter_set_global_state($filter, $state, $sortorder = false) {
     global $DB;
@@ -203,7 +204,7 @@ function filter_set_global_state($filter, $state, $sortorder = false) {
 
     // Automatic sort order.
     if ($sortorder === false) {
-        if ($state == TEXTFILTER_DISABLED) {
+        if ($state == TEXTFILTER_DISABLED && $insert) {
             $prevmaxsortorder = $DB->get_field('filter_active', 'MAX(sortorder)', array());
         } else {
             $prevmaxsortorder = $DB->get_field_select('filter_active', 'MAX(sortorder)', 'active <> ?', array(TEXTFILTER_DISABLED));
@@ -341,7 +342,7 @@ function filter_get_local_config($filter, $contextid) {
  *      empty array. So, an example return value for this function might be
  *      array('filter/tex' => array(), 'mod/glossary' => array('glossaryid', 123))
  */
-function get_active_filters($context) {
+function filter_get_active_in_context($context) {
     global $DB;
     $contextids = str_replace('/', ',', trim($context->path, '/'));
 
index 1237fbb397f6a12ebdbb9038ed6815728238b4d9..5f16665a66cbbd5a5b2c028eb62dc7832270df0e 100644 (file)
@@ -215,7 +215,7 @@ class filter_active_global_test extends UnitTestCaseUsingDatabase {
         // Exercise SUT.
         filter_set_global_state('filter/1', TEXTFILTER_DISABLED);
         // Validate.
-        $this->assert_global_sort_order(array('filter/2', 'filter/3', 'filter/1'));
+        $this->assert_global_sort_order(array('filter/2', 'filter/1', 'filter/3'));
     }
 }
 
@@ -342,7 +342,7 @@ class filter_config_test extends UnitTestCaseUsingDatabase {
     }
 }
 
-class get_active_filters_test extends UnitTestCaseUsingDatabase {
+class filter_get_active_in_context_test extends UnitTestCaseUsingDatabase {
     private $syscontext;
     private $childcontext;
     private $childcontext2;
@@ -387,7 +387,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         // Setup fixture.
         filter_set_global_state('filter/name', TEXTFILTER_ON);
         // Exercise SUT.
-        $filters = get_active_filters($this->syscontext);
+        $filters = filter_get_active_in_context($this->syscontext);
         // Validate.
         $this->assert_filter_list(array('filter/name'), $filters);
         // Check no config returned correctly.
@@ -398,7 +398,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         // Setup fixture.
         filter_set_global_state('filter/name', TEXTFILTER_OFF);
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext2);
+        $filters = filter_get_active_in_context($this->childcontext2);
         // Validate.
         $this->assert_filter_list(array(), $filters);
     }
@@ -408,7 +408,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_global_state('filter/name', TEXTFILTER_OFF);
         filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_ON);
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext2);
+        $filters = filter_get_active_in_context($this->childcontext2);
         // Validate.
         $this->assert_filter_list(array('filter/name'), $filters);
     }
@@ -418,7 +418,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_global_state('filter/name', TEXTFILTER_ON);
         filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_OFF);
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext2);
+        $filters = filter_get_active_in_context($this->childcontext2);
         // Validate.
         $this->assert_filter_list(array(), $filters);
     }
@@ -428,7 +428,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_global_state('filter/name', TEXTFILTER_DISABLED);
         filter_set_local_state('filter/name', $this->childcontext->id, TEXTFILTER_ON);
         // Exercise SUT.
-        $filters = get_active_filters($this->syscontext);
+        $filters = filter_get_active_in_context($this->syscontext);
         // Validate.
         $this->assert_filter_list(array(), $filters);
     }
@@ -438,7 +438,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_global_state('filter/name', TEXTFILTER_ON);
         filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value');
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext);
+        $filters = filter_get_active_in_context($this->childcontext);
         // Validate.
         $this->assertEqual(array('settingname' => 'A value'), $filters['filter/name']);
     }
@@ -449,7 +449,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value');
         filter_set_local_config('filter/name', $this->childcontext->id, 'anothersettingname', 'Another value');
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext);
+        $filters = filter_get_active_in_context($this->childcontext);
         // Validate.
         $this->assertEqual(array('settingname' => 'A value', 'anothersettingname' => 'Another value'), $filters['filter/name']);
     }
@@ -460,7 +460,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value');
         filter_set_local_config('filter/name', $this->childcontext2->id, 'anothersettingname', 'Another value');
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext2);
+        $filters = filter_get_active_in_context($this->childcontext2);
         // Validate.
         $this->assertEqual(array('anothersettingname' => 'Another value'), $filters['filter/name']);
     }
@@ -471,7 +471,7 @@ class get_active_filters_test extends UnitTestCaseUsingDatabase {
         filter_set_local_config('filter/name', $this->childcontext->id, 'settingname', 'A value');
         filter_set_local_config('filter/other', $this->childcontext->id, 'anothersettingname', 'Another value');
         // Exercise SUT.
-        $filters = get_active_filters($this->childcontext);
+        $filters = filter_get_active_in_context($this->childcontext);
         // Validate.
         $this->assertEqual(array('settingname' => 'A value'), $filters['filter/name']);
     }