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
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
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
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