MDL-73339 glossary_random: Add block only if main feature is enabled
The Random glossary entry block should be added only if the glossary module is enabled.
This commit is contained in:
@@ -270,5 +270,15 @@ class block_glossary_random extends block_base {
|
||||
'plugin' => new stdClass(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This block shouldn't be added to a page if the glossary module is disabled.
|
||||
*
|
||||
* @param moodle_page $page
|
||||
* @return bool
|
||||
*/
|
||||
public function can_block_be_added(moodle_page $page): bool {
|
||||
$pluginclass = \core_plugin_manager::resolve_plugininfo_class('mod');
|
||||
return $pluginclass::get_enabled_plugin('glossary');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
@block @block_glossary_random @javascript @addablocklink
|
||||
Feature: Add the glossary random block when main feature is enabled
|
||||
In order to add the glossary random block to my course
|
||||
As a teacher
|
||||
It should be added to courses only if the glossary module is enabled.
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And I am on the "C1" "course" page logged in as "admin"
|
||||
|
||||
Scenario: The glossary random block can be added when glossary module is enabled
|
||||
Given I turn editing mode on
|
||||
When I click on "Add a block" "link"
|
||||
Then I should see "Random glossary entry"
|
||||
|
||||
Scenario: The glossary random block cannot be added when glossary module is disabled
|
||||
Given I navigate to "Plugins > Activity modules > Manage activities" in site administration
|
||||
And I click on "Hide" "icon" in the "Glossary" "table_row"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
When I click on "Add a block" "link"
|
||||
Then I should not see "Random glossary entry"
|
||||
@@ -0,0 +1,36 @@
|
||||
@block @block_glossary_random @javascript
|
||||
Feature: Add the glossary random block when main feature is disabled
|
||||
In order to add the glossary random block to my course
|
||||
As a teacher
|
||||
It should be added to courses only if the glossary module is enabled.
|
||||
|
||||
Background:
|
||||
Given the following "courses" exist:
|
||||
| fullname | shortname | format |
|
||||
| Course 1 | C1 | topics |
|
||||
And I am on the "C1" "course" page logged in as "admin"
|
||||
|
||||
Scenario: The glossary random block is displayed even when glossary module is disabled
|
||||
Given I turn editing mode on
|
||||
And I add the "Random glossary entry" block
|
||||
When I navigate to "Plugins > Activity modules > Manage activities" in site administration
|
||||
And I click on "Hide" "icon" in the "Glossary" "table_row"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
Then I should see "Random glossary entry"
|
||||
|
||||
Scenario: The glossary random block can be removed even when glossary module is disabled
|
||||
Given I turn editing mode on
|
||||
And I add the "Random glossary entry" block
|
||||
And I open the "Random glossary entry" blocks action menu
|
||||
And I click on "Delete Random glossary entry block" "link" in the "Random glossary entry" "block"
|
||||
And "Delete block?" "dialogue" should exist
|
||||
And I click on "Cancel" "button" in the "Delete block?" "dialogue"
|
||||
And I should see "Random glossary entry"
|
||||
When I navigate to "Plugins > Activity modules > Manage activities" in site administration
|
||||
And I click on "Hide" "icon" in the "Glossary" "table_row"
|
||||
And I am on "Course 1" course homepage with editing mode on
|
||||
And I open the "Random glossary entry" blocks action menu
|
||||
And I click on "Delete Random glossary entry block" "link" in the "Random glossary entry" "block"
|
||||
And "Delete block?" "dialogue" should exist
|
||||
And I click on "Delete" "button" in the "Delete block?" "dialogue"
|
||||
Then I should not see "Random glossary entry"
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
namespace block_glossary_random\tests;
|
||||
|
||||
use advanced_testcase;
|
||||
use block_glossary_random;
|
||||
use context_course;
|
||||
|
||||
/**
|
||||
* PHPUnit block_glossary_random tests
|
||||
*
|
||||
* @package block_glossary_random
|
||||
* @category test
|
||||
* @copyright 2021 Sara Arjona ([email protected])
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @coversDefaultClass \block_glossary_random
|
||||
*/
|
||||
class glossary_random_test extends advanced_testcase {
|
||||
public static function setUpBeforeClass(): void {
|
||||
require_once(__DIR__ . '/../../moodleblock.class.php');
|
||||
require_once(__DIR__ . '/../block_glossary_random.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the behaviour of can_block_be_added() method.
|
||||
*
|
||||
* @covers ::can_block_be_added
|
||||
*/
|
||||
public function test_can_block_be_added(): void {
|
||||
$this->resetAfterTest();
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create a course and prepare the page where the block will be added.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$page = new \moodle_page();
|
||||
$page->set_context(context_course::instance($course->id));
|
||||
$page->set_pagelayout('course');
|
||||
|
||||
$block = new block_glossary_random();
|
||||
$pluginclass = \core_plugin_manager::resolve_plugininfo_class('mod');
|
||||
|
||||
// If glossary module is enabled, the method should return true.
|
||||
$pluginclass::enable_plugin('glossary', 1);
|
||||
$this->assertTrue($block->can_block_be_added($page));
|
||||
|
||||
// However, if the glossary module is disabled, the method should return false.
|
||||
$pluginclass::enable_plugin('glossary', 0);
|
||||
$this->assertFalse($block->can_block_be_added($page));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user