Tests de l'analyseur syntaxique

This page is a translated version of the page Parser tests and the translation is 50% complete.
Outdated translations are marked like this.
The Parsoid specific sections and Parsoid specific options are only relevant for (a) Parser test files in the Parsoid repository (b) Parser test files that have been marked Parsoid-compatible. Also note that MW 1.38 and prior do not have support for running Parsoid tests via the parserTests.php test runner in MediaWiki core. But, these options are available in Parsoid's test runner (bin/parserTests.php in Parsoid's repository).

Chaque cas de test de l'analyseur spécifie le texte wiki d'entrée et la sortie HTML, pour confirmer que les choses se déroulent comme on les attend. La sortie courante est comparée au résultat souhaité, et ainsi les cas de test de l'analyseur (connus également sous le nom de tests de l'analyseur) peuvent être utiles pour pointer les régressions.

Les cas de test de l'analyseur sont rangés dans tests/parser/parserTests.txt. Les extensions doivent placer leurs tests dans un répertoire tests/parser/.

Vous pouvez à la fois faire les tests en utilisant la suite de tests unitaires de php, ou bien utiliser parserTests.php de manière indépendante -- de sorte à ce qu'un test en échec de l'analyseur puisse déclencher une erreur de test Jenkins.

Syntaxe et exécution

Version 2 format

Starting with 1.35, parser tests are required to be in the Version 2 format. Specifying version 2 indicates that the tests are ready to be run in "tidy" mode (See T249138).
To indicate your parser tests are run in version 2 format, the first line in your parser test file must be !! Version 2

Enabling hooks

Pour être sûr que la balise d'extension tag1 soit chargée, ajoutez au début du fichier :

!! hooks
tag1
!! endhooks

Adding articles

In order to create a new article, the syntax is:

!! article
Template:Simple template
!! text
A ''simple'' template.
!! endarticle

Layout of a parser test

Besides the test time, a test has a number of sections: options (optional), config (optional), wikitext, wikitext/edited (optional), html (optional), html/php (optional), html/parsoid (optional), html/parsoid+standalone (optional).

The wikitext/edited and the various html/parsoid* sections are only relevant when running a test with Parsoid. Parsoid also allows additional configuration with additional test-specific options in the options section.

La syntaxe est la suivante :

!! Version 2
!! test
Simple paragraph
!! config
wgRestrictDisplayTitle=false
!! wikitext
This is a simple paragraph.
!! html
<p>This is a simple paragraph.
</p>
!! end

Configuration section

La section config peut être omise. Si vous spécifiez les paramètres de configuration ici, assurez-vous qu'il n'y ait aucun espace entre les expressions parce que l'espace n'est pas supprimé par le lanceur de tests.

Options section

Each option should come on its own line.

  • disabled disables the test.
  • php runs the test only with the core's default parser unless Parsoid-specific HTML sections are present. The "php" name is a historical remnant from when Parsoid was a Node.js codebase.
  • parsoid=comma-separated-modes or parsoid={...} (JSON format object) enable Parsoid-specific options.
    • Ex: parsoid=wt2html,wt2wt runs this test in only those 2 modes. By default, the test is run all available test modes for the test given the wikitext and html sections. In the common case, this defaults to running the test in wt2html, wt2wt, html2wt, html2html, and selser modes. The selser mode is an abbreviation for a test mode where the HTML section is edited in a number of automated ways which is then converted to wikitext using Parsoid's selective-serialization (selser henceforth) transformations. TODO: Add a link to a wikipage that explains Parsoid's various transformations.
    • In the JSON format object, the following keys are current recognized modes, selser, changes, suppressErrors, normalizePhp,
      • modes: This is a comma separated list of Parsoid modes to run
      • selser: If selser is one of the test modes in the modes property, this property can optionally specify "noauto" to indicate automatic edits for this test should not be generated. If so, only manual edits as specified by the changes property will be applied.
      • changes: This format is described separately below. This option will need to be paired with a wikitext/edited section in the test (see below) that specifies the expected wikitext output when this edited HTML is converted (via selser) to wikitext by Parsoid.

changes format

This is an array of individual changes to apply to the DOM of the HTML generated by transforming wikitext. Each element of the array contains 3 or more elements: (a) jquery selector to select a DOM node (b) the type of change to apply to the selected node (c) the relevant values / content needed to apply the change specified.

More succinctly, each array element represents a jquery method call. So, [x,y,z...] becomes $(x)[y](z....) So, ['fig', 'attr', 'width', '120'] is interpreted as $('fig').attr('width', '120')

Right now, the following jquery methods are recognized: after, addClass, append, attr, before, empty, html, remove, removeAttr, removeClass, text, wrap

See http://api.jquery.com/ for documentation of these methods.

"contents" as second argument calls the jquery .contents() method on the results of the selector in the first argument, which is a good way to get at the text and comment nodes.

Wikitext sections

  • wikitext section: This is expected to be present in all tests is the that specifies the wikitext to be processed to HTML (or in Parsoid html2wt and wt2wt test modes, the wikitext to generate from the HTML sections).
  • wikitext/edited section: This section is only relevant in Parsoid test runs. For tests that provide a manual set of changes to apply to the HTML generated from the wikitext section, this is the output expected when Parsoid converts that edited HTML back to wikitext.

HTML sections

TODO

Extension.json & parser tests

Les extensions qui enregistrent leurs tests dans tests/parser/ et qui utilisent extension.json will auront leurs tests d'analyseur automatiquement activés. Les extensions qui utilisent l'ancien système de chargement des extensions, peuvent utiliser :

$wgParserTestFiles[] = __DIR__ . "/myParserTests.txt";

Running tests with parserTests.php

Pour exécuter les tests de l'analyseur, allez dans le répertoire de votre installation locale MediaWiki et exécutez les instructions suivantes à partir de la ligne de commande :

php tests/parser/parserTests.php
Avant MediaWiki 1.28, ce fichier était mis dans tests/parserTests.php.

Pour exécuter les tests juste pour un seul fichier, utilisez le paramètre --file=... . Voir --help pour les autres paramètres.

php tests/parser/parserTests.php --file=extensions/Kartographer/tests/parser/parserTests.txt

Parsoid-specific test runner options

These options aren't available with MediaWiki core's paresr test runner in MW 1.38 and prior. You can run tests in Parsoid mode via the --parsoid option. The best and most up-to-date documentation of all available options is to run

php tests/parser/parserTests.php --help

Setting global config variables

To set default global variables for all parser tests in an extension, use the ParserTestGlobals hook.

In a specific test, set the config variables as follows:

!! test
Your Test Name
!! config
wgVariableName=true
!! wikitext
...

Voir aussi