Manual:Parser tests/fr

Le plus souvent, les cas de test de l'analyseur spécifie le wikicode (l'entrée généralement) et le HTML (la sortie généralement), 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 le répertoire. Les extensions doivent placer leurs tests dans un répertoire.

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. Ainsi un test en échec de l'analyseur déclenchera une erreur de test dans Jenkins.



Syntaxe et exécution


Format de la version 2
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, you can use the options section at the top of the file (see below).

Alternatively, as a shortcut, the first line in your parser test file must be.



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



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



Structure d'un test d'analyseur
Besides the test time, a test has a number of sections:  (optional),   (optional), ,   (optional),   (optional),   (optional),   (optional),   (optional),   (optional).



Sections spécifiques à l'ancien analyseur
The legacy parser expects the  and one of    or   sections to be always present.



Sections spécifiques à Parsoid
The  and the various   sections are only relevant when running a test with Parsoid. Parsoid also allows additional configuration with additional test-specific options in the options section. Since Parsoid supports running tests in different modes, the test modes determine what sections are expected.


 * For wt2html and html2wt modes, in addition to the wikitext section, at least one of html, html/parsoid, html/parsoid+standalone, or html/parsoid+integrated sections should be present.
 * For wt2wt mode, just the wikitext section is sufficient (but the test runner currently expects some html section to be present).
 * For html2html mode, one of the html sections is sufficient.
 * For selser modes, the wikitext and at least one of the html sections should be present.
 * For manual selser modes, the wikitext and wikitext/edited should both be present.

Exemple
La syntaxe pour un test simple est la suivante :



Section de configuration
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.



Section des options
Each option should come on its own line.

changes format
 * disables the test.
 * 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.
 * or  (JSON format object) enable Parsoid-specific options.
 * Ex:  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
 * : This is a comma separated list of Parsoid modes to run
 * : If selser is one of the test modes in the modes property, this property can optionally specify  to indicate automatic edits for this test should not be generated. If so, only manual edits as specified by the   property will be applied.
 * : This format is described separately below. This option will need to be paired with a   section in the test (see below)  that specifies the expected wikitext output when this edited HTML is converted (via selser) to wikitext by Parsoid.

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  So, ['fig', 'attr', 'width', '120'] is interpreted as

Right now, the following jquery methods are recognized:

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.



Sections wikicode

 * 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).
 * 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.



Sections HTML

 * : This is the original default output section for a parser test. Parsoid only uses this section if there isn't any Parsoid-specific section available (see below). If Parsoid uses this section for a test, Parsoid will heavily normalize Parsoid's HTML output before comparing against this HTML. This is because Parsoid generates different markup for a lot of wikitext constructs. The normalization ensures the semantic attributes and properties (that don't have a rendering impact) don't cause false test failures.
 * : This section is only used by the legacy parser and Parsoid ignores this.
 * : This is the default section used by Parsoid and is used for both standalone and integrated tests if specialized sections aren't present for those modes. The test runner will minimally normalize Parsoid's output and this section to verify test pass/fails. The normalization strips some noisy attributes to prevent the need to add all this noisy output to parser tests.
 * : This parsoid HTML section is only used in Parsoid standalone test runs (only implemented in Parsoid's test runner).
 * : This parsoid HTML section is only used in Parsoid integrated test runs (only implemented in the MediaWiki core's test runner).



Autoriser les tests de Parsoid
You can enable running tests in a file against by Parsoid via the parsoid-compatible option in the file options section. You can specify individual modes or enable all modes by omitting the options string. For example  enables running Parsoid tests in wt2html and wt2wt modes. But,  enables running Parsoid tests in all modes (wt2html, wt2wt, html2wt, html2html, selser)

See an example below.



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



Exécuter les tests avec 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 :

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



Options particulières au lanceur de test de Parsoid
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  option. The best and most up-to-date documentation of all available options is to run



Initialisation des paramètres de configuration globaux
Pour initialiser les variables globales par défaut pour tous les tests de l'analyseur dans une extension, utilisez l'accroche.

Pour un test donné, initialisez les paramètres de configuration ainsi :

<span id="See_also">