විකිපීඩියා:Template sandbox and test cases
Templates are a very powerful feature of the MediaWiki software used for Wikipedia, but mistakes can be easily made, even by experienced users. Edits to complex templates should therefore be carried out in sandboxes and accompanied by test cases to prevent bugs. Temporary sandboxes X1-X52 or the Template Sandbox may be useful places to try new experiments or for users new to template development. For the development of entirely new templates, user sandboxes are appropriate. Sandbox and testcases subpage namingMost protected templates already have a sandbox subpage and testcases subpage. The names of these pages are default. At the bottom of each template's page are links to create/edit the template's sandbox and testcases pages. For example, here are the subpages for {{FlagIOCmedalist}}:
What kind of templates should you use sandbox forIt is highly recommended to apply the test case pattern to templates using ParserFunctions that can generate very different looking output, such as ones that take many parameters, or the ones that have many branches of the For navigational boxes with mostly identical results on each transcluding page, the benefit may not outweigh the time and effort to create a sandbox page, but if in doubt, sandbox it. Any template that is marked as a High-risk Template should always be tested before an edit is made. With other pages, you should still check which pages use the template (via the "What Links Here" link in the Tools section of the linkbar at the left side of the screen). How to create /sandbox and /testcases subpages
How to update existing /sandbox and /testcases subpagesTo make a change to a template which already has /sandbox and /testcases subpages, the process is similar to the above.
Adding test casesOn the /testcases page, there should be one test case for each different behaviour of your template. For example, if your template outputs a banner message, and if the parameter There are quite a few different styles of test case that you can use. Which one you choose depends on the nature of the template you are working on. For example, for short template output that fits on one line, it can be useful to put the test cases inside a wikitable, and for long and thin templates such as infoboxes, it is often best to display them side by side by using {{testcase table}}. Manual formattingManually formatting gives you a great deal of flexibility, but care must be taken to ensure that all the template parameters are entered correctly. An error in one of the test cases is often harder to find than an error in the template itself. Basic formatThis format works well for banner templates and for lengthy text, e.g. citations. Note that you can format these kinds of test automatically using Template:Test case and other similar templates. == Descriptive title == * <code><nowiki>{{template|param1=value1|param2=value2}}</nowiki></code> '''Main''' {{template|param1=value1|param2=value2}} '''Sandbox''' {{template/sandbox|param1=value1|param2=value2}} Each value of template, param1, value1 etc. must be identical. For templates that use the "float" CSS attribute, you will need to use the {{clear}} template to stop the results from bunching together: == Descriptive title == * <code><nowiki>{{template|param1=value1|param2=value2}}</nowiki></code> '''Main''' {{template|param1=value1|param2=value2}} {{clear}} '''Sandbox''' {{template/sandbox|param1=value1|param2=value2}} {{clear}} WikitableUsing a wikitable to format test cases is often useful for templates with short output that need to be lined up correctly. Start the table like this: {| class="wikitable" |- ! Code ! Main ! Sandbox <!-- Each new test case can be added like this: --> |- | <code><nowiki>{{template|param1=value1|param2=value2}}</nowiki></code> | {{template|param1=value1|param2=value2}} | {{template/sandbox|param1=value1|param2=value2}} <!-- Finish the table like this: --> |} Automatic formattingThere are various templates that help you to format test cases automatically. With these templates, parameters and values are only entered once, but are still tested for both the main template and the sandbox templates. This avoids the problem of errors in test case parameters, and makes it easier to maintain test case pages. These templates include:
Note that all of these templates can produce collapsible test cases, but Template:Collapsible test case has this feature turned on by default. For detailed documentation, see the individual template pages. Tests that can't be made on /testcases pagesSome template features can't be tested on /testcases pages. For example, a template may only output certain text when in the main namespace, or it may output different things when it is used on a base page and when it is used on a subpage. For these kinds of tests, you can use the "Preview page with this template" feature that you can see underneath the edit window on template pages. To make this feature even more powerful, you can install User:Jackmcbarn/advancedtemplatesandbox.js, which makes it usable in any namespace, and lets you specify the title of the template as well as the page to preview it on. This means that you can edit the sandbox template, but preview pages as if you were actually editing the main template. If you can think of any tests that can't be made on the /testcases page, it may be helpful to leave a note at the top of the /testcases page outlining what else needs testing, so that future editors of that template are also aware. Examples
See also
|
Portal di Ensiklopedia Dunia