SlideShare a Scribd company logo
Tools and Tips for
Moodle Developers
Dan Poltawski
Integrator
Moodle HQ
@dan_p
the world’s open source learning platform
#mootus16
$CFG->debug = (E_ALL | E_STRICT); // DEBUG_DEVELOPER.
$CFG->debugdisplay = 1; // (unless you tail logs)
$CFG->cachejs = false; // But beware of browser cache!
$CFG->debugstringids = true; // With strings=1 url param.
$CFG->debugusers = ‘2,3,10’; // List of users ids
Debugging: config.php settings
the world’s open source learning platform
// Beginner.
echo "Course ID: $course->id”;
// Intermediate.
print_object($SESSION);
// Advanced.
debugging('a stack trace too!', DEBUG_DEVELOPER);
if ($CFG->debugdeveloper) {
echo '[..] some diagnostic code.';
}
// Wizard.
// (Uses xdebug and variable introspection)
Stages of Moodle printf() debugging (PHP)
the world’s open source learning platform
Stages of Moodle printf() debugging (JS)
// Beginner:
alert('courseid is: ' + course.id);
// Intermediate:
console.dir(course);
// Advanced:
Y.log('Info example in YUI module', 'info');
define(['core/log'], function(log) {
log.info('Info example from AMD Module.');
});
// Wizard:
// (uses web inspector, variable introspection)
the world’s open source learning platform
Performance debugging
the world’s open source learning platform
$CFG->perfdebug = 15; // First step.
xhprof
the world’s open source learning platform
xhprof
the world’s open source learning platform
the world’s open source learning platform
PHPUnit
Useful CLI Options
Filtering
vendor/bin/phpunit --filter block_online_users
vendor/bin/phpunit --testsuite block_online_users_testsuite
vendor/bin/phpunit blocks/online_users/tests/online_users_test.php
Coverage
vendor/bin/phpunit --coverage-html=coverage --filter block_online_users
PHPUnit
Test authoring tips:
• Use most specific assertion possible
• Make use of @dataProvider to
reduce duplication and get better
errors
• Remember we have data generators
to simplify setup code
/**
* Data provider for test_get_real_size().
*
* @return array An array of arrays contain test data
*/
public function data_for_test_get_real_size() {
return array(
array('8KB', 8192),
array('8G', 8589934592),
);
}
/**
* @dataProvider data_for_test_get_real_size
*/
public function test_get_real_size($input, $expectedbytes) {
$this->assertEquals($expectedbytes,get_real_size($input));
}
There was 1 failure:
1) core_setuplib_testcase::test_get_real_size with data set #0
('8KB', 8193)
Failed asserting that 8192 matches expected 8193.
the world’s open source learning platform
Behat
Useful CLI Options:
Filtering
—tags @block_online_users
—name “Add the online users on course
page and see other logged in users”
Rerun
—rerun
Profiles
—profile chrome
$CFG->behat_profiles = array(
'phantomjs' => array(
'browser' => ‘chrome’,
'wd_host' => ‘http://10.0.0.3:4444/wd/hub',
));
the world’s open source learning platform
Behat
Tips:
• Solutions for headless running:
• All platforms: Phantom JS
• Linux: Xvfb - X virtual framebuffer
• Mac: Fast user switching - with background user
• $x() in web developer console extremely useful for constructing
XPath queries
the world’s open source learning platform
Grunt
• grunt
• grunt watch
• grunt css
• grunt js
• grunt amd
• grunt yui
the world’s open source learning platform
• Analysing code for potential errors
• Good feedback loop
• Ensure consistency
• Integrate with your development workflow FTW!
Code Linting
the world’s open source learning platform
• Code-checker (local_codechecker)
• Available from Plugins Directory
• Uses PHP Code-sniffer underneath
• Integrations configured with path to local_codechecker/moodle/
location
Moodle Code Linters: PHP
the world’s open source learning platform
• ESLint
• New in Moodle 3.2 (MDL-52127), replaced jshint
• grunt js: checks for errors on AMD modules and YUI modules
• Integrations usually work without configuration ( eslintrc bundled)
Moodle Code Linters: Javascript
the world’s open source learning platform
• Packages: linter
• linter-phpcs
• linter-eslint
• Config:
"linter-phpcs":
codeStandardOrConfigFile: “/path/to/moodle-
Lint in your editor: Atom
the world’s open source learning platform
• Package: syntastic
• vimrc:
let g:syntastic_javascript_checkers = ['eslint']
let g:syntastic_php_checkers = ['php', 'phpcs']
let g:syntastic_php_phpcs_args='--standard="/
path/to/moodle-local_codechecker/moodle/"'
Lint in your editor: vim
the world’s open source learning platform
Lint in your editor: PHPStorm
Configured in Editor > Inspections:
• PHP > PHP Code SnifferValidation
• Select ‘Custom’ coding standard and
choose path to local_codechecker/
moodle/
• Javascript > Code Quality Tools >
ESLint
the world’s open source learning platform
• SublimeLinter
• SublimeLinter-phpcs
• SublimeLinter-contrib-eslint
Sublime
"linters": {
"eslint": {
"@disable": false,
"args": [],
"excludes": []
},
"phpcs": {
"@disable": false,
"args": [],
"excludes": [],
"standard": “/path/to/moodle-local_codechecker/moodle/"
}}the world’s open source learning platform
Lint in your editor….
I’m sure their is an emacs integration too 🙄😘
the world’s open source learning platform
the world’s open source learning platform
“The goal of this project is to facilitate the running of
tests and code analysis tools against a Moodle plugin in
Travis CI.”
• https://github.com/moodlerooms/moodle-plugin-ci
• Created by Mark Nielsen (Moodlerooms)
• Extremely simple and comprehensive way to add CI to
your plugin
moodle-plugin-ci
the world’s open source learning platform
moodle-plugin-ci
the world’s open source learning platform
“A collection of tools meant to make developers' lives easier.”
• https://github.com/FMCorz/mdk
• Created by Frédéric Massart (Moodle HQ)
• Python tools - works with Linux and Mac
• (Windows patches welcomed!)
• Developed for core development tasks, but useful for non-core
work too
Moodle Development Kit (mdk)
• mdk create
• mdk upgrade
• mdk install
• mdk run
• mdk remove
MDK: Instance management
the world’s open source learning platform
• mdk phpunit
• init
• mdk behat
• init
• fail dumps
• seleneium server start
MDK: Testing
the world’s open source learning platform
• mdk fix
• mdk pull
• mdk push
MDK: Fixing issues
the world’s open source learning platform
• mdk fix
• mdk pull
• mdk push
MDK: Fixing continued
the world’s open source learning platform
the world’s open source learning platform
Email testing: config options
// Disable all Email.
$CFG->noemailever = true;
// Divert all outgoing emails to this address to test and debug emailing features
$CFG->divertallemailsto = 'youremail@example.com';
// Except for certain email addresses you want to let through for testing. Accepts
// a comma separated list of regexes.
$CFG->divertallemailsexcept = 'tester@dev.com, fred(+.*)?@example.com';
Email testing: mailcatcher
$CFG->smtphosts = 'localhost:1025';
$ gem install mailcatcher
$ mailcatcher
Starting MailCatcher
==> smtp://127.0.0.1:1025
==> http://127.0.0.1:1080
*** MailCatcher runs as a daemon by default.
Go to the web interface to quit.
the world’s open source learning platform
the world’s open source learning platform
Accessibility testing
• ChromeVox
• Chrome Extension - Quick and straight forward to get started
• Not JAWS but better than nothing
• Accessibility Developer Tools - Accessibility audit useful
git
• git log
• git blame
• git bisect
• https://github.com/dmonllao/who-broke-it
• git log --author=Damyon --grep="services"
the world’s open source learning platform
Questions?
@dan_p
the world’s open source learning platform

