Moodle plugin testing with PHPUnit, Behat, code standards, and pre-release validation
Run comprehensive Moodle plugin tests including PHPUnit, Behat, code standards validation, and pre-release checks. Use it before deploying plugins to ensure quality, security, and compatibility across authentication methods and mobile apps.
/plugin marketplace add astoeffer/moodle-plugin-marketplace/plugin install moodle-dev-pro@astoeffer-dev-plugins/sc:test [target] [--type phpunit|behat|standards|mobile|all] [--coverage] [--fix] [--release]
Key behaviors:
/tests/ directory/tests/behat/# Test instance configuration
MOODLE_URL=https://your-test-instance.com
MOODLE_VERSION=4.5
PHP_VERSION=8.1
DB_TYPE=mariadb
--type standards)# PSR-12 with Moodle exceptions
phpcs --standard=PSR12 mod/nextcloudfolder/
phpcbf --standard=PSR12 mod/nextcloudfolder/
# Moodle-specific checks
php admin/cli/check_database_schema.php
php admin/cli/check_lang_strings.php
--type phpunit)# Initialize PHPUnit
php admin/tool/phpunit/cli/init.php
# Run plugin tests
vendor/bin/phpunit mod/nextcloudfolder/tests/
# With coverage
vendor/bin/phpunit --coverage-html coverage/ mod/nextcloudfolder/tests/
--type behat)# Initialize Behat
php admin/tool/behat/cli/init.php
# Run plugin features
vendor/bin/behat --tags @mod_nextcloudfolder
# Specific scenarios
vendor/bin/behat --tags @mod_nextcloudfolder_oauth2
vendor/bin/behat --tags @mod_nextcloudfolder_sharelink
--type mobile)# Test web services
php admin/cli/webservice_test.php --protocol=rest --function=mod_nextcloudfolder_get_folder
# Verify mobile handlers
php admin/cli/cfg.php --name=enablemobilewebservice --set=1
--release)| Feature | OAuth2 | Shared Link | Mobile |
|---|---|---|---|
| View folder | ✓ | ✓ | ✓ |
| Download file | ✓ | ✓ | ✓ |
| Browse subfolders | ✓ | ✓ | ✓ |
| Tree/Table view | ✓ | ✓ | ✓ |
| Inline display | ✓ | ✓ | ✓ |
| Download ZIP | ✓ | ✓ | ✓ |
/sc:test --type all
# Runs complete test suite:
# 1. Code standards check
# 2. PHPUnit with coverage
# 3. Behat acceptance tests
# 4. Mobile compatibility check
/sc:test --type standards --fix
# Check and auto-fix code standards
./dev.sh check
./dev.sh fix
/sc:test --release
# Complete pre-release checklist:
# - All automated tests
# - Generate coverage report
# - Security validation
# - Performance benchmarks
# - Mobile app verification
/sc:test tests/oauth2_test.php --type phpunit
# Test OAuth2 authentication flow
# Verify token refresh
# Check permission handling
/sc:test --type behat --tags @sharelink
# Test public folder access
# Verify file browsing
# Check download functionality
PHPUnit 9.5.10 by Sebastian Bergmann.
............................................... 47 / 47 (100%)
Time: 00:02.341, Memory: 24.00 MB
OK (47 tests, 182 assertions)
Code Coverage: 85.3%
Feature: Nextcloud folder browsing
Scenario: Browse shared folder # Passed
Scenario: Download file from folder # Passed
Scenario: Switch between view modes # Passed
3 scenarios (3 passed)
15 steps (15 passed)
Will:
Will Not: