MDL-57232 blocks: Split undeletableblocktypes

There are 2 kinds of blocks that are undeletable. Those required by the
theme and those protected via the admin page ui. We only want the theme
ones to be auto created site wide if they don't exist - so we need to
rename the theme ones and split the logic.
This commit is contained in:
Damyon Wiese
2016-12-02 12:32:03 +08:00
parent a0352aa95e
commit 9d1402abd8
6 changed files with 124 additions and 51 deletions
+19 -3
View File
@@ -545,6 +545,7 @@ class core_blocklib_testcase extends advanced_testcase {
public function test_create_all_block_instances() {
global $CFG, $PAGE, $DB;
$this->setAdminUser();
$this->resetAfterTest();
$regionname = 'side-pre';
$context = context_system::instance();
@@ -557,6 +558,7 @@ class core_blocklib_testcase extends advanced_testcase {
$blockmanager->load_blocks();
$blockmanager->create_all_block_instances();
$blocks = $blockmanager->get_blocks_for_region($regionname);
// Assert that we no auto created blocks in boost by default.
$this->assertEmpty($blocks);
// There should be no blocks in the DB.
@@ -571,6 +573,7 @@ class core_blocklib_testcase extends advanced_testcase {
$blockmanager->load_blocks();
$blockmanager->create_all_block_instances();
$blocks = $blockmanager->get_blocks_for_region($regionname);
// Assert that we no auto created blocks when viewing a fake blocks only page.
$this->assertEmpty($blocks);
$PAGE->reset_theme_and_output();
@@ -581,10 +584,22 @@ class core_blocklib_testcase extends advanced_testcase {
$blockmanager->load_blocks();
$blockmanager->create_all_block_instances();
$blocks = $blockmanager->get_blocks_for_region($regionname);
// Assert that we get the required block for this theme auto-created.
$this->assertCount(2, $blocks);
$undeletable = block_manager::get_undeletable_block_types();
foreach ($undeletable as $blockname) {
$PAGE->reset_theme_and_output();
list($page, $blockmanager) = $this->get_a_page_and_block_manager(array($regionname),
$context, 'page-type');
$blockmanager->protect_block('html');
$blockmanager->load_blocks();
$blockmanager->create_all_block_instances();
$blocks = $blockmanager->get_blocks_for_region($regionname);
// Assert that protecting a block does not make it auto-created.
$this->assertCount(2, $blocks);
$requiredbytheme = block_manager::get_required_by_theme_block_types();
foreach ($requiredbytheme as $blockname) {
$instance = $DB->get_record('block_instances', array('blockname' => $blockname));
$this->assertEquals(1, $instance->requiredbytheme);
}
@@ -598,9 +613,10 @@ class core_blocklib_testcase extends advanced_testcase {
$blockmanager->load_blocks();
$blockmanager->create_all_block_instances();
$blocks = $blockmanager->get_blocks_for_region($regionname);
// Assert that we do not return requiredbytheme blocks when they are not required.
$this->assertEmpty($blocks);
// But they should exist in the DB.
foreach ($undeletable as $blockname) {
foreach ($requiredbytheme as $blockname) {
$count = $DB->count_records('block_instances', array('blockname' => $blockname));
$this->assertEquals(1, $count);
}