Skip to content

Commit 09db89e

Browse files
Fix behat (#5)
* Added a patch so behat tests will be compatible with moodle 3 & 4 * Fixed behat test & codechecker * Fixed camel cases in behat test
1 parent e49ce12 commit 09db89e

File tree

2 files changed

+55
-25
lines changed

2 files changed

+55
-25
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
// This file is part of Moodle - http://moodle.org/
3+
//
4+
// Moodle is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// Moodle is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16+
17+
/**
18+
* File containing a class allowing set editing mode on either on moodle 3 & moodle 4.
19+
*
20+
* @package block_featured_courses
21+
* @copyright 2022 - CALL Learning
22+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23+
* @author Martin CORNU-MANSUY <martin@call-learning>
24+
*/
25+
26+
/**
27+
* A patch to make "I turn editing mode on" compatible with moodle 3.
28+
*
29+
* @package block_featured_courses
30+
* @copyright 2022 - CALL Learning
31+
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32+
* @author Martin CORNU-MANSUY <martin@call-learning>
33+
*/
34+
class behat_block_featured_courses extends behat_base {
35+
36+
/**
37+
* Turn on editing mode in moodle compatible with version 3 and 4.
38+
*
39+
* @Given I set editing mode on
40+
*/
41+
public function i_set_editing_mode_on() {
42+
global $CFG;
43+
require_once($CFG->dirroot . "/lib/environmentlib.php");
44+
$release = intval(get_config('', 'release')[0]);
45+
if (normalize_version($release) > 3) {
46+
$this->execute('behat_navigation::i_turn_editing_mode_on', []);
47+
} else {
48+
$this->execute('behat_general::i_click_on', ["Customise this page", "button"]);
49+
}
50+
}
51+
}

tests/behat/block_featured_courses.feature

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,34 +11,13 @@ Feature: Add a featured block on the dashboard
1111
| Course 4 | C4 | 0 | 1 |
1212

1313
@javascript
14-
Scenario: Add the block and set 3 featured courses
14+
Scenario: Add the block, set 4 featured courses and remove one after, only two should display
1515
Given I log in as "admin"
16-
Then I am on homepage
17-
When I press "Customise this page"
18-
And I add the "Featured Courses" block
16+
And I set editing mode on
17+
And I add the "Featured courses" block
1918
And I configure the "Featured courses" block
2019
And I expand all fieldsets
21-
Then I should see "Title"
22-
And I set the field "Title" to "My featured courses"
23-
And I press "Add 3 more courses"
24-
Then I set the following fields to these values:
25-
| Selected course 1 | Course 1 |
26-
| Selected course 2 | Course 2 |
27-
| Selected course 3 | Course 3 |
28-
And I set the field "Region" to "content"
29-
And I press "Save changes"
30-
Then I should see "Course 1" in the "My featured courses" "block"
31-
Then I should see "Course 2" in the "My featured courses" "block"
32-
Then I should see "Course 3" in the "My featured courses" "block"
33-
34-
@javascript
35-
Scenario: Add the block and set 3 featured courses and remove one after, only two should display
36-
Given I log in as "admin"
37-
When I press "Customise this page"
38-
Then I add the "Featured courses" block
39-
And I configure the "Featured courses" block
40-
And I expand all fieldsets
41-
Then I should see "Title"
20+
And I should see "Title"
4221
And I set the field "Title" to "My featured courses"
4322
And I press "Add 3 more courses"
4423
Then I set the following fields to these values:

0 commit comments

Comments
 (0)