More Related Content

ODP
Moodle Development Best Pracitces
PDF
Mastering Moodle Web Services development
ODP
Introduction to Moodle Development
PPTX
Debugging in drupal 8
PPTX
Getting started with drupal 8 code
PDF
Your first d8 module
PDF
Brisbane Drupal meetup - 2016 Mar - Build module in Drupal 8
PDF
How to create a joomla component from scratch
Moodle Development Best Pracitces
Mastering Moodle Web Services development
Introduction to Moodle Development
Debugging in drupal 8
Getting started with drupal 8 code
Your first d8 module
Brisbane Drupal meetup - 2016 Mar - Build module in Drupal 8
How to create a joomla component from scratch

What's hot (20)

PPT
How to learn to build your own PHP framework
PPTX
Building Scalable IMS LTI Tools Using the TSUGI Framework
PPTX
Introduction to building joomla! components using FOF
PPTX
PPTX
Node JS Express : Steps to Create Restful Web App
ODP
Bootstrap4 x pages
PPTX
Tsugi Workshop @ Notre Dame
PPTX
How Browser Works?
PDF
Codeigniter
PDF
Drupal debugging tips
PDF
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
PDF
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
PDF
Introduction to CakePHP
PDF
Django Documentation
KEY
MozTW Jetpack Workshop: Taipei
PPTX
Updated Version: Tsugi Overview
PPT
Build Automation of PHP Applications
PDF
Drupal 8 - Corso frontend development
PDF
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
PDF
Intro to PHP Testing
How to learn to build your own PHP framework
Building Scalable IMS LTI Tools Using the TSUGI Framework
Introduction to building joomla! components using FOF
Node JS Express : Steps to Create Restful Web App
Bootstrap4 x pages
Tsugi Workshop @ Notre Dame
How Browser Works?
Codeigniter
Drupal debugging tips
Unleashing Creative Freedom with MODX (2015-09-08 at PHPAmersfoort)
Unleashing Creative Freedom with MODX (2015-07-21 @ PHP FRL)
Introduction to CakePHP
Django Documentation
MozTW Jetpack Workshop: Taipei
Updated Version: Tsugi Overview
Build Automation of PHP Applications
Drupal 8 - Corso frontend development
Unleashing Creative Freedom with MODX (2015-09-03 at GroningenPHP)
Intro to PHP Testing
Ad

