forked from at-tools/moodle-block_massaction
-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add callbacks to add or keep section number #117
Closed
tuanngocnguyen
wants to merge
1
commit into
Syxton:MOODLE_401_STABLE
from
catalyst:issue115_limitation_to_add_course_section
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
<?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/>. | ||
|
||
/** | ||
* block_massaction phpunit test class. | ||
* | ||
* @package block_massaction | ||
* @copyright 2021 ISB Bayern | ||
* @author Philipp Memmel | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
namespace block_massaction; | ||
|
||
use advanced_testcase; | ||
|
||
/** | ||
* block_massaction phpunit test class. | ||
* | ||
* @package block_massaction | ||
* @author Nathan Nguyen <nathannguyen@catalyst-au.net> | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class massactionutils_test extends advanced_testcase { | ||
|
||
/** | ||
* Private test set up method. | ||
* | ||
* @return array course id and format. | ||
*/ | ||
private function get_course_and_format(): array { | ||
$this->resetAfterTest(); | ||
|
||
// Create a course. | ||
$course = $this->getDataGenerator()->create_course(); | ||
|
||
// Get course format. | ||
$coursemodinfo = get_fast_modinfo($course); | ||
$format = course_get_format($coursemodinfo->get_course())->get_format(); | ||
|
||
return [$course->id, $format]; | ||
} | ||
|
||
/** | ||
* Check default values of the get_restricted_sections method. | ||
* @covers \block_massaction\massactionutils::get_restricted_sections | ||
* | ||
*/ | ||
public function test_get_restricted_sections() { | ||
$this->resetAfterTest(); | ||
|
||
// Target course id and format. | ||
[$courseid, $format] = $this->get_course_and_format(); | ||
|
||
// Get restricted sections. | ||
$restrictedsections = massactionutils::get_restricted_sections($courseid, $format); | ||
|
||
// Check if the restricted sections are empty. | ||
$this->assertIsArray($restrictedsections); | ||
$this->assertEmpty($restrictedsections); | ||
} | ||
|
||
/** | ||
* Check default values of the can_add_section method. | ||
* @covers \block_massaction\massactionutils::can_add_section | ||
* | ||
*/ | ||
public function test_can_add_section() { | ||
$this->resetAfterTest(); | ||
|
||
// Create a user. | ||
$user = $this->getDataGenerator()->create_user(); | ||
// Set the user as the current user. | ||
$this->setUser($user); | ||
|
||
// Target course id and format. | ||
[$courseid, $format] = $this->get_course_and_format(); | ||
|
||
// Check if a section can be added. | ||
$this->assertFalse(massactionutils::can_add_section($courseid, $format)); | ||
|
||
// Enrol the user as a editing teacher. | ||
$this->getDataGenerator()->enrol_user($user->id, $courseid, 'editingteacher'); | ||
|
||
// Check if a section can be added. | ||
$this->assertTrue(massactionutils::can_add_section($courseid, $format)); | ||
} | ||
|
||
/** | ||
* Check default values of the can_keep_original_section_number method. | ||
* @covers \block_massaction\massactionutils::can_keep_original_section_number | ||
* | ||
*/ | ||
public function test_can_keep_original_section_number() { | ||
$this->resetAfterTest(); | ||
|
||
// Target course id and format. | ||
[$courseid, $format] = $this->get_course_and_format(); | ||
|
||
// Check if the original section number can be kept. | ||
$this->assertTrue(massactionutils::can_keep_original_section_number($courseid, $format)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FOUND 1 ERROR AFFECTING 1 LINE
140 | ERROR | [x] Functions must not contain multiple empty lines in a row; found 2 empty lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have removed the redundant empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @TomoTsuyuki for your review
I have updated the patch