Merge branch 'w51_MDL-29996_m25_oldfilters' of git://github.com/skodak/moodle

This commit is contained in:
Sam Hemelryk 2013-01-07 15:22:37 +13:00
commit dd89f61e68
24 changed files with 474 additions and 548 deletions

View file

@ -44,7 +44,7 @@ class filter_active_global_testcase extends advanced_testcase {
private function assert_only_one_filter_globally($filter, $state) {
global $DB;
$recs = $DB->get_records('filter_active');
$this->assertEquals(1, count($recs), 'More than one record returned %s.');
$this->assertCount(1, $recs);
$rec = reset($recs);
unset($rec->id);
$expectedrec = new stdClass();
@ -71,25 +71,25 @@ class filter_active_global_testcase extends advanced_testcase {
public function test_set_filter_globally_on() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/name', TEXTFILTER_ON, 1);
filter_set_global_state('name', TEXTFILTER_ON);
// Validate.
$this->assert_only_one_filter_globally('filter/name', TEXTFILTER_ON);
$this->assert_only_one_filter_globally('name', TEXTFILTER_ON);
}
public function test_set_filter_globally_off() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/name', TEXTFILTER_OFF, 1);
filter_set_global_state('name', TEXTFILTER_OFF);
// Validate.
$this->assert_only_one_filter_globally('filter/name', TEXTFILTER_OFF);
$this->assert_only_one_filter_globally('name', TEXTFILTER_OFF);
}
public function test_set_filter_globally_disabled() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/name', TEXTFILTER_DISABLED, 1);
filter_set_global_state('name', TEXTFILTER_DISABLED);
// Validate.
$this->assert_only_one_filter_globally('filter/name', TEXTFILTER_DISABLED);
$this->assert_only_one_filter_globally('name', TEXTFILTER_DISABLED);
}
/**
@ -97,135 +97,93 @@ class filter_active_global_testcase extends advanced_testcase {
* @return void
*/
public function test_global_config_exception_on_invalid_state() {
filter_set_global_state('filter/name', 0, 1);
filter_set_global_state('name', 0);
}
public function test_set_no_sortorder_clash() {
public function test_auto_sort_order() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/one', TEXTFILTER_DISABLED, 1);
filter_set_global_state('filter/two', TEXTFILTER_DISABLED, 1);
// Validate - should have pushed other filters down.
$this->assert_global_sort_order(array('filter/two', 'filter/one'));
}
public function test_auto_sort_order_disabled() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/one', TEXTFILTER_DISABLED);
filter_set_global_state('filter/two', TEXTFILTER_DISABLED);
filter_set_global_state('one', TEXTFILTER_DISABLED);
filter_set_global_state('two', TEXTFILTER_DISABLED);
// Validate.
$this->assert_global_sort_order(array('filter/one', 'filter/two'));
$this->assert_global_sort_order(array('one', 'two'));
}
public function test_auto_sort_order_enabled() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/one', TEXTFILTER_ON);
filter_set_global_state('filter/two', TEXTFILTER_OFF);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_OFF);
// Validate.
$this->assert_global_sort_order(array('filter/one', 'filter/two'));
}
public function test_auto_sort_order_mixed() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/0', TEXTFILTER_DISABLED);
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_DISABLED);
filter_set_global_state('filter/3', TEXTFILTER_OFF);
// Validate.
$this->assert_global_sort_order(array('filter/1', 'filter/3', 'filter/0', 'filter/2'));
$this->assert_global_sort_order(array('one', 'two'));
}
public function test_update_existing_dont_duplicate() {
// Setup fixture.
// Exercise SUT.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_global_state('filter/name', TEXTFILTER_OFF);
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_OFF);
// Validate.
$this->assert_only_one_filter_globally('filter/name', TEXTFILTER_OFF);
}
/**
* @expectedException coding_exception
* @return void
*/
public function test_sort_order_not_too_low() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
// Exercise SUT.
filter_set_global_state('filter/2', TEXTFILTER_ON, 0);
}
/**
* @expectedException coding_exception
* @return void
*/
public function test_sort_order_not_too_high() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
// Exercise SUT.
filter_set_global_state('filter/2', TEXTFILTER_ON, 3);
$this->assert_only_one_filter_globally('name', TEXTFILTER_OFF);
}
public function test_update_reorder_down() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_ON);
filter_set_global_state('filter/3', TEXTFILTER_ON);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_ON);
filter_set_global_state('three', TEXTFILTER_ON);
// Exercise SUT.
filter_set_global_state('filter/2', TEXTFILTER_ON, 1);
filter_set_global_state('two', TEXTFILTER_ON, -1);
// Validate.
$this->assert_global_sort_order(array('filter/2', 'filter/1', 'filter/3'));
$this->assert_global_sort_order(array('two', 'one', 'three'));
}
public function test_update_reorder_up() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_ON);
filter_set_global_state('filter/3', TEXTFILTER_ON);
filter_set_global_state('filter/4', TEXTFILTER_ON);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_ON);
filter_set_global_state('three', TEXTFILTER_ON);
filter_set_global_state('four', TEXTFILTER_ON);
// Exercise SUT.
filter_set_global_state('filter/2', TEXTFILTER_ON, 3);
filter_set_global_state('two', TEXTFILTER_ON, 1);
// Validate.
$this->assert_global_sort_order(array('filter/1', 'filter/3', 'filter/2', 'filter/4'));
$this->assert_global_sort_order(array('one', 'three', 'two', 'four'));
}
public function test_auto_sort_order_change_to_enabled() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_DISABLED);
filter_set_global_state('filter/3', TEXTFILTER_DISABLED);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_DISABLED);
filter_set_global_state('three', TEXTFILTER_DISABLED);
// Exercise SUT.
filter_set_global_state('filter/3', TEXTFILTER_ON);
filter_set_global_state('three', TEXTFILTER_ON);
// Validate.
$this->assert_global_sort_order(array('filter/1', 'filter/3', 'filter/2'));
$this->assert_global_sort_order(array('one', 'three', 'two'));
}
public function test_auto_sort_order_change_to_disabled() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_ON);
filter_set_global_state('filter/3', TEXTFILTER_DISABLED);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_ON);
filter_set_global_state('three', TEXTFILTER_DISABLED);
// Exercise SUT.
filter_set_global_state('filter/1', TEXTFILTER_DISABLED);
filter_set_global_state('one', TEXTFILTER_DISABLED);
// Validate.
$this->assert_global_sort_order(array('filter/2', 'filter/1', 'filter/3'));
$this->assert_global_sort_order(array('two', 'one', 'three'));
}
public function test_filter_get_global_states() {
// Setup fixture.
filter_set_global_state('filter/1', TEXTFILTER_ON);
filter_set_global_state('filter/2', TEXTFILTER_OFF);
filter_set_global_state('filter/3', TEXTFILTER_DISABLED);
filter_set_global_state('one', TEXTFILTER_ON);
filter_set_global_state('two', TEXTFILTER_OFF);
filter_set_global_state('three', TEXTFILTER_DISABLED);
// Exercise SUT.
$filters = filter_get_global_states();
// Validate.
$this->assertEquals(array(
'filter/1' => (object) array('filter' => 'filter/1', 'active' => TEXTFILTER_ON, 'sortorder' => 1),
'filter/2' => (object) array('filter' => 'filter/2', 'active' => TEXTFILTER_OFF, 'sortorder' => 2),
'filter/3' => (object) array('filter' => 'filter/3', 'active' => TEXTFILTER_DISABLED, 'sortorder' => 3)
'one' => (object) array('filter' => 'one', 'active' => TEXTFILTER_ON, 'sortorder' => 1),
'two' => (object) array('filter' => 'two', 'active' => TEXTFILTER_OFF, 'sortorder' => 2),
'three' => (object) array('filter' => 'three', 'active' => TEXTFILTER_DISABLED, 'sortorder' => 3)
), $filters);
}
}
@ -264,21 +222,21 @@ class filter_active_local_testcase extends advanced_testcase {
public function test_local_on() {
// Exercise SUT.
filter_set_local_state('filter/name', 123, TEXTFILTER_ON);
filter_set_local_state('name', 123, TEXTFILTER_ON);
// Validate.
$this->assert_only_one_local_setting('filter/name', 123, TEXTFILTER_ON);
$this->assert_only_one_local_setting('name', 123, TEXTFILTER_ON);
}
public function test_local_off() {
// Exercise SUT.
filter_set_local_state('filter/name', 123, TEXTFILTER_OFF);
filter_set_local_state('name', 123, TEXTFILTER_OFF);
// Validate.
$this->assert_only_one_local_setting('filter/name', 123, TEXTFILTER_OFF);
$this->assert_only_one_local_setting('name', 123, TEXTFILTER_OFF);
}
public function test_local_inherit() {
// Exercise SUT.
filter_set_local_state('filter/name', 123, TEXTFILTER_INHERIT);
filter_set_local_state('name', 123, TEXTFILTER_INHERIT);
// Validate.
$this->assert_no_local_setting();
}
@ -289,7 +247,7 @@ class filter_active_local_testcase extends advanced_testcase {
*/
public function test_local_invalid_state_throws_exception() {
// Exercise SUT.
filter_set_local_state('filter/name', 123, -9999);
filter_set_local_state('name', 123, -9999);
}
/**
@ -298,14 +256,14 @@ class filter_active_local_testcase extends advanced_testcase {
*/
public function test_throws_exception_when_setting_global() {
// Exercise SUT.
filter_set_local_state('filter/name', context_system::instance()->id, TEXTFILTER_INHERIT);
filter_set_local_state('name', context_system::instance()->id, TEXTFILTER_INHERIT);
}
public function test_local_inherit_deletes_existing() {
// Setup fixture.
filter_set_local_state('filter/name', 123, TEXTFILTER_INHERIT);
filter_set_local_state('name', 123, TEXTFILTER_INHERIT);
// Exercise SUT.
filter_set_local_state('filter/name', 123, TEXTFILTER_INHERIT);
filter_set_local_state('name', 123, TEXTFILTER_INHERIT);
// Validate.
$this->assert_no_local_setting();
}
@ -340,28 +298,28 @@ class filter_config_testcase extends advanced_testcase {
public function test_set_new_config() {
// Exercise SUT.
filter_set_local_config('filter/name', 123, 'settingname', 'An arbitrary value');
filter_set_local_config('name', 123, 'settingname', 'An arbitrary value');
// Validate.
$this->assert_only_one_config('filter/name', 123, 'settingname', 'An arbitrary value');
$this->assert_only_one_config('name', 123, 'settingname', 'An arbitrary value');
}
public function test_update_existing_config() {
// Setup fixture.
filter_set_local_config('filter/name', 123, 'settingname', 'An arbitrary value');
filter_set_local_config('name', 123, 'settingname', 'An arbitrary value');
// Exercise SUT.
filter_set_local_config('filter/name', 123, 'settingname', 'A changed value');
filter_set_local_config('name', 123, 'settingname', 'A changed value');
// Validate.
$this->assert_only_one_config('filter/name', 123, 'settingname', 'A changed value');
$this->assert_only_one_config('name', 123, 'settingname', 'A changed value');
}
public function test_filter_get_local_config() {
// Setup fixture.
filter_set_local_config('filter/name', 123, 'setting1', 'An arbitrary value');
filter_set_local_config('filter/name', 123, 'setting2', 'Another arbitrary value');
filter_set_local_config('filter/name', 122, 'settingname', 'Value from another context');
filter_set_local_config('filter/other', 123, 'settingname', 'Someone else\'s value');
filter_set_local_config('name', 123, 'setting1', 'An arbitrary value');
filter_set_local_config('name', 123, 'setting2', 'Another arbitrary value');
filter_set_local_config('name', 122, 'settingname', 'Value from another context');
filter_set_local_config('other', 123, 'settingname', 'Someone else\'s value');
// Exercise SUT.
$config = filter_get_local_config('filter/name', 123);
$config = filter_get_local_config('name', 123);
// Validate.
$this->assertEquals(array('setting1' => 'An arbitrary value', 'setting2' => 'Another arbitrary value'), $config);
}
@ -398,18 +356,18 @@ class filter_get_active_available_in_context_testcase extends advanced_testcase
public function test_globally_on_is_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_ON);
// Exercise SUT.
$filters = filter_get_active_in_context(self::$syscontext);
// Validate.
$this->assert_filter_list(array('filter/name'), $filters);
$this->assert_filter_list(array('name'), $filters);
// Check no config returned correctly.
$this->assertEquals(array(), $filters['filter/name']);
$this->assertEquals(array(), $filters['name']);
}
public function test_globally_off_not_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_OFF);
filter_set_global_state('name', TEXTFILTER_OFF);
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext2);
// Validate.
@ -418,18 +376,18 @@ class filter_get_active_available_in_context_testcase extends advanced_testcase
public function test_globally_off_overridden() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_OFF);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_OFF);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_ON);
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext2);
// Validate.
$this->assert_filter_list(array('filter/name'), $filters);
$this->assert_filter_list(array('name'), $filters);
}
public function test_globally_on_overridden() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_OFF);
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_OFF);
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext2);
// Validate.
@ -438,8 +396,8 @@ class filter_get_active_available_in_context_testcase extends advanced_testcase
public function test_globally_disabled_not_overridden() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_DISABLED);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_DISABLED);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_ON);
// Exercise SUT.
$filters = filter_get_active_in_context(self::$syscontext);
// Validate.
@ -448,45 +406,45 @@ class filter_get_active_available_in_context_testcase extends advanced_testcase
public function test_single_config_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_config('filter/name', self::$childcontext->id, 'settingname', 'A value');
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_config('name', self::$childcontext->id, 'settingname', 'A value');
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext);
// Validate.
$this->assertEquals(array('settingname' => 'A value'), $filters['filter/name']);
$this->assertEquals(array('settingname' => 'A value'), $filters['name']);
}
public function test_multi_config_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_config('filter/name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('filter/name', self::$childcontext->id, 'anothersettingname', 'Another value');
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_config('name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('name', self::$childcontext->id, 'anothersettingname', 'Another value');
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext);
// Validate.
$this->assertEquals(array('settingname' => 'A value', 'anothersettingname' => 'Another value'), $filters['filter/name']);
$this->assertEquals(array('settingname' => 'A value', 'anothersettingname' => 'Another value'), $filters['name']);
}
public function test_config_from_other_context_not_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_config('filter/name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('filter/name', self::$childcontext2->id, 'anothersettingname', 'Another value');
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_config('name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('name', self::$childcontext2->id, 'anothersettingname', 'Another value');
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext2);
// Validate.
$this->assertEquals(array('anothersettingname' => 'Another value'), $filters['filter/name']);
$this->assertEquals(array('anothersettingname' => 'Another value'), $filters['name']);
}
public function test_config_from_other_filter_not_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_config('filter/name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('filter/other', self::$childcontext->id, 'anothersettingname', 'Another value');
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_config('name', self::$childcontext->id, 'settingname', 'A value');
filter_set_local_config('other', self::$childcontext->id, 'anothersettingname', 'Another value');
// Exercise SUT.
$filters = filter_get_active_in_context(self::$childcontext);
// Validate.
$this->assertEquals(array('settingname' => 'A value'), $filters['filter/name']);
$this->assertEquals(array('settingname' => 'A value'), $filters['name']);
}
protected function assert_one_available_filter($filter, $localstate, $inheritedstate, $filters) {
@ -502,28 +460,28 @@ class filter_get_active_available_in_context_testcase extends advanced_testcase
public function test_available_in_context_localoverride() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_OFF);
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_OFF);
// Exercise SUT.
$filters = filter_get_available_in_context(self::$childcontext);
// Validate.
$this->assert_one_available_filter('filter/name', TEXTFILTER_OFF, TEXTFILTER_ON, $filters);
$this->assert_one_available_filter('name', TEXTFILTER_OFF, TEXTFILTER_ON, $filters);
}
public function test_available_in_context_nolocaloverride() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_OFF);
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_OFF);
// Exercise SUT.
$filters = filter_get_available_in_context(self::$childcontext2);
// Validate.
$this->assert_one_available_filter('filter/name', TEXTFILTER_INHERIT, TEXTFILTER_OFF, $filters);
$this->assert_one_available_filter('name', TEXTFILTER_INHERIT, TEXTFILTER_OFF, $filters);
}
public function test_available_in_context_disabled_not_returned() {
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_DISABLED);
filter_set_local_state('filter/name', self::$childcontext->id, TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_DISABLED);
filter_set_local_state('name', self::$childcontext->id, TEXTFILTER_ON);
// Exercise SUT.
$filters = filter_get_available_in_context(self::$childcontext);
// Validate.
@ -610,43 +568,43 @@ class filter_preload_activities_testcase extends advanced_testcase {
$this->assert_matches($modinfo);
// Enable filter globally, check
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_global_state('name', TEXTFILTER_ON);
$this->assert_matches($modinfo);
// Disable for activity 2
filter_set_local_state('filter/name', self::$activity2context->id, TEXTFILTER_OFF);
filter_set_local_state('name', self::$activity2context->id, TEXTFILTER_OFF);
$this->assert_matches($modinfo);
// Disable at category
filter_set_local_state('filter/name', self::$catcontext->id, TEXTFILTER_OFF);
filter_set_local_state('name', self::$catcontext->id, TEXTFILTER_OFF);
$this->assert_matches($modinfo);
// Enable for activity 1
filter_set_local_state('filter/name', self::$activity1context->id, TEXTFILTER_ON);
filter_set_local_state('name', self::$activity1context->id, TEXTFILTER_ON);
$this->assert_matches($modinfo);
// Disable globally
filter_set_global_state('filter/name', TEXTFILTER_DISABLED);
filter_set_global_state('name', TEXTFILTER_DISABLED);
$this->assert_matches($modinfo);
// Add another 2 filters
filter_set_global_state('filter/frog', TEXTFILTER_ON);
filter_set_global_state('filter/zombie', TEXTFILTER_ON);
filter_set_global_state('frog', TEXTFILTER_ON);
filter_set_global_state('zombie', TEXTFILTER_ON);
$this->assert_matches($modinfo);
// Disable random one of these in each context
filter_set_local_state('filter/zombie', self::$activity1context->id, TEXTFILTER_OFF);
filter_set_local_state('filter/frog', self::$activity2context->id, TEXTFILTER_OFF);
filter_set_local_state('zombie', self::$activity1context->id, TEXTFILTER_OFF);
filter_set_local_state('frog', self::$activity2context->id, TEXTFILTER_OFF);
$this->assert_matches($modinfo);
// Now do some filter options
filter_set_local_config('filter/name', self::$activity1context->id, 'a', 'x');
filter_set_local_config('filter/zombie', self::$activity1context->id, 'a', 'y');
filter_set_local_config('filter/frog', self::$activity1context->id, 'a', 'z');
filter_set_local_config('name', self::$activity1context->id, 'a', 'x');
filter_set_local_config('zombie', self::$activity1context->id, 'a', 'y');
filter_set_local_config('frog', self::$activity1context->id, 'a', 'z');
// These last two don't do anything as they are not at final level but I
// thought it would be good to have that verified in test
filter_set_local_config('filter/frog', self::$coursecontext->id, 'q', 'x');
filter_set_local_config('filter/frog', self::$catcontext->id, 'q', 'z');
filter_set_local_config('frog', self::$coursecontext->id, 'q', 'x');
filter_set_local_config('frog', self::$catcontext->id, 'q', 'z');
$this->assert_matches($modinfo);
}
}
@ -666,19 +624,19 @@ class filter_delete_config_testcase extends advanced_testcase {
global $DB;
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_global_state('filter/other', TEXTFILTER_ON);
filter_set_local_config('filter/name', context_system::instance()->id, 'settingname', 'A value');
filter_set_local_config('filter/other', context_system::instance()->id, 'settingname', 'Other value');
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('filter/name');
filter_delete_all_for_filter('name');
// Validate.
$this->assertEquals(1, $DB->count_records('filter_active'));
$this->assertTrue($DB->record_exists('filter_active', array('filter' => 'filter/other')));
$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' => 'filter/other')));
$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'));
@ -689,18 +647,18 @@ class filter_delete_config_testcase extends advanced_testcase {
global $DB;
// Setup fixture.
filter_set_global_state('filter/name', TEXTFILTER_ON);
filter_set_local_state('filter/name', 123, TEXTFILTER_OFF);
filter_set_local_config('filter/name', 123, 'settingname', 'A value');
filter_set_local_config('filter/other', 123, 'settingname', 'Other value');
filter_set_local_config('filter/other', 122, 'settingname', 'Other value');
filter_set_global_state('name', TEXTFILTER_ON);
filter_set_local_state('name', 123, TEXTFILTER_OFF);
filter_set_local_config('name', 123, 'settingname', 'A value');
filter_set_local_config('other', 123, 'settingname', 'Other value');
filter_set_local_config('other', 122, 'settingname', 'Other value');
// Exercise SUT.
filter_delete_all_for_context(123);
// Validate.
$this->assertEquals(1, $DB->count_records('filter_active'));
$this->assertTrue($DB->record_exists('filter_active', array('contextid' => context_system::instance()->id)));
$this->assertEquals(1, $DB->count_records('filter_config'));
$this->assertTrue($DB->record_exists('filter_config', array('filter' => 'filter/other')));
$this->assertTrue($DB->record_exists('filter_config', array('filter' => 'other')));
}
}
@ -735,9 +693,9 @@ class filter_filter_set_applies_to_strings extends advanced_testcase {
$CFG->filterall = 0;
$CFG->stringfilters = '';
// Exercise SUT.
filter_set_applies_to_strings('filter/name', true);
filter_set_applies_to_strings('name', true);
// Validate.
$this->assertEquals('filter/name', $CFG->stringfilters);
$this->assertEquals('name', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);
}
@ -745,9 +703,9 @@ class filter_filter_set_applies_to_strings extends advanced_testcase {
global $CFG;
// Setup fixture.
$CFG->filterall = 1;
$CFG->stringfilters = 'filter/name';
$CFG->stringfilters = 'name';
// Exercise SUT.
filter_set_applies_to_strings('filter/name', false);
filter_set_applies_to_strings('name', false);
// Validate.
$this->assertEquals('', $CFG->stringfilters);
$this->assertEquals('', $CFG->filterall);
@ -757,11 +715,11 @@ class filter_filter_set_applies_to_strings extends advanced_testcase {
global $CFG;
// Setup fixture.
$CFG->filterall = 1;
$CFG->stringfilters = 'filter/name,filter/other';
$CFG->stringfilters = 'name,other';
// Exercise SUT.
filter_set_applies_to_strings('filter/name', false);
filter_set_applies_to_strings('name', false);
// Validate.
$this->assertEquals('filter/other', $CFG->stringfilters);
$this->assertEquals('other', $CFG->stringfilters);
$this->assertEquals(1, $CFG->filterall);
}
}