Viewers also liked (8)

PDF
How integrators bring you a better Moodle
PDF
Lifecycle of a Moodle Bug - #mootus16
PDF
Continuous Integration: Improving Quality in Moodle
PDF
Testing Moodle functionality automatically
PDF
Moodle & Moodle Mobile 3.2 Release Party Barcelona
PPTX
Building a Moodle theme with bootstrap
PPT
A basic introduction to the Moodle architecture
PPT
What is Moodle explained with Lego
How integrators bring you a better Moodle
Lifecycle of a Moodle Bug - #mootus16
Continuous Integration: Improving Quality in Moodle
Testing Moodle functionality automatically
Moodle & Moodle Mobile 3.2 Release Party Barcelona
Building a Moodle theme with bootstrap
A basic introduction to the Moodle architecture
What is Moodle explained with Lego
Ad

Similar to Tools and Tips for Moodle Developers - #mootus16 (20)

ODP
Making the Most of Moodle
PDF
Collapsed topics presentation
KEY
CakePHP - The Path to 2.0
PDF
How to guarantee your change is integrated to Moodle core
KEY
CakePHP 2.0 - It'll rock your world
PPT
Movingto moodle2 v1 1
PPTX
Moodle Developing Environment (E)
PPTX
Os dev tool box
PDF
Living With Legacy Code
PDF
4TVirtualCon- Moodle Administration
ODP
Installing Moodle is Easy
PPTX
Continuous feature-development
PDF
Shannon Lin_Resume
PDF
Real world Webapp
PDF
Turbo Charging Moodle
ODP
Aztea Peaks 2006
PPTX
Improving your team’s source code searching capabilities
PPTX
Improving your team's source code searching capabilities - Voxxed Thessalonik...
PDF
Workshop quality assurance for php projects - phpbelfast
PDF
Php Crash Course - Macq Electronique 2010
Making the Most of Moodle
Collapsed topics presentation
CakePHP - The Path to 2.0
How to guarantee your change is integrated to Moodle core
CakePHP 2.0 - It'll rock your world
Movingto moodle2 v1 1
Moodle Developing Environment (E)
Os dev tool box
Living With Legacy Code
4TVirtualCon- Moodle Administration
Installing Moodle is Easy
Continuous feature-development
Shannon Lin_Resume
Real world Webapp
Turbo Charging Moodle
Aztea Peaks 2006
Improving your team’s source code searching capabilities
Improving your team's source code searching capabilities - Voxxed Thessalonik...
Workshop quality assurance for php projects - phpbelfast
Php Crash Course - Macq Electronique 2010

