public function test_filter_delete_all_for_filter() { // Setup fixture. filter_set_global_state('filter/name', TEXTFILTER_ON); filter_set_global_state('filter/other', TEXTFILTER_ON); filter_set_local_config('filter/name', $this->syscontext->id, 'settingname', 'A value'); filter_set_local_config('filter/other', $this->syscontext->id, 'settingname', 'Other value'); set_config('configname', 'A config value', 'filter_name'); set_config('configname', 'Other config value', 'filter_other'); // Exercise SUT. filter_delete_all_for_filter('filter/name'); // Validate. $this->assertEqual(1, $this->testdb->count_records('filter_active')); $this->assertTrue($this->testdb->record_exists('filter_active', array('filter' => 'filter/other'))); $this->assertEqual(1, $this->testdb->count_records('filter_config')); $this->assertTrue($this->testdb->record_exists('filter_config', array('filter' => 'filter/other'))); $expectedconfig = new stdClass(); $expectedconfig->configname = 'Other config value'; $this->assertEqual($expectedconfig, get_config('filter_other')); $this->assertFalse(get_config('filter_name')); }
if (!optional_param('confirm', '', PARAM_BOOL)) { $title = get_string('deletefilterareyousure', 'admin', $filtername); admin_externalpage_print_header(); echo $OUTPUT->heading($title); $linkcontinue = new moodle_url($returnurl, array('action' => 'delete', 'filterpath' => $filterpath, 'confirm' => 1)); $formcancel = html_form::make_button($returnurl, null, get_string('no'), 'get'); echo $OUTPUT->confirm(get_string('deletefilterareyousuremessage', 'admin', $filtername), $linkcontinue, $formcancel); echo $OUTPUT->footer(); exit; } // Do the deletion. $title = get_string('deletingfilter', 'admin', $filtername); admin_externalpage_print_header(); echo $OUTPUT->heading($title); // Delete all data for this plugin. filter_delete_all_for_filter($filterpath); $a = new stdClass(); $a->filter = $filtername; $a->directory = $filterpath; echo $OUTPUT->box(get_string('deletefilterfiles', 'admin', $a), 'generalbox', 'notice'); echo $OUTPUT->continue_button($returnurl); echo $OUTPUT->footer(); exit; } // Add any missing filters to the DB table. foreach ($newfilters as $filter => $notused) { filter_set_global_state($filter, TEXTFILTER_DISABLED); } // Reset caches and return if ($action) { reset_text_filters_cache();
public function test_filter_delete_all_for_filter() { global $DB; // Setup fixture. filter_set_global_state('name', TEXTFILTER_ON); filter_set_global_state('other', TEXTFILTER_ON); filter_set_local_config('name', context_system::instance()->id, 'settingname', 'A value'); filter_set_local_config('other', context_system::instance()->id, 'settingname', 'Other value'); set_config('configname', 'A config value', 'filter_name'); set_config('configname', 'Other config value', 'filter_other'); // Exercise SUT. filter_delete_all_for_filter('name'); // Validate. $this->assertEquals(1, $DB->count_records('filter_active')); $this->assertTrue($DB->record_exists('filter_active', array('filter' => 'other'))); $this->assertEquals(1, $DB->count_records('filter_config')); $this->assertTrue($DB->record_exists('filter_config', array('filter' => 'other'))); $expectedconfig = new stdClass(); $expectedconfig->configname = 'Other config value'; $this->assertEquals($expectedconfig, get_config('filter_other')); $this->assertEquals(get_config('filter_name'), new stdClass()); }