Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions classes/workflow_manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,9 @@ public function get_step_class_names($steptype = null) {
]
];
foreach ($plugins as $plugin => $dir) {
if (!PHPUNIT_TEST && $plugin == 'testplugin') {
continue;
}
$dirs[] = (object)[
'path' => $dir . '/classes',
'namespace' => "trigger_$plugin",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?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 trigger_testplugin\steps\lookups;
use tool_trigger\steps\lookups\base_lookup_step;

/**
* A lookup step for testing purposes.
*
* @package trigger_testplugin
* @copyright 2025 Moodle US
* @author Oscar Nadjar <oscar.nadjar@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class subplugin_lookup_test_step extends base_lookup_step {

/**
* The fields supplied by this step.
* A string containing all the cohorts a user is assigned to.
*
* @var array
*/
private static $stepfields = array(
'testlookupresult'
);

protected function init() {
}

/**
* {@inheritDoc}
* @see \tool_trigger\steps\base\base_step::execute()
*/
public function execute($step, $trigger, $event, $stepresults) {
global $DB;
$stepresults = [ 'testlookupresult' => 'test' ];
return [true, $stepresults];
}

/**
* {@inheritDoc}
* @see \tool_trigger\steps\base\base_step::form_definition_extra()
*/
public function form_definition_extra($form, $mform, $customdata) {
}

/**
* {@inheritDoc}
* @see \tool_trigger\steps\base\base_step::get_step_desc()
*/
public static function get_step_desc() {
return get_string('subplugin_lookup_test_step_desc', 'trigger_testplugin');
}

/**
* {@inheritDoc}
* @see \tool_trigger\steps\base\base_step::get_step_name()
*/
public static function get_step_name() {
return get_string('subplugin_lookup_test_step_name', 'trigger_testplugin');
}

/**
* {@inheritDoc}
* @see \tool_trigger\steps\base\base_step::get_privacyfields()
*/
public static function get_privacyfields() {
}

/**
* Get a list of fields this step provides.
*
* @return array $stepfields The fields this step provides.
*/
public static function get_fields() {
return self::$stepfields;
}
}
31 changes: 31 additions & 0 deletions custom/testplugin/lang/en/trigger_testplugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?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/>.

/**
* Language file for trigger_testplugin.
*
* @package trigger_testplugin
* @copyright 2025 Moodle US
* @author Oscar Nadjar <oscar.nadjar@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$string['pluginname'] = 'Test Trigger Subplugin';
$string['pluginname_help'] = 'This plugin is used for testing the subplugin functionality of the Tool Trigger plugin.';
$string['subplugin_lookup_test_step_desc'] = 'This is a test subplugin step for the Tool Trigger plugin. It is used to test the functionality of the subplugin system.';
$string['subplugin_lookup_test_step_name'] = 'Test Subplugin Step';
33 changes: 33 additions & 0 deletions custom/testplugin/version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?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/>.

/**
* Plugin version and other meta-data are defined here.
*
* @package trigger_testplugin
* @copyright 2025 Moodle US
* @author Oscar Nadjar <oscar.nadjar@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

defined('MOODLE_INTERNAL') || die();

$plugin->component = 'trigger_testplugin';
$plugin->version = 2025042200;
$plugin->requires = 2021051701;
$plugin->supported = [404, 405];
$plugin->maturity = MATURITY_STABLE;
$plugin->release = '1.0.0';
78 changes: 78 additions & 0 deletions tests/subplugin_step_test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?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/>.

/**
* "Fail" filter step's unit tests.
*
* @package tool_trigger
* @author Aaron Wells <aaronw@catalyst.net.nz>
* @copyright Catalyst IT 2018
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

namespace tool_trigger;

defined('MOODLE_INTERNAL') || die();

global $CFG;

class subplugin_step_test extends \advanced_testcase {

/**
* Test user.
* @var
*/
protected $user;

/**
* Test event.
* @var
*/
protected $event;

/**
* Create an event to use for testing.
*/
public function setup():void {

// Create a user event.
$this->user = \core_user::get_user_by_username('admin');
$this->event = \core\event\user_profile_viewed::create([
'objectid' => $this->user->id,
'relateduserid' => $this->user->id,
'context' => \context_user::instance($this->user->id),
'other' => [
'courseid' => 1,
'courseshortname' => 'short name',
'coursefullname' => 'full name'
]
]);
}

/**
* Basic use-case, with default values for settings. Find the
* user identified at "userid", and add their data with the
* prefix "user_".
*/
public function test_execute_basic() {
$step = new \trigger_testplugin\steps\lookups\subplugin_lookup_test_step(json_encode([]));

list($status, $stepresults) = $step->execute(null, null, $this->event, []);

$this->assertTrue($status);
$this->assertEquals('test', $stepresults['testlookupresult']);
}
}
14 changes: 14 additions & 0 deletions tests/workflow_manager_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,20 @@ public function test_get_steps_by_type() {
);
}

/**
* Test getting step from custom plugin.
*/
public function test_custom_step_names() {

$stepclasses = ['\trigger_testplugin\steps\lookups\subplugin_lookup_test_step'];
$stepobj = new \tool_trigger\workflow_manager();
$steps = $stepobj->lookup_step_names($stepclasses);
$this->assertEquals(
get_string('subplugin_lookup_test_step_name', 'trigger_testplugin'),
$steps['\trigger_testplugin\steps\lookups\subplugin_lookup_test_step']
);
}

/**
* Test the code for validating the name of a step class and instantiating it.
*
Expand Down
Loading