Recently uploaded (20)

PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
KodekX | Application Modernization Development
PDF
cuic standard and advanced reporting.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Advanced IT Governance
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Big Data Technologies - Introduction.pptx
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Advanced Soft Computing BINUS July 2025.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
Review of recent advances in non-invasive hemoglobin estimation
Reach Out and Touch Someone: Haptics and Empathic Computing
KodekX | Application Modernization Development
cuic standard and advanced reporting.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Advanced methodologies resolving dimensionality complications for autism neur...
NewMind AI Monthly Chronicles - July 2025
Advanced IT Governance
Understanding_Digital_Forensics_Presentation.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MYSQL Presentation for SQL database connectivity
Big Data Technologies - Introduction.pptx
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....

Tools and Tips for Moodle Developers - #mootus16

  • 1. Tools and Tips for Moodle Developers Dan Poltawski Integrator Moodle HQ @dan_p the world’s open source learning platform #mootus16
  • 2. $CFG->debug = (E_ALL | E_STRICT); // DEBUG_DEVELOPER. $CFG->debugdisplay = 1; // (unless you tail logs) $CFG->cachejs = false; // But beware of browser cache! $CFG->debugstringids = true; // With strings=1 url param. $CFG->debugusers = ‘2,3,10’; // List of users ids Debugging: config.php settings the world’s open source learning platform
  • 3. // Beginner. echo "Course ID: $course->id”; // Intermediate. print_object($SESSION); // Advanced. debugging('a stack trace too!', DEBUG_DEVELOPER); if ($CFG->debugdeveloper) { echo '[..] some diagnostic code.'; } // Wizard. // (Uses xdebug and variable introspection) Stages of Moodle printf() debugging (PHP) the world’s open source learning platform
  • 4. Stages of Moodle printf() debugging (JS) // Beginner: alert('courseid is: ' + course.id); // Intermediate: console.dir(course); // Advanced: Y.log('Info example in YUI module', 'info'); define(['core/log'], function(log) { log.info('Info example from AMD Module.'); }); // Wizard: // (uses web inspector, variable introspection) the world’s open source learning platform
  • 5. Performance debugging the world’s open source learning platform $CFG->perfdebug = 15; // First step.
  • 6. xhprof the world’s open source learning platform
  • 7. xhprof the world’s open source learning platform
  • 8. the world’s open source learning platform PHPUnit Useful CLI Options Filtering vendor/bin/phpunit --filter block_online_users vendor/bin/phpunit --testsuite block_online_users_testsuite vendor/bin/phpunit blocks/online_users/tests/online_users_test.php Coverage vendor/bin/phpunit --coverage-html=coverage --filter block_online_users
  • 9. PHPUnit Test authoring tips: • Use most specific assertion possible • Make use of @dataProvider to reduce duplication and get better errors • Remember we have data generators to simplify setup code /** * Data provider for test_get_real_size(). * * @return array An array of arrays contain test data */ public function data_for_test_get_real_size() { return array( array('8KB', 8192), array('8G', 8589934592), ); } /** * @dataProvider data_for_test_get_real_size */ public function test_get_real_size($input, $expectedbytes) { $this->assertEquals($expectedbytes,get_real_size($input)); } There was 1 failure: 1) core_setuplib_testcase::test_get_real_size with data set #0 ('8KB', 8193) Failed asserting that 8192 matches expected 8193. the world’s open source learning platform
  • 10. Behat Useful CLI Options: Filtering —tags @block_online_users —name “Add the online users on course page and see other logged in users” Rerun —rerun Profiles —profile chrome $CFG->behat_profiles = array( 'phantomjs' => array( 'browser' => ‘chrome’, 'wd_host' => ‘http://10.0.0.3:4444/wd/hub', )); the world’s open source learning platform
  • 11. Behat Tips: • Solutions for headless running: • All platforms: Phantom JS • Linux: Xvfb - X virtual framebuffer • Mac: Fast user switching - with background user • $x() in web developer console extremely useful for constructing XPath queries the world’s open source learning platform
  • 12. Grunt • grunt • grunt watch • grunt css • grunt js • grunt amd • grunt yui the world’s open source learning platform
  • 13. • Analysing code for potential errors • Good feedback loop • Ensure consistency • Integrate with your development workflow FTW! Code Linting the world’s open source learning platform
  • 14. • Code-checker (local_codechecker) • Available from Plugins Directory • Uses PHP Code-sniffer underneath • Integrations configured with path to local_codechecker/moodle/ location Moodle Code Linters: PHP the world’s open source learning platform
  • 15. • ESLint • New in Moodle 3.2 (MDL-52127), replaced jshint • grunt js: checks for errors on AMD modules and YUI modules • Integrations usually work without configuration ( eslintrc bundled) Moodle Code Linters: Javascript the world’s open source learning platform
  • 16. • Packages: linter • linter-phpcs • linter-eslint • Config: "linter-phpcs": codeStandardOrConfigFile: “/path/to/moodle- Lint in your editor: Atom the world’s open source learning platform
  • 17. • Package: syntastic • vimrc: let g:syntastic_javascript_checkers = ['eslint'] let g:syntastic_php_checkers = ['php', 'phpcs'] let g:syntastic_php_phpcs_args='--standard="/ path/to/moodle-local_codechecker/moodle/"' Lint in your editor: vim the world’s open source learning platform
  • 18. Lint in your editor: PHPStorm Configured in Editor > Inspections: • PHP > PHP Code SnifferValidation • Select ‘Custom’ coding standard and choose path to local_codechecker/ moodle/ • Javascript > Code Quality Tools > ESLint the world’s open source learning platform
  • 19. • SublimeLinter • SublimeLinter-phpcs • SublimeLinter-contrib-eslint Sublime "linters": { "eslint": { "@disable": false, "args": [], "excludes": [] }, "phpcs": { "@disable": false, "args": [], "excludes": [], "standard": “/path/to/moodle-local_codechecker/moodle/" }}the world’s open source learning platform
  • 20. Lint in your editor…. I’m sure their is an emacs integration too 🙄😘 the world’s open source learning platform
  • 21. the world’s open source learning platform “The goal of this project is to facilitate the running of tests and code analysis tools against a Moodle plugin in Travis CI.” • https://github.com/moodlerooms/moodle-plugin-ci • Created by Mark Nielsen (Moodlerooms) • Extremely simple and comprehensive way to add CI to your plugin moodle-plugin-ci
  • 22. the world’s open source learning platform moodle-plugin-ci
  • 23. the world’s open source learning platform “A collection of tools meant to make developers' lives easier.” • https://github.com/FMCorz/mdk • Created by Frédéric Massart (Moodle HQ) • Python tools - works with Linux and Mac • (Windows patches welcomed!) • Developed for core development tasks, but useful for non-core work too Moodle Development Kit (mdk)
  • 24. • mdk create • mdk upgrade • mdk install • mdk run • mdk remove MDK: Instance management the world’s open source learning platform
  • 25. • mdk phpunit • init • mdk behat • init • fail dumps • seleneium server start MDK: Testing the world’s open source learning platform
  • 26. • mdk fix • mdk pull • mdk push MDK: Fixing issues the world’s open source learning platform
  • 27. • mdk fix • mdk pull • mdk push MDK: Fixing continued the world’s open source learning platform
  • 28. the world’s open source learning platform Email testing: config options // Disable all Email. $CFG->noemailever = true; // Divert all outgoing emails to this address to test and debug emailing features $CFG->divertallemailsto = 'youremail@example.com'; // Except for certain email addresses you want to let through for testing. Accepts // a comma separated list of regexes. $CFG->divertallemailsexcept = 'tester@dev.com, fred(+.*)?@example.com';
  • 29. Email testing: mailcatcher $CFG->smtphosts = 'localhost:1025'; $ gem install mailcatcher $ mailcatcher Starting MailCatcher ==> smtp://127.0.0.1:1025 ==> http://127.0.0.1:1080 *** MailCatcher runs as a daemon by default. Go to the web interface to quit. the world’s open source learning platform
  • 30. the world’s open source learning platform Accessibility testing • ChromeVox • Chrome Extension - Quick and straight forward to get started • Not JAWS but better than nothing • Accessibility Developer Tools - Accessibility audit useful
  • 31. git • git log • git blame • git bisect • https://github.com/dmonllao/who-broke-it • git log --author=Damyon --grep="services" the world’s open source learning platform
  • 32. Questions? @dan_p the world’s open source learning platform