devel:unittesting
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| devel:unittesting [2023-10-09 20:35] – old revision restored (2023-06-19 08:57) Klap-in | devel:unittesting [2025-09-30 19:18] (current) – [Javascript + Frontend-tests] 85.7.9.186 | ||
|---|---|---|---|
| Line 5: | Line 5: | ||
| DokuWiki' | DokuWiki' | ||
| - | We use the [[http:// | + | We use the [[http:// |
| ===== Setup ===== | ===== Setup ===== | ||
| - | Download | + | Install |
| - | < | + | < |
| cd dokuwiki/ | cd dokuwiki/ | ||
| - | php fetchphpunit.php | + | composer install |
| </ | </ | ||
| Line 26: | Line 26: | ||
| < | < | ||
| cd _test/ | cd _test/ | ||
| - | php phpunit.phar | + | composer run test |
| </ | </ | ||
| Line 34: | Line 34: | ||
| cd _test | cd _test | ||
| - | | + | |
| ==== Grouped Tests ==== | ==== Grouped Tests ==== | ||
| Line 43: | Line 43: | ||
| cd _test | cd _test | ||
| # run all tests that require an internet connection | # run all tests that require an internet connection | ||
| - | | + | |
| # run all tests that don't require an internet connection | # run all tests that don't require an internet connection | ||
| - | | + | |
| </ | </ | ||
| + | Note the ''< | ||
| ==== Plugins ==== | ==== Plugins ==== | ||
| Line 55: | Line 56: | ||
| <code bash> | <code bash> | ||
| cd _test | cd _test | ||
| - | php phpunit.phar | + | composer run test -- --group plugin_extension |
| </ | </ | ||
| + | |||
| + | Note the ''< | ||
| Please note that some plugins may require other plugins in order to pass, either as dependencies, | Please note that some plugins may require other plugins in order to pass, either as dependencies, | ||
| Line 74: | Line 77: | ||
| This means a class '' | This means a class '' | ||
| - | Each test class need to inherit from [xref> | + | Each test class need to inherit from [[xref> |
| Line 139: | Line 142: | ||
| - | Finally you have to execute the request. This can be done by calling the '' | + | Finally you have to execute the request. This can be done by calling the '' |
| + | <code php> | ||
| + | $response = $request-> | ||
| + | </ | ||
| - | Additionally there are two methods for '' | + | Additionally there are two methods for '' |
| <code php> | <code php> | ||
| // a get request | // a get request | ||
| - | $request-> | + | $response = $request-> |
| // a post request | // a post request | ||
| - | $request-> | + | $response = $request-> |
| </ | </ | ||
| Line 156: | Line 162: | ||
| As mentioned the requests are not real requests. Every call you make in your test changes the behavior of DokuWiki on the request. | As mentioned the requests are not real requests. Every call you make in your test changes the behavior of DokuWiki on the request. | ||
| - | Here this is used to hook an event. | + | Here this is used to hook an event |
| <code php> | <code php> | ||
| - | function testHookTriggering() { | + | public |
| + | { | ||
| global $EVENT_HANDLER; | global $EVENT_HANDLER; | ||
| Line 187: | Line 194: | ||
| With this you can operate in a jQuery like style on the returned HTML. | With this you can operate in a jQuery like style on the returned HTML. | ||
| - | A simple | + | Two simple |
| <code php> | <code php> | ||
| - | function testSimpleRun() { | + | public |
| + | { | ||
| // make a request | // make a request | ||
| $request = new TestRequest(); | $request = new TestRequest(); | ||
| Line 195: | Line 203: | ||
| // get the generator name from the meta tag. | // get the generator name from the meta tag. | ||
| - | $generator = $response-> | + | $generator = $response-> |
| - | + | | |
| // check the result | // check the result | ||
| $this-> | $this-> | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | <code php> | ||
| + | public function testPageContent() | ||
| + | { | ||
| + | // make a request | ||
| + | $request = new TestRequest(); | ||
| + | $response = $request-> | ||
| + | |||
| + | // search your html | ||
| + | $links = $response-> | ||
| + | $countLinks = $links-> | ||
| + | |||
| + | // check the result | ||
| + | $this-> | ||
| } | } | ||
| </ | </ | ||
| Line 221: | Line 246: | ||
| * @group plugins | * @group plugins | ||
| */ | */ | ||
| - | class helper_plugin_data_test extends DokuWikiTest { | + | class helper_plugin_data_test extends DokuWikiTest |
| + | { | ||
| - | protected $pluginsEnabled = array(' | + | protected $pluginsEnabled = [' |
| public static function setUpBeforeClass(){ | public static function setUpBeforeClass(){ | ||
| parent:: | parent:: | ||
| // copy our own config files to the test directory | // copy our own config files to the test directory | ||
| - | TestUtils:: | + | TestUtils:: |
| } | } | ||
| public function testExample() { | public function testExample() { | ||
| - | $this-> | + | $this-> |
| } | } | ||
| } | } | ||
| Line 240: | Line 266: | ||
| <code php> | <code php> | ||
| - | function setUp(){ | + | |
| + | | ||
| global $conf; | global $conf; | ||
| parent:: | parent:: | ||
| - | $conf [' | + | $conf[' |
| - | $conf [' | + | $conf[' |
| } | } | ||
| </ | </ | ||
| Line 254: | Line 281: | ||
| ===== Continous Integration with Github Actions ===== | ===== Continous Integration with Github Actions ===== | ||
| - | Plugin authors are encouraged to have their tests run automatically on Github Actions.The [[http:// | + | |
| + | Plugin authors are encouraged to have their tests run automatically on Github Actions.The [[http:// | ||
| ==== Requirements ==== | ==== Requirements ==== | ||
| + | FIXME update | ||
| If your tests require additional plugins to be installed, provide a '' | If your tests require additional plugins to be installed, provide a '' | ||
| Line 263: | Line 292: | ||
| - | FIXME this section needs to be rewritten for Github Actions since Travis is no longer recommended. | + | |
| + | FIXME This section needs to be rewritten for Github Actions since Travis is no longer recommended. | ||
| It is possible to integrate javascript-tests written in [[http:// | It is possible to integrate javascript-tests written in [[http:// | ||
devel/unittesting.1696876509.txt.gz · Last modified: by Klap-in
