Skip to content

Commit

Permalink
MDL-81915 admin: Fix test_admin_output_new_settings_by_page unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
AnupamaSarjoshi committed May 24, 2024
1 parent d32844c commit f016835
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions lib/tests/adminlib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,33 +128,34 @@ public function test_db_should_replace_additional_skip_tables(string $table, str
}

/**
* Test method used by upgradesettings.php to make sure
* there are no missing settings in PHPUnit and Behat tests.
* Test admin_output_new_settings_by_page method.
*
* @covers ::admin_output_new_settings_by_page
*/
public function test_admin_output_new_settings_by_page() {
$this->resetAfterTest();
$this->setAdminUser();

$root = admin_get_root(true, true);
// The initial list of html pages with no default settings.
$initialsettings = admin_output_new_settings_by_page($root);
$this->assertArrayHasKey('supportcontact', $initialsettings);
$this->assertArrayHasKey('frontpagesettings', $initialsettings);
// Existing default setting.
$this->assertArrayNotHasKey('modsettingbook', $initialsettings);

// Add settings not set during PHPUnit init.
set_config('supportemail', '[email protected]');
$frontpage = new \admin_setting_special_frontpagedesc();
$frontpage->write_setting('test test');

// NOTE: if this test fails then it is most likely extra setting in
// some additional plugin without default - developer needs to add
// a workaround into their db/install.php for PHPUnit and Behat.

$root = admin_get_root(true, true);
$new = admin_output_new_settings_by_page($root);
$this->assertSame([], $new);

// Remove a default setting.
unset_config('numbering', 'book');
unset_config('supportemail');

$root = admin_get_root(true, true);
$new = admin_output_new_settings_by_page($root);
$this->assertCount(2, $new);
$this->assertArrayNotHasKey('supportcontact', $new);
$this->assertArrayNotHasKey('frontpagesettings', $new);
$this->assertArrayHasKey('modsettingbook', $new);
}

/**
Expand Down

0 comments on commit f016835

Please sign in to comment.