Skip to content
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

Adjust filter plugin validation requirements to comply with Moodle 4.5 #326

Merged
merged 2 commits into from
Nov 5, 2024

Conversation

kabalin
Copy link
Member

@kabalin kabalin commented Oct 11, 2024

This patch is addressing filter plugin validation compliance with 4.5 raised at #321. Filter API have been updated to use the standard Moodle Class Autoloading infrastructure (https://moodledev.io/docs/4.5/devupdate#filter-plugins), this introduced requirement for backward compatibility in addition to new filter class location.

Possible Moodle version compatibility options for plugins now become:

  • 4.4 and below → expect file filter.php containing class filter_[pluginname].
  • 4.5 → expect file classes/text_filter.php containing class text_filter.
  • 4.5 and below → expect file classes/text_filter.php containing class text_filter and file filter.php containing class_alias.

Possible Moodle versions test scenarios matrix:

  • Moodle 4.5, plugin compatibility 4.5 → pass
  • Moodle 4.5, plugin compatibility 4.4 and below → fail
  • Moodle 4.4, plugin compatibility 4.4 and below → pass
  • Moodle 4.4, plugin compatibility 4.5 and below → pass
  • Moodle 4.4, plugin compatibility 4.5 → fail

The patch implements validation logic listed above and introduces 2 new methods:

  • getRequiredFunctionCalls in plugin type specific Requirements class to validate that file contains function call.
  • FileTokens::notFoundHint can be used to give some context for validation error to improve developer experience.

Currently this tool does not support the determine version compatibility declared in version.php ($plugin->supported), for this simple scenario I use file existence check as indicator of backward compatibility implemented in plugin, in future the tool would possibly benefit from using information from $plugin->supported property.

Changeset has been tested locally with https://github.com/gjbarnard/moodle-filter_synhi plugin:

4.5, filter_synhi main:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
> Found required file: classes/text_filter.php
! Skipping validation of missing or optional file: db/upgrade.php
> In classes/text_filter.php, found class filter_synhi\text_filter
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml
> In filter.php, found function call class_alias

4.5, filter_synhi main, filter.php deleted:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
> Found required file: classes/text_filter.php
! Skipping validation of missing or optional file: db/upgrade.php
> In classes/text_filter.php, found class filter_synhi\text_filter
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml
! Skipping validation of missing or optional file: filter.php

4.5, filter_synhi V402.1.0:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
X Failed to find required file: classes/text_filter.php
! Skipping validation of missing or optional file: db/upgrade.php
! Skipping validation of missing or optional file: classes/text_filter.php
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml
X In filter.php, failed to find function call class_alias
X Hint: https://moodledev.io/docs/4.5/devupdate#filter-plugins

4.4, filter_synhi V402.1.0:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
> Found required file: filter.php
! Skipping validation of missing or optional file: db/upgrade.php
> In filter.php, found class filter_synhi
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml

4.4, filter_synhi main:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
> Found required file: filter.php
! Skipping validation of missing or optional file: db/upgrade.php
> In classes/text_filter.php, found class filter_synhi\text_filter
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml
> In filter.php, found function call class_alias

4.4, filter_synhi main, filter.php deleted:

 RUN  Validating filter_synhi
> Found required file: version.php
> Found required file: lang/en/filter_synhi.php
X Failed to find required file: filter.php
! Skipping validation of missing or optional file: db/upgrade.php
> In classes/text_filter.php, found class filter_synhi\text_filter
> In lang/en/filter_synhi.php, found language filtername
! Skipping validation of missing or optional file: db/install.xml
! Skipping validation of missing or optional file: filter.php

@kabalin kabalin linked an issue Oct 11, 2024 that may be closed by this pull request
Copy link

codecov bot commented Oct 11, 2024

Codecov Report

Attention: Patch coverage is 87.80488% with 5 lines in your changes missing coverage. Please review.

Project coverage is 88.34%. Comparing base (cd11318) to head (1326d19).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/PluginValidate/Finder/FunctionCallFinder.php 71.42% 2 Missing ⚠️
...uginValidate/Requirements/AbstractRequirements.php 0.00% 2 Missing ⚠️
src/PluginValidate/PluginValidate.php 66.66% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #326      +/-   ##
============================================
- Coverage     88.37%   88.34%   -0.03%     
- Complexity      738      757      +19     
============================================
  Files            76       77       +1     
  Lines          2296     2333      +37     
============================================
+ Hits           2029     2061      +32     
- Misses          267      272       +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

docs/CHANGELOG.md Outdated Show resolved Hide resolved
docs/CHANGELOG.md Outdated Show resolved Hide resolved
@mudrd8mz
Copy link
Member

mudrd8mz commented Nov 5, 2024

I am not familiar with PhpParser and MoodlePluginCI much. Just going through the description and the logic of the implementation, this makes perfect sense to me. Thanks Ruslan.

+1

…validation.

This address scenario where file is supposed to contain certain function
call, such as `class_alias` in Filter plugin type backward compatibility
support per https://moodledev.io/docs/4.5/devupdate#filter-plugins

The patch makes possible for deleveloper to specify:
* getRequiredFunctionCalls to make sure file contains function call as
  name suggests.
* FileTokens::notFoundHint to give some context for requirement to improve developer experience. This works with FileTokens in any other validation methods.
@kabalin
Copy link
Member Author

kabalin commented Nov 5, 2024

Thanks David! I addressed those minor comments. Ignoring codecov for now, validating of rendered error string containing info from the hint will be covered when we add hints to other types of plugin errors (#330), one can see from snippets above that string containing a hint rendered correctly.

@kabalin kabalin merged commit 2284369 into moodlehq:main Nov 5, 2024
25 of 27 checks passed
@kabalin kabalin deleted the filter-req branch November 5, 2024 21:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MDL-82427 class alias usage for M4.5 filters fails validation.
2 participants