Skip to content

Commit

Permalink
Improved Moodle CI
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Nov 26, 2023
1 parent 438b60b commit 93da7ea
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ public function i_create_pulsenotification_template_with_general($title, $refere
*/
public function i_create_pulsenotification_instance_with_general($title, $reference, TableNode $notificationdata) {

$this->execute('behat_forms::i_set_the_field_to', ["templateid", $title]);
$this->execute('behat_forms::i_open_the_autocomplete_suggestions_list', []);
$this->execute('behat_forms::i_click_on_item_in_the_autocomplete_list', [$title]);
$this->execute("behat_general::i_click_on", ["Add automation instance", "button"]);
$this->execute('behat_forms::i_set_the_field_to', ["Reference", $reference]);
$this->execute("behat_general::i_click_on_in_the", ["Notification", "link", "#automation-tabs", "css_element"]);
Expand All @@ -88,7 +89,8 @@ public function i_create_pulsenotification_instance_with_general($title, $refere
*/
public function i_set_pulsenotification_instance_with_general($title, TableNode $generaldata) {

$this->execute('behat_forms::i_set_the_field_to', ["templateid", $title]);
$this->execute('behat_forms::i_open_the_autocomplete_suggestions_list', []);
$this->execute('behat_forms::i_click_on_item_in_the_autocomplete_list', [$title]);
$this->execute("behat_general::i_click_on", ["Add automation instance", "button"]);
$this->execute('behat_forms::i_set_the_following_fields_to_these_values', [$generaldata]);
}
Expand Down
22 changes: 20 additions & 2 deletions automation/automationlib.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,30 @@ public function definition() {
$mform->setType('courseid', PARAM_INT);

// List of templates to create instance.
$templates = mod_pulse\automation\helper::get_templates_forinstance($courseid);
$templates = [0 => ''] + mod_pulse\automation\helper::get_templates_forinstance($courseid);
if (!empty($templates)) {
$mform->addElement('autocomplete', 'templateid', '', $templates);
}

$this->add_action_buttons(false, get_string('addtemplatebtn', 'pulse'));
$this->add_action_buttons(true, get_string('addtemplatebtn', 'pulse'));
}

/**
* validation
*
* @param mixed $data
* @param mixed $files
* @return array
*/
public function validation($data, $files) {
$errors = parent::validation($data, $files);

if (empty($data['templateid'])) {
$errors['templateid'] = get_string('required');
}

return $errors;

}
}

Expand Down
12 changes: 11 additions & 1 deletion automation/instances/list.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

// Require config.
require(__DIR__.'/../../../../config.php');
require_once($CFG->dirroot. '/mod/pulse/automation/automationlib.php');

require_login();

Expand Down Expand Up @@ -63,6 +64,15 @@
$PAGE->set_url(new moodle_url('/mod/pulse/automation/instances/list.php', ['courseid' => $courseid]));
$PAGE->set_course($course);

// Add instance template form submitted.
$instanceaddform = new \template_addinstance_form(null, ['courseid' => $courseid]);
if ($data = $instanceaddform->get_data()) {
$url = (new moodle_url('/mod/pulse/automation/instances/edit.php',
['courseid' => $courseid, 'templateid' => $data->templateid, 'sesskey' => sesskey()]))->out(false);

redirect($url);
}

// Process actions.
if ($action !== null && confirm_sesskey()) {
// Every action is based on a template, thus the template ID param has to exist.
Expand Down Expand Up @@ -135,7 +145,7 @@

// Prepare 'Create smart menu' button. // TODO Review.
$createbutton = $OUTPUT->box_start();
$createbutton .= mod_pulse\automation\helper::get_addtemplate_instance($courseid);
$createbutton .= mod_pulse\automation\helper::get_addtemplate_instance($instanceaddform, $courseid);
$createbutton .= $OUTPUT->box_end();

// If there aren't any smart menus yet.
Expand Down
6 changes: 2 additions & 4 deletions classes/automation/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,16 @@ public static function template_buttons($filtered=false) {
/**
* Create instance from templates.
*
* @param moodleform $form
* @param int $courseid
* @return string Form with templates list and manage templates button.
*/
public static function get_addtemplate_instance($courseid) {
public static function get_addtemplate_instance($form, $courseid) {
global $OUTPUT, $CFG, $PAGE;

require_once($CFG->dirroot. '/mod/pulse/automation/automationlib.php');

// Form to add automation template as instance for the course.
$url = (new moodle_url('/mod/pulse/automation/instances/edit.php', ['course' => $courseid]))->out(false);
$form = new \template_addinstance_form($url, ['courseid' => $courseid], 'get');

$html = \html_writer::start_tag('div', ['class' => 'template-add-form']);
$templates = self::get_templates_forinstance($courseid);
if (!empty($templates)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Feature: Activity trigger event.
| student1 | C1 | student |

@javascript
Scenario: Check the pluse condition activity trigger workflow.
Scenario: Check the pluse condition activity trigger workflow
Given I log in as "admin"
Then I create automation template with the following fields to these values:
| Title | WELCOME MESSAGE 01 |
Expand All @@ -33,7 +33,8 @@ Feature: Activity trigger event.
| Trigger operator | All |
And I am on "Course 1" course homepage
And I follow "Automation"
And I set the field "templateid" to "WELCOME MESSAGE 01"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 01" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage |
Expand All @@ -45,7 +46,8 @@ Feature: Activity trigger event.
Then I should see "TestPage 01" in the "#fitem_id_condition_activity_modules .form-autocomplete-suggestions" "css_element"
Then I should see "TestPage 02" in the "#fitem_id_condition_activity_modules .form-autocomplete-suggestions" "css_element"
And I press "Save changes"
And I set the field "templateid" to "WELCOME MESSAGE 02"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 02" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Feature: Cohort trigger event.
| Trigger operator | All |
And I am on "Course 1" course homepage
And I follow "Automation"
And I set the field "templateid" to "WELCOME MESSAGE 01"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 01" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage |
Expand All @@ -51,7 +52,8 @@ Feature: Cohort trigger event.
Then I should see "Cohort 1" in the "#fitem_id_condition_cohort_cohorts .form-autocomplete-suggestions" "css_element"
Then I should see "Cohort 2" in the "#fitem_id_condition_cohort_cohorts .form-autocomplete-suggestions" "css_element"
And I press "Save changes"
And I set the field "templateid" to "WELCOME MESSAGE 02"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 02" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ Feature: Course Completion trigger event.
| Trigger operator | All |
And I am on "Course 1" course homepage
And I follow "Automation"
And I set the field "templateid" to "WELCOME MESSAGE 01"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 01" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage |
Then I follow "Condition"
Then I should see "Course completion"
Then the field "Course completion" matches value "All"
And I press "Save changes"
And I set the field "templateid" to "WELCOME MESSAGE 02"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 02" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,17 @@ Feature: Course Enrolment trigger event.
| Trigger operator | All |
And I am on "Course 1" course homepage
And I follow "Automation"
And I set the field "templateid" to "WELCOME MESSAGE 01"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 01" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage |
Then I follow "Condition"
Then I should see "User enrolment"
Then the field "User enrolment" matches value "All"
And I press "Save changes"
And I set the field "templateid" to "WELCOME MESSAGE 02"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 02" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage2 |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Feature: Session trigger event.
| Trigger operator | All |
And I am on "Course 1" course homepage
And I follow "Automation"
And I set the field "templateid" to "WELCOME MESSAGE 01"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 01" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage |
Expand All @@ -52,7 +53,8 @@ Feature: Session trigger event.
And I should see "Session module"
Then I should see "FaceFace 01" in the "#fitem_id_condition_session_modules" "css_element"
And I press "Save changes"
And I set the field "templateid" to "WELCOME MESSAGE 02"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE 02" item in the autocomplete list
Then I press "Add automation instance"
And I set the following fields to these values:
| insreference | Welcomemessage2 |
Expand Down
23 changes: 18 additions & 5 deletions tests/behat/pulse_automation_instance.feature
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Feature: Pulse automation instances
And I should see "WELCOME MESSAGE" in the "#pulse_automation_template" "css_element"
And I am on "Course 1" course homepage
And I follow "Automation"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
And I set the following fields to these values:
| override[title] | 1 |
Expand All @@ -54,6 +56,8 @@ Feature: Pulse automation instances
And I should see "WELCOME MESSAGE" in the "#pulse_automation_template" "css_element"
And I am on "Course 1" course homepage
And I follow "Automation"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
And I set the following fields to these values:
| insreference | Welcomemessage |
Expand Down Expand Up @@ -83,6 +87,8 @@ Feature: Pulse automation instances
| Visibility| Show |
And I am on "Course 1" course homepage
And I follow "Automation"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
And I set the following fields to these values:
| override[title] | 1 |
Expand All @@ -104,6 +110,8 @@ Feature: Pulse automation instances
| Visibility| Show |
And I am on "Course 1" course homepage
And I follow "Automation"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
And I set the following fields to these values:
| insreference | Welcomemessage |
Expand All @@ -119,7 +127,7 @@ Feature: Pulse automation instances
And "#pulse_automation_template" "css_element" should not exist

@javascript
Scenario: Check the multiple automation template instance.
Scenario: Check the multiple automation template instance
Given I log in as "admin"
Then I create automation template with the following fields to these values:
| Title | WELCOME MESSAGE |
Expand All @@ -129,22 +137,27 @@ Feature: Pulse automation instances
| Reference | notification |
And I am on "Course 1" course homepage
And I follow "Automation"
Then I should see "WELCOME MESSAGE" in the ".template-add-form .custom-select" "css_element"
Then I should see "Notification" in the ".template-add-form .custom-select" "css_element"
When I open the autocomplete suggestions list
Then I should see "WELCOME MESSAGE" in the ".template-add-form .form-autocomplete-suggestions" "css_element"
Then I should see "Notification" in the ".template-add-form .form-autocomplete-suggestions" "css_element"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
Then the field "Title" matches value "WELCOME MESSAGE"
And I set the following fields to these values:
| insreference | Welcomemessageinstance |
And I press "Save changes"
And I should see "WELCOME MESSAGE" in the "#pulse_automation_template tbody tr:nth-child(1)" "css_element"
And I set the field "templateid" to "Notification"
When I open the autocomplete suggestions list
And I click on "Notification" item in the autocomplete list
Then I click on "Add automation instance" "button"
Then the field "Title" matches value "Notification"
And I set the following fields to these values:
| insreference | notificationinstance |
And I press "Save changes"
And I should see "Notification" in the "#pulse_automation_template tbody tr:nth-child(2)" "css_element"
And I set the field "templateid" to "WELCOME MESSAGE"
When I open the autocomplete suggestions list
And I click on "WELCOME MESSAGE" item in the autocomplete list
Then I click on "Add automation instance" "button"
Then the field "Title" matches value "WELCOME MESSAGE"
And I set the following fields to these values:
Expand Down
Loading

0 comments on commit 93da7ea

Please sign in to comment.