Extension:Page Forms/Testing

From MediaWiki.org
Jump to: navigation, search
Page Forms - navigation (viewTemplate:Page Forms navigation)
Basics Main pageExtension:Page Forms (talk) · Download and installationExtension:Page Forms/Download and installation · Quick start guideExtension:Page Forms/Quick start guide · HostingExtension:Page Forms/Hosting · Special pagesExtension:Page Forms/Special pages
Using Page Forms PF and templatesExtension:Page Forms/Page Forms and templates · Defining formsExtension:Page Forms/Defining forms   (Input typesExtension:Page Forms/Input types) · The "Edit with form" tabExtension:Page Forms/The "edit with form" tab · Linking to formsExtension:Page Forms/Linking to forms · Creating query formsExtension:Page Forms/Creating query forms
Resources for help Common problemsExtension:Page Forms/Common problems · Known bugs and planned featuresExtension:Page Forms/Known bugs and planned features · Getting supportExtension:Page Forms/Getting support · Developers' documentationExtension:Page Forms/Developers' documentation · TestingExtension:Page Forms/Testing
About Page Forms Authors and creditsExtension:Page Forms/Authors and credits · Version historyExtension:Page Forms/Version history · Sites that use Page FormsExtension:Page Forms/Sites that use Page Forms · Related extensionsExtension:Page Forms/Related extensions

This page covers the ways in which the Page Forms code can be tested.

Unit testing with PHPUnit[edit]

To run unit tests for the Page Forms extension, install PHPUnit (See Installing PHPUnit) and run the following command from the MediaWiki root directory:

php tests/phpunit/phpunit.php extensions/PageForms/tests

The unit tests for Page Forms only cover the following at present:

  • Testing of the {{{section}}} tag processing in the formHTML() method in the pFFormPrinter class.

Page Forms could benefit from additional unit tests to improve test coverage. To get started with writing tests for Page Forms, see Manual:PHP unit testing.

Front-end testing with Cucumber[edit]

Cucumber is a tool (written in Ruby) that lets you do testing of an application's front-end UI.

How to run[edit]

To run Cucumber tests for the Page Forms extension follow these steps:

Temporarily: obtain the Cucumber tests equipped SF codebase[edit]

This step is necessary until the Cucumber tests have been integrated upstream.

git clone https://github.com/LinuxCompetenceCenter/mediawiki-extensions-SemanticForms.git

Install Firefox[edit]

The Cucumber tests require Firefox, and, if run in a VM, ssh forwarding settings (see e.g. for Vagrant) as for the time being they're not headless.

Note: You might need to investigate the correct combination of selenium-webdriver and your version of Firefox, although the newest versions of both should work together.

Install Ruby and Bundler[edit]

First, install Ruby 2.2 (including its corresponding DevKit). Then, call the following:

w/extensions/PageForms$ gem install bundler
w/extensions/PageForms$ bundle install

Set permissions for the anonymous user[edit]

The Cucumber tests require your MediaWiki instance to grant the anonymous user the following permissions:

$wgGroupPermissions['*']['read'] = true;
$wgGroupPermissions['*']['edit'] = true;
$wgGroupPermissions['*']['createpage'] = true;

Create the test form page[edit]

If your MediaWiki instance is at "mywiki.com" and your $wgScriptPath is "/w", then in your browser:

  1. Log into MediaWiki as user "WikiSysop" (or any other user that has API write permissions).
  2. Then go to:

MediaWiki should now have created the page "Form:Main_Test_Form".

Run the Cucumber tests in Page Forms[edit]

w/extensions/PageForms/tests/browser$ bundle exec cucumber -q

Implementation details[edit]

Work in progress[edit]

  1. Add more expectations to be met in terms of what ends up in the templates instantiated.
  2. Add an option to run the Cucumber tests headless.
  3. Speed up the xpath location processes.
  4. Add more form inputs. (See Allowed input types for data types)
  5. Have the main test form declaration be injected into the test SMW automatically.
  6. Make the tests independent of the user interface language set. Currently only English is supported.