Wikipedia:Template sandbox and test cases: Difference between revisions

Content deleted Content added
Reverted 1 edit by Lambertkante (talk): Revert test? (TW)
Manual formatting: <syntaxhighlight lang="wikitext">
 
(46 intermediate revisions by 33 users not shown)
Line 1:
{{short description|Template how-to guide}}
{{Wikipedia how to|WP:TEMPTEST|WP:TESTCASE|WP:TESTCASES}}
{{pp-semi-indef|small=yes}}
{{Wikipedia how to|WP:TEMPTEST|WP:TESTCASE|WP:TESTCASES}}
{{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. ComplexEdits to complex templates should therefore be accompaniedcarried byout in [[Sandbox (software development)|sandboxes]] and accompanied by [[test case]]s to prevent bugs. Temporary sandboxes [[Template:X1|X1]]-[[Template:X20|X20]] or the [[Template:Template_sandbox|Template Sandbox]] may be useful places to try new experiments or for users new to template development.
 
== For whatthe kinddevelopment of entirely new templates, user sandboxes are ==appropriate.
 
== Sandbox and testcases subpage naming ==
It is recommended to apply the test case pattern to templates using [[mw:Help:Extension:ParserFunctions|ParserFunctions]] that can generate very different looking output, such as the ones that take many parameters, or the ones that have many branches of the <code>#switch</code> operator.
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/edit the template's sandbox and testcases pages.
 
For example, here are the subpages for '''{{tl|FlagIOCmedalist}}''':
For navigational boxes, of which the outputs are almost identical on each transcluding page, the benefit may not outweigh the time and effort.
&#123;&#124; {|class="wikitable"
!Template
!Link
|-
| Main template || [[Template:FlagIOCmedalist]]
|-
| Template's sandbox || [[Template:FlagIOCmedalist/sandbox]]
|-
| Template's testcases page || [[Template:FlagIOCmedalist/testcases]]
|}
 
== What kind of templates should you use sandbox for ==
Any template that is transcluded in thousands of pages should of course be tested before an edit is made.
 
It is highly recommended to apply the test case pattern to templates using [[mw:Help:Extension:ParserFunctions|ParserFunctions]] that can generate very different looking output, such as the ones that take many parameters, or the ones that have many branches of the <code>#switch</code> operator.
 
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 [[Wikipedia:High-risk templates|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 ==
{{tip|Use "create" and "mirror" links at the bottom of documentation box to create /sandbox and /testcases subpages automatically.}}
# 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>.
#* Note: if you use the "mirror" link at the bottom of the blue documentation box, tags like <code><nowiki><noinclude></nowiki></code>, and their contents, will be missing. It's best just to copy and paste manually.
# 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 42 ⟶ 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">
 
== ''Descriptive title'' ==
&nbsp;
* &lt;<code&gt;&lt;><nowiki&gt;&#123;&#123;''>{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;&lt;}}</nowiki&gt;&lt;></code&gt;>
&nbsp;
<nowiki>'''Main'''</nowiki>
&nbsp;
&#123;&#123;''{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
&nbsp;
<nowiki>'''Sandbox'''</nowiki>
&nbsp;
&#123;&#123;''{{template''/sandbox&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
</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">
 
== ''Descriptive title'' ==
&nbsp;
* &lt;<code&gt;&lt;><nowiki&gt;&#123;&#123;''>{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;&lt;}}</nowiki&gt;&lt;></code&gt;>
&nbsp;
<nowiki>'''Main'''</nowiki>
&nbsp;
&#123;&#123;''{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
&nbsp;
{{clear}}
&#123;&#123;clear&#125;&#125;
&nbsp;
<nowiki>'''Sandbox'''</nowiki>
&nbsp;
&#123;&#123;''{{template''/sandbox&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
&nbsp;
{{clear}}
&#123;&#123;clear&#125;&#125;
</syntaxhighlight>
 
==== Wikitable ====
 
Line 80 ⟶ 98:
 
Start the table like this:
<syntaxhighlight lang="wikitext">
{| class="wikitable"
|-
! Code
! Main
! Sandbox
 
<!-- Each new test case can be added like this: -->
&#123;&#124; class="wikitable"
&#124;-
! Code
! Main
! Sandbox
 
Each new test case can be added like this:
 
|-
| &lt;<code&gt;&lt;><nowiki&gt;&#123;&#123;''>{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;&lt;}}</nowiki&gt;&lt;></code&gt;>
| &#123;&#123;''{{template''&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
| &#123;&#123;''{{template''/sandbox&#124;''|param1''=''value1''&#124;''|param2''=''value2''&#125;&#125;}}
 
<!-- Finish the table like this: -->
 
|}
&#124;&#125;
</syntaxhighlight>
 
=== Automatic formatting ===
Line 119 ⟶ 138:
 
; Basic format
: [[Template:Quote]], [[Template:Quote/sandbox]], and [[Template:Quote/testcases]], and [[Template:Unicode_chart/footer/sandbox]]
; Wikitable
: [[Template:Diff]], [[Template:Diff/sandbox]] and [[Template:Diff/testcases]]
Line 131 ⟶ 150:
* [[Wikipedia:Template limits]] - technical limitations on template use
* {{tl|Template sandbox}} - sandbox for use in testing templates
* [[Special:ExpandTemplates]]
* [[Special:TemplateSandbox]]
 
{{Wikipedia technical help|collapsed}}
[[Category:Wikipedia templatestemplate administration|{{PAGENAME}}Sandbox and test cases]]