Wikipedia:Template sandbox and test cases: Difference between revisions
Content deleted Content added
JsfasdF252 (talk | contribs) →How to update existing /sandbox and /testcases subpages: On another wiki I didn't sync the sandbox of a template and the sandbox got deleted. Oh well, you can just recreate it. Tags: Reverted 2017 wikitext editor |
→Manual formatting: <syntaxhighlight lang="wikitext"> |
||
(6 intermediate revisions by 6 users not shown) | |||
Line 4:
{{see also|Wikipedia:Lua#Unit testing}}
[[Help:Template|Templates]] are a very powerful feature of the [[MediaWiki]] software used for [[Wikipedia]], but mistakes can be easily made, even by experienced users.
For the development of entirely new templates, user sandboxes are appropriate.
== Sandbox and testcases subpage naming ==
Most 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
For example, here are the subpages for '''{{tl|FlagIOCmedalist}}''':
Line 31 ⟶ 33:
# Suppose your template is named <code>Template:X</code>. Create a subpage with the name <code>Template:X/sandbox</code>. If the main template is using the {{tl|documentation}} template, you can do this from a link at the bottom of the blue documentation box on the template main page. Or you can type it into the search box, or directly into the URL bar of your browser. Note that "/sandbox" is all lowercase.
# Copy the entire contents of the main template, including <code><nowiki><noinclude></nowiki></code> tags and the {{tl|documentation}} template if present, paste it into the edit window of the /sandbox subpage, and save the page. Your edit summary should be something like <code><nowiki>create sandbox version of [[Template:X]]</nowiki></code>.
# Create another subpage with the name <code>Template:X/testcases</code>. This page is only linked from the bottom of the blue documentation box if it actually exists, so to create it you will need to create it by typing the page name into the search box or into the URL bar of your browser. Again, note that "/testcases" is all lowercase, and all one word.
# Put the {{tl|testcases notice}} template at the top of the page, add some test cases (see below), and save the page.
Line 40 ⟶ 41:
To make a change to a template which already has /sandbox and /testcases subpages, the process is similar to the above.
# The /sandbox may not have the latest version of the template code in it, so before you make a change, you need to synchronize it with the main template
# Have fun editing the sandbox. When you have some code you want to test, save the page.
# If you have added any new features or changed any parameters, you should add new test cases to the /testcases subpage so that they can be tested. Also, bear in mind that the existing test cases may not be complete. It's okay to rewrite the test cases if they aren't useful for what you're trying to achieve, but also consider editors who may use the test cases after you.
Line 59 ⟶ 60:
This 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.
<syntaxhighlight lang="wikitext">
</syntaxhighlight>
Each value of ''template'', ''param1'', ''value1'' etc. must be identical.
For templates that use the "float" CSS attribute, you will need to use the {{tl|clear}} template to stop the results from bunching together:
<syntaxhighlight lang="wikitext">
{{clear}}
{{clear}}
</syntaxhighlight>
==== Wikitable ====
Line 97 ⟶ 98:
Start the table like this:
<syntaxhighlight lang="wikitext">
▲ {| class="wikitable"
|-
▲ ! Code
| <code><nowiki>{{template|param1=value1|param2=value2}}</nowiki></code>
▲ ! Main
| {{template|param1=value1|param2=value2}}
▲ ! Sandbox
▲ <nowiki><!-- Each new test case can be added like this: --></nowiki>
▲ |-
|}
</syntaxhighlight>
▲ | {{''template''/sandbox|''param1''=''value1''|''param2''=''value2''}}
▲ <nowiki><!-- Finish the table like this: --></nowiki>
=== Automatic formatting ===
|