diff --git a/classes/workflow_manager.php b/classes/workflow_manager.php index f5729ca..8f7fff7 100644 --- a/classes/workflow_manager.php +++ b/classes/workflow_manager.php @@ -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", diff --git a/custom/testplugin/classes/steps/lookups/subplugin_lookup_test_step.php b/custom/testplugin/classes/steps/lookups/subplugin_lookup_test_step.php new file mode 100644 index 0000000..39b5784 --- /dev/null +++ b/custom/testplugin/classes/steps/lookups/subplugin_lookup_test_step.php @@ -0,0 +1,91 @@ +. + +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 + * @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; + } +} diff --git a/custom/testplugin/lang/en/trigger_testplugin.php b/custom/testplugin/lang/en/trigger_testplugin.php new file mode 100755 index 0000000..a3cf314 --- /dev/null +++ b/custom/testplugin/lang/en/trigger_testplugin.php @@ -0,0 +1,31 @@ +. + +/** + * Language file for trigger_testplugin. + * + * @package trigger_testplugin + * @copyright 2025 Moodle US + * @author Oscar Nadjar + * @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'; diff --git a/custom/testplugin/version.php b/custom/testplugin/version.php new file mode 100755 index 0000000..84c2021 --- /dev/null +++ b/custom/testplugin/version.php @@ -0,0 +1,33 @@ +. + +/** + * Plugin version and other meta-data are defined here. + * + * @package trigger_testplugin + * @copyright 2025 Moodle US + * @author Oscar Nadjar + * @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'; diff --git a/tests/subplugin_step_test.php b/tests/subplugin_step_test.php new file mode 100644 index 0000000..9e9d9fd --- /dev/null +++ b/tests/subplugin_step_test.php @@ -0,0 +1,78 @@ +. + +/** + * "Fail" filter step's unit tests. + * + * @package tool_trigger + * @author Aaron Wells + * @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']); + } +} diff --git a/tests/workflow_manager_test.php b/tests/workflow_manager_test.php index 491652a..884b9fa 100644 --- a/tests/workflow_manager_test.php +++ b/tests/workflow_manager_test.php @@ -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. *