From 4ac9fa081a7c045f6a9f1cfc529d82423f485b2e Mon Sep 17 00:00:00 2001
From: Pierre Schmitz
a +b +
+a +b +
+a +b +
+a +
b +
+a +
b +
+a +
+b
+
a +
+b
+
a +
b +
+a +
+b
+
a +b +
+a +b +
+a +
b +
+a +
+b
+
a +
+b
+
a +
+
a +
+
a +
+!! end + !! test Parsing an URL !! input @@ -180,9 +404,12 @@ Simple list * Item 1 * Item 2 !! result -obtained by Lunar Prospector's gamma-ray spectrometer +
+!! end + +# this example taken from [[en:Flaming Pie]] (bug 49926) +!! test +Italics and possessives (2) +!! input +'''''Flaming Pie''''' is ... released in 1997. In ''Flaming Pie'''s liner notes +!! result +Flaming Pie is ... released in 1997. In Flaming Pie's liner notes +
+!! end +# this example taken from [[en:Dictionary]] (bug 49926) +!! test +Italics and possessives (3) +!! input +The first monolingual dictionary written in a Romance language was ''Sebastián Covarrubias''' ''Tesoro de la lengua castellana o española'', published in 1611 in Madrid. In 1612 the first edition of the ''Vocabolario dell'[[Accademia della Crusca]]'', for Italian, was published. In 1690 in Rotterdam was published, posthumously, the ''Dictionnaire Universel''. +!! result +The first monolingual dictionary written in a Romance language was Sebastián Covarrubias' Tesoro de la lengua castellana o española, published in 1611 in Madrid. In 1612 the first edition of the Vocabolario dell'Accademia della Crusca, for Italian, was published. In 1690 in Rotterdam was published, posthumously, the Dictionnaire Universel. +
!! end + ### ### 2-quote opening sequence tests ### @@ -258,13 +532,26 @@ Italics and bold: 2-quote opening sequence: (2,4) !! test -Italics and bold: 2-quote opening sequence: (2,5) +Italics and bold: 2-quote opening sequence: (2,5) (php) +!! options +php !! input ''foo''''' !! resultfoo
!!end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +Italics and bold: 2-quote opening sequence: (2,5) (parsoid) +!! options +parsoid +!! input +''foo''''' +!! result +foo +
+!!end ### @@ -302,13 +589,26 @@ Italics and bold: 3-quote opening sequence: (3,4) !! test -Italics and bold: 3-quote opening sequence: (3,5) +Italics and bold: 3-quote opening sequence: (3,5) (php) +!! options +php !! input '''foo''''' !! resultfoo
!!end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +Italics and bold: 3-quote opening sequence: (3,5) (parsoid) +!! options +parsoid +!! input +'''foo''''' +!! result +foo +
+!!end ### @@ -346,13 +646,26 @@ Italics and bold: 4-quote opening sequence: (4,4) !! test -Italics and bold: 4-quote opening sequence: (4,5) +Italics and bold: 4-quote opening sequence: (4,5) (php) +!! options +php !! input ''''foo''''' !! result'foo
!!end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +Italics and bold: 4-quote opening sequence: (4,5) (parsoid) +!! options +parsoid +!! input +''''foo''''' +!! result +'foo +
+!!end ### @@ -361,6 +674,7 @@ Italics and bold: 4-quote opening sequence: (4,5) !! test Italics and bold: 5-quote opening sequence: (5,2) +!! options !! input '''''foo'' !! result @@ -432,23 +746,49 @@ Italics and bold: multiple quote sequences: (2,4,4) !! test -Italics and bold: multiple quote sequences: (3,4,2) +Italics and bold: multiple quote sequences: (3,4,2) (php) +!! options +php !! input '''foo''''bar'' !! resultfoo'bar
!!end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +Italics and bold: multiple quote sequences: (3,4,2) (parsoid) +!! options +parsoid +!! input +'''foo''''bar'' +!! result +foo'bar +
+!!end + - !! test -Italics and bold: multiple quote sequences: (3,4,3) +Italics and bold: multiple quote sequences: (3,4,3) (php) +!! options +php !! input '''foo''''bar''' !! resultfoo'bar
!!end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +Italics and bold: multiple quote sequences: (3,4,3) (parsoid) +!! options +parsoid +!! input +'''foo''''bar''' +!! result +foo'bar +
+!!end ### ### other quote tests @@ -485,6 +825,7 @@ Italics and bold: other quote tests: (3,2,3,2) !! test Italics and bold: other quote tests: (3,2,3,3) +!! options !! input '''this is about ''foo'''s family''' !! result @@ -512,6 +853,23 @@ The ''[[Main Page]]'''s talk page. !! end +!! test +Parsoid only: Quote balancing context should be restricted to td/th cells on the same wikitext line +(Requires tidy for PHP parser output to be fixed up) +!! options +parsoid=wt2html,wt2wt +!! input +{| +!''a!!''b +|''a||''b +|} +!! result +a | b | +a | b |
---|
strike
+
s
+
<b→> doesn't work! </b> +
<bä> doesn't work! </b> +
<boo> works fine </b> +
<s.foo>foo</s> +
<s.foo>s.foo</s.foo> +
<sub-ID#1> +
+!! end + +### +### Special characters +### + +!! test +Bare pipe character (bug 52363) +!! input +| +!! result +| +
+!! end + +!! test +Bare pipe character from a template (bug 52363) +!! input +{{pipe}} +!! result +| +
+!! end + ### ###– +
+!! end ### ### Comments @@ -781,7 +1226,7 @@ b !! end ### -### paragraph wraping tests +### paragraph wrapping tests ### !! test No block tags @@ -794,8 +1239,9 @@ bb
!! end + !! test -Block tag on one line +Block tag on one line () +!! input +afoo+ +b +!! result +afoo+b +
+!! end + +!! test +Block tag on both lines () !! input afoo@@ -818,6 +1276,18 @@ bfoo!! end +!! test +Block tag on both lines () +!! input +a+foo+ +bfoo+!! result +afoo+bfoo+ +!! end + !! test Multiple lines without block tags !! input @@ -837,7 +1307,7 @@ xfooz !! end !! test -Empty lines between block tags to test open p-tags are closed between the block tags +Empty lines between lines with block tags !! input @@ -845,6 +1315,12 @@ Empty lines between block tags to test open p-tags are closed between the block a b +ab + +bd + + +e!! resulta
@@ -852,6 +1328,12 @@ bb
+ab +bd ++
+e+ !! end ### @@ -874,6 +1356,22 @@ And a link !! end +!! test +Tabs don't trigger preformatted text +!! input + This is not + preformatted text. + This is preformatted text. + So is this. +!! result +This is not + preformatted text. +
+This is preformatted text. + So is this. ++!! end + !! test Ident preformatting with inline content !! input @@ -916,17 +1414,61 @@ Regression with preformatted in!! end -# Expected output in the following test is not really expected (there should be -# in the output) -- it's only testing for well-formedness. !! test -Bug 6200: Preformatted in!!end +# TODO / maybe: fix wt2wt for this !! test -Templates: Single-line variant of parameter whitespace stripping test +Parsoid: Don't paragraph-wrap fosterable content +!! options +parsoid=wt2html !! input -{{echo| a}} +{| ++Bug 52763: Preformatted in!! inputBlah!! result- Blah ++ +!! end + +!! test +Bug 51086: Double newlines in blockquotes should be turned into paragraphs +!! input +Blah +
++Foo + +Bar ++!! result +++ +!! end + +!! test +Bug 15491: /Foo +
Bar +
+in blockquote +!! input ++Foo+!! result +barbaz quux +++ +!! end + +# Note that the p-wrapping is newline sensitive, which could be +# considered a bug: tidy will wrap only the 'Foo' in the example +# below in aFoo
+barbaz quux +tag. (see comment 23-25 of bug #6200) +!! test +Bug 15491: /
in blockquote (2) +!! input +Foo+!! result +barbaz quux +Foo!! end @@ -1156,82 +1698,253 @@ Templates: Indent-Pre: 1f: Wrapping should be based on expanded contentbarbaz quux+ -{{echo|1= a}} -{{echo|{{echo| a}}}} -{{echo|1={{echo| a}}}} +|} !! result - a --a -
-a --a -
++ + +
!! end !! test -Templates: Strip whitespace from named parameters, but not positional ones +Parsoid: Don't paragraph-wrap fosterable content even if table syntax is unbalanced +!! options +parsoid=wt2html !! input -{{echo| - foo}} +{| ++ + + + ++ + + + -{{echo| -* foo}} + + +|} +!! result ++ + +
+!! end + + +#-------------------------------------------------------------------- +# Transclusion parameter whitespace stripping tests +# Behavior is different for positional and named parameters +#-------------------------------------------------------------------- +!! test +Templates: Strip leading and trailing whitespace from named-param values +!! input +{{echo|1= a }} + +{{echo|1= {{echo|b}} }} {{echo| 1 = - foo}} + c }} {{echo| 1 = -* foo}} +* d +}} !! result -+ + + + ++ + + foo ---
--
- foo -
foo +
a +
b +
c
-+
- foo -
+
!! end -### -### Parsoid-centric tests for testing RT edge cases for pre -### +!! test +Templates: Don't strip whitespace from positional-param values +!! input +{{echo|a }} -!!test -1a. Indent-Pre and Comments -!!input - a - -c -!!result -- d +
+a +{{echo|{{echo|b}} }} + +{{echo| c +}} + +{{echo| {{echo|d}} +}} + +{{echo| + e}} + +{{echo| +* f}} + +{{echo| + }}g +!! result +a +
b +
+c-c +
-!!end - -!!test -1b. Indent-Pre and Comments -!!input - a - -c -!!result -
a +d-c +
+
+e +++
++
+- f +
++
+g ++!! end + +!! test +Templates: Handle empty comment-and-ws-only lines correctly +!! input +{{echo|foo + + +bar}} +!! result +foo +bar +
+!! end + +#-------------------------------------------------------------------- +# Transclusion parameter escaping tests +#-------------------------------------------------------------------- +!! test +Templates: Parsoid parameter escaping test 1 +!! options +parsoid +!! input +{{echo|[foo]|{{echo|[bar]}}}} +!! result +[foo]
+!! end + +!! test +Parsoid: Pipes in external links in template parameter +!! options +parsoid +!! input +{{echo|[{{echo|http://example.com}} link]}} +!! result + +!! end + +!! test +Parsoid: pipe in transclusion parameter +!! options +parsoid +!! input +{{echo|http://foo.com/a|b}} +!! result + +!! end + +!! test +Parsoid: Pipe in external link target and content in template parameter +!! options +parsoid=html2wt,wt2wt +!! input +{{echo|[http://foo.com/a|b a|b]}} +!! result + +!! end + +!! test +Templates: Dont escape already nowiki-escaped text in template parameters +!! options +parsoid=html2wt,wt2wt +!! input +{{echo|foo| bar}} +{{echo|<div> }} +{{echo|}} +!! result + foo|bar +<div> + +
+!! end + +## Bug 52824 +!! test +Templates: '=' char in nested transclusions should not trigger nowiki escapes or conversion to named param +!! options +parsoid=html2wt,wt2wt +!! input +{{echo|{{echo|1=bar}}}} +!! result +bar
+!! end + +### +### Parsoid-centric tests for testing RT edge cases for pre +### + +!!test +1a. Indent-Pre and Comments +!!input + a + +c +!!result +a ++c +
+!!end + +!!test +1b. Indent-Pre and Comments +!!input + a + +c +!!result +a ++c
!!end @@ -1248,6 +1961,20 @@ c !!end +!!test +1d. Indent-Pre and Comments +(Pre-handler currently cannot distinguish between comment/ws order and normalizes them to [comment,ws] order) +!!input + a + + b +!!result +a ++b ++!!end + !!test 2a. Indent-Pre and tables !!input @@ -1307,10 +2034,12 @@ c !!inputfoo
foo+foofoo !!resultfoo
foo+foofoo
!!end @@ -1334,6 +2063,12 @@ c foo+++foo ++@@ -1355,7 +2090,13 @@ c
foo - foo ++foo +
+++foo +!! end @@ -1812,18 +2680,27 @@ Table / list interaction: lists nested in tables nested in indented lists
foo @@ -1400,6 +2141,56 @@ b!! end +!! test +6. Pre-blocks should extend across lines with leading WS even when there is no wrappable content +!! input + a + + + b + + c + +d +!! result +a + +b ++c + ++d +
+!! end + +!! test +7a. Indent-pre and category links +!! options +parsoid=wt2html,wt2wt +!! input + [[Category:foo]] +{{echo| [[Category:foo]]}} +!! result + + + +!! end + +!! test +7b. Indent-pre and category links +!! options +parsoid=wt2html,wt2wt +!! input + [[Category:foo]] a + [[Category:foo]] {{echo|b}} +!! result ++ a + + b
+!! end + ### ### HTML-pre (some to spec PHP parser behavior and some Parsoid-RT-centric) ### @@ -1482,8 +2273,11 @@ Simple definition !! input ; name : Definition !! result -+
- name
- Definition -
+
!! end @@ -1492,8 +2286,10 @@ Definition list for indentation only !! input : Indented text !! result -- name
+- Definition +
++
- Indented text -
+
!! end @@ -1502,8 +2298,11 @@ Definition list with no space !! input ;name:Definition !! result -- Indented text +
++
- name
- Definition -
+
!!end @@ -1512,8 +2311,11 @@ Definition list with URL link !! input ; http://example.com/ : definition !! result -- name
+- Definition +
++
- http://example.com/
- definition -
+
!! end @@ -1522,8 +2324,11 @@ Definition list with bracketed URL link !! input ;[http://www.example.com/ Example]:Something about it !! result -- http://example.com/
+- definition +
++
- Example
- Something about it -
+
!! end @@ -1532,8 +2337,11 @@ Definition list with wikilink containing colon !! input ; [[Help:FAQ]]: The least-read page on Wikipedia !! result -- Example
+- Something about it +
++
- Help:FAQ
- The least-read page on Wikipedia -
+
!! end @@ -1543,8 +2351,11 @@ Definition list with news link containing colon !! input ; news:alt.wikipedia.rox: This isn't even a real newsgroup! !! result -- Help:FAQ
+- The least-read page on Wikipedia +
++
- news:alt.wikipedia.rox
- This isn't even a real newsgroup! -
+
!! end @@ -1553,8 +2364,10 @@ Malformed definition list with colon !! input ; news:alt.wikipedia.rox -- don't crash or enter an infinite loop !! result -- news:alt.wikipedia.rox
+- This isn't even a real newsgroup! +
++
- news:alt.wikipedia.rox -- don't crash or enter an infinite loop -
+
!! end @@ -1563,8 +2376,11 @@ Definition lists: colon in external link text !! input ; [http://www.wikipedia2.org/ Wikipedia : The Next Generation]: OK, I made that up !! result -- news:alt.wikipedia.rox -- don't crash or enter an infinite loop +
++
- Wikipedia : The Next Generation
- OK, I made that up -
+
!! end @@ -1573,8 +2389,10 @@ Definition lists: colon in HTML attribute !! input ;bold !! result -- Wikipedia : The Next Generation
+- OK, I made that up +
++
- bold -
+
!! end @@ -1583,8 +2401,11 @@ Definition lists: self-closed tag !! input ;one- bold +
+
two : two-line fun !! result -+
- one
two- two-line fun -
+
!! end @@ -1613,16 +2434,19 @@ Definition and unordered list using wiki syntax nested in unordered list using h- one
+
two- two-line fun +
++ !! result
- ; term : description * unordered -
-!! end @@ -1633,8 +2457,11 @@ Definition list with empty definition and following paragraph ; term: Paragraph text !! result -
- -
-
- term
- description -
+
- unordered -
+
+- term
+- description +
++
+- unordered
+
- term
- -
+
- term
+- +
+Paragraph text
!! end @@ -1663,10 +2490,14 @@ Definition Lists: No nesting: Multiple dd's :a :b !! result -+
- x -
- a -
- b -
+
!! end @@ -1677,12 +2508,18 @@ Definition Lists: Indentation: Regular ::i2 :::i3 !! result -- x +
+- a +
+- b +
++
- i1 -
-
- i2 -
-
- i3 -
+
!! end @@ -1692,11 +2529,17 @@ Definition Lists: Indentation: Missing 1st level ::i2 :::i3 !! result -- i1 +
++
+- i2 +
++
+- i3 +
++
-
- i2 -
-
- i3 -
+
!! end @@ -1705,10 +2548,16 @@ Definition Lists: Indentation: Multi-level indent !! input :::i3 !! result -- +
+
+- i2 +
++
+- i3 +
++
-
-
- i3 -
+
!! end @@ -1732,6 +2581,21 @@ should be left alone should be left alone !! end + +# Bug 52473 +!! test +Definition Lists: Hacky use to indent tables (WS-insensitive) +!! options +parsoid +!! input +: {| +|a +|} +!! result +- +
+
+- +
+
+- i3 +
++
+!! end ## The PHP parser treats : items (dd) without a corresponding ; item (dt) ## as an empty dt item. It also ignores all but the last ";" when followed ## by ":" later on. So, ";" are not ignored in ";;;t3" but are ignored in @@ -1783,13 +2647,17 @@ Table / list interaction: indented table with lists in table contents- +
a a - +
- b -
+
- b +
+c - +
- d -
+
- d +
+-
- +
- a -
- b -
+
- a +
+- b +
+- +
- c -
- d -
+
- c +
+- d +
++
- e -
- f -
+
!!end @@ -1911,43 +2788,91 @@ Definition Lists: Nesting: Test 4 ::;t3 :::d3 !! result -- e +
+- f +
++
-
-
- t3 -
- d3 -
+
!! end +## The Parsoid team believes the following three test exposes a +## bug in the PHP parser. (Parsoid team thinks the PHP parser is +## wrong to close the- +
+
+- +
+
+- t3 +
+- d3 +
+after the
-- containing the
.) !! test -Definition Lists: Mixed Lists: Test 1 +Definition Lists: Mixed Lists: Test 1 (php) +!! options +php !! input :;* foo ::* bar :; baz !! result -
- -!! end - - +
-
-
- foo -
- bar -
-
- baz -
+
+ +!! end +!! test +Definition Lists: Mixed Lists: Test 1 (parsoid) +!! options +parsoid +!! input +:;* foo +::* bar +:; baz +!! result +- +
+
+- +
+
+- foo +
+- bar +
++
+- baz +
++
+!! end + !! test Definition Lists: Mixed Lists: Test 2 !! input *: d1 *: d2 !! result -- +
+
- +
+
- foo +
+- +
+
- bar +
+- baz
++
-
- d1 -
- d2 -
+
!! end @@ -1958,12 +2883,21 @@ Definition Lists: Mixed Lists: Test 3 *::: d1 *::: d2 !! result -- +
+
+- d1 +
+- d2 +
++
-
-
-
- d1 -
- d2 -
+
!! end @@ -1974,10 +2908,17 @@ Definition Lists: Mixed Lists: Test 4 *;d1 :d2 *;d3 :d4 !! result -- +
+
+- +
+
+- +
+
+- d1 +
+- d2 +
++
-
- d1
- d2 -
- d3
- d4 -
+
!! end @@ -1988,11 +2929,17 @@ Definition Lists: Mixed Lists: Test 5 *:d1 *:: d2 !! result -- +
+
+- d1
+- d2 +
+- d3
+- d4 +
++
-
- d1 -
-
- d2 -
+
!! end @@ -2003,13 +2950,23 @@ Definition Lists: Mixed Lists: Test 6 #*:d1 #*::: d3 !! result -- +
+
+- d1 +
++
+- d2 +
++
-
-
- d1 -
-
-
- d3 -
+
!! end @@ -2020,10 +2977,15 @@ Definition Lists: Mixed Lists: Test 7 :* d1 :* d2 !! result -- +
+
+- +
+
+- d1 +
++
+- +
+
+- d3 +
++
-
- d1 -
- d2 -
+
!! end @@ -2034,12 +2996,20 @@ Definition Lists: Mixed Lists: Test 8 :* d1 ::* d2 !! result -- +
+
+- d1 +
+- d2 +
++
-
- d1 -
-
-
- d2 -
+
!! end @@ -2049,9 +3019,14 @@ Definition Lists: Mixed Lists: Test 9 !! input *;foo :bar !! result -- +
+
+- d1 +
++
+- +
+
+- d2 +
++
-
- foo
- bar -
+
!! end @@ -2061,50 +3036,171 @@ Definition Lists: Mixed Lists: Test 10 !! input *#;foo :bar !! result -- +
+
+- foo
+- bar +
++
-
-
- foo
- bar -
+
!! end +# The Parsoid team disagrees with the PHP parser's seemingly-random +# rules regarding dd/dt on the next two tests. Parsoid is more +# consistent, and recognizes the shared nesting and keeps the +# still-open tags around until the nesting is complete. !! test -Definition Lists: Mixed Lists: Test 11 +Definition Lists: Mixed Lists: Test 11 (php) +!! options +php !! input *#*#;*;;foo :bar *#*#;boo :baz !! result -- +
+
+- +
+
+- foo
+- bar +
+
-
-
- foo
-
- bar -
- - - - +
- boo
- baz -
+
+ + + + !! end +!! test +Definition Lists: Mixed Lists: Test 11 (parsoid) +!! options +parsoid +!! input +*#*#;*;;foo :bar +*#*#;boo :baz +!! result +- +
+
+- +
+
+ + ++
- +
+
+- foo
+- +
+
+
+
+- bar +
++
+- boo
+- baz +
++
+ + +!! end !! test -Definition Lists: Weird Ones: Test 1 +Definition Lists: Weird Ones: Test 1 (php) +!! options +php !! input *#;*::;; foo : bar (who uses this?) !! result -- +
++
- +
++
+- +
+
- +
++
- +
++
- +
+
- +
+
- foo
+- bar
+- boo
+- baz
+- - - +
-
- foo
-
-
-
- bar (who uses this?) -
+
+ + + + + + +!! end +!! test +Definition Lists: Weird Ones: Test 1 (parsoid) +!! options +parsoid +!! input +*#;*::;; foo : bar (who uses this?) +!! result ++
- +
+
+- foo
+- +
+
+
+- +
+
+- +
+
+
+- bar (who uses this?) +
++
+ + + !! end ### @@ -2269,6 +3365,17 @@ External image from https: https://meta.wikimedia.org/upload/f/f1/Ncwikicol.png !! end +!! test +External image (when not allowed) +!! options +wgAllowExternalImages=0 +!! input +External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png +!! result +- +
+
- +
++
+ +- +
++
- +
+
- +
+
- +
+
- +
+
- foo
+- bar (who uses this?)
+External image: http://meta.wikimedia.org/upload/f/f1/Ncwikicol.png +
+!! end + !! test Link to non-http image, no img tag !! input @@ -2691,6 +3798,15 @@ External link containing double-single-quotes with no space separating the url f !! end +!! test +External link with comments in link text +!! input +[http://www.google.com Google ] +!! result +Google +
+!! end + !! test URL-encoding in URL functions (single parameter) !! input @@ -2763,6 +3879,28 @@ Non-extlinks in brackets !! end +!! test +Parsoid: Percent encoding in external links +!! options +parsoid +!! input +[https://github.com/search?l=&q=ResourceLoader+%40wikimedia Search] +!! result + +!! end + +!! test +Parsoid: use url link syntax for links where the content is equal the link +target +!! options +parsoid +!! input +http://example.com +!! result + +!! end + ### ### Quotes ### @@ -2781,7 +3919,9 @@ Normal text. '''''Bold italic text.''''' Normal text. !! test -Unclosed and unmatched quotes +Unclosed and unmatched quotes (php) +!! options +php !! input '''''Bold italic text '''with bold deactivated''' in between.''''' @@ -2816,6 +3956,47 @@ Plain ''italic'''s plainPlain italic's plain
!! end +# Parsoid inserts an empty bold tag pair at the end of the line, that the PHP +# parser strips. The wikitext contains just the first half of the bold +# quote pair. +!! test +Unclosed and unmatched quotes (parsoid) +!! options +parsoid +!! input +'''''Bold italic text '''with bold deactivated''' in between.''''' + +'''''Bold italic text ''with italic deactivated'' in between.''''' + +'''Bold text.. + +..spanning two paragraphs (should not work).''' + +'''Bold tag left open + +''Italic tag left open + +Normal text. + + +'''This year''''s election ''should'' beat '''last year''''s. + +''Tom'''s car is bigger than ''Susan'''s. + +Plain ''italic'''s plain +!! result +Bold italic text with bold deactivated in between. +
Bold italic text with italic deactivated in between. +
Bold text.. +
..spanning two paragraphs (should not work). +
Bold tag left open +
Italic tag left open +
Normal text. +
This year's election should beat last year's. +
Toms car is bigger than Susans. +
Plain italic's plain +
+!! end ### ### Tables @@ -2824,19 +4005,33 @@ Plain ''italic'''s plain ### # This should not produceas
-# is the bare minimun required by the spec, see: +# is the bare minimum required by the spec, see: # http://www.w3.org/TR/xhtml-modularization/dtd_module_defs.html#a_module_Basic_Tables !! test -A table with no data. +A table with no data. (php) +!! options +php +!! input +{||} +!! result +!! end +# Parsoid team replies: empty table tags are legal in HTML5 +!! test +A table with no data. (parsoid) +!! options +parsoid !! input {||} !! result +
!! end # A table with nothing but a caption is invalid XHTML, we might want to render # this as
caption
!! test -A table with nothing but a caption +A table with nothing but a caption (php) +!! options +php !! input {| |+ caption @@ -2847,13 +4042,25 @@ A table with nothing but a caption!! end - +# Parsoid team replies: table with only a caption is legal in HTML5 !! test -A table with caption with default-spaced attributes and a table row +A table with nothing but a caption (parsoid) +!! options +parsoid !! input {| -|+ style="color: red;" | caption1 -|- +|+ caption +|} +!! result + +!! end + +!! test +A table with caption with default-spaced attributes and a table row +!! input +{| +|+ style="color: red;" | caption1 +|- | foo |} !! result @@ -3243,11 +4450,44 @@ Template-generated table cell attributes and cell content !! input {| |{{table_attribs}} +| {{table_attribs}} |} !! result
caption + +!! end + +!! test +Template-generated table cell attributes and cell content (2) +!! input +{| +|align=center {{table_attribs}} +|} +!! result +
Foo + +Foo + +
+ +!! end + +!! test +Template-generated table cell attributes and cell content (3) +!! input +{| +|align=center {{table_cells}} +|} +!! result ++ Foo + +
!! end @@ -3270,21 +4510,40 @@ Table with row followed by newlines and table heading !! end +!! test +Table with empty line following the start tag +!! input +{| + +|- +| foo +|} +!! result ++ Foo +Bar +Baz + + +
+ +!! end + # FIXME: Preserve the attribute properly (with an empty string as value) in # the PHP parser. Parsoid implements the behavior below. !! test Table attributes with empty value !! options -disabled +parsoid !! input {| | style=| hello |} !! result+ foo + +
+ !! end @@ -3311,6 +4570,159 @@ Wikitext table with a lot of comments !! end +!! test +Wikitext table with double-line table cell +!! input +{| +|a +b +|} +!! result +hello - +
+ +!! end + +!! test +Table cell with a single comment +!! input +{| +| +| a +|} +!! result ++ a + b +
++
+ +!! end + +# The expected HTML structure in this test is debatable. The PHP parser does +# not parse this kind of table at all. The main focus for Parsoid is on +# round-tripping, so this output is ok for now. TODO: revisit! +!! test +Wikitext table with html-syntax row (Parsoid) +!! options +parsoid +!! input +{| +|- ++ + +a + foo +|} +!! result ++ +
+!! end + +!! test +Implicit+ foo after a |- +(PHP parser relies on Tidy to add the missing tags) +!! options +parsoid=wt2html,wt2wt +!! input +{| +|- +a +|} +!! result + +
+!! end + +!! test +Pres should be recognized in an explicit+ a context, but not in an implicit context +(PHP parser relies on Tidy to add the missing tags) +!! options +parsoid=wt2html,wt2wt +!! input +{| +|- +| + a +|- + b +|} +!! result + + +
+!! end + +!! test +Lists should be recognized in an implicit+ a+ + b context +(PHP parser relies on Tidy to add the missing tags) +!! options +parsoid=wt2html,wt2wt +!! input +{| +|- +*a +|} +!! result + +
+!! end + +!! test +Parsoid: Round-trip tables directly followed by content (bug 51219) +!! options +parsoid=wt2html,wt2wt +!! input +{| +|foo +|} bar + +{| +|baz +|}quux +!! result ++ ++ +
- a
++
bar ++ foo + +
quux +!! end + +!! test +Parsoid: Default to a newline after tables in new content (bug 51219) +!! options +parsoid=html2wt +!! input +{| +|foo +|} ++ baz bar +{| +|baz +|} +'''quux''' +!! result + +
bar +foo +
quux +!! end + ### ### Internal links ### @@ -3341,6 +4753,15 @@ Piped link !! end +!! test +Piped link with comment in link text +!! input +[[Main Page|The Main Page]] +!! result + +!! end + !! test Broken link !! input @@ -3462,6 +4883,22 @@ Link to namespaces !! end +!! article +MemoryAlpha:AlphaTest +!! text +This is an article in the MemoryAlpha namespace +(which shadows the memoryalpha interwiki link). +!! endarticle + +!! test +Namespace takes precedence over interwiki link (bug 51680) +!! input +[[MemoryAlpha:AlphaTest]] +!! result + +!! end + !! test Piped link to namespace !! input @@ -3526,6 +4963,33 @@ Link containing "<#" and ">#" as a hex sequences !! end +!! test +Link containing an equals sign +!! input +[[Special:BookSources/isbn=4-00-026157-6]] +!! result +baz Special:BookSources/isbn=4-00-026157-6 +
+!! end + +!! article +Foo~bar +!! text +Just a test of an article title containing a tilde. +!! endarticle + +# note that links containing signatures, like [[Foo~~~~]], are +# massaged by the pre-save transform (PST) and so the tildes are never +# seen by the parser. +!! test +Link containing a tilde +!! input +[[Foo~bar]] +!! result +Foo~bar +
+!! end + !! test Link containing double-single-quotes '' (bug 4598) !! input @@ -3787,6 +5251,69 @@ language=kaa !! end +!! article +Söfnuður +!! text +Test. +!! endarticle + +!! test +Internal link with is link prefix +!! options +language=is +!! input +Aðrir mótmælenda[[söfnuður|söfnuðir]] og +!! result +Aðrir mótmælendasöfnuðir og +
+!! end + +!! article +Mótmælendatrú +!! text +Test. +!! endarticle + +!! test +Internal link with is link trail and link prefix +!! options +language=is +!! input +[[mótmælendatrú|xxx]]ar +[[mótmælendatrú]]ar +mótmælenda[[söfnuður]] +mótmælenda[[söfnuður|söfnuðir]] +mótmælenda[[söfnuður|söfnuðir]]xxx +!! result +xxxar +mótmælendatrúar +mótmælendasöfnuður +mótmælendasöfnuðir +mótmælendasöfnuðirxxx +
+!! end + +!! test +Parsoid link trail escaping +!! options +parsoid=html2wt,html2html +!! input +[[apple]]s +!! result + +!! end + +!! test +Parsoid link prefix escaping +!! options +language=is +parsoid=html2wt,html2html +!! input +Aðrir mótmælenda [[söfnuður]] +!! result + Aðrir mótmælendasöfnuður
+!! end + !! test Parsoid-centric test: Whitespace in ext- and wiki-links should be preserved !! input @@ -3833,9 +5360,12 @@ Interwiki link encoding conversion (bug 1636) *[[Wikipedia:ro:Olteniţa]] *[[Wikipedia:ro:Olteniţa]] !! result - + !! end @@ -3848,6 +5378,12 @@ Interwiki link with fragment (bug 2130) !! end + +### +### Interlanguage links +### Language links (so that searching for '### language' matches..) +### + !! test Interlanguage link !! input @@ -3905,21 +5441,206 @@ language=ln !! end -## -## XHTML tidiness -### - !! test -
to
+Parsoid bug 53221: Wikilinks should be properly entity-escaped +!! options +parsoid=html2wt !! input -1
2
3 -!! result -1
+He llo [[Foo|He llo]] + +He llo [[He llo]] +!!result +
2
3 -He llo He llo
+He llo He llo
!! end !! test -Broken br tag sanitization +Parsoid: handle constructor well +!! options +parsoid +!! input +[[constructor]] + +[[constructor:foo]] +!! result + + + + +!! end + +!! test +Parsoid: recognize interlanguage links without a target page +!! options +parsoid +!! input +[[ko:]] +!! result ++
+!! end + +!! test +Parsoid: recognize interwiki links without a target page +!! options +parsoid +!! input +[[:ko:]] +!! result + +!! end + +### +### Redirects, Parsoid-only +### +!! test +Simple redirect to page +!! options +parsoid +!! input +#REDIRECT [[Main Page]] +!! result + +!! end + +!! test +Optional colon in #REDIRECT +!! options +# the colon is archaic syntax. we support it for wt2html, but we +# don't care that it roundtrips back to the modern syntax. +parsoid=wt2html,html2html +!! input +#REDIRECT:[[Main Page]] +!! result + +!! end + +!! test +Whitespace in #REDIRECT with optional colon +!! options +# the colon and gratuitous whitespace is archaic syntax. we support +# it for wt2html, but we don't care that it roundtrips back to the +# modern syntax (without extra whitespace) +parsoid=wt2html,html2html +!! input + + #REDIRECT +: +[[Main Page]] +!! result + +!! end + +!! test +Piped link in #REDIRECT +!! options +# content after piped link is ignored. we support this syntax, +# but don't care that the piped link is lost when we roundtrip this. +parsoid=wt2html +!! input +#REDIRECT [[Main Page|bar]] +!! result + +!! end + +!! test +Redirect to category +!! options +parsoid=wt2html +!! input +#REDIRECT [[Category:Foo]] +!! result + +!! end + +!! test +Redirect to category with URL encoding +!! options +parsoid=wt2html +!! input +#REDIRECT [[Category%3AFoo]] +!! result + +!! end + +!! test +Redirect to category page +!! options +parsoid=wt2html,html2html +!! input +#REDIRECT [[:Category:Foo]] +!! result + +!! end + +!! test +Redirect to image page (1) +!! options +parsoid +!! input +#REDIRECT [[File:Wiki.png]] +!! result + +!! end + +!! test +Redirect to image page (2) +!! options +parsoid +!! input +#REDIRECT [[Image:Wiki.png]] +!! result + +!! end + +!! test +Redirect to language +!! options +parsoid +!! input +#REDIRECT [[en:File:Wiki.png]] +!! result + +!! end + +!! test +Redirect to interwiki +!! options +parsoid +!! input +#REDIRECT [[meatball:File:Wiki.png]] +!! result + +!! end + +!! test +Non-English #REDIRECT +!! options +parsoid +language=is +!! input +#TILVÍSUN [[Main Page]] +!! result + +!! end + +## +## XHTML tidiness +### + +!! test +
to
+!! input +1
2
3 +!! result +1
+!! end + +!! test +Broken br tag sanitization +!! options +php !! input !! result @@ -3927,6 +5648,17 @@ Broken br tag sanitization !! end +# TODO: Fix html2html mode (bug 51055)! +!! test +Parsoid: Broken br tag recognition +!! options +parsoid=wt2html +!! input + +!! result +
2
3 ++!! end + !! test Incorrecly removing closing slashes from correctly formed XHTML !! input @@ -4023,7 +5755,7 @@ Horizontal ruler -- eats additional dashes on the same line !! end !! test -Horizontal ruler -- does not collaps dashes on consecutive lines +Horizontal ruler -- does not collapse dashes on consecutive lines !! input ---- ---- @@ -4061,10 +5793,14 @@ Common list * item 2 *item 3 !! result -
+
- Common list -
- item 2 -
- item 3 -
+
!! end @@ -4075,10 +5811,14 @@ Numbered list #item 2 # item 3 !! result -- Common list +
+- item 2 +
+- item 3 +
++
- Numbered list -
- item 2 -
- item 3 -
+
!! end @@ -4101,35 +5841,67 @@ Mixed list *** Level 3 #** Level 3, but ordered !! result -- Numbered list +
+- item 2 +
+- item 3 +
+-
- Mixed list -
-
- with numbers -
-
- and bullets -
-
- and numbers -
- bullets again -
-
- bullet level 2 -
-
- bullet level 3 -
-
- Number on level 4 -
- bullet level 2 -
-
- Number on level 3 -
- Number on level 3 -
-
- number level 2 -
- Level 1 -
-
-
- Level 3 -
+
-
-
- Level 3, but ordered -
+
+- Mixed list +
++
+- with numbers +
++
+- and bullets +
++
+- and numbers +
+- bullets again +
++
+- bullet level 2 +
++
+- bullet level 3 +
++
+- Number on level 4 +
+- bullet level 2 +
++
+- Number on level 3 +
+- Number on level 3 +
++
+- number level 2 +
+- Level 1 +
++
+- +
+
+- Level 3 +
++
!! end @@ -4139,10 +5911,14 @@ Nested lists 1 *foo **bar !! result -- +
+
+- +
+
+- Level 3, but ordered +
++
- foo -
-
- bar -
+
!! end @@ -4152,10 +5928,15 @@ Nested lists 2 **foo *bar !! result -- foo +
++
+- bar +
++
-
- foo -
- bar -
+
!! end @@ -4165,10 +5946,14 @@ Nested lists 3 (first element empty) * **bar !! result -- +
+
+- foo +
+- bar +
++
- -
-
- bar -
+
!! end @@ -4178,10 +5963,15 @@ Nested lists 4 (first element empty) ** *bar !! result -- +
++
+- bar +
++
-
- -
- bar -
+
!! end @@ -4191,10 +5981,15 @@ Nested lists 5 (both elements empty) ** * !! result -- +
+
+- +
+- bar +
++
-
- -
- -
+
!! end @@ -4204,10 +5999,14 @@ Nested lists 6 (both elements empty) * ** !! result -- +
+
+- +
+- +
++
- -
-
- -
+
!! end @@ -4216,10 +6015,16 @@ Nested lists 7 (skip initial nesting levels) !! input *** foo !! result -- +
++
+- +
++
-
-
- foo -
+
!! end @@ -4231,16 +6036,24 @@ Nested lists 8 (multiple nesting transitions) ** baz * boo !! result -- +
+
+- +
+
+- foo +
+- -!! end - +
- foo -
-
-
- bar -
- baz -
- boo -
+
+ +!! end + !! test 1. Lists with start-of-line-transparent tokens before bullets: Comments !! input @@ -4248,10 +6061,14 @@ Nested lists 8 (multiple nesting transitions) *bar *baz !! result -- foo +
++
+- +
+
+- bar +
+- baz +
+- boo +
++
- foo -
- bar -
- baz -
+
!! end @@ -4261,78 +6078,14 @@ Nested lists 8 (multiple nesting transitions) *foo {{echo|bar }}*baz !! result -- foo +
+- bar +
+- baz +
+- -!! end - -!! test -Unbalanced closing block tags break a list -(Disabled since php parser generates broken html -- relies on Tidy to fix up) -!! options -disabled -!! input -
- foo bar -
- baz -
-*a-*b-!! result --
- a -
--!! end - -!! test -Unbalanced closing non-block tags don't break a list -(Disabled since php parser generates broken html -- relies on Tidy to fix up) -!! options -disabled -!! input - -*a -*b -!! result -
- b -
-
--!! end - -!! test -Unclosed formatting tags that straddle lists are closed and reopened -(Disabled since php parser generates broken html -- relies on Tidy to fix up) -!! options -disabled -!! input -#
- a -
- b -
a -# b-!! result --!! end - -!!test -List embedded in a non-block tag -(Ugly Parsoid output -- worth fixing; Disabled for PHP parser since it relies on Tidy) -!! options -parsoid -!!input - -* foo - -!!result - -
a-b--
- - -!!end + +!! end !! test List items are not parsed correctly following a- foo
+- foo bar +
+- baz +
block (bug 785) @@ -4341,10 +6094,14 @@ List items are not parsed correctly following ablock (bug 785) *bar* zar !! result -+
foo- bar-- zar -
+
!! end @@ -4363,18 +6120,30 @@ List items from template * notSOL{{inner list}} * item 2 !! result -- +
foo+- +
bar+- zar +
+-
- item 1 -
- item 2 -
-
- item 0 -
- item 1 -
- item 2 -
+
- item 0 -
- notSOL -
- item 1 -
- item 2 -
+
+- item 1 +
+- item 2 +
++
+- item 0 +
+- item 1 +
+- item 2 +
++
!! end @@ -4387,14 +6156,22 @@ List interrupted by empty line or heading == A heading == * Another list item !! result -- item 0 +
+- notSOL +
+- item 1 +
+- item 2 +
+-
- foo -
-
-
- bar -
[edit] A heading
-+
- Another list item -
+
+- foo +
++
+- +
+
+- bar +
+A heading[edit]
++
!!end @@ -4413,1629 +6190,2281 @@ Multiple list tags generated by templates !!end -### -### Magic Words -### +!!test +Single-comment whitespace lines dont break lists, and neither do multi-comment whitespace lines +!!input +*a + +*b + +*c + +*d +!!result +- Another list item +
++
-!! test -Magic Word: {{CURRENTDAY}} -!! input -{{CURRENTDAY}} -!! result -- a +
+- b +
+- c +
+- d +
+1 -
-!! end +!!end -!! test -Magic Word: {{CURRENTDAY2}} -!! input -{{CURRENTDAY2}} -!! result -01 -
-!! end +!!test +Replacing whitespace with tabs still doesn't break the list (gerrit 78327) +!!input +*a + +*b + +*c + +*d +!!result ++
+ +!!end + +!!test +Test the li-hack +(Cannot test this with PHP parser since it relies on Tidy for the hack) +!!options +parsoid=wt2html,wt2wt +!!input +* foo +*- a +
+- b +
+- c +
+- d +
+li-hack +* {{echo| templated li-hack}} +* unsupported li-hack with preceding comments + + +
+!!result +- not a li-hack +
++
+ +- foo
+- li-hack
+- templated li-hack
+- +
- li-hack with preceding comments
++ +
+!!end !! test -Magic Word: {{CURRENTDAYNAME}} +Parsoid: Make sure nested lists are serialized on their own line even if HTML contains no newlines +!! options +parsoid !! input -{{CURRENTDAYNAME}} +# foo +## bar +* foo +** bar +: foo +:: bar !! result -- not a li-hack +
+Thursday -
++
- foo
++
- bar
++
- foo
++
- bar
++
!! end !! test -Magic Word: {{CURRENTDOW}} +Parsoid: Test of whitespace serialization with Templated bullets +!! options +parsoid !! input -{{CURRENTDOW}} +* {{bullet}} !! result -- foo
++
- bar
+4 -
++
!! end +# ------------------------------------------------------------------------ +# The next set of tests are about Parsoid's ability to handle badly nested +# tags (parse, minimize scope of fixup, and roundtrip back) +# ------------------------------------------------------------------------ + !! test -Magic Word: {{CURRENTMONTH}} +Unbalanced closing block tags break a list +(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up) +!! options +parsoid !! input -{{CURRENTMONTH}} +- Bar
++*a+*b!! result -01 -
+++
- a +
++!! end !! test -Magic Word: {{CURRENTMONTHABBREV}} +Unbalanced closing non-block tags don't break a list +(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up) +!! options +parsoid !! input -{{CURRENTMONTHABBREV}} + +*a +*b !! result -+
- b +
+Jan +
+
+
!! end !! test -Magic Word: {{CURRENTMONTHNAME}} +Unclosed formatting tags that straddle lists are closed and reopened +(Parsoid-only since php parser generates broken html -- relies on Tidy to fix up) +!! options +parsoid !! input -{{CURRENTMONTHNAME}} +#- a +
+- b +
+a +# b!! result -January -
++
!! end -!! test -Magic Word: {{CURRENTMONTHNAMEGEN}} -!! input -{{CURRENTMONTHNAMEGEN}} -!! result -- +
a+- +
b+January -
-!! end +!!test +List embedded in a non-block tag +(Ugly Parsoid output -- worth fixing; Disabled for PHP parser since it relies on Tidy) +!! options +parsoid +!!input + +* foo + +!!result + + ++
+ + +!!end !! test -Magic Word: {{CURRENTTIME}} +Table with missing opening- foo
+tag +!! options +parsoid=wt2html,wt2wt !! input -{{CURRENTTIME}} + +
!! result -foo + +00:02 -
++
!! end +### +### Magic Words +### + +# Note that the current date is hard-coded as +# 1970-01-01T00:02:03Z (a Thursday) +# when running parser tests. The timezone is also fixed to GMT, so +# local date will be identical to current date. + !! test -Magic Word: {{CURRENTWEEK}} (@bug 4594) +Magic Word: {{CURRENTDAY}} !! input -{{CURRENTWEEK}} +{{CURRENTDAY}} !! result+ +foo +1
!! end !! test -Magic Word: {{CURRENTYEAR}} +Magic Word: {{CURRENTDAY2}} !! input -{{CURRENTYEAR}} +{{CURRENTDAY2}} !! result -1970 +
01
!! end !! test -Magic Word: {{FULLPAGENAME}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTDAYNAME}} !! input -{{FULLPAGENAME}} +{{CURRENTDAYNAME}} !! result -User:Ævar Arnfjörð Bjarmason +
Thursday
!! end !! test -Magic Word: {{FULLPAGENAMEE}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTDOW}} !! input -{{FULLPAGENAMEE}} +{{CURRENTDOW}} !! result -User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason +
4
!! end !! test -Magic Word: {{NAMESPACE}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTMONTH}} !! input -{{NAMESPACE}} +{{CURRENTMONTH}} !! result -User +
01
!! end !! test -Magic Word: {{NAMESPACEE}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTMONTH1}} !! input -{{NAMESPACEE}} +{{CURRENTMONTH1}} !! result -User +
1
!! end !! test -Magic Word: {{NAMESPACENUMBER}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTMONTHABBREV}} !! input -{{NAMESPACENUMBER}} +{{CURRENTMONTHABBREV}} !! result -2 +
Jan
!! end !! test -Magic Word: {{NUMBEROFFILES}} +Magic Word: {{CURRENTMONTHNAME}} !! input -{{NUMBEROFFILES}} +{{CURRENTMONTHNAME}} !! result -2 +
January
!! end !! test -Magic Word: {{PAGENAME}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTMONTHNAMEGEN}} !! input -{{PAGENAME}} +{{CURRENTMONTHNAMEGEN}} !! result -Ævar Arnfjörð Bjarmason +
January
!! end !! test -Magic Word: {{PAGENAME}} with metacharacters -!! options -title=[['foo & bar = baz']] +Magic Word: {{CURRENTTIME}} !! input -''{{PAGENAME}}'' +{{CURRENTTIME}} !! result -'foo & bar = baz' +
00:02
!! end !! test -Magic Word: {{PAGENAME}} with metacharacters (bug 26781) -!! options -title=[[*RFC 1234 http://example.com/]] +Magic Word: {{CURRENTHOUR}} !! input -{{PAGENAME}} +{{CURRENTHOUR}} !! result -*RFC 1234 http://example.com/ +
00
!! end !! test -Magic Word: {{PAGENAMEE}} -!! options -title=[[User:Ævar Arnfjörð Bjarmason]] +Magic Word: {{CURRENTWEEK}} (@bug 4594) !! input -{{PAGENAMEE}} +{{CURRENTWEEK}} !! result -%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason +
1
!! end !! test -Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781) -!! options -title=[[*RFC 1234 http://example.com/]] +Magic Word: {{CURRENTYEAR}} !! input -{{PAGENAMEE}} +{{CURRENTYEAR}} !! result -*RFC_1234_http://example.com/ +
1970
!! end !! test -Magic Word: {{REVISIONID}} +Magic Word: {{CURRENTTIMESTAMP}} !! input -{{REVISIONID}} +{{CURRENTTIMESTAMP}} !! result -1337 +
19700101000203
!! end !! test -Magic Word: {{SCRIPTPATH}} +Magic Words LOCAL (UTC) !! input -{{SCRIPTPATH}} +* {{LOCALMONTH}} +* {{LOCALMONTH1}} +* {{LOCALMONTHNAME}} +* {{LOCALMONTHNAMEGEN}} +* {{LOCALMONTHABBREV}} +* {{LOCALDAY}} +* {{LOCALDAY2}} +* {{LOCALDAYNAME}} +* {{LOCALYEAR}} +* {{LOCALTIME}} +* {{LOCALHOUR}} +* {{LOCALWEEK}} +* {{LOCALDOW}} +* {{LOCALTIMESTAMP}} !! result -/ +
+
+ +!! end + +!! test +Magic Word: {{FULLPAGENAME}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] +!! input +{{FULLPAGENAME}} +!! result +- 01 +
+- 1 +
+- January +
+- January +
+- Jan +
+- 1 +
+- 01 +
+- Thursday +
+- 1970 +
+- 00:02 +
+- 00 +
+- 1 +
+- 4 +
+- 19700101000203 +
+User:Ævar Arnfjörð Bjarmason
!! end !! test -Magic Word: {{SERVER}} +Magic Word: {{FULLPAGENAMEE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{SERVER}} +{{FULLPAGENAMEE}} !! result -User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end !! test -Magic Word: {{SERVERNAME}} +Magic Word: {{TALKSPACE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{SERVERNAME}} +{{TALKSPACE}} !! result -example.org +
User talk
!! end !! test -Magic Word: {{SITENAME}} +Magic Word: {{TALKSPACE}}, same namespace +!! options +title=[[User talk:Ævar Arnfjörð Bjarmason]] !! input -{{SITENAME}} +{{TALKSPACE}} !! result -MediaWiki +
User talk
!! end !! test -Namespace 1 {{ns:1}} +Magic Word: {{TALKSPACE}}, main namespace +!! options +title=[[Parser Test]] !! input -{{ns:1}} +{{TALKSPACE}} !! resultTalk
!! end !! test -Namespace 1 {{ns:01}} +Magic Word: {{TALKSPACEE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{ns:01}} +{{TALKSPACEE}} !! result -Talk +
User_talk
!! end !! test -Namespace 0 {{ns:0}} (bug 4783) +Magic Word: {{SUBJECTSPACE}} +!! options +title=[[User talk:Ævar Arnfjörð Bjarmason]] !! input -{{ns:0}} +{{SUBJECTSPACE}} !! result +User +
+!! end +!! test +Magic Word: {{SUBJECTSPACE}}, same namespace +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] +!! input +{{SUBJECTSPACE}} +!! result +User +
!! end !! test -Namespace 0 {{ns:00}} (bug 4783) +Magic Word: {{SUBJECTSPACE}}, main namespace +!! options +title=[[Parser Test]] !! input -{{ns:00}} +{{SUBJECTSPACE}} !! result !! end !! test -Namespace -1 {{ns:-1}} +Magic Word: {{SUBJECTSPACEE}} +!! options +title=[[User talk:Ævar Arnfjörð Bjarmason]] !! input -{{ns:-1}} +{{SUBJECTSPACEE}} !! result -Special +
User
!! end !! test -Namespace User {{ns:User}} +Magic Word: {{NAMESPACE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{ns:User}} +{{NAMESPACE}} !! resultUser
!! end !! test -Namespace User talk {{ns:User_talk}} +Magic Word: {{NAMESPACEE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{ns:User_talk}} +{{NAMESPACEE}} !! result -User talk +
User
!! end !! test -Namespace User talk {{ns:uSeR tAlK}} +Magic Word: {{NAMESPACENUMBER}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{ns:uSeR tAlK}} +{{NAMESPACENUMBER}} !! result -User talk +
2
!! end !! test -Namespace File {{ns:File}} +Magic Word: {{SUBPAGENAME}} +!! options +title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage !! input -{{ns:File}} +{{SUBPAGENAME}} !! result -File +
sub ö
!! end !! test -Namespace File {{ns:Image}} +Magic Word: {{SUBPAGENAMEE}} +!! options +title=[[Ævar Arnfjörð Bjarmason/sub ö]] subpage !! input -{{ns:Image}} +{{SUBPAGENAMEE}} !! result -File +
sub_%C3%B6
!! end !! test -Namespace (lang=de) Benutzer {{ns:User}} +Magic Word: {{ROOTPAGENAME}} !! options -language=de +title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage !! input -{{ns:User}} +{{ROOTPAGENAME}} !! result -Benutzer +
Ævar Arnfjörð Bjarmason
!! end !! test -Namespace (lang=de) Benutzer Diskussion {{ns:3}} +Magic Word: {{ROOTPAGENAMEE}} !! options -language=de +title=[[Ævar Arnfjörð Bjarmason/sub/sub2]] subpage !! input -{{ns:3}} +{{ROOTPAGENAMEE}} !! result -Benutzer Diskussion +
%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end - !! test -Urlencode +Magic Word: {{BASEPAGENAME}} +!! options +title=[[Ævar Arnfjörð Bjarmason/sub]] subpage !! input -{{urlencode:hi world?!}} -{{urlencode:hi world?!|WIKI}} -{{urlencode:hi world?!|PATH}} -{{urlencode:hi world?!|QUERY}} +{{BASEPAGENAME}} !! result -hi+world%3F%21 -hi_world%3F! -hi%20world%3F%21 -hi+world%3F%21 +
Ævar Arnfjörð Bjarmason
!! end -### -### Magic links -### !! test -Magic links: internal link to RFC (bug 479) +Magic Word: {{BASEPAGENAMEE}} +!! options +title=[[Ævar Arnfjörð Bjarmason/sub]] subpage !! input -[[RFC 123]] +{{BASEPAGENAMEE}} !! result -RFC 123 +
%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end !! test -Magic links: RFC (bug 479) +Magic Word: {{TALKPAGENAME}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -RFC 822 +{{TALKPAGENAME}} !! result -RFC 822 +
User talk:Ævar Arnfjörð Bjarmason
!! end !! test -Magic links: ISBN (bug 1937) +Magic Word: {{TALKPAGENAMEE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -ISBN 0-306-40615-2 +{{TALKPAGENAMEE}} !! result -User_talk:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end !! test -Magic links: PMID incorrectly converts space to underscore +Magic Word: {{SUBJECTPAGENAME}} +!! options +title=[[User talk:Ævar Arnfjörð Bjarmason]] !! input -PMID 1234 +{{SUBJECTPAGENAME}} !! result -User:Ævar Arnfjörð Bjarmason
!! end -### -### Templates -#### - !! test -Nonexistent template +Magic Word: {{SUBJECTPAGENAMEE}} +!! options +title=[[User talk:Ævar Arnfjörð Bjarmason]] !! input -{{thistemplatedoesnotexist}} +{{SUBJECTPAGENAMEE}} !! result -Template:Thistemplatedoesnotexist +
User:%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end !! test -Template with invalid target containing tags +Magic Word: {{NUMBEROFFILES}} !! input -{{ab|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}} +{{NUMBEROFFILES}} !! result -{{ab|foo|a=b|a = b}} +
4
!! end !! test -Template with invalid target containing unclosed tag +Magic Word: {{PAGENAME}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{a|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}} +{{PAGENAME}} !! result -{{a|foo|a=b|a = b}} +
Ævar Arnfjörð Bjarmason
!! end -!! article -Template:test -!! text -This is a test template -!! endarticle - !! test -Simple template +Magic Word: {{PAGENAME}} with metacharacters +!! options +title=[['foo & bar = baz']] !! input -{{test}} +''{{PAGENAME}}'' !! result -This is a test template +
'foo & bar = baz'
!! end !! test -Template with explicit namespace +Magic Word: {{PAGENAME}} with metacharacters (bug 26781) +!! options +title=[[*RFC 1234 http://example.com/]] !! input -{{Template:test}} +{{PAGENAME}} !! result -This is a test template +
*RFC 1234 http://example.com/
!! end - -!! article -Template:paramtest -!! text -This is a test template with parameter {{{param}}} -!! endarticle - !! test -Template parameter +Magic Word: {{PAGENAMEE}} +!! options +title=[[User:Ævar Arnfjörð Bjarmason]] !! input -{{paramtest|param=foo}} +{{PAGENAMEE}} !! result -This is a test template with parameter foo +
%C3%86var_Arnfj%C3%B6r%C3%B0_Bjarmason
!! end -!! article -Template:paramtestnum -!! text -[[{{{1}}}|{{{2}}}]] -!! endarticle - !! test -Template unnamed parameter +Magic Word: {{PAGENAMEE}} with metacharacters (bug 26781) +!! options +title=[[*RFC 1234 http://example.com/]] !! input -{{paramtestnum|Main Page|the main page}} +{{PAGENAMEE}} !! result -*RFC_1234_http://example.com/
!! end -!! article -Template:templatesimple -!! text -(test) -!! endarticle - -!! article -Template:templateredirect -!! text -#redirect [[Template:templatesimple]] -!! endarticle - -!! article -Template:templateasargtestnum -!! text -{{{{{1}}}}} -!! endarticle - -!! article -Template:templateasargtest -!! text -{{template{{{templ}}}}} -!! endarticle - -!! article -Template:templateasargtest2 -!! text -{{{{{templ}}}}} -!! endarticle - !! test -Template with template name as unnamed argument +Magic Word: {{REVISIONID}} !! input -{{templateasargtestnum|templatesimple}} +{{REVISIONID}} !! result -(test) +
1337
!! end !! test -Template with template name as argument +Magic Word: {{SCRIPTPATH}} !! input -{{templateasargtest|templ=simple}} +{{SCRIPTPATH}} !! result -(test) +
/
!! end !! test -Template with template name as argument (2) +Magic Word: {{STYLEPATH}} !! input -{{templateasargtest2|templ=templatesimple}} +{{STYLEPATH}} !! result -(test) +
/skins
!! end -!! article -Template:templateasargtestdefault -!! text -{{{{{templ|templatesimple}}}}} -!! endarticle - -!! article -Template:templa -!! text -'''templ''' -!! endarticle - !! test -Template with default value +Magic Word: {{SERVER}} !! input -{{templateasargtestdefault}} +{{SERVER}} !! result -(test) +
!! end !! test -Template with default value (value set) +Magic Word: {{SERVERNAME}} !! input -{{templateasargtestdefault|templ=templa}} +{{SERVERNAME}} !! result -templ +
example.org
!! end !! test -Template redirect +Magic Word: {{SITENAME}} !! input -{{templateredirect}} +{{SITENAME}} !! result -(test) +
MediaWiki
!! end !! test -Template with argument in separate line +Case-sensitive magic words, when cased differently, should just be template transclusions !! input -{{ templateasargtest | - templ = simple }} +{{CurrentMonth}} +{{currentday}} +{{cURreNTweEK}} +{{currentHour}} !! result -(test) +
Template:CurrentMonth +Template:Currentday +Template:CURreNTweEK +Template:CurrentHour
!! end !! test -Template with complex template as argument +Case-insensitive magic words should still work with weird casing. !! input -{{paramtest| - param ={{ templateasargtest | - templ = simple }}}} +{{sErVeRNaMe}} +{{LCFirst:AOEU}} +{{ucFIRST:aoeu}} +{{SERver}} !! result -This is a test template with parameter (test) +
example.org +aOEU +Aoeu +http://example.org
!! end !! test -Template with thumb image (with link in description) +Namespace 1 {{ns:1}} !! input -{{paramtest| - param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}} +{{ns:1}} !! result -This is a test template with parameter - +Talk +
!! end -!! article -Template:complextemplate -!! text -{{{1}}} {{paramtest| - param ={{{param}}}}} -!! endarticle - !! test -Template with complex arguments +Namespace 1 {{ns:01}} !! input -{{complextemplate| - param ={{ templateasargtest | - templ = simple }}|[[Template:complextemplate|link]]}} +{{ns:01}} !! result -link This is a test template with parameter (test) +
Talk
!! end !! test -BUG 553: link with two variables in a piped link +Namespace 0 {{ns:0}} (bug 4783) !! input -{| -|[[{{{1}}}|{{{2}}}]] -|} +{{ns:0}} !! result --
!! end !! test -Magic variable as template parameter +Namespace 0 {{ns:00}} (bug 4783) !! input -{{paramtest|param={{SITENAME}}}} +{{ns:00}} !! result -- [[{{{1}}}|{{{2}}}]] - This is a test template with parameter MediaWiki -
-!! end -!! article -Template:linktest -!! text -[[{{{param}}}|link]] -!! endarticle +!! end !! test -Template parameter as link source +Namespace -1 {{ns:-1}} !! input -{{linktest|param=Main Page}} +{{ns:-1}} !! result -link +
Special
!! end -!!test -Template-generated attribute string (k='v') -!!input -bar -!!result -bar +!! test +Namespace User {{ns:User}} +!! input +{{ns:User}} +!! result +
User
-!!end - -!!article -Template:paramtest2 -!! text -including another template, {{paramtest|param={{{arg}}}}} -!! endarticle +!! end !! test -Template passing argument to another template +Namespace User talk {{ns:User_talk}} !! input -{{paramtest2|arg='hmm'}} +{{ns:User_talk}} !! result -including another template, This is a test template with parameter 'hmm' +
User talk
!! end -!! article -Template:Linktest2 -!! text -Main Page -!! endarticle - !! test -Template as link source +Namespace User talk {{ns:uSeR tAlK}} !! input -[[{{linktest2}}]] - -[[{{linktest2}}|Main Page]] - -[[{{linktest2}}]]Page +{{ns:uSeR tAlK}} !! result -Main PagePage +
User talk
!! end +!! test +Namespace File {{ns:File}} +!! input +{{ns:File}} +!! result +File +
+!! end -!! article -Template:loop1 -!! text -{{loop2}} -!! endarticle - -!! article -Template:loop2 -!! text -{{loop1}} -!! endarticle +!! test +Namespace File {{ns:Image}} +!! input +{{ns:Image}} +!! result +File +
+!! end !! test -Template infinite loop +Namespace (lang=de) Benutzer {{ns:User}} +!! options +language=de !! input -{{loop1}} +{{ns:User}} !! result -Template loop detected: Template:Loop1 +
Benutzer
!! end !! test -Template from main namespace +Namespace (lang=de) Benutzer Diskussion {{ns:3}} +!! options +language=de !! input -{{:Main Page}} +{{ns:3}} !! result -blah blah +
Benutzer Diskussion
!! end -!! article -Template:table -!! text -{| -| 1 || 2 -|- -| 3 || 4 -|} -!! endarticle !! test -BUG 529: Template with table, not included at beginning of line +Urlencode !! input -foo {{table}} +{{urlencode:hi world?!}} +{{urlencode:hi world?!|WIKI}} +{{urlencode:hi world?!|PATH}} +{{urlencode:hi world?!|QUERY}} !! result -foo +
hi+world%3F%21 +hi_world%3F! +hi%20world%3F%21 +hi+world%3F%21
--
+!! end +### +### Magic links +### +!! test +Magic links: internal link to RFC (bug 479) +!! input +[[RFC 123]] +!! result +- -1 -2 - - 3 -4 - RFC 123 +
!! end !! test -BUG 523: Template shouldn't eat newline (or add an extra one before table) +Magic links: RFC (bug 479) !! input -foo -{{table}} +RFC 822 !! result -foo +
--
+!! end +!! test +Magic links: ISBN (bug 1937) +!! input +ISBN 0-306-40615-2 +!! result + !! end !! test -BUG 41: Template parameters shown as broken links +Magic links: PMID incorrectly converts space to underscore !! input -{{{parameter}}} +PMID 1234 !! result -- -1 -2 - - 3 -4 - {{{parameter}}} +
!! end +### +### Templates +#### + !! test -Template with targets containing wikilinks +Nonexistent template !! input -{{[[foo]]}} +{{thistemplatedoesnotexist}} +!! result +Template:Thistemplatedoesnotexist +
+!! end -{{[[{{echo|foo}}]]}} +!! test +Template with invalid target containing tags +!! input +{{ab|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}} +!! result +{{ab|foo|a=b|a = b}} +
+!! end -{{{{echo|[[foo}}]]}} +!! test +Template with invalid target containing unclosed tag +!! input +{{a|{{echo|foo}}|{{echo|a}}={{echo|b}}|a = b}} !! result -{{foo}} -
{{foo}} -
{{[[foo}}]] +
{{a|foo|a=b|a = b}}
!! end !! article -Template:MSGNW test +Template:test !! text -''None'' of '''this''' should be -* interpreted - but rather passed unmodified -{{test}} +This is a test template !! endarticle -# hmm, fix this or just deprecate msgnw and document its behavior? !! test -msgnw keyword -!! options -disabled +Simple template !! input -{{msgnw:MSGNW test}} -!! result -''None'' of '''this''' should be -* interpreted - but rather passed unmodified {{test}} +!! result +
This is a test template
!! end !! test -int keyword +Template with explicit namespace !! input -{{int:youhavenewmessages|lots of money|not!}} +{{Template:test}} !! result -You have lots of money (not!). +
This is a test template
!! end + !! article -Template:Includes +Template:paramtest !! text -Foozar bar +This is a test template with parameter {{{param}}} !! endarticle !! test -and -|d -|} -!!result -being included +Template parameter !! input -{{Includes}} +{{paramtest|param=foo}} !! result - Foobar +
This is a test template with parameter foo
!! end !! article -Template:Includes2 +Template:paramtestnum !! text -Foo bar +[[{{{1}}}|{{{2}}}]] !! endarticle !! test -being included +Template unnamed parameter !! input -{{Includes2}} +{{paramtestnum|Main Page|the main page}} !! result - Foo +
!! end +!! article +Template:templatesimple +!! text +(test) +!! endarticle + +!! article +Template:templateredirect +!! text +#redirect [[Template:templatesimple]] +!! endarticle !! article -Template:Includes3 +Template:templateasargtestnum !! text -Foo barzar +{{{{{1}}}}} +!! endarticle + +!! article +Template:templateasargtest +!! text +{{template{{{templ}}}}} +!! endarticle + +!! article +Template:templateasargtest2 +!! text +{{{{{templ}}}}} !! endarticle !! test -and being included +Template with template name as unnamed argument !! input -{{Includes3}} +{{templateasargtestnum|templatesimple}} !! result - Foo +
(test)
!! end !! test -and on a page +Template with template name as argument !! input -Foo -|czar bar +{{templateasargtest|templ=simple}} !! result -Foozar +
(test)
!! end !! test -Un-closed+Template with template name as argument (2) !! input - +{{templateasargtest2|templ=templatesimple}} !! result + -|b(test) +
!! end +!! article +Template:templateasargtestdefault +!! text +{{{{{templ|templatesimple}}}}} +!! endarticle + +!! article +Template:templa +!! text +'''templ''' +!! endarticle + !! test -on a page +Template with default value !! input - Foo bar +{{templateasargtestdefault}} !! result -Foobar +
(test)
!! end !! test -Un-closed+Template with default value (value set) !! input - +{{templateasargtestdefault|templ=templa}} !! result + templ +
!! end -!!test -Self-closed noinclude, includeonly, onlyinclude tags -!!input -- - -!!result -
+!! test +Template redirect +!! input +{{templateredirect}} +!! result +(test)
-!!end - -!!test -Unbalanced includeonly and noinclude tags -!!input -{| -|a-
- -!!end - -!! article -Template:Includeonly section -!! text -- a - -b - -c</includeonly> - -d</includeonly></includeonly> - -==Includeonly section== - -==Section T-1== -!!endarticle +!! end !! test -Bug 6563: Edit link generation for section shown by+Template with argument in separate line !! input -{{includeonly section}} +{{ templateasargtest | + templ = simple }} !! result - [edit] Includeonly section
-[edit] Section T-1
- +(test) +
!! end -# Uses same input as the contents of [[Template:Includeonly section]] !! test -Bug 6563: Section extraction for section shown by-!! options -section=T-2 +Template with complex template as argument !! input - -==Includeonly section== - -==Section T-2== +{{paramtest| + param ={{ templateasargtest | + templ = simple }}}} !! result -==Section T-2== +This is a test template with parameter (test) +
!! end !! test -Bug 6563: Edit link generation for section suppressed by+Template with thumb image (with link in description) !! input - -==Includeonly section== - -==Section 1== +{{paramtest| + param =[[Image:noimage.png|thumb|[[no link|link]] [[no link|caption]]]]}} !! result -[edit] Section 1
+This is a test template with parameter !! end +!! article +Template:complextemplate +!! text +{{{1}}} {{paramtest| + param ={{{param}}}}} +!! endarticle + !! test -Bug 6563: Section extraction for section suppressed by-!! options -section=1 +Template with complex arguments !! input - -==Includeonly section== - -==Section 1== +{{complextemplate| + param ={{ templateasargtest | + templ = simple }}|[[Template:complextemplate|link]]}} !! result -==Section 1== +link This is a test template with parameter (test) +
!! end !! test -Un-closed+BUG 553: link with two variables in a piped link !! input - +|} !!result -+{| +|[[{{{1}}}|{{{2}}}]] +|} !! result + +
+ !! end -### -###+ [[{{{1}}}|{{{2}}}]] + and in attributes -### -!!test -0. includeonly around the entire attribute -!!input -id="v1" id="v2" >bar -!!result -bar +!! test +Magic variable as template parameter +!! input +{{paramtest|param={{SITENAME}}}} +!! result +
This is a test template with parameter MediaWiki
-!!end +!! end -!!test -1. includeonly in html attr key -!!input -idabout ="foo">bar -!!result -bar +!! article +Template:linktest +!! text +[[{{{param}}}|link]] +!! endarticle + +!! test +Template parameter as link source +!! input +{{linktest|param=Main Page}} +!! result +
-!!end +!! end !!test -2. includeonly in html attr value +Template-generated attribute string (k='v') !!input -bar -"v1""v2" >bar +bar !!resultbar -bar
!!end -!!test -3. includeonly in part of an attr value -!!input -bar -!!result -bar -
-!!end +!!article +Template:paramtest2 +!! text +including another template, {{paramtest|param={{{arg}}}}} +!! endarticle -### -### Testing parsing of templates where a template arg -### has the same name as the template itself. -### +!! test +Template passing argument to another template +!! input +{{paramtest2|arg='hmm'}} +!! result +including another template, This is a test template with parameter 'hmm' +
+!! end !! article -Template:quote +Template:Linktest2 !! text -{{{quote|{{{1}}}}}} +Main Page !! endarticle -!!test -Templates: Template Name/Arg clash: 1. Use of positional param -!!input -{{quote|foo}} -!!result -foo -
-!!end +!! test +Template as link source +!! input +[[{{linktest2}}]] -!!test -Templates: Template Name/Arg clash: 2. Use of named param -!!input -{{quote|quote=foo}} -!!result -foo -
-!!end +[[{{linktest2}}|Main Page]] -!!test -Templates: Template Name/Arg clash: 3. Use of named param with empty input -!!input -{{quote|quote}} -!!result -quote +[[{{linktest2}}]]Page +!! result +
Main PagePage
-!!end +!! end -### -### Parsoid-centric tests to stress Parsoid's ability to RT them unchanged -### -!!test -Templates: 1. Simple use -!!input -{{echo|Foo}} -!!result -Foo -
-!!end - -!!test -Templates: 2. Inside a block tag -!!input -{{echo|Foo}}-!!result -Foo+!! article +Template:loop1 +!! text +{{loop2}} +!! endarticle -!!end +!! article +Template:loop2 +!! text +{{loop1}} +!! endarticle -!!test -Templates: P-wrapping: 1a. Templates on consecutive lines -!!input -{{echo|Foo}} -{{echo|bar}} -!!result -Foo -bar +!! test +Template infinite loop +!! input +{{loop1}} +!! result +
Template loop detected: Template:Loop1
-!!end - -!!test -Templates: P-wrapping: 1b. Templates on consecutive lines -!!input -Foo +!! end -{{echo|bar}} -{{echo|baz}} -!!result -Foo -
bar -baz +!! test +Template from main namespace +!! input +{{:Main Page}} +!! result +
blah blah
-!!end +!! end -!!test -Templates: P-wrapping: 1c. Templates on consecutive lines -!!input -{{echo|Foo}} -{{echo|bar}}baz-!!result -Foo +!! article +Template:table +!! text +{| +| 1 || 2 +|- +| 3 || 4 +|} +!! endarticle + +!! test +BUG 529: Template with table, not included at beginning of line +!! input +foo {{table}} +!! result +
foo
-barbaz++
-!!end +!! end -!!test -Templates: Inline Text: 1. Multiple tmeplate uses -!!input -{{echo|Foo}}bar{{echo|baz}} -!!result -+ +1 +2 + + 3 +4 + Foobarbaz +!! test +BUG 523: Template shouldn't eat newline (or add an extra one before table) +!! input +foo +{{table}} +!! result +
foo
-!!end ++
-!!test -Templates: Inline Text: 2. Back-to-back template uses -!!input -{{echo|Foo}}{{echo|bar}} -!!result -+ +1 +2 + + 3 +4 + Foobar +!! end + +!! test +BUG 41: Template parameters shown as broken links +!! input +{{{parameter}}} +!! result +
{{{parameter}}}
-!!end +!! end -!!test -Templates: Block Tags: 1. Multiple template uses -!!input -{{echo|Foo}}bar{{echo|baz}} -!!result -Foobarbaz+!! test +Template with targets containing wikilinks +!! input +{{[[foo]]}} -!!end +{{[[{{echo|foo}}]]}} -!!test -Templates: Block Tags: 2. Back-to-back template uses -!!input -{{echo|Foo}}{{echo|bar}} -!!result -Foobar+{{{{echo|[[foo}}]]}} +!! result +{{foo}} +
{{foo}} +
{{[[foo}}]] +
+!! end -!!end +!! article +Template:MSGNW test +!! text +''None'' of '''this''' should be +* interpreted + but rather passed unmodified +{{test}} +!! endarticle -!!test -Templates: Links: 1. Simple example -!!input -{{echo|[[Foo|bar]]}} -!!result -bar +# hmm, fix this or just deprecate msgnw and document its behavior? +!! test +msgnw keyword +!! options +disabled +!! input +{{msgnw:MSGNW test}} +!! result +
''None'' of '''this''' should be +* interpreted + but rather passed unmodified +{{test}}
-!!end +!! end -!!test -Templates: Links: 2. Generation of link href -!!input -[[{{echo|Foo}}|bar]] -!!result -bar +!! test +int keyword +!! input +{{int:youhavenewmessages|lots of money|not!}} +!! result +
You have lots of money (not!).
-!!end - -!!test -Templates: Links: 3. Generation of part of a link href -!!input -[[Fo{{echo|o}}|bar]] - -[[Foo{{echo|bar}}]] +!! end -[[Foo{{echo|bar}}baz]] +!! article +Template:Includes +!! text +Foozar bar +!! endarticle -[[Foo{{echo|bar}}|bar]] +!! test +and +|dbeing included +!! input +{{Includes}} +!! result + Foobar +
+!! end -[[:Foo{{echo|bar}}]] +!! article +Template:Includes2 +!! text +Foo bar +!! endarticle -[[:Foo{{echo|bar}}|bar]] -!!result -bar -
Foobar -
bar -
Foobar -
bar +!! test +
being included +!! input +{{Includes2}} +!! result + Foo
-!!end +!! end -!!test -Templates: Links: 4. Multiple templates generating link href -!!input -[[{{echo|F}}{{echo|o}}ob{{echo|ar}}]] -!!result -Foobar -
-!!end -!!test -Templates: Links: 5. Generation of link text -!!input -[[Foo|{{echo|bar}}]] -!!result -bar +!! article +Template:Includes3 +!! text +
Foo barzar +!! endarticle + +!! test +and being included +!! input +{{Includes3}} +!! result + Foo
-!!end +!! end + +!! test +and on a page +!! input +Foo +|czar bar +!! result +Foozar +
+!! end + +!! test +Un-closed+!! input + +!! result +!! end + +!! test + +|bon a page +!! input + Foo bar +!! result +Foobar +
+!! end + +!! test +Un-closed+!! input + +!! result +!! end !!test -Templates: Links: 5. Nested templates (only outermost template should be marked) +Self-closed noinclude, includeonly, onlyinclude tags !!input -{{echo|[[{{echo|Foo}}|bar]]}} + + + !!result - bar +
!!end !!test -Templates: HTML Tag: 1. Generation of HTML attr. key +Unbalanced includeonly and noinclude tags !!input -
foo+{| +|afoo++
!!end -!!test -Templates: HTML Tag: 2. Generation of HTML attr. value -!!input -+ a + +b + +c</includeonly> + +d</includeonly></includeonly> + foo-!!result -foo+!! article +Template:Includeonly section +!! text ++==Includeonly section== + +==Section T-1== +!!endarticle + +!! test +Bug 6563: Edit link generation for section shown by+!! input +{{includeonly section}} +!! result + Includeonly section[edit]
+Section T-1[edit]
+ +!! end + +# Uses same input as the contents of [[Template:Includeonly section]] +!! test +Bug 6563: Section extraction for section shown by+!! options +section=T-2 +!! input + +==Includeonly section== + +==Section T-2== +!! result +==Section T-2== +!! end + +!! test +Bug 6563: Edit link generation for section suppressed by+!! input + +==Includeonly section== + +==Section 1== +!! result +Section 1[edit]
+ +!! end + +!! test +Bug 6563: Section extraction for section suppressed by+!! options +section=1 +!! input + +==Includeonly section== + +==Section 1== +!! result +==Section 1== +!! end + +!! test +Un-closed+!! input + +!! result +!! end + +# TODO: test with DOM fragment reuse! +!! test +Parsoid: DOM fragment reuse +!! options +parsoid=wt2wt,wt2html +!! input +a{{echo|b c}}d + +a{{echo|b +
+c}}d + +{{echo|a + +
+ +b}} +!! result +ab +
cd + + +
ab
+ ++ +
cd
-!!end +a
+ + ++ + +
b
+!! end + +!! test +Parsoid: Merge double tds (bug 50603) +!! options +parsoid +!! input +{| +|{{echo|{{!}} foo}} +|} +!! result ++
+!! end + +!! test +Parsoid: Merge double tds in nested transclusion content (bug 50603) +!! options +parsoid +!! input +{{echo|+ foo }} +{| +|{{echo|{{!}} foo}} +|} +{{echo|}} +!! result +++!! end + +### +###+
++ foo and in attributes +### !!test -Templates: HTML Tag: 3. Generation of HTML attr key and value +0. includeonly around the entire attribute !!input - foo+id="v1"id="v2" >bar !!result -foo- +bar +
!!end !!test -Templates: HTML Tag: 4. Generation of starting piece of HTML attr value +1. includeonly in html attr key !!input -foo+idabout ="foo">bar !!result -foo- +bar +
!!end !!test -Templates: HTML Tag: 5. Generation of middle piece of HTML attr value +2. includeonly in html attr value !!input -foo+bar +"v1""v2" >bar !!result -foo- +bar +bar +
!!end !!test -Templates: HTML Tag: 6. Generation of end piece of HTML attr value +3. includeonly in part of an attr value !!input -foo+bar !!result -foo- +bar +
!!end +### +### Testing parsing of templates where a template arg +### has the same name as the template itself. +### + +!! article +Template:quote +!! text +{{{quote|{{{1}}}}}} +!! endarticle + !!test -Templates: HTML Tables: 1. Generating start of a HTML table +Templates: Template Name/Arg clash: 1. Use of positional param !!input -{{echo|+{{quote|foo}} !!result -
foo }}- +
foo foo +
!!end !!test -Templates: HTML Tables: 2a. Generating middle of a HTML table +Templates: Template Name/Arg clash: 2. Use of named param !!input -+{{quote|quote=foo}} !!result -
{{echo| foo }}- +
foo foo +
!!end !!test -Templates: HTML Tables: 2b. Generating middle of a HTML table +Templates: Template Name/Arg clash: 3. Use of named param with empty input !!input -{{echo|
+{{quote|quote}} !!result -}} foo - +
foo quote +
!!end +### +### Parsoid-centric tests to stress Parsoid's ability to RT them unchanged +### + !!test -Templates: HTML Tables: 3. Generating end of a HTML table +Templates: 1. Simple use !!input -}} +{{echo|Foo}} !!result -
{{echo| foo - +
foo Foo +
!!end !!test -Templates: HTML Tables: 4a. Generating a single tag of a HTML table +Templates: 2. Inside a block tag !!input -{{echo|}}
+foo {{echo|Foo}}+{{echo|Foo}}!!result -+
foo Foo+Foo!!end !!test -Templates: HTML Tables: 4b. Generating a single tag of a HTML table +Templates: P-wrapping: 1a. Templates on consecutive lines !!input -{{echo|
+{{echo|Foo}} +{{echo|bar}} !!result -}} foo +
foo Foo +bar +
+!!end + +!!test +Templates: P-wrapping: 1b. Templates on consecutive lines +!!input +Foo +{{echo|bar}} +{{echo|baz}} +!!result +Foo +
bar +baz +
!!end !!test -Templates: HTML Tables: 4c. Generating a single tag of a HTML table +Templates: P-wrapping: 1c. Templates on consecutive lines !!input -+{{echo|Foo}} +{{echo|bar}}
{{echo| }}foo baz!!result -+
foo Foo +
+barbaz!!end !!test -Templates: HTML Tables: 4d. Generating a single tag of a HTML table +Templates: P-wrapping: 1d. Template preceded by comment-only line +!!options +parsoid !!input -+ +{{echo|Bar}} !!result -
foo{{echo| }}+ +
foo Bar
!!end !!test -Templates: HTML Tables: 4e. Generating a single tag of a HTML table +Templates: Inline Text: 1. Multiple tmeplate uses !!input -+{{echo|Foo}}bar{{echo|baz}} !!result -
}} foo {{echo|+
foo Foobarbaz +
+!!end +!!test +Templates: Inline Text: 2. Back-to-back template uses +!!input +{{echo|Foo}}{{echo|bar}} +!!result +Foobar +
!!end !!test -Templates: HTML Tables: 4f. Generating a single tag of a HTML table +Templates: Block Tags: 1. Multiple template uses !!input -}} +{{echo|
{{echo| foo Foo}}bar{{echo|baz}} !!result -+
foo Foobarbaz!!end !!test -Templates: Wiki Tables: 1a. Fostering of entire template content +Templates: Block Tags: 2. Back-to-back template uses !!input -{| -{{echo|a}} -|} +{{echo|Foo}}{{echo|bar}} !!result --a -
+ Foobar!!end !!test -Templates: Wiki Tables: 1b. Fostering of entire template content +Templates: Links: 1. Simple example !!input -{| -{{echo|}} -foo -{{echo|}} -|} +{{echo|[[Foo|bar]]}} !!result --
+!!end +!!test +Templates: Links: 2. Generation of link href +!!input +[[{{echo|Foo}}|bar]] +!!result +--foo +
-bar +
!!end !!test -Templates: Wiki Tables: 2. Fostering of partial template content +Templates: Links: 3. Generation of part of a link href !!input -{| -{{echo|a -b}} -|} +[[Fo{{echo|o}}|bar]] + +[[Foo{{echo|bar}}]] + +[[Foo{{echo|bar}}baz]] + +[[Foo{{echo|bar}}|bar]] + +[[:Foo{{echo|bar}}]] + +[[:Foo{{echo|bar}}|bar]] !!result --a -
+b-bar +
Foobar +
bar +
Foobar +
bar +
+!!end +!!test +Templates: Links: 4. Multiple templates generating link href +!!input +[[{{echo|F}}{{echo|o}}ob{{echo|ar}}]] +!!result +Foobar +
!!end !!test -Templates: Wiki Tables: 3. td-content via multiple templates +Templates: Links: 5. Generation of link text !!input -{| -{{echo|{{pipe}}a}}{{echo|b}} -|} +[[Foo|{{echo|bar}}]] !!result --
+- ab - bar +
+!!end +!!test +Templates: Links: 5. Nested templates (only outermost template should be marked) +!!input +{{echo|[[{{echo|Foo}}|bar]]}} +!!result +bar +
!!end !!test -Templates: Wiki Tables: 4. Templated tags, no content +Templates: HTML Tag: 1. Generation of HTML attr. key !!input -{{tbl-start}} -{{tbl-end}} +foo!!result --
+ foo!!end !!test -Templates: Wiki Tables: 5. Templated tags, regular td-tags +Templates: HTML Tag: 2. Generation of HTML attr. value !!input -{{tbl-start}} -|foo -{{tbl-end}} +foo!!result --
+- foo - foo!!end !!test -Templates: Wiki Tables: 6. Templated tags, templated td-tags +Templates: HTML Tag: 3. Generation of HTML attr key and value !!input -{{tbl-start}} -{{!}}foo -{{tbl-end}} +foo!!result --
+- foo - foo!!end !!test -Templates: Lists: Multi-line list-items via templates +Templates: HTML Tag: 4. Generation of starting piece of HTML attr value !!input -*{{echo|a {{nonexistent| -unused}}}} -*{{echo|b {{nonexistent| -unused}}}} +foo!!result - +foo!!end !!test -Templates: Ugly nesting: 1. Quotes opened/closed across templates (echo) +Templates: HTML Tag: 5. Generation of middle piece of HTML attr value !!input -{{echo|''a}}{{echo|b''c''d}}{{echo|''e}} +foo!!result -abcde -
+foo+ !!end !!test -Templates: Ugly nesting: 2. Quotes opened/closed across templates (echo_with_span) -(PHP parser generates misnested html) -!! options -disabled +Templates: HTML Tag: 6. Generation of end piece of HTML attr value !!input -{{echo_with_span|''a}}{{echo_with_span|b''c''d}}{{echo_with_span|''e}} +foo!!result -abcde
+foo+ !!end !!test -Templates: Ugly nesting: 3. Quotes opened/closed across templates (echo_with_div) -(PHP parser generates misnested html) -!! options -disabled +Templates: HTML Tag: 7. Generation of partial attribute key string !!input -{{echo_with_div|''a}}{{echo_with_div|b''c''d}}{{echo_with_div|''e}} +foo!!result -a-bcd-e+foo+ !!end !!test -Templates: Ugly nesting: 4. Divs opened/closed across templates +Templates: HTML Tables: 1. Generating start of a HTML table !!input -ab{{echo|cd}}e +{{echo|!!result -a
foo }}bcde +!!end !!test -Templates: Ugly templates: 1. Navbox template parses badly leading to table misnesting -(Parsoid-centric) -!! options -parsoid +Templates: HTML Tables: 2a. Generating middle of a HTML table !!input -{| -|{{echo|foo}} -|bar -|} +
foo !!result -
{{echo| foo }}-
-bar - +foo + !!end !!test -Templates: Ugly templates: 2. Navbox template parses badly leading to table misnesting -(Parsoid-centric) -!! options +Templates: HTML Tables: 2b. Generating middle of a HTML table +!!input +
foo {{echo|
+!!result +}} foo + +!!end + +!!test +Templates: HTML Tables: 3. Generating end of a HTML table +!!input +
foo }} +!!result +
{{echo| foo + +!!end + +!!test +Templates: HTML Tables: 4a. Generating a single tag of a HTML table +!!input +{{echo|
foo }}
+!!result +foo + +!!end + +!!test +Templates: HTML Tables: 4b. Generating a single tag of a HTML table +!!input +
foo {{echo|
+!!result +}} foo + +!!end + +!!test +Templates: HTML Tables: 4c. Generating a single tag of a HTML table +!!input +
foo +!!result +
{{echo| }}foo + +!!end + +!!test +Templates: HTML Tables: 4d. Generating a single tag of a HTML table +!!input +
foo +!!result +
foo{{echo| }}+ +!!end + +!!test +Templates: HTML Tables: 4e. Generating a single tag of a HTML table +!!input +
foo +!!result +
}} foo {{echo|+ +!!end + +!!test +Templates: HTML Tables: 4f. Generating a single tag of a HTML table +!!input +
foo }} +!!result +
{{echo| foo + +!!end + +!!test +Templates: HTML Tables: 5. Proper fostering of categories from inside +!!options +parsoid=wt2html,wt2wt +!!input +
foo [[Category:foo1]]
+ +foo [[Category:bar1]][[Category:bar2]]
+!!result +foo + +
foo +!!end + +!!test +Templates: Wiki Tables: 1a. Fostering of entire template content +!!input +{| +{{echo|a}} +|} +!!result +
foo +a +
+ +!!end + +!!test +Templates: Wiki Tables: 1b. Fostering of entire template content +!!input +{| +{{echo| }} +foo +{{echo|}} +|} +!!result ++
+ +!!end + +!!test +Templates: Wiki Tables: 2. Fostering of partial template content +!!input +{| +{{echo|a +++foo +
+ b}} +|} +!!result ++a +
+ +!!end + +!!test +Templates: Wiki Tables: 3. td-content via multiple templates +!!input +{| +{{echo|{{pipe}}a}}{{echo|b}} +|} +!!result +b++
+ +!!end + +!!test +Templates: Wiki Tables: 4. Templated tags, no content +!!input +{{tbl-start}} +{{tbl-end}} +!!result ++ ab + +
+ +!!end + +!!test +Templates: Wiki Tables: 5. Templated tags, regular td-tags +!!input +{{tbl-start}} +|foo +{{tbl-end}} +!!result ++
+ +!!end + +!!test +Templates: Wiki Tables: 6. Templated tags, templated td-tags +!!input +{{tbl-start}} +{{!}}foo +{{tbl-end}} +!!result ++ foo + +
+ +!!end + +!!test +Templates: Lists: Multi-line list-items via templates +!!input +*{{echo|a {{nonexistent| +unused}}}} +*{{echo|b {{nonexistent| +unused}}}} +!!result ++ foo + +
+ +!!end + +!!test +Templates: Ugly nesting: 1. Quotes opened/closed across templates (echo) +!!input +{{echo|''a}}{{echo|b''c''d}}{{echo|''e}} +!!result +- a Template:Nonexistent +
+- b Template:Nonexistent +
+abcde +
+!!end + +!!test +Templates: Ugly nesting: 2. Quotes opened/closed across templates (echo_with_span) +(PHP parser generates misnested html) +!! options +parsoid +!!input +{{echo_with_span|''a}}{{echo_with_span|b''c''d}}{{echo_with_span|''e}} +!!result +abcde
+!!end + +!!test +Templates: Ugly nesting: 3. Quotes opened/closed across templates (echo_with_div) +(PHP parser generates misnested html; Parsoid html2wt mode adds newlines between {{echo}}s) +!! options +parsoid=wt2html,wt2wt +!!input +{{echo_with_div|''a}}{{echo_with_div|b''c''d}}{{echo_with_div|''e}} +!!result +a+bcd+e+!!end + +!!test +Templates: Ugly nesting: 4. Divs opened/closed across templates +!!input +ab{{echo|cd}}e +!!result +abcde + +!!end + +!!test +Templates: Ugly templates: 1. Navbox template parses badly leading to table misnesting +(Parsoid-centric) +!! options +parsoid +!!input +{| +|{{echo|foo}} +|bar +|} +!!result ++ + +
+bar + +!!end + +!!test +Templates: Ugly templates: 2. Navbox template parses badly leading to table misnesting +(Parsoid-centric) +!! options parsoid !!input+ foo @@ -6058,24 +8487,24 @@ parsoid
!!result --
- - - abc - - - - - - xyz - +- - --
- 1. foo bar -2. baz +
+ + + abc + + + + + + xyz + !!end @@ -6237,10 +8666,13 @@ wiki+ + ++
+ 1. foo bar +2. baz nowiki But just in case it doesn't... !! result - [edit] =
+=[edit]
The line above must have a trailing space!
-[edit] =
+=[edit]
But just in case it doesn't...
!! end @@ -7811,7 +10836,7 @@ section 5 !! resultThe tooltips shall not show entities to the user (ie. be double escaped)
--
+Contents
Contents
-
- 1 text > text
- 2 text < text
@@ -7819,20 +10844,21 @@ section 5- 4 text ' text
- 5 text " text
[edit] text > text
+ + +text > text[edit]
section 1
-[edit] text < text
+text < text[edit]
section 2
-[edit] text & text
+text & text[edit]
section 3
-[edit] text ' text
+text ' text[edit]
section 4
-[edit] text " text
+text " text[edit]
section 5
!! end @@ -7846,18 +10872,59 @@ Headers with excess '=' characters =''italic'' heading== ==''italic'' heading= !! result --
+Contents
-Contents
[edit] foo=
-[edit] =foo
-[edit] italic heading=
-[edit] =italic heading
+ + +foo=[edit]
+=foo[edit]
+italic heading=[edit]
+=italic heading[edit]
+ +!! end + +!! test +HTML headers vs TOC (bug 23393) +(__NOEDITSECTION__ for clearer output, doesn't matter here) +!! input +Header 1
+== Header 1.1 == +== Header 1.2 == + +Header 2 +
+== Header 2.1 == +== Header 2.2 == +__NOEDITSECTION__ +!! result ++ ++Contents
+
+- 1 Header 1 + +
+- 2 Header 2 + +
+Header 1
+Header 1.1
+Header 1.2
+Header 2
+Header 2.1
+Header 2.2
!! end @@ -7953,7 +11020,7 @@ div with illegal double attributes !! test div with empty attribute value, space before equals !! options -disabled +parsoid !! inputHTML rocks!! result @@ -7966,7 +11033,7 @@ disabled !! test div with braces in attribute value !! options -disabled +parsoid !! inputFoo!! result @@ -7983,7 +11050,7 @@ disabled !! test div with empty attribute value, no space before equals !! options -disabled +parsoid !! inputHTML rocks!! result @@ -8078,6 +11145,81 @@ I always thought &xacute; was a cute letter. !! end +### +### Nesting tests (see bug 41545, 50604, 51081) +### + +# This test case is fixed in Parsoid by domino 1.0.12. (bug 50604) +# Note that html2wt is considerably more difficult if we use in +# the test case, instead of +!! test +Ensure that HTML adoption agency algorithm is properly implemented. +!! input +XYZ +!! result +XYZ +
+!! end + +# This was bug 41545 in the PHP parser. +!! test +Nesting of +!! input +XYZ +!! result +XYZ +
+!! end + +# The following cases were bug 51081 in the PHP parser. +# Note that there are some other nestable tags (b, i, etc) which are +# not covered; see bug 51081 for discussion. +!! test +Nesting of +!! input +XYZ +!! result +XYZ +
+!! end + +!! test +Nesting of +!! input +XYZ +!! result +XYZ +
+!! end + +!! test +Nesting of+!! input +X+!! result +YZ+!! end + +!! test +Nesting of +!! input +XYZ +!! result +
X+YZXYZ +
+!! end + +!! test +Nesting of +!! input +XYZ +!! result +XYZ +
+!! end + + ### ### Media links ### @@ -8470,70 +11612,6 @@ MSIE CSS safety test: comment in expression !! end -!! test -CSS safety test: vertical tab -!! input -A
-!! result -A
- -!! end - -!! test -MSIE CSS safety test: Fullwidth -!! input -A
-B-!! result -A
-B- -!! end - -!! test -MSIE CSS safety test: IPA extensions -!! input -A-B
-!! result -A-B
- -!! end - -!! test -MSIE CSS safety test: sup/sub script -!! input -A-B-C
-!! result -A-B-C
- -!! end - -!! test -MSIE CSS safety test: Repetition markers -!! input -A
-B
-C
-D
-E
-F
-G
-!! result -A
-B
-C
-D
-E
-F
-G
- -!! end !! test Table attribute legitimate extension @@ -8617,7 +11695,7 @@ Expansion of multi-line templates in attribute values (bug 6255 sanity check 2) !! end ### -### Parser hooks (see maintenance/parserTestsParserHook.php for theextension) +### Parser hooks (see tests/parser/parserTestsParserHook.php for the extension) ### !! test Parser hook: empty input @@ -8782,7 +11860,7 @@ array ( !! end ### -### (see maintenance/parserTestsStaticParserHook.php for the extension) +### (see tests/parser/parserTestsParserHook.php for the extension) ### !! test @@ -9014,11 +12092,13 @@ disabled !! result - -!! end - + +
- One -
- Two -
Two + + + +!! end + !! test HTML ordered list, closed tags (bug 5497) !! input @@ -9046,8 +12126,10 @@ disabled !! result+ +
- One -
- Two -
Two + + !! end @@ -9092,12 +12174,16 @@ disabled !! result+ +
- One -
- Two: +
+- Two:
-
- Sub-one -
- Sub-two -
Sub-two + + + + !! end @@ -9142,21 +12228,27 @@ disabled !! result+ +
- One -
- Two: +
+- Two:
-
- Sub-one -
- Sub-two -
Sub-two + + + + !! end !! test HTML ordered list item with parameters oddity !! input -+
- One
!! result -
- One
++
- One
!! end @@ -9208,12 +12300,13 @@ Fuzz testing: Parser14 == onmouseover= == http://__TOC__ !! result -
- One
+[edit] onmouseover=
-http://+ + !! end @@ -9223,7 +12316,7 @@ Fuzz testing: Parser14-table ==a== {| STYLE=__TOC__ !! result -
+Contents
onmouseover=[edit]
+http://-Contents
[edit] a
+a[edit]
@@ -9369,7 +12462,7 @@ Fuzz testing: image with bogus manual thumbnail !!input [[Image:foobar.jpg|thumbnail= ]] !!result -
+Error creating thumbnail:!!end @@ -10380,17 +13473,33 @@ Handling of in URLs !! input **irc:// a !! result -Error creating thumbnail:+
- -
+
!!end !! test -5 quotes, code coverage +1 line +5 quotes, code coverage +1 line (php) +!! options +php +!! input +''''' +!! result +!! end +# The PHP parser strips the empty tags out for giggles; parsoid doesn't. +!! test +5 quotes, code coverage +1 line (parsoid) +!! options +parsoid !! input ''''' !! result +- +
+
+- irc://%0Aa +
+!! end !! test @@ -10404,43 +13513,78 @@ Special:Search page linking. !! test Say the magic word +!! options +title=[[Parser test]] !! input * {{PAGENAME}} +* {{PAGENAMEE}} +* {{FULLPAGENAME}} +* {{FULLPAGENAMEE}} * {{BASEPAGENAME}} +* {{BASEPAGENAMEE}} * {{SUBPAGENAME}} * {{SUBPAGENAMEE}} -* {{BASEPAGENAME}} -* {{BASEPAGENAMEE}} +* {{ROOTPAGENAME}} +* {{ROOTPAGENAMEE}} * {{TALKPAGENAME}} * {{TALKPAGENAMEE}} * {{SUBJECTPAGENAME}} * {{SUBJECTPAGENAMEE}} * {{NAMESPACEE}} * {{NAMESPACE}} +* {{NAMESPACENUMBER}} * {{TALKSPACE}} * {{TALKSPACEE}} * {{SUBJECTSPACE}} * {{SUBJECTSPACEE}} * {{Dynamic|{{NUMBEROFUSERS}}|{{NUMBEROFPAGES}}|{{CURRENTVERSION}}|{{CONTENTLANGUAGE}}|{{DIRECTIONMARK}}|{{CURRENTTIMESTAMP}}|{{NUMBEROFARTICLES}}}} !! result -
+
- Parser test -
- Parser test -
- Parser test -
- Parser_test -
- Parser test -
- Parser_test -
- Talk:Parser test -
- Talk:Parser_test -
- Parser test -
- Parser_test -
- -
- -
- Talk -
- Talk -
- -
- -
- Template:Dynamic -
+
!! end ### Note: Above tests excludes the "{{NUMBEROFADMINS}}" magic word because it generates a MySQL error when included. @@ -10459,40 +13603,40 @@ image4 |300px| centre * image6 !! result -- Parser test +
+- Parser_test +
+- Parser test +
+- Parser_test +
+- Parser test +
+- Parser_test +
+- Parser test +
+- Parser_test +
+- Parser test +
+- Parser_test +
+- Talk:Parser test +
+- Talk:Parser_test +
+- Parser test +
+- Parser_test +
+- +
+- +
+- 0 +
+- Talk +
+- Talk +
+- +
+- +
+- Template:Dynamic +
++
-Image1.png+Image1.png -Image2.gif+Image2.gif||||
-Image3+Image3 -Image4+Image4300px| centre
- @@ -10511,17 +13655,17 @@ image:foobar.jpg image:foobar.jpg|Blabla|alt=This is a foo-bar.|blabla. !! result -
-* image6+* image6+
-Nonexistant.jpg+Nonexistant.jpgcaption
- @@ -10556,7 +13700,7 @@ File:foobar.jpg|[[File:foobar.jpg|20px|desc|alt=inneralt]]|alt=galleryalt File:foobar.jpg|{{Test|unamedParam|alt=param}}|alt=galleryalt !! result -
-Nonexistant.jpg+Nonexistant.jpg+
+ +@@ -10585,9 +13729,9 @@ image:foobar.jpg|some '''caption''' [[Main Page]] File:Foobar.jpg !! result -+ ++
-+ +Nonexistant.jpg+Nonexistant.jpg@@ -10630,14 +13774,14 @@ image:foobar.jpg foobar.jpg !! result -+ ++
-Nonexistant.jpg+Nonexistant.jpg- @@ -10828,13 +13972,25 @@ disabled !! input :;;;:: !! result -
-Nonexistant.jpg+Nonexistant.jpg+
-
-
-
-
-
- -
+
!!end @@ -10861,7 +14017,7 @@ Images with the "|" character in the comment !! test HTML with raw HTML ($wgRawHtml==true) !! options -rawhtml +wgRawHtml=1 !! input !! result @@ -10930,6 +14086,45 @@ subpage title=[[Subpage test/L1/L2/L3]] !! end +!! article +Subpage test/L1/L2/L3Sibling +!! text +Sibling article +!! endarticle + +!! test +Transclusion of a sibling page (one level up) +!! options +subpage title=[[Subpage test/L1/L2/L3]] +!! input +{{../L3Sibling}} +!! result +- +
+
++
+ ++
+ ++
+ +- +
+
+- +
+Sibling article +
+!! end + +!! test +Transclusion of a child page +!! options +subpage title=[[Subpage test/L1/L2]] +!! input +{{/L3Sibling}} +!! result +Sibling article +
+!! end + +!! test +Non-transclusion because of too many up levels +!! options +subpage title=[[Subpage test/L1/L2/L3]] +!! input +{{../../../../More than parent}} +!! result +{{../../../../More than parent}} +
+!! end + !! test Definition list code coverage !! input @@ -10937,10 +14132,17 @@ Definition list code coverage ; title : def ;title: def !! result -+
- title
- def -
- title
- def -
- title
- def -
+
!! end @@ -11004,7 +14206,7 @@ Inclusion of !userCanEdit() content !! input {{MediaWiki:Fake}} !! result -- title
+- def +
+- title
+- def +
+- title
+- def +
+[edit] header
+header[edit]
!! end @@ -11019,7 +14221,7 @@ Out-of-order TOC heading levels =====5===== ==2== !! result --
+Contents
Contents
-
- 1 2
@@ -11034,13 +14236,14 @@ Out-of-order TOC heading levels
[edit] 2
-[edit] 6
-[edit] 3
-[edit] 1
-[edit] 5
-[edit] 2
+2[edit]
+6[edit]
+3[edit]
+1[edit]
+5[edit]
+2[edit]
!! end @@ -11147,14 +14350,11 @@ anchorencode encodes like the TOC generator: (bug 18431) {{anchorencode: _ +:.3A%3A&&]] }} __NOEDITSECTION__ !! result -_ +:.3A%3A&&]]
+_ +:.3A%3A&&]]
.2B:.3A.253A.26.26.5D.5D
!! end -# Expected output in the following test is not necessarily expected (there -# should probably betags inside the
in the output) -- it's -# only testing for well-formedness. !! test Bug 6200: blockquotes and paragraph formatting !! input @@ -11167,7 +14367,8 @@ bar baz !! result-foo +foo +
bar
@@ -11196,6 +14397,27 @@ bar !! end +!!test +Parsing of overlapping (improperly nested) inline html tags (PHP parser) +!!options +php +!!input +x+!!result ++!!end + +!!test +Parsing of overlapping (improperly nested) inline html tags (Parsoid) +!!options +parsoid +!!input +
x</span>+x+!!result ++!!end ### ### Language variants related tests @@ -11228,6 +14450,17 @@ title=[[Duna]] language=sr !! end +!! test +Link to a section of a variant of this title shouldn't be parsed as self-link +!! options +title=[[Duna]] language=sr +!! input +[[Dуна]] is a self-link while [[Dunа#Foo]] and [[Dуна#Foo]] are not self-links. +!! result +
x+Dуна is a self-link while Dunа#Foo and Dуна#Foo are not self-links. +
+!! end + !! test Link to pages in language variants !! options @@ -11377,7 +14610,7 @@ language=sr variant=sr-ec !! input == -{Naslov}- == !! result -[уреди] Naslov
+Naslov[уреди]
!! end @@ -11490,6 +14723,30 @@ This won't take interferes with the title rule. !! end +!! test +Partly disable title conversion if variant == main language code +!! options +language=zh variant=zh title=[[ZH]] showtitle +!! input +-{T|zh-cn:CN;zh-tw:TW}- +!! result +ZH ++
+!! end + +!! test +Partly disable title conversion if variant == main language code, more +!! options +language=zh variant=zh title=[[ZH]] showtitle +!! input +-{T|TW}- +!! result +ZH ++
+!! end + !! test Raw output of variant escape tags (R flag) !! options @@ -11568,20 +14825,17 @@ language=sr !!end -!!article -Template:Bullet -!!text -* Bar -!!endarticle - !! test Bug 529: Uncovered bullet !! input * Foo {{bullet}} !! result -+
- Foo -
- Bar -
+
!! end @@ -11596,15 +14850,30 @@ Bug 529: Uncovered bullet leaving empty list, normally removed by tidy !! input ******* Foo {{bullet}} !! result -- Foo +
+- Bar +
++
-
-
-
-
-
-
- Foo -
- Bar -
+
!! end @@ -11636,9 +14905,12 @@ Bug 529: Uncovered bullet in parser function result !! input * Foo {{lc:{{bullet}} }} !! result -- +
+
+- +
+
+- +
+
+- +
+
+- +
+
+- +
+
+- Foo +
+- Bar +
++
- Foo -
- bar -
+
!! end @@ -11694,7 +14966,7 @@ Morwen/13: Unclosed link followed by heading !! result- Foo +
+- bar +
+[[link
-[edit] heading
+heading[edit]
!! end @@ -11706,7 +14978,7 @@ HHP2.1: Heuristics for headings in preprocessor parenthetical structures !! result{{foo|
-heading
+heading
!! end @@ -11718,7 +14990,7 @@ HHP2.2: Heuristics for headings in preprocessor parenthetical structures !! result{{foo|
-[edit] heading
+heading[edit]
!! end @@ -11808,8 +15080,6 @@ B # Bug 6200:should behave likewith respect to line breaks !! test Bug 6200: paragraphs inside blockquotes (no extra line breaks) -!! options -disabled !! input+ +Line one @@ -11822,8 +15092,6 @@ Line two!! test Bug 6200: paragraphs inside blockquotes (extra line break on open) -!! options -disabled !! inputLine one @@ -11839,8 +15107,6 @@ Line two!! test Bug 6200: paragraphs inside blockquotes (extra line break on close) -!! options -disabled !! inputLine one @@ -11856,8 +15122,6 @@ Line two !! test Bug 6200: paragraphs inside blockquotes (extra line break on open and close) -!! options -disabled !! inputLine one @@ -12078,7 +15342,7 @@ comment title=[[Main Page]] !! input pre-comment text /* External links */ removed bogus entries !! result -pre-comment text - →External links: removed bogus entries +pre-comment text →External links: removed bogus entries !!end !! test @@ -12309,6 +15573,40 @@ Screen !! end +!! test +Verify that displaytitle handles inline CSS styles (bug 26547) - rejected value +!! options +showtitle +title=[[Screen]] +!! config +wgAllowDisplayTitle=true +wgRestrictDisplayTitle=true +!! input +this is not the the title +{{DISPLAYTITLE: creen}} +!! result +screen +this is not the the title +
+!! end + +!! test +Verify that displaytitle handles inline CSS styles (bug 26547) - accepted value +!! options +showtitle +title=[[Screen]] +!! config +wgAllowDisplayTitle=true +wgRestrictDisplayTitle=true +!! input +this is not the the title +{{DISPLAYTITLE:screen}} +!! result +screen +this is not the the title +
+!! end + !! test preload: checkand !! options @@ -12533,12 +15831,13 @@ title=[[Main Page]] __TOC__ == ''Lost'' episodes == !! result - -
+Contents
-Contents
[edit] Lost episodes
+Lost episodes[edit]
!! end @@ -12550,12 +15849,13 @@ title=[[Main Page]] __TOC__ == '''should be bold''' then normal text == !! result --
+Contents
-Contents
[edit] should be bold then normal text
+should be bold then normal text[edit]
!! end @@ -12567,12 +15867,13 @@ title=[[Main Page]] __TOC__ == Image [[Image:foobar.jpg]] == !! result --
+Contents
-Contents
[edit] Image
+Image [edit]
!! end @@ -12584,12 +15885,13 @@ title=[[Main Page]] __TOC__ ==Quote== !! result --
+Contents
-Contents
[edit]
+Quote!! end @@ -12603,12 +15905,13 @@ __TOC__ Hanc marginis exiguitas non caperet. QED !! result -
Quote[edit]-
+Contents
-Contents
[edit] Proof: 2 < 3
+ + +Proof: 2 < 3[edit]
Hanc marginis exiguitas non caperet. QED
@@ -12622,14 +15925,15 @@ __TOC__ == FooBar== !! result --
+Contents
[edit] Foo Bar
-[edit] Foo
+ + +BarFoo Bar[edit]
+Foo
!! end @@ -12641,14 +15945,15 @@ __TOC__ == Evilbye == !! result -Bar[edit]-
+Contents
-Contents
[edit] Hello
-[edit] b">Evilbye
+ + +Hello[edit]
+b">Evilbye[edit]
!! end @@ -12666,7 +15971,7 @@ __TOC__ == Attributes after dir on these span tags must be deleted from the TOC == !! result --
+Contents
Contents
-
- 1 C++
- 2 זבנג!
@@ -12674,12 +15979,13 @@ __TOC__- 4 All attributes on these span tags must be deleted from the TOC
- 5 Attributes after dir on these span tags must be deleted from the TOC
[edit] C++
-[edit] זבנג!
-[edit] The attributes on these span tags must be deleted from the TOC
-[edit] All attributes on these span tags must be deleted from the TOC
-[edit] Attributes after dir on these span tags must be deleted from the TOC
+ + +C++[edit]
+זבנג![edit]
+The attributes on these span tags must be deleted from the TOC[edit]
+All attributes on these span tags must be deleted from the TOC[edit]
+Attributes after dir on these span tags must be deleted from the TOC[edit]
!! end @@ -12696,7 +16002,7 @@ title=[[Main Page]] !! input {{int:Bug32057}} !! result -[edit] Headline text
+Headline text[edit]
!! end @@ -12798,7 +16104,7 @@ nowiki inside link inside heading (bug 18295) !! input ==[[foo|xy z]]== !! result -[edit] xyz
+xyz[edit]
!! end @@ -12837,7 +16143,7 @@ Gallery override link with WikiLink (bug 34852) File:foobar.jpg|caption|alt=galleryalt|link=InterWikiLink !! result -+
@@ -12856,7 +16162,7 @@ Gallery override link with absolute external link (bug 34852) File:foobar.jpg|caption|alt=galleryalt|link=http://www.example.org !! result -+
@@ -12875,7 +16181,7 @@ Gallery override link with malicious javascript (bug 34852) File:foobar.jpg|caption|alt=galleryalt|link=" onclick="alert('malicious javascript code!'); !! result -+
@@ -12894,7 +16200,7 @@ Gallery with invalid title as link (bug 43964) File:foobar.jpg|link=< !! result -+
@@ -12924,6 +16230,19 @@ abc !! end +!!test +Special parser function +!! input +{{#special:RandomPage}} +{{#special:BaDtItLe}} +{{#special:Foobar}} +!! result +Special:Random +Special:Badtitle +Special:Foobar +
+!! end + !!test Bug 34939 - Case insensitive link parsing ([HttP://]) !! input @@ -12951,6 +16270,30 @@ HttP://MediaWiki.Org/ !! end +!!test +Disable TOC +!! options +notoc +!! input +Lead +== Section 1 == +== Section 2 == +== Section 3 == +== Section 4 == +== Section 5 == +!! result +Lead +
+ +Section 1[edit]
+Section 2[edit]
+Section 3[edit]
+Section 4[edit]
+Section 5[edit]
+ +!! end + + ### ### Parsoids-specific tests ### Parsoid-PHP parser incompatibilities @@ -12958,963 +16301,2213 @@ HttP://MediaWiki.Org/ !!test 1. SOL-sensitive wikitext tokens as template-args !!options -disabled +parsoid=wt2html,wt2wt !!input {{echo|*a}} {{echo|#a}} {{echo|:a}} !!result -*a -#a -:a -
+ ++ +
- a
++ +
- a
+!!end -#### The following section of tests are primarily to test -#### wikitext escaping capabilities of Parsoid. -#### A lot of the tests are disabled for the PHP parser either -#### because of minor newline diffs or other reasons. -#### As Parsoid serializer can handle newlines and other HTML -#### more robustly, some of these tests might get reenabled -#### for the PHP parser. - -#### --------------- Headings --------------- -#### 0. Unnested -#### 1. Nested inside html
- a
+=foo=
-#### 2. Outside heading nest on a single linefoo
*bar -#### 3. Nested inside html with wikitext split by html tags -#### 4. No escape needed -#### 5. Empty headings -#### 6. Heading chars in SOL context -#### ---------------------------------------- -!! test -Headings: 0. Unnested -!! input -=foo= +#### ---------------------------------------------------------------- +#### Parsoid-only testing of Parsoid's impl of and+#### tags. Parsoid's output for these tags differs from that of the +#### PHP parser. +#### ---------------------------------------------------------------- - =foo ''a''= -!! result -=foo= -
=fooa= -
+!!test +Ref: 1. ref-location should be replaced with an index span +!!options +parsoid +!!input +A foo +B foo +C +!!result + !!end -!! test -Headings: 1. Nested inside html -!! options -disabled -!! input -==foo= = -===foo= == -====foo= === -=====foo= ==== -======foo= ===== -=======foo= ====== -!! result -=foo=
-=foo=
-=foo=
-=foo=
-=foo=
-=foo=
+!!test +Ref: 2. ref-tags with identical names should all get the same index +!!options +parsoid +!!input +A foo +B +!!result + !!end -!! test -Headings: 2. Outside heading nest on a single linefoo
*bar -!! options -disabled -!! input -=foo= -*bar -=foo= -=bar -=foo= -=bar= -!! result -foo
*bar -foo
=bar -foo
=bar= +!!test +Ref: 3. spaces in ref-names should be ignored +!!options +parsoid +!!input +A foo +B +C +!!result + !!end -!! test -Headings: 3. Nested inside html with wikitext split by html tags -!! options -disabled -!! input -== '''bold'''foo== -!! result -=boldfoo=
+!!test +Ref: 4. 'constructor' should be accepted as a valid ref-name +(NOTE: constructor is a predefined property in JS and constructor as a ref-name can clash with it if not handled properly) +!!options +parsoid +!!input +A foo +!!result +A [1]
!!end -!! test -Headings: 4. No escaping needed (testing just h1 and h2) -!! options -disabled -!! input -==foo= -=foo== -===foo== -==foo=== -=''=''foo== -=== -!! result -=foo
-foo=
-=foo
-foo=
-=foo=
-=
-!!end +!!test +Ref: 5. body should accept generic wikitext +!!options +parsoid +!!input +A + This is a '''[[bolded link]]''' and this is a {{echo|transclusion}} + -!! test -Headings: 5. Empty headings -!! options -disabled -!! input -== -== == -=== === -==== ==== -===== ===== -====== ====== -!! result - - - - - - -!!end + +!!result + A [1]
-!! test -Headings: 6. Heading chars in SOL context -!! options -disabled -!! input -=h1= -!! result -=h1= -
++
!!end -#### --------------- Lists --------------- -#### 0. Outside nests (*foo, etc.) -#### 1. Nested inside html- ↑ This is a bolded link and this is a transclusion +
+-#### 2. Inside definition lists -#### 3. Only bullets at start should be escaped -#### 4. No escapes needed -#### 5. No unnecessary escapes -#### 6. Escape bullets in SOL position -#### 7. Escape bullets in a multi-line context -#### ---------------------------------------- +!!test +Ref: 6. indent-pres should not be output in ref-body +!!options +parsoid +!!input +A + foo + bar + baz + -!! test -Lists: 0. Outside nests -!! input -
- *foo
*foo ++!!result + A [1]
-#foo -!! result -*foo -
#foo -
++
!!end -!! test -Lists: 1. Nested inside html -!! input -*- ↑ foo + bar + baz +
+*foo +!!test +Ref: 7. No p-wrapping in ref-body +!!options +parsoid +!!input +A +foo -*#foo +bar -*:foo -*;foo +baz -#*foo -##foo -#:foo +booz + -#;foo -!! result --
- *foo -
-
- #foo -
-
- :foo -
-
- ;foo -
-
- *foo -
-
- #foo -
-
- :foo -
+
- ;foo -
+!!result + A [1]
-!!end ++
!!end -!! test -Lists: 3. Only bullets at start of text should be escaped -!! input -*- ↑ foo -!! test -Lists: 2. Inside definition lists -!! input -;
+;foo +bar -;:foo -;:foo -:bar +baz + -::foo -!! result --
- ;foo -
-
- :foo -
-
- :foo -
- bar -
+booz +
- :foo -
*foo*bar +!!test +Ref: 8. transclusion wikitext has lower precedence +!!options +parsoid +!!input +A foo {{echo| B C}} -**foo ''it''*bar -!! result --
- *foo*bar -
+
- *fooit*bar -
+!!result + A [1] B C}}
++
!!end -!! test -Lists: 4. No escapes needed -!! options -disabled -!! input -*foo*bar +!!test +Ref: 9. unclosed comments should not leak out of ref-body +!!options +parsoid +!!input +A foo "},"attrs":{}}' id="cite_ref-1-0" rel="dc:references" typeof="mw:Extension/ref">[1] B C -*[[Foo]]: bar -!! result -- ↑ foo {{echo|
+-
- foo*bar -
-
- foo*bar -
+
- Foo: bar -
+
!!end -!! test -Lists: 5. No unnecessary escapes -!! input -* bar- ↑ foo
+[[foo]] - -*=bar[[foo]] +!!test +Ref: 10. Unclosed HTML tags should not leak out of ref-body +!!options +parsoid +!!input +A foo B C -*[[bar[[foo]] ++!!result + A [1] B C
-*]]bar [[foo]] ++
+!!end + +!!test +Ref: 11. ref-tags acts like an inline element wrt P-wrapping +!!options +parsoid +!!input +A foo B +C bar D +!!result + +!!end + +!!test +Ref: 12. ref-tags act as trailing newline migration barrier +!!options +parsoid +!!input +a + +b + + +c +!!result +- ↑ foo
+a
+ + + -*=bar foo]]= -!! result --
- bar [[foo]] -
-
- =bar [[foo]] -
-
- [[bar [[foo]] -
-
- ]]bar [[foo]] -
+
- =bar foo]]= -
c
!!end -!! test -Lists: 6. Escape bullets in SOL position -!! options -disabled -!! input -*foo -!! result -*foo -
+!!test +Ref: 13. ref-tags are not SOL-transparent and block indent-pres +!!options +parsoid +!!input +foo A +bar + B +!!result + !!end -!! test -Lists: 7. Escape bullets in a multi-line context -!! input -a -*b -!! result -a -*b -
+!!test +Ref: 14. A nested ref-tag should be emitted as plain text +!!options +parsoid +!!input +foo bar baz + ++!!result + + + +
!!end -#### --------------- HRs --------------- -#### 1. Single line -#### ----------------------------------- +!!test +Ref: 15. ref-tags with identical names should get identical indexes +!!options +parsoid +!!input +A1 foo A2 +B1 B2 bar + +- ↑ foo <ref>bar</ref> baz
++!!result + + + +!!end + +!!test +References: 1. references tag without any refs should be handled properly +!!options +parsoid +!!input + +!!result + +!!end + +!!test +References: 2. references tag with group only outputs references from that group +!!options +parsoid +!!input +A foo +B bar + +
+!!result + + + +!!end + +!!test +References: 3. ref list should be cleared after processing references +!!options +parsoid +!!input +A foo + +
- ↑ foo
++ +B bar + + +!!result + A [1]
+ ++ +
- ↑ foo
+B [1]
+ ++!!end + +!!test +References: 4. only referenced group should be cleared after processing references +!!options +parsoid +!!input +A afoo +B bfoo + +
- ↑ bar
++ +C cfoo + + +!!result + + + + +
- ↑ afoo
+C [2]
+ + +!!end + +!!test +References: 5. ref tags in references should be processed while ignoring all other content +!!options +parsoid +!!input +A +B bar + ++foo +This should just get lost. + +!!result + + + +!!end + +!!test +References: 6.from a transclusion +!!options +parsoid +!!input +{{echo| }} +!!result + +!!end !! test -HRs: 1. Single line +References: 7. Multiple references tags (one without and one with nested refs) should be correctly handled !! options -disabled +parsoid !! input ----- -
---- ----- -=foo= ----- -*foo +A foo bar for a +B + ++ + +foo + !! result -
---- -
=foo= -
*foo + + + + ++
!! end -#### --------------- Tables --------------- -#### 1a. Simple example -#### 1b. No escaping needed (!foo) -#### 1c. No escaping needed (|foo) -#### 1d. No escaping needed (|}foo) -#### -#### 2a. Nested in td (- ↑ foo
+foo|bar ) -#### 2b. Nested in td (foo||bar ) -#### 2c. Nested in td -- no escaping needed(foo!!bar ) -#### -#### 3a. Nested in th (foo!bar ) -#### 3b. Nested in th (foo!!bar ) -#### 3c. Nested in th -- no escaping needed(foo||bar ) +#### ---------------------------------------------------------------- +#### The following section of tests are primarily to test +#### wikitext escaping capabilities of Parsoid. Given that +#### escaping can be done any number of ways, the wikitext (input) +#### is always adjusted to reflect how Parsoid adds nowiki +#### escape tags. #### -#### 4a. Escape - -#### 4b. Escape + -#### 4c. No escaping needed -#### -------------------------------------- +#### We are marking several tests as parsoid-only since the +#### HTML in the result section is different from what the +#### PHP parser generates for it. +#### ---------------------------------------------------------------- -!! test -Tables: 1a. Simple example -!! input -{| -|} -!! result -{| -|} -
-!! end +#### --------------- Headings --------------- +#### 0. Unnested +#### 1. Nested inside html=foo=
+#### 2. Outside heading nest on a single linefoo
*bar +#### 3. Nested inside html with wikitext split by html tags +#### 4. No escape needed +#### 5. Empty headings +#### 6. Heading chars in SOL context +#### ---------------------------------------- !! test -Tables: 1b. No escaping needed +Headings: 0. Unnested +!! options +parsoid !! input -!foo -!! result -!foo -
-!! end +=foo= -!! test -Tables: 1c. No escaping needed -!! input -|foo +=foo= + +=foo= + +=foo''a''= !! result -|foo -
-!! end +=foo=
+ +=foo= + +=foo=
+ +=fooa=
+!!end !! test -Tables: 1d. No escaping needed +Headings: 1. Nested inside html +!! options +parsoid !! input -|}foo +==foo= = + +===foo= == + +====foo= === + +=====foo= ==== + +======foo= ===== + +=======foo= ====== !! result -|}foo -
-!! end +=foo=
+=foo=
+=foo=
+=foo=
+=foo=
+=foo=
+!!end !! test -Tables: 2a. Nested in td +Headings: 2. Outside heading nest on a single linefoo
*bar !! options -disabled +parsoid !! input -{| -|foo|bar -|} -!! result --
+=foo= +foo|bar - * bar -!! end +=foo= +=bar + +=foo= +=bar= +!! result +foo
*bar +foo
=bar +foo
=bar= +!!end !! test -Tables: 2b. Nested in td +Headings: 3. Nested inside html with wikitext split by html tags !! options -disabled +parsoid !! input -{| -|foo||bar -|''it''foo||bar -|} +=='''bold'''foo= = !! result --
- -!! end +foo||bar - itfoo||bar - =boldfoo=
+!!end !! test -Tables: 2c. Nested in td -- no escaping needed +Headings: 4a. No escaping needed (testing just h1 and h2) !! options -disabled +parsoid !! input -{| -|foo!!bar -|} -!! result --
+==foo= -!! end +=foo== -!! test -Tables: 3a. Nested in th -!! options -disabled -!! input -{| -!foo!bar -|} -!! result -foo!!bar - -
+= =foo= = -!! end +==foo= bar= -!! test -Tables: 3b. Nested in th -!! options -disabled -!! input -{| -!foo!bar - foo!!bar -|} -!! result --
+===foo== -!! end +==foo=== -!! test -Tables: 3c. Nested in th -- no escaping needed -!! options -disabled -!! input -{| -!foo||bar -|} -!! result -foo!!bar - -
+=''=''foo== -!! end +=foo||bar - = = +!! result +=foo
+foo=
+=foo=
+=foo= bar
+=foo
+foo=
+=foo=
+=
+!!end !! test -Tables: 4a. Escape - +Headings: 4b. No escaping needed (inside p-tags) !! options -disabled +parsoid !! input -{| -|- -!-bar -|- -|-bar -|} +=== +=foo= x +=foo=!! result --
-!! end +- -bar - -bar === +=foo= x +=foo=
+!!end !! test -Tables: 4b. Escape + +Headings: 5. Empty headings !! options -disabled +parsoid !! input -{| -|- -!+bar -|- -|++bar -|} +== + +== == + +=== === + +==== ==== + +===== ===== + +====== ====== !! result - -
-!! end + + + + + + +!!end !! test -Tables: 4c. No escaping needed +Headings: 6a. Heading chars in SOL context (with trailing spaces) !! options -disabled +parsoid !! input -{| -|- -|foo-bar -|foo+bar -|- -|''foo''-bar -|''foo''+bar -|} -!! result -- +bar - +bar -
-!! end +- foo-bar foo+bar - foo-bar foo+bar =a= -!! test -Tables: 4d. No escaping needed -!! input -{| -||+1 -||-2 -|} -!! result --
+- +1 - --2 - =a= -!! end +=a= -#### --------------- Links --------------- -#### 1. Quote marks in link text -#### 2. Wikilinks: Escapes needed -#### 3. Wikilinks: No escapes needed -#### 4. Extlinks: Escapes needed -#### 5. Extlinks: No escapes needed -#### -------------------------------------- -!! test -Links 1. Quote marks in link text -!! options -disabled -!! input -[[Foo|Foo''boo'' ]] +=a= !! result -Foo''boo'' -!! end +=a=
+=a=
+=a=
+=a=
+!!end !! test -Links 2. WikiLinks: Escapes needed +Headings: 6b. Heading chars in SOL context (with trailing newlines) !! options -disabled +parsoid !! input -[[Foo|[Foobar] ]] -[[Foo|Foobar] ]] -[[Foo|x [Foobar] x ]] -[[Foo|x [http://google.com g] x ]] -[[Foo|[[Bar]] ]] -[[Foo|x [[Bar]] x ]] -[[Foo||Bar ]] +=a= +b + +=a= +b + +=a= +b + +=a= +b !! result -[Foobar] -Foobar] -x [Foobar] x -x [http://google.com g] x -[[Bar]] -x [[Bar]] x -|Bar -!! end +=a= +b
+=a= +b
+=a= +b
+=a= +b
+ +!!end !! test -Links 3. WikiLinks: No escapes needed +Headings: 6c. Heading chars in SOL context (leading newline break) !! options -disabled +parsoid !! input -[[Foo|[Foobar]] -[[Foo|foo|bar]] +a +=b= !! result -[Foobar -foo|bar -!! end +a +=b=
+!!end !! test -Links 4. ExtLinks: Escapes needed +Headings: 6d. Heading chars in SOL context (with interspersed comments) !! options -disabled +parsoid !! input -[http://google.com[google] ] -[http://google.comgoogle] ] +=a= + +=a= !! result -[google] -google] -!! end +=a=
+=a=
+!!end !! test -Links 5. ExtLinks: No escapes needed +Headings: 6d. Heading chars in SOL context (No escaping needed) !! options -disabled +parsoid=html2wt !! input -[http://google.com [google] +=a=b!! result -[google -!! end +=a=b+!!end -#### --------------- Quotes --------------- -#### 1. Quotes inside and -#### 2. Link fragments separated by and tags -#### 3. Link fragments inside and -#### -------------------------------------- -!! test -1. Quotes inside and -!! input -'''foo' '' -''''foo'' '' -'''''foo''' '' -''''foo' ''' -'''''foo'' ''' -''''''foo''' ''' -'''foo' ''bar' ''baz''' -!! result -'foo' -''foo'' -'''foo''' -'foo' -''foo'' -'''foo''' -foo'bar'baz -
-!! end +#### --------------- Lists --------------- +#### 0. Outside nests (*foo, etc.) +#### 1. Nested inside html+#### 2. Inside definition lists +#### 3. Only bullets at start should be escaped +#### 4. No escapes needed +#### 5. No unnecessary escapes +#### 6. Escape bullets in SOL position +#### 7. Escape bullets in a multi-line context +#### ---------------------------------------- !! test -2. Link fragments separated by and tags +Lists: 0. Outside nests !! input -[[''foo''
- *foo
hello]] +* foo -[['''foo'''hello]] +# foo !! result -[[foohello]] -
[[foohello]] +
*foo +
#foo
-!! end +!!end !! test -2. Link fragments inside and -(FIXME: Escaping one or both of [[ and ]] is also acceptable -- - this is one of the shortcomings of this format) +Lists: 1. Nested inside html !! input -''[[foo'']] +**foo + +*#foo + +*:foo + +*;foo + +#*foo + +##foo + +#:foo + +#;foo +!! result ++
+- *foo +
++
+- #foo +
++
+- :foo +
++
+- ;foo +
++
+- *foo +
++
+- #foo +
++
+- :foo +
++
+ +!!end + +!! test +Lists: 2. Inside definition lists +!! input +;- ;foo +
+;foo + +;:foo + +;:foo +:bar + +::foo +!! result ++
+- ;foo +
++
+- :foo +
++
+- :foo +
+- bar +
++
+ +!!end + +!! test +Lists: 3. Only bullets at start of text should be escaped +!! input +*- :foo +
+*foo*bar + +**foo ''it''*bar +!! result ++
+- *foo*bar +
++
+ +!!end + +!! test +Lists: 4. No escapes needed +!! options +parsoid +!! input +*foo*bar + +*''foo''*bar + +*[[Foo]]: bar +!! result +- *fooit*bar +
++
+- foo*bar +
++
+- foo*bar +
++
+!!end + +!! test +Lists: 5. No unnecessary escapes +!! input +* bar- Foo: bar +
+[[foo]] + +*=bar[[foo]] + +*[[bar[[foo]] + +*]]bar[[foo]] + +*=bar foo]]= + +*: a +!! result ++
+- bar [[foo]] +
++
+- =bar [[foo]] +
++
+- [[bar [[foo]] +
++
+- ]]bar [[foo]] +
++
+- =bar foo]]= +
++
+ +!!end + +!! test +Lists: 6. Escape bullets in SOL position +!! options +parsoid +!! input +- +
: a +*foo +!! result +*foo
+!!end + +!! test +Lists: 7. Escape bullets in a multi-line context +!! input +a +* b +!! result +a +*b +
+!!end + +#### --------------- HRs --------------- +#### 1. Single line +#### ----------------------------------- + +!! test +HRs: 1. Single line +!! options +parsoid +!! input +-------- +----=foo= +----*foo +!! result +
---- +
=foo= +
*foo +!! end + +#### --------------- Tables --------------- +#### 1a. Simple example +#### 1b. No escaping needed (!foo) +#### 1c. No escaping needed (|foo) +#### 1d. No escaping needed (|}foo) +#### +#### 2a. Nested in td (foo|bar ) +#### 2b. Nested in td (foo||bar ) +#### 2c. Nested in td -- no escaping needed(foo!!bar ) +#### +#### 3a. Nested in th (foo!bar ) +#### 3b. Nested in th (foo!!bar ) +#### 3c. Nested in th -- no escaping needed(foo||bar ) +#### +#### 4a. Escape - +#### 4b. Escape + +#### 4c. No escaping needed +#### -------------------------------------- + +!! test +Tables: 1a. Simple example +!! input +{| +|} +!! result +{| +|} +
+!! end + +!! test +Tables: 1b. No escaping needed +!! input +!foo +!! result +!foo +
+!! end + +!! test +Tables: 1c. No escaping needed +!! input +|foo +!! result +|foo +
+!! end + +!! test +Tables: 1d. No escaping needed +!! input +|}foo +!! result +|}foo +
+!! end + +!! test +Tables: 2a. Nested in td +!! options +parsoid +!! input +{| +|foo|bar +|} +!! result ++!! end + +!! test +Tables: 2b. Nested in td +!! options +parsoid +!! input +{| +|
+ foo|bar foo||bar +|''it''foo||bar +|} +!! result ++!! end + +!! test +Tables: 2c. Nested in td -- no escaping needed +!! options +parsoid +!! input +{| +|foo!!bar +|} +!! result +
+ foo||bar +itfoo||bar + +!! end + +!! test +Tables: 3a. Nested in th +!! options +parsoid +!! input +{| +!foo!bar +|} +!! result +
foo!!bar + + +!! end + +!! test +Tables: 3b. Nested in th +!! options +parsoid +!! input +{| +!
foo!bar + foo!!bar +|} +!! result ++
+!! end + +!! test +Tables: 3c. Nested in th -- no escaping needed +!! options +parsoid +!! input +{| +!+ foo!!bar foo||bar +|} +!! result ++!! end + +!! test +Tables: 4a. Escape - +!! options +parsoid +!! input +{| +!-bar +|- +|
+ foo||bar -bar +|} +!! result ++
+!! end + +!! test +Tables: 4b. Escape + +!! options +parsoid +!! input +{| +!+bar +|- +|+ -bar + -bar +bar +|} +!! result ++
+!! end + +!! test +Tables: 4c. No escaping needed +!! options +parsoid +!! input +{| +|foo-bar +|foo+bar +|- +|''foo''-bar +|''foo''+bar +|- +|foo +bar|baz ++bar +-bar +|} +!! result ++ +bar + +bar +
+!! end + +### SSS FIXME: Disabled right now because accurate html2wt +### on this snippet requires data-parsoid flags that we've +### stripped out of these tests. We should scheme how we +### we want to handle these kind of tests that require +### data-parsoid flags for accurate html2wt serialization + +!! test +Tables: 4d. No escaping needed +!! options +disabled +!! input +{| +||+1 +||-2 +|} +!! result ++ foo-bar foo+bar + foo-bar foo+bar + foo + bar|baz ++bar +-bar
+
+ +!! end + +#### --------------- Links ---------------- +#### 1. Quote marks in link text +#### 2. Wikilinks: Escapes needed +#### 3. Wikilinks: No escapes needed +#### 4. Extlinks: Escapes needed +#### 5. Extlinks: No escapes needed +#### -------------------------------------- +!! test +Links 1. Quote marks in link text +!! options +parsoid +!! input +[[Foo|Foo+ +1 + +-2 + ''boo'' ]] +!! result +Foo''boo'' +!! end + +!! test +Links 2. WikiLinks: Escapes needed +!! options +parsoid +!! input +[[Foo|[Foobar] ]] +[[Foo|Foobar] ]] +[[Foo|x [Foobar] x]] +[[Foo|x [http://google.com g] x ]] +[[Foo|[[Bar]] ]] +[[Foo|x [[Bar]] x ]] +[[Foo||Bar ]] +[[Foo|]]bar ]] +[[Foo|[[bar ]] +[[Foo|x ]] y [[ z ]] +!! result +[Foobar] +Foobar] +x [Foobar] x +x [http://google.com g] x +[[Bar]] +x [[Bar]] x +|Bar +]]bar +[[bar +x ]] y [[ z +!! end + +!! test +Links 3. WikiLinks: No escapes needed +!! options +parsoid +!! input +[[Foo|[Foobar]] +[[Foo|foo|bar]] +!! result +[Foobar +foo|bar +!! end + +!! test +Links 4. ExtLinks: Escapes needed +!! options +parsoid +!! input +[http://google.com[google] ] +[http://google.comgoogle] ] +!! result +[google] +google] +!! end + +!! test +Links 5. ExtLinks: No escapes needed +!! options +parsoid +!! input +[http://google.com [google] +!! result +[google +!! end + +#### --------------- Quotes --------------- +#### 1. Quotes inside and +#### 2. Link fragments separated by and tags +#### 3. Link fragments inside and +#### 4. No escaping needed +#### -------------------------------------- +!! test +1. Quotes inside and +!! options +parsoid=html2wt,wt2wt +!! input +'''foo' '' +''''foo'' '' +'''''foo''' '' +''foo'''s +''' 'foo' ''' +'''''foo'' ''' +''''''foo''' ''' +'''foo' ''bar' ''baz''' +'''foo''''s +'''foo'' +''foo'' ' +' ''foo'' ' +''''foo''' +'''foo''' ' +' '''foo''' ' +!! result + 'foo' +''foo'' +'''foo''' +foo's +'foo' +''foo'' +'''foo''' +foo'bar'baz +foo's +'foo +foo' +'foo' +'foo +foo' +'foo'
+!! end + +!! test +2. Link fragments separated by and tags +!! input +[[''foo''hello]] + +[['''foo'''hello]] +!! result +[[foohello]] +
[[foohello]] +
+!! end + +!! test +3. Link fragments inside and +(FIXME: Escaping one or both of [[ and ]] is also acceptable -- + this is one of the shortcomings of this format) +!! input +''[[foo'']] + +'''[[foo''']] +!! result +[[foo]] +
[[foo]] +
+!! end + +!! test +4. No escaping needed +!! input +'''bar''' +''''bar'''' +!! result +'bar' +'bar' +
+!! end + +#### ----------- Paragraphs --------------- +#### 1. No unnecessary escapes +#### -------------------------------------- + +!! test +1. No unnecessary escapes +!! input +bar[[foo]] + +=bar[[foo]] + +[[bar[[foo]] + +]]bar[[foo]] + +=bar foo]]= +!! result +bar [[foo]] +
=bar [[foo]] +
[[bar [[foo]] +
]]bar [[foo]] +
=bar foo]]= +
+!!end + +#### ----------------------- PRE -------------------------- +#### 1. Leading whitespace in SOL context should be escaped +#### ------------------------------------------------------ +!! test +1. Leading whitespace in SOL context should be escaped +!! options +parsoid +!! input +a + + a + + a(tab) + + a + + a + +a + b + +a + b + +a + b +!! result + a
+a
+a(tab)
+a
+a
+a + b
+a + b
+a + b
+!! end + +#### --------------- Behavior Switches -------------------- +!! test +1. Valid behavior switches should be escaped +!! options +parsoid=html2wt +!! input +__TOC__ +!! result +__TOC__ +!! end + +!! test +2. Invalid behavior switches should not be escaped +!! options +parsoid=html2wt +!! input +__TOO__ +__|__ +!! result +__TOO__ +__|__ +!! end + +#### --------------- HTML tags --------------- +#### 1. a tags +#### 2. other tags +#### 3. multi-line html tag +#### ----------------------------------------- +!! test +1. a tags +!! options +parsoid +!! input +google +!! result +<a href="http://google.com">google</a> +!! end + +!! test +2. other tags +!! input ++!! result + foo+foo<div>foo</div> +<div style="color:red">foo</div> +
+!! end + +!! test +3. multi-line html tag +!! input ++!! result + foo<div +>foo</div +> +
+!! end + +!! test +4. extension tags +!! input +foo +!! result +<ref>foo</ref> +
+!! end + +#### --------------- Others --------------- +!! test +Escaping nowikis +!! input +<nowiki>foo</nowiki> +!! result +<nowiki>foo</nowiki> +
+!! end + +## The quote-char in the input is necessary for triggering the bug +!! test +(Bug 52035) Nowiki-escaping should not get tripped by " :" in text +!! options +parsoid=wt2wt,html2wt +!! input +foo's bar : +!! result +foo's bar :
+!! end + +!! test + +Tag-like HTML structures are passed through as text +!! input ++ + + + + +1>2 + +x b + +1 f +!! result + <x y> +
<x.y> +
<x-y> +
1>2 +
x<y +
a>b +
1<d e>f +
+!! end + + +# This was a bug in the PHP parser (see bug 17663 and its dups, +# https://bugzilla.wikimedia.org/show_bug.cgi?id=17663) +!! test +Tag names followed by punctuation should not be recognized as tags +!! input +text +!! result + <s.ome> text +
+!! end + +!! test +HTML tag with necessary entities in attributes +!! input +foo +!! result +foo +
+!! end + +!! test +HTML tag with 'unnecessary' entity encoding in attributes +!! input +foo +!! result +foo +
+!! end + +!! test +HTML tag with broken attribute value quoting +!! input +Foo +!! result +Foo +
+!! end + +!! test +Table with broken attribute value quoting +!! input +{| +| title="Hello world|Foo +|} +!! result ++
+ +!! end + +!! test +Table with broken attribute value quoting on consecutive lines +!! input +{| +| title="Hello world|Foo +| style="color:red|Bar +|} +!! result ++ Foo + +
+ +!! end + +!! test +Parsoid-only: Table with broken attribute value quoting on consecutive lines +!! options +parsoid +!! input +{| +| title="Hello world|Foo +| style="color:red|Bar +|} +!! result ++ Foo + +Bar + +
+ +!! end + +!! test +Parsoid-only: Don't wrap broken template tags in+ Foo + Bar + on wt2wt (Bug 42353) +!! options +parsoid +!! input +{{}} +!! result +{{}} +!! end + +!! test +Parsoid-only: Don't wrap broken template tags in on wt2wt (Bug 42353) +!! options +parsoid +!! input +}}{{ +!! result +}}{{ +!! end + +!!test +Accept empty td cell attribute +!!input +{| +| align="center" | foo || | +|} +!!result + +
+ +!!end + +!!test +Non-empty attributes in th-cells +!!input +{| +! Foo !! style="color: red" | Bar +|} +!!result ++ foo ++ +
+ +!!end + +!!test +Accept empty attributes in th-cells +!!input +{| +!| foo !!| bar +|} +!!result ++ Foo +Bar + +
+ +!!end + +!!test +Empty table rows go away +!!input +{| +| Hello +| there +|- class="foo" +|- +|} +!! result ++ foo +bar + +
+ +!! end + +### +### Parsoid-centric tests for testing RTing of inter-element separators +### Edge cases not tested by existing parser tests and specific to +### Parsoid-specific serialization strategies. +### + +!!test +RT-ed inter-element separators should be valid separators +!!input +{| +|- [[foo]] +|} +!!result ++ + +Hello + +there + + +
+ +!!end + +!!test +Trailing newlines in a deep dom-subtree that ends a wikitext line should be migrated out +(Parsoid-only since PHP parser relies on Tidy for correct output) +!!options +parsoid +!!input +{| +|foo +bar +|} + +{| +|foo +|} +!!result +!!end + +!!test +Empty TD followed by TD with tpl-generated attribute +!!input +{| +|- +| +|{{echo|style='color:red'}}|foo +|} +!!result ++ +
+ +!!end + +!!test +Indented table with an empty td +!!input + {| + |- + | + |foo + |} +!!result ++ + +foo + + +
+ +!!end + +!!test +Empty TR followed by a template-generated TR +(Parsoid-specific since PHP parser doesn't handle this mixed tbl-wikitext) +!!options +parsoid +!!input +{| +|- +{{echo|+ + +foo + }} +|} +!!result + foo + +
+!!end + +## PHP and parsoid output differ for this, and since this is primarily +## for testing Parsoid's serializer, marking this Parsoid only +!!test +Empty TR followed by mixed-ws-comment line should RT correctly +!!options +parsoid +!!input +{| +|- + +|- + +|} +!!result ++ + +foo + +
+ +!!end + +!!test +Multi-line image caption generated by templates with/without trailing newlines +!!options +parsoid +!!input +[[File:foo.jpg|thumb|300px|foo\n{{echo|A}}\n{{echo|B}}\n{{echo|C}}]] +[[File:foo.jpg|thumb|300px|foo\n{{echo|A}}\n{{echo|B}}\n{{echo|C}}\n\n]] +!!result + + + +!!end + +## PHP emits broken html for this, and since this is primarily +## a Parsoid serializer test, marking this Parsoid only +!!test +Improperly nested inline or quotes tags with whitespace in between +!!options +parsoid +!!input ++ + + +x+''' ''x''' '' +!!result ++!!end + +!!test +Encapsulate protected attributes from wt +!!options +parsoid +!!input +
x+ x +foo+!!result +foo+ +!!end + +## Currently the p-wrapper is fragile in how adds / removes transformations. +## Having nested or stray pre tags results in the attempt to add duplicates, +## causing an assertion fail. This test tries to prevent that situation. +!!test +Ensure ParagraphWrapper can deal with stray closing pre tags +!!options +parsoid=wt2html +!!input +plain text +!!result +plain text +!!end + +!!test +Ensure fostered text content is wrapped in spans +!!options +parsoid=wt2html +!!input +hi
ho
+!!result +hi ++ho +
+!!end + +!!test +Encapsulation properly handles null DSR information from foster box +!!options +parsoid=wt2html,wt2wt +!!input +{{echo|
foo
}} +!!result +foo +bar + +
+!!end + +!!test +1. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ bar {{echo|foo
+!!result +foo +}} bar + +
+!!end + +!!test +2. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ bar +!!result +
{{echo|foo}}bar foo++ +
+!!end + +!!test +3. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ bar +!!result +
{{echo|foo
}}bar ++foo
+ +
+!!end + +!!test +4. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ bar +!!result +
{{echo|foo
}}bar ++foo
+ +
+!!end + +!!test +5. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ bar +!!result +foo +
foo}} {{echo|foo
+ +
+!!end + +!!test +6. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input ++ + +foo
}}
foo {{echo|foo
ok
+!!result +foo ++ +
++ + +foo
ok
+!!end + +!!test +7. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input +{{echo|
+!!result +foo
}}bar foo
++ +
+!!end -'''[[foo'''+ bar ]] -!! result -[[foo]] -
[[foo]] -
-!! end +!!test +8. Encapsulate foster-parented transclusion content +!!options +parsoid=wt2wt,wt2html +!!input +{{echo|a +}}{|{{echo|style='color:red'}} +|- +|b +|} +!!result +a
{{{1}}} ++ +
+!!end -#### --------------- Paragraphs --------------- -#### 1. No unnecessary escapes -#### -------------------------------------- +# ----------------------------------------------------------------- +# The following section of tests are primarily to spec requirements +# around serialization of new/edited content. +# +# All these tests are marked Parsoid html2wt and html2html only +# ---------------------------------------------------------------- !! test -1. No unnecessary escapes +Image: Modifying size of an image +!! options +parsoid=html2wt !! input -bar+ b [[foo]] - -=bar[[foo]] - -[[bar[[foo]] - -]]bar [[foo]] - -=bar foo]]= +[[Image:Wiki.png|230x230px]] !! result -bar [[foo]] -
=bar [[foo]] -
[[bar [[foo]] -
]]bar [[foo]] -
=bar foo]]= -
+ !!end -#### --------------- PRE ------------------ -#### 1. Leading space in SOL context should be escaped -#### -------------------------------------- !! test -1. Leading space in SOL context should be escaped +Image: New block level image should have \n before and after !! options -disabled +parsoid=html2wt !! input -foo -foo +123 +[[File:Wiki.png|right|thumb|150x150px]] +456 !! result -foo - foo -
-!! end +123
456
+!!end -#### --------------- HTML tags --------------- -#### 1. a tags -#### 2. other tags -#### 3. multi-line html tag -#### -------------------------------------- +# Wacky -- the leading newline in input is required because +# that is what the serializer emits. To be fixed. Not fixing +# the test because this test is required to test serialization of +# new content and preferred whitespace style. !! test -1. a tags +Lists: Serialize correctly even when list content is wrapped in p-tags (like VE does) !! options -disabled +parsoid=html2wt !! input -google -!! result -<a href="http://google.com">google</a> -!! end -!! test -2. other tags -!! input -+* foo !! result - foo-foo<div>foo</div> -<div style="color:red">foo</div> -
++
!! end +# Wacky -- the leading newline in input is required because +# that is what the serializer emits. To be fixed. Not fixing +# the test because this test is required to test serialization of +# new content and preferred whitespace style. !! test -3. multi-line html tag +Lists: Add space after bullets +!! options +parsoid=html2wt !! input -- +
foo
-!! result - foo<div ->foo</div -> -
-!! end -#### --------------- Others --------------- -!! test -Escaping nowikis -!! input -<nowiki>foo</nowiki> +* foo +* bar +* baz !! result -<nowiki>foo</nowiki> -
++
!! end !! test -Tag-like HTML structures are passed through as text +Parsoid: Serialize positional parameters with = in them as named parameter +!! options +parsoid=html2wt !! input -- foo
+- bar
+- baz
+- - +{{echo|1 = f=oo}} - - -1>2 +{{echo|1 = f=oo|2 = bar}} -x + +{{echo| f=oo |bar}} +!! result +foo
-a>b +foo
-1f -!! result - <x y> -
<x.y> -
<x-y> -
1>2 -
x<y -
a>b -
1<d e>f -
+ + +foo
!! end - -# This fails in the PHP parser (see bug 40670, -# https://bugzilla.wikimedia.org/show_bug.cgi?id=40670), so disabled for it. !! test -Tag names followed by punctuation should not be recognized as tags +Parsoid: Correctly serialize block-node children when they are a combination of text and p-nodes !! options -disabled +parsoid=html2wt !! input -text -!! result - <s.ome> text -
-!! end +a +b ++a +b +++a -!! test -HTML tag with necessary entities in attributes -!! input -foo +b +!! result -foo -
+a+b
a ++b
+a +!! end -!! test -HTML tag with 'unnecessary' entity encoding in attributes -!! input -foo -!! result -b
foo -
-!! end +#----------------------------- +# I/B quote minimization tests +#----------------------------- !! test -HTML tag with broken attribute value quoting +1. I/B quote minimization: wikitext-only tags should be combined +!! options +parsoid=html2wt !! input -Foo -!! result -Foo -
-!! end +''A''B -!! test -Table with broken attribute value quoting -!! input -{| -| title="Hello world|Foo -|} +''A'''''B''' !! result --
- +- Foo - AB
+AB
!! end !! test -Table with broken attribute value quoting on consecutive lines +3. I/B quote minimization: templated content stops minimization +!! options +parsoid=html2wt !! input -{| -| title="Hello world|Foo -| style="color:red|Bar -|} -!! result --
+''A''{{echo|''B''}} +''A''{{echo|'''''B'''''}} +!! result +- Foo - -Bar - AB +
AB !! end !! test -Parsoid-only: Table with broken attribute value quoting on consecutive lines +4. I/B quote minimization: new content should be mimimized with adjacent old content !! options -parsoid +parsoid=html2wt !! input -{| -| title="Hello world|Foo -| style="color:red|Bar -|} -!! result -
-
- -!! end - -!!test -Accept empty td cell attribute -!!input -{| -| align="center" | foo || | -|} -!!result -- Foo - Bar - -
- -!!end - -!!test -Non-empty attributes in th-cells -!!input -{| -! Foo !! style="color: red" | Bar -|} -!!result -- foo -- -
- -!!end - -!!test -Accept empty attributes in th-cells -!!input -{| -!| foo !!| bar -|} -!!result -- Foo -Bar - -
+''AB'' -!!end +'''AB''' -!!test -Empty table rows go away -!!input -{| -| Hello -| there -|- class="foo" -|- -|} +''A'''B''''' !! result -- foo -bar - -
- +- - -Hello - -there - AB
+AB
+AB
!! end +# ----------------------------------------------------------------- +# End of section for Parsoid-only html2wt tests for serialization +# of new content +# ----------------------------------------------------------------- + TODO: more images more tables diff --git a/tests/parser/preprocess/All_system_messages.expected b/tests/parser/preprocess/All_system_messages.expected index 897c5fb0..078d8f0d 100644 --- a/tests/parser/preprocess/All_system_messages.expected +++ b/tests/parser/preprocess/All_system_messages.expected @@ -1239,27 +1239,6 @@ diff </td><td>int:Difference </td></tr><tr><td> -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguations&action=edit disambiguations]<br> -[[MediaWiki_talk:Disambiguations|Talk]] -</td><td> -Disambiguation pages -</td><td> -int:Disambiguations -</td></tr><tr><td> -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguationspage&action=edit disambiguationspage]<br> -[[MediaWiki_talk:Disambiguationspage|Talk]] -</td><td> -Wiktionary:Links_to_disambiguating_pages -</td><td> -int:Disambiguationspage -</td></tr><tr><td> -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguationstext&action=edit disambiguationstext]<br> -[[MediaWiki_talk:Disambiguationstext|Talk]] -</td><td> -The following pages link to a <i>disambiguation page</i>. They should link to the appropriate topic instead.<br />A page is treated as dismbiguation if it is linked from $1.<br />Links from other namespaces are <i>not</i> listed here. -</td><td> -int:Disambiguationstext -</td></tr><tr><td> [http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disclaimerpage&action=edit disclaimerpage]<br> [[MediaWiki_talk:Disclaimerpage|Talk]] </td><td> diff --git a/tests/parser/preprocess/All_system_messages.txt b/tests/parser/preprocess/All_system_messages.txt index fc10d7cf..3c30da94 100644 --- a/tests/parser/preprocess/All_system_messages.txt +++ b/tests/parser/preprocess/All_system_messages.txt @@ -1239,27 +1239,6 @@ diff{{int:Difference}} -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguations&action=edit disambiguations]
-[[MediaWiki_talk:Disambiguations|Talk]] --Disambiguation pages - -{{int:Disambiguations}} - -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguationspage&action=edit disambiguationspage]
-[[MediaWiki_talk:Disambiguationspage|Talk]] --Wiktionary:Links_to_disambiguating_pages - -{{int:Disambiguationspage}} - -[http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disambiguationstext&action=edit disambiguationstext]
-[[MediaWiki_talk:Disambiguationstext|Talk]] --The following pages link to a <i>disambiguation page</i>. They should link to the appropriate topic instead.<br />A page is treated as dismbiguation if it is linked from $1.<br />Links from other namespaces are <i>not</i> listed here. - -{{int:Disambiguationstext}} - [http://tl.wiktionary.org/w/wiki.phtml?title=MediaWiki:Disclaimerpage&action=edit disclaimerpage]
[[MediaWiki_talk:Disclaimerpage|Talk]]diff --git a/tests/parserTests.php b/tests/parserTests.php index 804a30cb..debb3575 100644 --- a/tests/parserTests.php +++ b/tests/parserTests.php @@ -27,8 +27,8 @@ $otions = array( 'quick', 'color', 'quiet', 'help', 'show-output', 'record', 'run-disabled', 'run-parsoid' ); $optionsWithArgs = array( 'regex', 'filter', 'seed', 'setversion' ); -require_once( __DIR__ . '/../maintenance/commandLine.inc' ); -require_once( __DIR__ . '/TestsAutoLoader.php' ); +require_once __DIR__ . '/../maintenance/commandLine.inc'; +require_once __DIR__ . '/TestsAutoLoader.php'; if ( isset( $options['help'] ) ) { echo << fuzzTest( $files ); } else { $ok = $tester->runTestsFromFiles( $files ); - exit ( $ok ? 0 : 1 ); + exit( $ok ? 0 : 1 ); } diff --git a/tests/phpunit/AutoLoaderTest.php b/tests/phpunit/AutoLoaderTest.php deleted file mode 100644 index c8f38685..00000000 --- a/tests/phpunit/AutoLoaderTest.php +++ /dev/null @@ -1,51 +0,0 @@ -assertEquals( - $results['expected'], - $results['actual'] - ); - } - - protected static function checkAutoLoadConf() { - global $wgAutoloadLocalClasses, $wgAutoloadClasses, $IP; - static $supportsParsekit; - $supportsParsekit = function_exists( 'parsekit_compile_file' ); - - // wgAutoloadLocalClasses has precedence, just like in includes/AutoLoader.php - $expected = $wgAutoloadLocalClasses + $wgAutoloadClasses; - $actual = array(); - - $files = array_unique( $expected ); - - foreach ( $files as $file ) { - // Only prefix $IP if it doesn't have it already. - // Generally local classes don't have it, and those from extensions and test suites do. - if ( substr( $file, 0, 1 ) != '/' && substr( $file, 1, 1 ) != ':' ) { - $filePath = "$IP/$file"; - } else { - $filePath = $file; - } - if ( $supportsParsekit ) { - $parseInfo = parsekit_compile_file( "$filePath" ); - $classes = array_keys( $parseInfo['class_table'] ); - } else { - $contents = file_get_contents( "$filePath" ); - $m = array(); - preg_match_all( '/\n\s*(?:final)?\s*(?:abstract)?\s*(?:class|interface)\s+([a-zA-Z0-9_]+)/', $contents, $m, PREG_PATTERN_ORDER ); - $classes = $m[1]; - } - foreach ( $classes as $class ) { - $actual[$class] = $file; - } - } - - return array( - 'expected' => $expected, - 'actual' => $actual, - ); - } -} diff --git a/tests/phpunit/MediaWikiLangTestCase.php b/tests/phpunit/MediaWikiLangTestCase.php index 0cf6e383..1131385f 100644 --- a/tests/phpunit/MediaWikiLangTestCase.php +++ b/tests/phpunit/MediaWikiLangTestCase.php @@ -15,6 +15,10 @@ abstract class MediaWikiLangTestCase extends MediaWikiTestCase { "\$wgContLang->getCode() (" . $wgContLang->getCode() . ")" ); } + // HACK: Call getLanguage() so the real $wgContLang is cached as the user language + // rather than our fake one. This is to avoid breaking other, unrelated tests. + RequestContext::getMain()->getLanguage(); + $langCode = 'en'; # For mainpage to be 'Main Page' $langObj = Language::factory( $langCode ); diff --git a/tests/phpunit/MediaWikiPHPUnitCommand.php b/tests/phpunit/MediaWikiPHPUnitCommand.php index 12c2e003..042956a9 100644 --- a/tests/phpunit/MediaWikiPHPUnitCommand.php +++ b/tests/phpunit/MediaWikiPHPUnitCommand.php @@ -12,13 +12,29 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { 'use-normal-tables' => false, 'reuse-db' => false, 'wiki=' => false, + 'debug-tests' => false, ); public function __construct() { foreach ( self::$additionalOptions as $option => $default ) { $this->longOptions[$option] = $option . 'Handler'; } + } + + protected function handleArguments( array $argv ) { + parent::handleArguments( $argv ); + + if ( !isset( $this->arguments['listeners'] ) ) { + $this->arguments['listeners'] = array(); + } + foreach ( $this->options[0] as $option ) { + switch ( $option[0] ) { + case '--debug-tests': + $this->arguments['listeners'][] = new MediaWikiPHPUnitTestListener( 'PHPUnitCommand' ); + break; + } + } } public static function main( $exit = true ) { @@ -86,7 +102,7 @@ class MediaWikiPHPUnitCommand extends PHPUnit_TextUI_Command { ParserTest-specific options: --regex=" " Only run parser tests that match the given regex - --file=" " Prints the version and exits. + --file=" " File describing parser tests --keep-uploads Re-use the same upload directory for each test, don't delete it @@ -95,7 +111,9 @@ Database options: --reuse-db Init DB only if tables are missing and keep after finish. +Debugging options: + --debug-tests Log testing activity to the PHPUnitCommand log channel. + EOT; } - } diff --git a/tests/phpunit/MediaWikiPHPUnitTestListener.php b/tests/phpunit/MediaWikiPHPUnitTestListener.php new file mode 100644 index 00000000..7237ef32 --- /dev/null +++ b/tests/phpunit/MediaWikiPHPUnitTestListener.php @@ -0,0 +1,114 @@ +logChannel = $logChannel; + } + + protected function getTestName( PHPUnit_Framework_Test $test ) { + $name = get_class( $test ); + + if ( $test instanceof PHPUnit_Framework_TestCase ) { + $name .= '::' . $test->getName( true ); + } + + return $name; + } + + protected function getErrorName( Exception $exception ) { + $name = get_class( $exception ); + $name = "[$name] " . $exception->getMessage(); + + return $name; + } + + /** + * An error occurred. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + */ + public function addError( PHPUnit_Framework_Test $test, Exception $e, $time ) { + wfDebugLog( $this->logChannel, 'ERROR in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + } + + /** + * A failure occurred. + * + * @param PHPUnit_Framework_Test $test + * @param PHPUnit_Framework_AssertionFailedError $e + * @param float $time + */ + public function addFailure( PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time ) { + wfDebugLog( $this->logChannel, 'FAILURE in ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + } + + /** + * Incomplete test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + */ + public function addIncompleteTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { + wfDebugLog( $this->logChannel, 'Incomplete test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + } + + /** + * Skipped test. + * + * @param PHPUnit_Framework_Test $test + * @param Exception $e + * @param float $time + * + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest( PHPUnit_Framework_Test $test, Exception $e, $time ) { + wfDebugLog( $this->logChannel, 'Skipped test ' . $this->getTestName( $test ) . ': ' . $this->getErrorName( $e ) ); + } + + /** + * A test suite started. + * + * @param PHPUnit_Framework_TestSuite $suite + * @since Method available since Release 2.2.0 + */ + public function startTestSuite( PHPUnit_Framework_TestSuite $suite ) { + wfDebugLog( $this->logChannel, 'START suite ' . $suite->getName() ); + } + + /** + * A test suite ended. + * + * @param PHPUnit_Framework_TestSuite $suite + * @since Method available since Release 2.2.0 + */ + public function endTestSuite( PHPUnit_Framework_TestSuite $suite ) { + wfDebugLog( $this->logChannel, 'END suite ' . $suite->getName() ); + } + + /** + * A test started. + * + * @param PHPUnit_Framework_Test $test + */ + public function startTest( PHPUnit_Framework_Test $test ) { + wfDebugLog( $this->logChannel, 'Start test ' . $this->getTestName( $test ) ); + } + + /** + * A test ended. + * + * @param PHPUnit_Framework_Test $test + * @param float $time + */ + public function endTest( PHPUnit_Framework_Test $test, $time ) { + wfDebugLog( $this->logChannel, 'End test ' . $this->getTestName( $test ) ); + } +} diff --git a/tests/phpunit/MediaWikiTestCase.php b/tests/phpunit/MediaWikiTestCase.php index 7e6e0ab8..6ce78b56 100644 --- a/tests/phpunit/MediaWikiTestCase.php +++ b/tests/phpunit/MediaWikiTestCase.php @@ -64,7 +64,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 'oracle' ); - function __construct( $name = null, array $data = array(), $dataName = '' ) { + function __construct( $name = null, array $data = array(), $dataName = '' ) { parent::__construct( $name, $data, $dataName ); $this->backupGlobals = false; @@ -137,6 +137,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { protected function getNewTempFile() { $fname = tempnam( wfTempDir(), 'MW_PHPUnit_' . get_class( $this ) . '_' ); $this->tmpfiles[] = $fname; + return $fname; } @@ -158,6 +159,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { // where temporary directory creation is bundled and can be improved unlink( $fname ); $this->assertTrue( wfMkdirParents( $fname ) ); + return $fname; } @@ -171,7 +173,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->called['setUp'] = 1; /* - //@todo: global variables to restore for *every* test + // @todo global variables to restore for *every* test array( 'wgLang', 'wgContLang', @@ -348,7 +350,8 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * Stub. If a test needs to add additional data to the database, it should * implement this method and do so */ - function addDBData() {} + function addDBData() { + } private function addCoreDBData() { # disabled for performance @@ -377,7 +380,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { 'page_touched' => $this->db->timestamp(), 'page_latest' => 0, 'page_len' => 0 ), __METHOD__, array( 'IGNORE' ) ); - } User::resetIdByNameCache(); @@ -394,7 +396,6 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $user->saveSettings(); } - //Make 1 page with 1 revision $page = WikiPage::factory( Title::newFromText( 'UTPage' ) ); if ( !$page->getId() == 0 ) { @@ -438,7 +439,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * even if using different parameters. * * @param DatabaseBase $db The database connection - * @param String $prefix The prefix to use for the new table set (aka schema). + * @param String $prefix The prefix to use for the new table set (aka schema). * * @throws MWException if the database table prefix is already $prefix */ @@ -461,6 +462,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( ( $db->getType() == 'oracle' || !self::$useTemporaryTables ) && self::$reuseDB ) { CloneDatabase::changePrefix( $prefix ); + return; } else { $dbClone->cloneTableStructure(); @@ -523,6 +525,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { private static function unprefixTable( $tableName ) { global $wgDBprefix; + return substr( $tableName, strlen( $wgDBprefix ) ); } @@ -534,6 +537,12 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { global $wgDBprefix; $tables = $db->listTables( $wgDBprefix, __METHOD__ ); + + if ( $db->getType() === 'mysql' ) { + # bug 43571: cannot clone VIEWs under MySQL + $views = $db->listViews( $wgDBprefix, __METHOD__ ); + $tables = array_diff( $tables, $views ); + } $tables = array_map( array( __CLASS__, 'unprefixTable' ), $tables ); // Don't duplicate test tables from the previous fataled run @@ -547,6 +556,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { unset( $tables['searchindex_segments'] ); $tables = array_flip( $tables ); } + return $tables; } @@ -561,13 +571,11 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( isset( MediaWikiPHPUnitCommand::$additionalOptions[$offset] ) ) { return MediaWikiPHPUnitCommand::$additionalOptions[$offset]; } - } public function setCliArg( $offset, $value ) { MediaWikiPHPUnitCommand::$additionalOptions[$offset] = $value; - } /** @@ -775,7 +783,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { } /** - * Returns true iff the given namespace defaults to Wikitext + * Returns true if the given namespace defaults to Wikitext * according to $wgNamespaceContentModels * * @param int $ns The namespace ID to check @@ -839,12 +847,13 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { ) { $wikitextNS = $ns; + return $wikitextNS; } } // give up - // @todo: Inside a test, we could skip the test as incomplete. + // @todo Inside a test, we could skip the test as incomplete. // But frequently, this is used in fixture setup. throw new MWException( "No namespace defaults to wikitext!" ); } @@ -906,6 +915,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { if ( !$loaded ) { $this->markTestSkipped( "PHP extension '$extName' is not loaded, skipping." ); } + return $loaded; } @@ -914,6 +924,7 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { * the provided code. * * @since 1.21 + * @deprecated since 1.22 Use setExpectedException * * @param callable $code * @param string $expected @@ -934,5 +945,4 @@ abstract class MediaWikiTestCase extends PHPUnit_Framework_TestCase { $this->assertInstanceOf( $expected, $pokemons, $message ); } - } diff --git a/tests/phpunit/StructureTest.php b/tests/phpunit/StructureTest.php deleted file mode 100644 index a9420981..00000000 --- a/tests/phpunit/StructureTest.php +++ /dev/null @@ -1,63 +0,0 @@ -markTestSkipped( 'This test does not work on Windows' ); - } - $rootPath = escapeshellarg( __DIR__ ); - $testClassRegex = implode( '|', array( - 'ApiFormatTestBase', - 'ApiTestCase', - 'ApiQueryTestBase', - 'ApiQueryContinueTestBase', - 'MediaWikiLangTestCase', - 'MediaWikiTestCase', - 'PHPUnit_Framework_TestCase', - 'DumpTestCase', - ) ); - $testClassRegex = "^class .* extends ($testClassRegex)"; - $finder = "find $rootPath -name '*.php' '!' -name '*Test.php'" . - " | xargs grep -El '$testClassRegex|function suite\('"; - - $results = null; - $exitCode = null; - exec( $finder, $results, $exitCode ); - - $this->assertEquals( - 0, - $exitCode, - 'Verify find/grep command succeeds.' - ); - - $results = array_filter( - $results, - array( $this, 'filterSuites' ) - ); - $strip = strlen( $rootPath ) - 1; - foreach ( $results as $k => $v ) { - $results[$k] = substr( $v, $strip ); - } - $this->assertEquals( - array(), - $results, - "Unit test file in $rootPath must end with Test." - ); - } - - /** - * Filter to remove testUnitTestFileNamesEndWithTest false positives. - */ - public function filterSuites( $filename ) { - return strpos( $filename, __DIR__ . '/suites/' ) !== 0; - } -} diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php index 01caf8f4..d929b79d 100644 --- a/tests/phpunit/bootstrap.php +++ b/tests/phpunit/bootstrap.php @@ -11,22 +11,5 @@ if ( !defined( 'MW_PHPUNIT_TEST' ) ) { You are running these tests directly from phpunit. You may not have all globals correctly set. Running phpunit.php instead is recommended. EOF; - require_once ( __DIR__ . "/phpunit.php" ); + require_once __DIR__ . "/phpunit.php"; } - -// Output a notice when running with older versions of PHPUnit -if ( version_compare( PHPUnit_Runner_Version::id(), "3.6.7", "<" ) ) { - echo << - array ( + array( 'CameraOwnerName' => 'Me!', ), 'xmp-general' => - array ( + array( 'LicenseUrl' => 'http://creativecommons.com/cc-by-2.9', 'ImageDescription' => - array ( + array( 'x-default' => 'Test image for the cc: xmp: xmpRights: namespaces in xmp', '_type' => 'lang', ), 'ObjectName' => - array ( + array( 'x-default' => 'xmp core/xmp rights/cc ns test', '_type' => 'lang', ), 'DateTimeDigitized' => '2005:04:03', 'Software' => 'The one true editor: Vi (ok i used gimp)', 'Identifier' => - array ( + array( 0 => 'http://example.com/identifierurl', 1 => 'urn:sha1:342524abcdef', '_type' => 'ul', @@ -33,12 +33,12 @@ $result = array ( 'RightsCertificate' => 'http://example.com/rights-certificate/', 'Copyrighted' => 'True', 'CopyrightOwner' => - array ( + array( 0 => 'Bawolff is copyright owner', '_type' => 'ul', ), 'UsageTerms' => - array ( + array( 'x-default' => 'do whatever you want', 'en-gb' => 'Do whatever you want in british english', '_type' => 'lang', @@ -46,7 +46,7 @@ $result = array ( 'WebStatement' => 'http://example.com/web_statement', ), 'xmp-deprecated' => - array ( + array( 'Identifier' => 'http://example.com/identifierurl/wrong', ), ); diff --git a/tests/phpunit/includes/ArticleTablesTest.php b/tests/phpunit/includes/ArticleTablesTest.php index 967ffa17..0f159ae4 100644 --- a/tests/phpunit/includes/ArticleTablesTest.php +++ b/tests/phpunit/includes/ArticleTablesTest.php @@ -5,7 +5,7 @@ */ class ArticleTablesTest extends MediaWikiLangTestCase { - function testbug14404() { + public function testbug14404() { global $wgContLang, $wgLanguageCode, $wgLang; $title = Title::newFromText( 'Bug 14404' ); @@ -16,18 +16,17 @@ class ArticleTablesTest extends MediaWikiLangTestCase { $wgContLang = Language::factory( 'es' ); $wgLang = Language::factory( 'fr' ); - $status = $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', 0, false, $user ); + $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', 0, false, $user ); $templates1 = $title->getTemplateLinksFrom(); $wgLang = Language::factory( 'de' ); $page->mPreparedEdit = false; // In order to force the rerendering of the same wikitext // We need an edit, a purge is not enough to regenerate the tables - $status = $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', EDIT_UPDATE, false, $user ); + $page->doEditContent( new WikitextContent( '{{:{{int:history}}}}' ), 'Test code for bug 14404', EDIT_UPDATE, false, $user ); $templates2 = $title->getTemplateLinksFrom(); $this->assertEquals( $templates1, $templates2 ); $this->assertEquals( $templates1[0]->getFullText(), 'Historial' ); } - } diff --git a/tests/phpunit/includes/ArticleTest.php b/tests/phpunit/includes/ArticleTest.php index 867c4f00..b4d6dca6 100644 --- a/tests/phpunit/includes/ArticleTest.php +++ b/tests/phpunit/includes/ArticleTest.php @@ -25,14 +25,14 @@ class ArticleTest extends MediaWikiTestCase { $this->article = null; } - function testImplementsGetMagic() { + public function testImplementsGetMagic() { $this->assertEquals( false, $this->article->mLatest, "Article __get magic" ); } /** * @depends testImplementsGetMagic */ - function testImplementsSetMagic() { + public function testImplementsSetMagic() { $this->article->mLatest = 2; $this->assertEquals( 2, $this->article->mLatest, "Article __set magic" ); } @@ -40,13 +40,13 @@ class ArticleTest extends MediaWikiTestCase { /** * @depends testImplementsSetMagic */ - function testImplementsCallMagic() { + public function testImplementsCallMagic() { $this->article->mLatest = 33; $this->article->mDataLoaded = true; $this->assertEquals( 33, $this->article->getLatest(), "Article __call magic" ); } - function testGetOrSetOnNewProperty() { + public function testGetOrSetOnNewProperty() { $this->article->ext_someNewProperty = 12; $this->assertEquals( 12, $this->article->ext_someNewProperty, "Article get/set magic on new field" ); @@ -59,7 +59,7 @@ class ArticleTest extends MediaWikiTestCase { /** * Checks for the existence of the backwards compatibility static functions (forwarders to WikiPage class) */ - function testStaticFunctions() { + public function testStaticFunctions() { $this->hideDeprecated( 'Article::getAutosummary' ); $this->hideDeprecated( 'WikiPage::getAutosummary' ); $this->hideDeprecated( 'CategoryPage::getAutosummary' ); // Inherited from Article @@ -76,7 +76,7 @@ class ArticleTest extends MediaWikiTestCase { "Article static functions" ); } - function testWikiPageFactory() { + public function testWikiPageFactory() { $title = Title::makeTitle( NS_FILE, 'Someimage.png' ); $page = WikiPage::factory( $title ); $this->assertEquals( 'WikiFilePage', get_class( $page ) ); diff --git a/tests/phpunit/includes/BlockTest.php b/tests/phpunit/includes/BlockTest.php index 19c9b687..21de0985 100644 --- a/tests/phpunit/includes/BlockTest.php +++ b/tests/phpunit/includes/BlockTest.php @@ -51,36 +51,36 @@ class BlockTest extends MediaWikiLangTestCase { } else { throw new MWException( "Failed to insert block for BlockTest; old leftover block remaining?" ); } + + $this->addXffBlocks(); } /** * debug function : dump the ipblocks table */ function dumpBlocks() { - $v = $this->db->query( 'SELECT * FROM unittest_ipblocks' ); + $v = $this->db->select( 'ipblocks', '*' ); print "Got " . $v->numRows() . " rows. Full dump follow:\n"; foreach ( $v as $row ) { print_r( $row ); } } - function testInitializerFunctionsReturnCorrectBlock() { + public function testInitializerFunctionsReturnCorrectBlock() { // $this->dumpBlocks(); $this->assertTrue( $this->block->equals( Block::newFromTarget( 'UTBlockee' ) ), "newFromTarget() returns the same block as the one that was made" ); $this->assertTrue( $this->block->equals( Block::newFromID( $this->blockId ) ), "newFromID() returns the same block as the one that was made" ); - } /** * per bug 26425 */ - function testBug26425BlockTimestampDefaultsToTime() { + public function testBug26425BlockTimestampDefaultsToTime() { // delta to stop one-off errors when things happen to go over a second mark. $delta = abs( $this->madeAt - $this->block->mTimestamp ); $this->assertLessThan( 2, $delta, "If no timestamp is specified, the block is recorded as time()" ); - } /** @@ -91,7 +91,7 @@ class BlockTest extends MediaWikiLangTestCase { * * @dataProvider provideBug29116Data */ - function testBug29116LoadWithEmptyIp( $vagueTarget ) { + public function testBug29116LoadWithEmptyIp( $vagueTarget ) { $this->hideDeprecated( 'Block::load' ); $uid = User::idFromName( 'UTBlockee' ); @@ -111,7 +111,7 @@ class BlockTest extends MediaWikiLangTestCase { * * @dataProvider provideBug29116Data */ - function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { + public function testBug29116NewFromTargetWithEmptyIp( $vagueTarget ) { $block = Block::newFromTarget( 'UTBlockee', $vagueTarget ); $this->assertTrue( $this->block->equals( $block ), "newFromTarget() returns the same block as the one that was made when given empty vagueTarget param " . var_export( $vagueTarget, true ) ); } @@ -124,14 +124,13 @@ class BlockTest extends MediaWikiLangTestCase { ); } - function testBlockedUserCanNotCreateAccount() { + public function testBlockedUserCanNotCreateAccount() { $username = 'BlockedUserToCreateAccountWith'; $u = User::newFromName( $username ); $u->setPassword( 'NotRandomPass' ); $u->addToDatabase(); unset( $u ); - // Sanity check $this->assertNull( Block::newFromTarget( $username ), @@ -185,7 +184,7 @@ class BlockTest extends MediaWikiLangTestCase { ); } - function testCrappyCrossWikiBlocks() { + public function testCrappyCrossWikiBlocks() { // Delete the last round's block if it's still there $oldBlock = Block::newFromTarget( 'UserOnForeignWiki' ); if ( $oldBlock ) { @@ -228,4 +227,128 @@ class BlockTest extends MediaWikiLangTestCase { $this->assertEquals( 'MetaWikiUser', $block->getByName(), 'Correct blocker name' ); $this->assertEquals( 0, $block->getBy(), 'Correct blocker id' ); } + + protected function addXffBlocks() { + static $inited = false; + + if ( $inited ) { + return; + } + + $inited = true; + + $blockList = array( + array( 'target' => '70.2.0.0/16', + 'type' => Block::TYPE_RANGE, + 'desc' => 'Range Hardblock', + 'ACDisable' => false, + 'isHardblock' => true, + 'isAutoBlocking' => false, + ), + array( 'target' => '2001:4860:4001::/48', + 'type' => Block::TYPE_RANGE, + 'desc' => 'Range6 Hardblock', + 'ACDisable' => false, + 'isHardblock' => true, + 'isAutoBlocking' => false, + ), + array( 'target' => '60.2.0.0/16', + 'type' => Block::TYPE_RANGE, + 'desc' => 'Range Softblock with AC Disabled', + 'ACDisable' => true, + 'isHardblock' => false, + 'isAutoBlocking' => false, + ), + array( 'target' => '50.2.0.0/16', + 'type' => Block::TYPE_RANGE, + 'desc' => 'Range Softblock', + 'ACDisable' => false, + 'isHardblock' => false, + 'isAutoBlocking' => false, + ), + array( 'target' => '50.1.1.1', + 'type' => Block::TYPE_IP, + 'desc' => 'Exact Softblock', + 'ACDisable' => false, + 'isHardblock' => false, + 'isAutoBlocking' => false, + ), + ); + + foreach ( $blockList as $insBlock ) { + $target = $insBlock['target']; + + if ( $insBlock['type'] === Block::TYPE_IP ) { + $target = User::newFromName( IP::sanitizeIP( $target ), false )->getName(); + } elseif ( $insBlock['type'] === Block::TYPE_RANGE ) { + $target = IP::sanitizeRange( $target ); + } + + $block = new Block(); + $block->setTarget( $target ); + $block->setBlocker( 'testblocker@global' ); + $block->mReason = $insBlock['desc']; + $block->mExpiry = 'infinity'; + $block->prevents( 'createaccount', $insBlock['ACDisable'] ); + $block->isHardblock( $insBlock['isHardblock'] ); + $block->isAutoblocking( $insBlock['isAutoBlocking'] ); + $block->insert(); + } + } + + public static function providerXff() { + return array( + array( 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Range Hardblock' + ), + array( 'xff' => '1.2.3.4, 50.2.1.1, 60.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Range Softblock with AC Disabled' + ), + array( 'xff' => '1.2.3.4, 70.2.1.1, 50.1.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Exact Softblock' + ), + array( 'xff' => '1.2.3.4, 70.2.1.1, 50.2.1.1, 50.1.1.1, 2.3.4.5', + 'count' => 3, + 'result' => 'Exact Softblock' + ), + array( 'xff' => '1.2.3.4, 70.2.1.1, 50.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Range Hardblock' + ), + array( 'xff' => '1.2.3.4, 70.2.1.1, 60.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Range Hardblock' + ), + array( 'xff' => '50.2.1.1, 60.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Range Softblock with AC Disabled' + ), + array( 'xff' => '1.2.3.4, 50.1.1.1, 60.2.1.1, 2.3.4.5', + 'count' => 2, + 'result' => 'Exact Softblock' + ), + array( 'xff' => '1.2.3.4, <$A_BUNCH-OF{INVALID}TEXT\>, 60.2.1.1, 2.3.4.5', + 'count' => 1, + 'result' => 'Range Softblock with AC Disabled' + ), + array( 'xff' => '1.2.3.4, 50.2.1.1, 2001:4860:4001:802::1003, 2.3.4.5', + 'count' => 2, + 'result' => 'Range6 Hardblock' + ), + ); + } + + /** + * @dataProvider providerXff + */ + public function testBlocksOnXff( $xff, $exCount, $exResult ) { + $list = array_map( 'trim', explode( ',', $xff ) ); + $xffblocks = Block::getBlocksForIPList( $list, true ); + $this->assertEquals( $exCount, count( $xffblocks ), 'Number of blocks for ' . $xff ); + $block = Block::chooseBlock( $xffblocks, $list ); + $this->assertEquals( $exResult, $block->mReason, 'Correct block type for XFF header ' . $xff ); + } } diff --git a/tests/phpunit/includes/CdbTest.php b/tests/phpunit/includes/CdbTest.php index add585d7..e3d9da7c 100644 --- a/tests/phpunit/includes/CdbTest.php +++ b/tests/phpunit/includes/CdbTest.php @@ -66,7 +66,6 @@ class CdbTest extends MediaWikiTestCase { $this->cdbAssert( "PHP error", $key, $v1, $value ); $this->cdbAssert( "DBA error", $key, $v2, $value ); } - } private function randomString() { @@ -75,6 +74,7 @@ class CdbTest extends MediaWikiTestCase { for ( $j = 0; $j < $len; $j++ ) { $s .= chr( mt_rand( 0, 255 ) ); } + return $s; } diff --git a/tests/phpunit/includes/CollationTest.php b/tests/phpunit/includes/CollationTest.php index c746208b..43bb3941 100644 --- a/tests/phpunit/includes/CollationTest.php +++ b/tests/phpunit/includes/CollationTest.php @@ -20,7 +20,7 @@ class CollationTest extends MediaWikiLangTestCase { * * @dataProvider prefixDataProvider */ - function testIsPrefix( $lang, $base, $extended ) { + public function testIsPrefix( $lang, $base, $extended ) { $cp = Collator::create( $lang ); $cp->setStrength( Collator::PRIMARY ); $baseBin = $cp->getSortKey( $base ); @@ -47,12 +47,13 @@ class CollationTest extends MediaWikiLangTestCase { array( 'en', 'A', 'Aꦲ' ), ); } + /** * Opposite of testIsPrefix * * @dataProvider notPrefixDataProvider */ - function testNotIsPrefix( $lang, $base, $extended ) { + public function testNotIsPrefix( $lang, $base, $extended ) { $cp = Collator::create( $lang ); $cp->setStrength( Collator::PRIMARY ); $baseBin = $cp->getSortKey( $base ); @@ -80,10 +81,11 @@ class CollationTest extends MediaWikiLangTestCase { * * @dataProvider firstLetterProvider */ - function testGetFirstLetter( $collation, $string, $firstLetter ) { + public function testGetFirstLetter( $collation, $string, $firstLetter ) { $col = Collation::factory( $collation ); $this->assertEquals( $firstLetter, $col->getFirstLetter( $string ) ); } + function firstLetterProvider() { return array( array( 'uppercase', 'Abc', 'A' ), diff --git a/tests/phpunit/includes/DiffHistoryBlobTest.php b/tests/phpunit/includes/DiffHistoryBlobTest.php index dcd9dddf..a4d5b91a 100644 --- a/tests/phpunit/includes/DiffHistoryBlobTest.php +++ b/tests/phpunit/includes/DiffHistoryBlobTest.php @@ -4,14 +4,17 @@ class DiffHistoryBlobTest extends MediaWikiTestCase { protected function setUp() { if ( !extension_loaded( 'xdiff' ) ) { $this->markTestSkipped( 'The xdiff extension is not available' ); + return; } if ( !function_exists( 'xdiff_string_rabdiff' ) ) { $this->markTestSkipped( 'The version of xdiff extension is lower than 1.5.0' ); + return; } - if ( !extension_loaded( 'hash' ) && !extension_loaded( 'mhash' ) ) { - $this->markTestSkipped( 'Neither the hash nor mhash extension is available' ); + if ( !extension_loaded( 'hash' ) ) { + $this->markTestSkipped( 'The hash extension is not available' ); + return; } parent::setUp(); @@ -21,7 +24,7 @@ class DiffHistoryBlobTest extends MediaWikiTestCase { * Test for DiffHistoryBlob::xdiffAdler32() * @dataProvider provideXdiffAdler32 */ - function testXdiffAdler32( $input ) { + public function testXdiffAdler32( $input ) { $xdiffHash = substr( xdiff_string_rabdiff( $input, '' ), 0, 4 ); $dhb = new DiffHistoryBlob; $myHash = $dhb->xdiffAdler32( $input ); diff --git a/tests/phpunit/includes/EditPageTest.php b/tests/phpunit/includes/EditPageTest.php index 00eba30a..87272a4c 100644 --- a/tests/phpunit/includes/EditPageTest.php +++ b/tests/phpunit/includes/EditPageTest.php @@ -9,12 +9,12 @@ * @group medium * ^--- tell phpunit that these test cases may take longer than 2 seconds. */ -class EditPageTest extends MediaWikiTestCase { +class EditPageTest extends MediaWikiLangTestCase { /** * @dataProvider provideExtractSectionTitle */ - function testExtractSectionTitle( $section, $title ) { + public function testExtractSectionTitle( $section, $title ) { $extracted = EditPage::extractSectionTitle( $section ); $this->assertEquals( $title, $extracted ); } @@ -173,15 +173,90 @@ class EditPageTest extends MediaWikiTestCase { } public function testCreatePage() { - $text = "Hello World!"; - $edit = array( - 'wpTextbox1' => $text, - 'wpSummary' => 'just testing', + $this->assertEdit( + 'EditPageTest_testCreatePage', + null, + null, + array( + 'wpTextbox1' => "Hello World!", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "Hello World!", + "expected article being created" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'EditPageTest_testCreatePage', + null, + null, + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected article not being created if empty" + ); + + + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "Not January", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "Not January", + "expected MediaWiki: page being created" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'MediaWiki:EditPageTest_testCreatePage', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected not-registered MediaWiki: page not being created if empty" ); - $this->assertEdit( 'EditPageTest_testCreatePafe', null, null, $edit, - EditPage::AS_SUCCESS_NEW_ARTICLE, $text, - "expected successfull creation with given text" ); + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_SUCCESS_NEW_ARTICLE, + "", + "expected registered MediaWiki: page being created even if empty" + )->doDeleteArticleReal( 'EditPageTest_testCreatePage' ); + + $this->assertEdit( + 'MediaWiki:Ipb-default-expiry', + null, + 'UTSysop', + array( + 'wpTextbox1' => "", + ), + EditPage::AS_BLANK_ARTICLE, + "", + "expected registered MediaWiki: page whose default content is empty not being created if empty" + ); + + $this->assertEdit( + 'MediaWiki:January', + null, + 'UTSysop', + array( + 'wpTextbox1' => "January", + ), + EditPage::AS_BLANK_ARTICLE, + null, + "expected MediaWiki: page not being created if text equals default message" + ); } public function testUpdatePage() { diff --git a/tests/phpunit/includes/ExternalStoreTest.php b/tests/phpunit/includes/ExternalStoreTest.php index 99544e7e..fcffcbc2 100644 --- a/tests/phpunit/includes/ExternalStoreTest.php +++ b/tests/phpunit/includes/ExternalStoreTest.php @@ -5,7 +5,7 @@ class ExternalStoreTest extends MediaWikiTestCase { - function testExternalFetchFromURL() { + public function testExternalFetchFromURL() { $this->setMwGlobals( 'wgExternalStores', false ); $this->assertFalse( diff --git a/tests/phpunit/includes/ExtraParserTest.php b/tests/phpunit/includes/ExtraParserTest.php index 067cfc4a..6c67beb1 100644 --- a/tests/phpunit/includes/ExtraParserTest.php +++ b/tests/phpunit/includes/ExtraParserTest.php @@ -27,7 +27,7 @@ class ExtraParserTest extends MediaWikiTestCase { } // Bug 8689 - Long numeric lines kill the parser - function testBug8689() { + public function testBug8689() { global $wgUser; $longLine = '1.' . str_repeat( '1234567890', 100000 ) . "\n"; @@ -38,13 +38,13 @@ class ExtraParserTest extends MediaWikiTestCase { } /* Test the parser entry points */ - function testParse() { + public function testParse() { $title = Title::newFromText( __FUNCTION__ ); $parserOutput = $this->parser->parse( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); $this->assertEquals( " Test\nContent of Template:Foo\nContent of Template:Bar\n
", $parserOutput->getText() ); } - function testPreSaveTransform() { + public function testPreSaveTransform() { global $wgUser; $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->preSaveTransform( "Test\r\n{{subst:Foo}}\n{{Bar}}", $title, $wgUser, $this->options ); @@ -52,7 +52,7 @@ class ExtraParserTest extends MediaWikiTestCase { $this->assertEquals( "Test\nContent of ''Template:Foo''\n{{Bar}}", $outputText ); } - function testPreprocess() { + public function testPreprocess() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->preprocess( "Test\n{{Foo}}\n{{Bar}}", $title, $this->options ); @@ -62,7 +62,7 @@ class ExtraParserTest extends MediaWikiTestCase { /** * cleanSig() makes all templates substs and removes tildes */ - function testCleanSig() { + public function testCleanSig() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); @@ -72,9 +72,8 @@ class ExtraParserTest extends MediaWikiTestCase { /** * cleanSig() should do nothing if disabled */ - function testCleanSigDisabled() { - global $wgCleanSignatures; - $wgCleanSignatures = false; + public function testCleanSigDisabled() { + $this->setMwGlobals( 'wgCleanSignatures', false ); $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->cleanSig( "{{Foo}} ~~~~" ); @@ -86,7 +85,7 @@ class ExtraParserTest extends MediaWikiTestCase { * cleanSigInSig() just removes tildes * @dataProvider provideStringsForCleanSigInSig */ - function testCleanSigInSig( $in, $out ) { + public function testCleanSigInSig( $in, $out ) { $this->assertEquals( Parser::cleanSigInSig( $in ), $out ); } @@ -98,7 +97,7 @@ class ExtraParserTest extends MediaWikiTestCase { ); } - function testGetSection() { + public function testGetSection() { $outputText2 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 2 ); $outputText1 = $this->parser->getSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1 ); @@ -106,7 +105,7 @@ class ExtraParserTest extends MediaWikiTestCase { $this->assertEquals( "== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2", $outputText1 ); } - function testReplaceSection() { + public function testReplaceSection() { $outputText = $this->parser->replaceSection( "Section 0\n== Heading 1 ==\nSection 1\n=== Heading 2 ===\nSection 2\n== Heading 3 ==\nSection 3\n", 1, "New section 1" ); $this->assertEquals( "Section 0\nNew section 1\n\n== Heading 3 ==\nSection 3", $outputText ); @@ -115,7 +114,7 @@ class ExtraParserTest extends MediaWikiTestCase { /** * Templates and comments are not affected, but noinclude/onlyinclude is. */ - function testGetPreloadText() { + public function testGetPreloadText() { $title = Title::newFromText( __FUNCTION__ ); $outputText = $this->parser->getPreloadText( "{{Foo}}censored information ", $title, $this->options ); @@ -135,7 +134,7 @@ class ExtraParserTest extends MediaWikiTestCase { /** * @group Database */ - function testTrackingCategory() { + public function testTrackingCategory() { $title = Title::newFromText( __FUNCTION__ ); $catName = wfMessage( 'broken-file-category' )->inContentLanguage()->text(); $cat = Title::makeTitleSafe( NS_CATEGORY, $catName ); @@ -148,7 +147,7 @@ class ExtraParserTest extends MediaWikiTestCase { /** * @group Database */ - function testTrackingCategorySpecial() { + public function testTrackingCategorySpecial() { // Special pages shouldn't have tracking cats. $title = SpecialPage::getTitleFor( 'Contributions' ); $parserOutput = $this->parser->parse( "[[file:nonexistent]]", $title, $this->options ); diff --git a/tests/phpunit/includes/FallbackTest.php b/tests/phpunit/includes/FallbackTest.php new file mode 100644 index 00000000..f408f471 --- /dev/null +++ b/tests/phpunit/includes/FallbackTest.php @@ -0,0 +1,73 @@ +markTestSkipped( "The mb_string functions must be installed to test the fallback functions" ); + } + + $sampleUTF = "Östergötland_coat_of_arms.png"; + + //mb_substr + $substr_params = array( + array( 0, 0 ), + array( 5, -4 ), + array( 33 ), + array( 100, -5 ), + array( -8, 10 ), + array( 1, 1 ), + array( 2, -1 ) + ); + + foreach ( $substr_params as $param_set ) { + $old_param_set = $param_set; + array_unshift( $param_set, $sampleUTF ); + + $this->assertEquals( + call_user_func_array( 'mb_substr', $param_set ), + call_user_func_array( 'Fallback::mb_substr', $param_set ), + 'Fallback mb_substr with params ' . implode( ', ', $old_param_set ) + ); + } + + //mb_strlen + $this->assertEquals( + mb_strlen( $sampleUTF ), + Fallback::mb_strlen( $sampleUTF ), + 'Fallback mb_strlen' + ); + + //mb_str(r?)pos + $strpos_params = array( + //array( 'ter' ), + //array( 'Ö' ), + //array( 'Ö', 3 ), + //array( 'oat_', 100 ), + //array( 'c', -10 ), + //Broken for now + ); + + foreach ( $strpos_params as $param_set ) { + $old_param_set = $param_set; + array_unshift( $param_set, $sampleUTF ); + + $this->assertEquals( + call_user_func_array( 'mb_strpos', $param_set ), + call_user_func_array( 'Fallback::mb_strpos', $param_set ), + 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set ) + ); + + $this->assertEquals( + call_user_func_array( 'mb_strrpos', $param_set ), + call_user_func_array( 'Fallback::mb_strrpos', $param_set ), + 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set ) + ); + } + } + +} \ No newline at end of file diff --git a/tests/phpunit/includes/FauxRequestTest.php b/tests/phpunit/includes/FauxRequestTest.php new file mode 100644 index 00000000..9f3aa11d --- /dev/null +++ b/tests/phpunit/includes/FauxRequestTest.php @@ -0,0 +1,15 @@ +setHeader( 'Content-Type', $value ); + + $this->assertEquals( $request->getHeader( 'Content-Type' ), $value ); + $this->assertEquals( $request->getHeader( 'CONTENT-TYPE' ), $value ); + $this->assertEquals( $request->getHeader( 'content-type' ), $value ); + } +} diff --git a/tests/phpunit/includes/FauxResponseTest.php b/tests/phpunit/includes/FauxResponseTest.php index 56691c9e..f9ba1b3b 100644 --- a/tests/phpunit/includes/FauxResponseTest.php +++ b/tests/phpunit/includes/FauxResponseTest.php @@ -30,13 +30,13 @@ class FauxResponseTest extends MediaWikiTestCase { $this->response = new FauxResponse; } - function testCookie() { + public function testCookie() { $this->assertEquals( null, $this->response->getcookie( 'key' ), 'Non-existing cookie' ); $this->response->setcookie( 'key', 'val' ); $this->assertEquals( 'val', $this->response->getcookie( 'key' ), 'Existing cookie' ); } - function testHeader() { + public function testHeader() { $this->assertEquals( null, $this->response->getheader( 'Location' ), 'Non-existing header' ); $this->response->header( 'Location: http://localhost/' ); @@ -47,9 +47,12 @@ class FauxResponseTest extends MediaWikiTestCase { $this->response->header( 'Location: http://127.0.0.2/', false ); $this->assertEquals( 'http://127.0.0.1/', $this->response->getheader( 'Location' ), 'Same header with override disabled' ); + + $this->response->header( 'Location: http://localhost/' ); + $this->assertEquals( 'http://localhost/', $this->response->getheader( 'LOCATION' ), 'Get header case insensitive' ); } - function testResponseCode() { + public function testResponseCode() { $this->response->header( 'HTTP/1.1 200' ); $this->assertEquals( 200, $this->response->getStatusCode(), 'Header with no message' ); diff --git a/tests/phpunit/includes/FormOptionsInitializationTest.php b/tests/phpunit/includes/FormOptionsInitializationTest.php index 4053683f..fb2304dc 100644 --- a/tests/phpunit/includes/FormOptionsInitializationTest.php +++ b/tests/phpunit/includes/FormOptionsInitializationTest.php @@ -81,5 +81,4 @@ class FormOptionsInitializationTest extends MediaWikiTestCase { $this->object->getOptions() ); } - } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php index 24fc47cf..6154df1d 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalTest.php @@ -29,7 +29,10 @@ class GlobalTest extends MediaWikiTestCase { parent::tearDown(); } - /** @dataProvider provideForWfArrayDiff2 */ + /** + * @dataProvider provideForWfArrayDiff2 + * @covers ::wfArrayDiff2 + */ public function testWfArrayDiff2( $a, $b, $expected ) { $this->assertEquals( wfArrayDiff2( $a, $b ), $expected @@ -53,25 +56,37 @@ class GlobalTest extends MediaWikiTestCase { ); } - function testRandom() { + /** + * @covers ::wfRandom + */ + public function testRandom() { # This could hypothetically fail, but it shouldn't ;) $this->assertFalse( wfRandom() == wfRandom() ); } - function testUrlencode() { + /** + * @covers ::wfUrlencode + */ + public function testUrlencode() { $this->assertEquals( "%E7%89%B9%E5%88%A5:Contributions/Foobar", wfUrlencode( "\xE7\x89\xB9\xE5\x88\xA5:Contributions/Foobar" ) ); } - function testExpandIRI() { + /** + * @covers ::wfExpandIRI + */ + public function testExpandIRI() { $this->assertEquals( "https://te.wikibooks.org/wiki/ఉబుంటు_వాడుకరి_మార్గదర్శని", wfExpandIRI( "https://te.wikibooks.org/wiki/%E0%B0%89%E0%B0%AC%E0%B1%81%E0%B0%82%E0%B0%9F%E0%B1%81_%E0%B0%B5%E0%B0%BE%E0%B0%A1%E0%B1%81%E0%B0%95%E0%B0%B0%E0%B0%BF_%E0%B0%AE%E0%B0%BE%E0%B0%B0%E0%B1%8D%E0%B0%97%E0%B0%A6%E0%B0%B0%E0%B1%8D%E0%B0%B6%E0%B0%A8%E0%B0%BF" ) ); } - function testReadOnlyEmpty() { + /** + * @covers ::wfReadOnly + */ + public function testReadOnlyEmpty() { global $wgReadOnly; $wgReadOnly = null; @@ -79,7 +94,10 @@ class GlobalTest extends MediaWikiTestCase { $this->assertFalse( wfReadOnly() ); } - function testReadOnlySet() { + /** + * @covers ::wfReadOnly + */ + public function testReadOnlySet() { global $wgReadOnly, $wgReadOnlyFile; $f = fopen( $wgReadOnlyFile, "wt" ); @@ -97,19 +115,6 @@ class GlobalTest extends MediaWikiTestCase { $this->assertFalse( wfReadOnly() ); } - function testQuotedPrintable() { - $this->assertEquals( - "=?UTF-8?Q?=C4=88u=20legebla=3F?=", - UserMailer::quotedPrintable( "\xc4\x88u legebla?", "UTF-8" ) ); - } - - function testTime() { - $start = wfTime(); - $this->assertInternalType( 'float', $start ); - $end = wfTime(); - $this->assertTrue( $end > $start, "Time is running backwards!" ); - } - public static function provideArrayToCGI() { return array( array( array(), '' ), // empty @@ -130,13 +135,17 @@ class GlobalTest extends MediaWikiTestCase { /** * @dataProvider provideArrayToCGI + * @covers ::wfArrayToCgi */ - function testArrayToCGI( $array, $result ) { + public function testArrayToCGI( $array, $result ) { $this->assertEquals( $result, wfArrayToCgi( $array ) ); } - function testArrayToCGI2() { + /** + * @covers ::testWfArrayDiff2 + */ + public function testArrayToCGI2() { $this->assertEquals( "baz=bar&foo=bar", wfArrayToCgi( @@ -161,8 +170,9 @@ class GlobalTest extends MediaWikiTestCase { /** * @dataProvider provideCgiToArray + * @covers ::wfCgiToArray */ - function testCgiToArray( $cgi, $result ) { + public function testCgiToArray( $cgi, $result ) { $this->assertEquals( $result, wfCgiToArray( $cgi ) ); } @@ -181,12 +191,16 @@ class GlobalTest extends MediaWikiTestCase { /** * @dataProvider provideCgiRoundTrip + * @covers ::wfArrayToCgi */ - function testCgiRoundTrip( $cgi ) { + public function testCgiRoundTrip( $cgi ) { $this->assertEquals( $cgi, wfArrayToCgi( wfCgiToArray( $cgi ) ) ); } - function testMimeTypeMatch() { + /** + * @covers ::mimeTypeMatch + */ + public function testMimeTypeMatch() { $this->assertEquals( 'text/html', mimeTypeMatch( 'text/html', @@ -208,7 +222,10 @@ class GlobalTest extends MediaWikiTestCase { 'image/svg+xml' => 0.5 ) ) ); } - function testNegotiateType() { + /** + * @covers ::wfNegotiateType + */ + public function testNegotiateType() { $this->assertEquals( 'text/html', wfNegotiateType( @@ -249,77 +266,11 @@ class GlobalTest extends MediaWikiTestCase { array( 'application/xhtml+xml' => 1.0 ) ) ); } - function testFallbackMbstringFunctions() { - - if ( !extension_loaded( 'mbstring' ) ) { - $this->markTestSkipped( "The mb_string functions must be installed to test the fallback functions" ); - } - - $sampleUTF = "Östergötland_coat_of_arms.png"; - - - //mb_substr - $substr_params = array( - array( 0, 0 ), - array( 5, -4 ), - array( 33 ), - array( 100, -5 ), - array( -8, 10 ), - array( 1, 1 ), - array( 2, -1 ) - ); - - foreach ( $substr_params as $param_set ) { - $old_param_set = $param_set; - array_unshift( $param_set, $sampleUTF ); - - $this->assertEquals( - MWFunction::callArray( 'mb_substr', $param_set ), - MWFunction::callArray( 'Fallback::mb_substr', $param_set ), - 'Fallback mb_substr with params ' . implode( ', ', $old_param_set ) - ); - } - - - //mb_strlen - $this->assertEquals( - mb_strlen( $sampleUTF ), - Fallback::mb_strlen( $sampleUTF ), - 'Fallback mb_strlen' - ); - - - //mb_str(r?)pos - $strpos_params = array( - //array( 'ter' ), - //array( 'Ö' ), - //array( 'Ö', 3 ), - //array( 'oat_', 100 ), - //array( 'c', -10 ), - //Broken for now - ); - - foreach ( $strpos_params as $param_set ) { - $old_param_set = $param_set; - array_unshift( $param_set, $sampleUTF ); - - $this->assertEquals( - MWFunction::callArray( 'mb_strpos', $param_set ), - MWFunction::callArray( 'Fallback::mb_strpos', $param_set ), - 'Fallback mb_strpos with params ' . implode( ', ', $old_param_set ) - ); - - $this->assertEquals( - MWFunction::callArray( 'mb_strrpos', $param_set ), - MWFunction::callArray( 'Fallback::mb_strrpos', $param_set ), - 'Fallback mb_strrpos with params ' . implode( ', ', $old_param_set ) - ); - } - - } - - - function testDebugFunctionTest() { + /** + * @covers ::wfDebug + * @covers ::wfDebugMem + */ + public function testDebugFunctionTest() { global $wgDebugLogFile, $wgDebugTimestamps; @@ -329,7 +280,6 @@ class GlobalTest extends MediaWikiTestCase { $old_wgDebugTimestamps = $wgDebugTimestamps; $wgDebugTimestamps = false; - wfDebug( "This is a normal string" ); $this->assertEquals( "This is a normal string", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); @@ -338,7 +288,6 @@ class GlobalTest extends MediaWikiTestCase { $this->assertEquals( "This is nöt an ASCII string", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); - wfDebug( "\00305This has böth UTF and control chars\003" ); $this->assertEquals( " 05This has böth UTF and control chars ", file_get_contents( $wgDebugLogFile ) ); unlink( $wgDebugLogFile ); @@ -351,12 +300,14 @@ class GlobalTest extends MediaWikiTestCase { $this->assertGreaterThan( 5000000, preg_replace( '/\D/', '', file_get_contents( $wgDebugLogFile ) ) ); unlink( $wgDebugLogFile ); - $wgDebugLogFile = $old_log_file; $wgDebugTimestamps = $old_wgDebugTimestamps; } - function testClientAcceptsGzipTest() { + /** + * @covers ::wfClientAcceptsGzip + */ + public function testClientAcceptsGzipTest() { $settings = array( 'gzip' => true, @@ -387,7 +338,10 @@ class GlobalTest extends MediaWikiTestCase { } } - function testSwapVarsTest() { + /** + * @covers ::swap + */ + public function testSwapVarsTest() { $var1 = 1; $var2 = 2; @@ -398,10 +352,12 @@ class GlobalTest extends MediaWikiTestCase { $this->assertEquals( $var1, 2, 'var1 is swapped' ); $this->assertEquals( $var2, 1, 'var2 is swapped' ); - } - function testWfPercentTest() { + /** + * @covers ::wfPercent + */ + public function testWfPercentTest() { $pcts = array( array( 6 / 7, '0.86%', 2, false ), @@ -429,6 +385,7 @@ class GlobalTest extends MediaWikiTestCase { /** * test @see wfShorthandToInteger() * @dataProvider provideShorthand + * @covers ::wfShorthandToInteger */ public function testWfShorthandToInteger( $shorthand, $expected ) { $this->assertEquals( $expected, @@ -439,7 +396,7 @@ class GlobalTest extends MediaWikiTestCase { /** array( shorthand, expected integer ) */ public static function provideShorthand() { return array( - # Null, empty ... + # Null, empty ... array( '', -1 ), array( ' ', -1 ), array( null, -1 ), @@ -489,6 +446,7 @@ class GlobalTest extends MediaWikiTestCase { * * @dataProvider provideMerge() * @group medium + * @covers ::wfMerge */ public function testMerge( $old, $mine, $yours, $expectedMergeResult, $expectedText ) { $this->checkHasDiff3(); @@ -564,13 +522,14 @@ class GlobalTest extends MediaWikiTestCase { /** * @dataProvider provideMakeUrlIndexes() + * @covers ::wfMakeUrlIndexes */ - function testMakeUrlIndexes( $url, $expected ) { + public function testMakeUrlIndexes( $url, $expected ) { $index = wfMakeUrlIndexes( $url ); $this->assertEquals( $expected, $index, "wfMakeUrlIndexes(\"$url\")" ); } - function provideMakeUrlIndexes() { + public static function provideMakeUrlIndexes() { return array( array( // just a regular :) @@ -621,13 +580,14 @@ class GlobalTest extends MediaWikiTestCase { /** * @dataProvider provideWfMatchesDomainList + * @covers ::wfMatchesDomainList */ - function testWfMatchesDomainList( $url, $domains, $expected, $description ) { + public function testWfMatchesDomainList( $url, $domains, $expected, $description ) { $actual = wfMatchesDomainList( $url, $domains ); $this->assertEquals( $expected, $actual, $description ); } - function provideWfMatchesDomainList() { + public static function provideWfMatchesDomainList() { $a = array(); $protocols = array( 'HTTP' => 'http:', 'HTTPS' => 'https:', 'protocol-relative' => '' ); foreach ( $protocols as $pDesc => $p ) { @@ -638,18 +598,30 @@ class GlobalTest extends MediaWikiTestCase { array( "$p//www.example2.com", array( 'www.example.com', 'www.example2.com', 'www.example3.com' ), true, "Exact match with other domains in array, $pDesc URL" ), array( "$p//www.example2.com", array( 'example.com', 'example2.com', 'example3,com' ), true, "Match without subdomain with other domains in array, $pDesc URL" ), array( "$p//www.example4.com", array( 'example.com', 'example2.com', 'example3,com' ), false, "Domain not in array, $pDesc URL" ), - - // FIXME: This is a bug in wfMatchesDomainList(). If and when this is fixed, update this test case - array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), true, "Substrings of domains match while they shouldn't, $pDesc URL" ), + array( "$p//nds-nl.wikipedia.org", array( 'nl.wikipedia.org' ), false, "Non-matching substring of domain, $pDesc URL" ), ) ); } + return $a; } + /** + * @covers ::wfMkdirParents + */ + public function testWfMkdirParents() { + // Should not return true if file exists instead of directory + $fname = $this->getNewTempFile(); + wfSuppressWarnings(); + $ok = wfMkdirParents( $fname ); + wfRestoreWarnings(); + $this->assertFalse( $ok ); + } + /** * @dataProvider provideWfShellMaintenanceCmdList + * @covers ::wfShellMaintenanceCmd */ - function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) { + public function testWfShellMaintenanceCmd( $script, $parameters, $options, $expected, $description ) { if ( wfIsWindows() ) { // Approximation that's good enough for our purposes just now $expected = str_replace( "'", '"', $expected ); @@ -658,8 +630,9 @@ class GlobalTest extends MediaWikiTestCase { $this->assertEquals( $expected, $actual, $description ); } - function provideWfShellMaintenanceCmdList() { + public static function provideWfShellMaintenanceCmdList() { global $wgPhpCli; + return array( array( 'eval.php', array( '--help', '--test' ), array(), "'$wgPhpCli' 'eval.php' '--help' '--test'", @@ -675,5 +648,5 @@ class GlobalTest extends MediaWikiTestCase { "Called eval.php --help --test with wrapper and php option" ), ); } - /* TODO: many more! */ + /* @TODO many more! */ } diff --git a/tests/phpunit/includes/GlobalFunctions/GlobalWithDBTest.php b/tests/phpunit/includes/GlobalFunctions/GlobalWithDBTest.php index 4879a38d..cf891e7b 100644 --- a/tests/phpunit/includes/GlobalFunctions/GlobalWithDBTest.php +++ b/tests/phpunit/includes/GlobalFunctions/GlobalWithDBTest.php @@ -6,13 +6,15 @@ class GlobalWithDBTest extends MediaWikiTestCase { /** * @dataProvider provideWfIsBadImageList + * @covers ::wfIsBadImage */ - function testWfIsBadImage( $name, $title, $blacklist, $expected, $desc ) { + public function testWfIsBadImage( $name, $title, $blacklist, $expected, $desc ) { $this->assertEquals( $expected, wfIsBadImage( $name, $title, $blacklist ), $desc ); } - function provideWfIsBadImageList() { + public static function provideWfIsBadImageList() { $blacklist = '* [[File:Bad.jpg]] except [[Nasty page]]'; + return array( array( 'Bad.jpg', false, $blacklist, true, 'Called on a bad image' ), diff --git a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php index 4bd8c685..9bb74873 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfAssembleUrlTest.php @@ -1,9 +1,11 @@ assertEquals( @@ -87,7 +89,6 @@ class WfAssembleUrlTest extends MediaWikiTestCase { $url .= '#' . $fragment; } - $cases[] = array( $parts, $url, diff --git a/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php b/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php index 8df038dd..a01c0d49 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php +++ b/tests/phpunit/includes/GlobalFunctions/wfBCP47Test.php @@ -1,6 +1,6 @@ assertEquals( $expected, wfBCP47( $code ), "Applying BCP47 standard to lower case '$code'" @@ -28,7 +28,7 @@ class WfBCP47Test extends MediaWikiTestCase { /** * Array format is ($code, $expected) */ - function provideLanguageCodes() { + public static function provideLanguageCodes() { return array( // Extracted from BCP47 (list not exhaustive) # 2.1.1 @@ -115,20 +115,6 @@ class WfBCP47Test extends MediaWikiTestCase { // de-419-DE // a-DE // ar-a-aaa-b-bbb-a-ccc - - /* - // ISO 15924 : - array( 'sr-Cyrl', 'sr-Cyrl' ), - # @todo FIXME: Fix our function? - array( 'SR-lATN', 'sr-Latn' ), - array( 'fr-latn', 'fr-Latn' ), - // Use lowercase for single segment - // ISO 3166-1-alpha-2 code - array( 'US', 'us' ), # USA - array( 'uS', 'us' ), # USA - array( 'Fr', 'fr' ), # France - array( 'va', 'va' ), # Holy See (Vatican City State) - */ ); } } diff --git a/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php b/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php index 10b62b3c..7da804e6 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfBaseConvertTest.php @@ -1,6 +1,6 @@ assertEquals( $basename, wfBaseName( $fullpath ), "wfBaseName('$fullpath') => '$basename'" ); } - function providePaths() { + public static function providePaths() { return array( array( '', '' ), array( '/', '' ), diff --git a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php index c1225e3e..41230a1e 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfExpandUrlTest.php @@ -1,16 +1,17 @@ setMwGlobals( array( + 'wgServer' => $server, + 'wgCanonicalServer' => $canServer, + ) ); // Fake $_SERVER['HTTPS'] if needed if ( $httpsMode ) { @@ -20,10 +21,6 @@ class WfExpandUrlTest extends MediaWikiTestCase { } $this->assertEquals( $fullUrl, wfExpandUrl( $shortUrl, $defaultProto ), $message ); - - // Restore $wgServer and $wgCanonicalServer - $wgServer = $oldServer; - $wgCanonicalServer = $oldCanServer; } /** @@ -108,6 +105,7 @@ class WfExpandUrlTest extends MediaWikiTestCase { } } } + return $retval; } } diff --git a/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php b/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php index 58cf6b95..62296245 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfGetCallerTest.php @@ -1,8 +1,11 @@ assertEquals( __METHOD__, wfGetCaller( 1 ) ); } @@ -10,7 +13,7 @@ class WfGetCallerTest extends MediaWikiTestCase { return wfGetCaller(); } - function testOne() { + public function testOne() { $this->assertEquals( 'WfGetCallerTest::testOne', self::callerOne() ); } @@ -18,18 +21,20 @@ class WfGetCallerTest extends MediaWikiTestCase { if ( $n > 0 ) { return self::intermediateFunction( $level, $n - 1 ); } + return wfGetCaller( $level ); } - function testTwo() { + public function testTwo() { $this->assertEquals( 'WfGetCallerTest::testTwo', self::intermediateFunction() ); } - function testN() { + public function testN() { $this->assertEquals( 'WfGetCallerTest::testN', self::intermediateFunction( 2, 0 ) ); $this->assertEquals( 'WfGetCallerTest::intermediateFunction', self::intermediateFunction( 1, 0 ) ); - for ( $i = 0; $i < 10; $i++ ) + for ( $i = 0; $i < 10; $i++ ) { $this->assertEquals( 'WfGetCallerTest::intermediateFunction', self::intermediateFunction( $i + 1, $i ) ); + } } } diff --git a/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php b/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php index 841a1b12..5032dc11 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfParseUrlTest.php @@ -1,7 +1,5 @@ assertEquals( diff --git a/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php b/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php index 67861eeb..238a2c9c 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfRemoveDotSegmentsTest.php @@ -1,9 +1,11 @@ assertEquals( $outputPath, diff --git a/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php b/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php index 9d66d6b9..aadec87f 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfShorthandToIntegerTest.php @@ -1,10 +1,13 @@ assertEquals( wfShorthandToInteger( $input ), $output, @@ -12,7 +15,7 @@ class WfShorthandToIntegerTest extends MediaWikiTestCase { ); } - function provideABunchOfShorthands() { + public static function provideABunchOfShorthands() { return array( array( '', -1, 'Empty string' ), array( ' ', -1, 'String of spaces' ), @@ -24,5 +27,4 @@ class WfShorthandToIntegerTest extends MediaWikiTestCase { array( '1k', 1024, 'One kb lowercased' ), ); } - } diff --git a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php index cf1830f5..5998f186 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfTimestampTest.php @@ -1,17 +1,18 @@ assertEquals( $output, wfTimestamp( $format, $input ), $desc ); } - function provideNormalTimestamps() { + public static function provideNormalTimestamps() { $t = gmmktime( 12, 34, 56, 1, 15, 2001 ); + return array( // TS_UNIX array( $t, TS_MW, '20010115123456', 'TS_UNIX to TS_MW' ), @@ -56,11 +57,11 @@ class WfTimestampTest extends MediaWikiTestCase { * See r74778 and bug 25451 * @dataProvider provideOldTimestamps */ - function testOldTimestamps( $input, $format, $output, $desc ) { + public function testOldTimestamps( $input, $format, $output, $desc ) { $this->assertEquals( $output, wfTimestamp( $format, $input ), $desc ); } - function provideOldTimestamps() { + public static function provideOldTimestamps() { return array( array( '19011213204554', TS_RFC2822, 'Fri, 13 Dec 1901 20:45:54 GMT', 'Earliest time according to php documentation' ), array( '20380119031407', TS_RFC2822, 'Tue, 19 Jan 2038 03:14:07 GMT', 'Latest 32 bit time' ), @@ -95,11 +96,11 @@ class WfTimestampTest extends MediaWikiTestCase { * @see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.3.1 * @dataProvider provideHttpDates */ - function testHttpDate( $input, $output, $desc ) { + public function testHttpDate( $input, $output, $desc ) { $this->assertEquals( $output, wfTimestamp( TS_MW, $input ), $desc ); } - function provideHttpDates() { + public static function provideHttpDates() { return array( array( 'Sun, 06 Nov 1994 08:49:37 GMT', '19941106084937', 'RFC 822 date' ), array( 'Sunday, 06-Nov-94 08:49:37 GMT', '19941106084937', 'RFC 850 date' ), @@ -113,9 +114,9 @@ class WfTimestampTest extends MediaWikiTestCase { * There are a number of assumptions in our codebase where wfTimestamp() * should give the current date but it is not given a 0 there. See r71751 CR */ - function testTimestampParameter() { + public function testTimestampParameter() { $now = wfTimestamp( TS_UNIX ); - // We check that wfTimestamp doesn't return false (error) and use a LessThan assert + // We check that wfTimestamp doesn't return false (error) and use a LessThan assert // for the cases where the test is run in a second boundary. $zero = wfTimestamp( TS_UNIX, 0 ); diff --git a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php index 77685d50..ce6c82c5 100644 --- a/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php +++ b/tests/phpunit/includes/GlobalFunctions/wfUrlencodeTest.php @@ -1,18 +1,21 @@ verifyEncodingFor( 'Apache', $input, $expected ); } - /** @dataProvider provideURLS */ + /** + * @dataProvider provideURLS + */ public function testEncodingUrlWithMicrosoftIis7( $input, $expected ) { $this->verifyEncodingFor( 'Microsoft-IIS/7', $input, $expected ); } diff --git a/tests/phpunit/includes/HTMLCheckMatrixTest.php b/tests/phpunit/includes/HTMLCheckMatrixTest.php new file mode 100644 index 00000000..5bbafd37 --- /dev/null +++ b/tests/phpunit/includes/HTMLCheckMatrixTest.php @@ -0,0 +1,102 @@ + array( 'r1', 'r2' ), + 'columns' => array( 'c1', 'c2' ), + 'fieldname' => 'test', + ); + + public function testPlainInstantiation() { + try { + $form = new HTMLCheckMatrix( array() ); + } catch ( MWException $e ) { + $this->assertInstanceOf( 'HTMLFormFieldRequiredOptionsException', $e ); + return; + } + + $this->fail( 'Expected MWException indicating missing parameters but none was thrown.' ); + } + + public function testInstantiationWithMinimumRequiredParameters() { + $form = new HTMLCheckMatrix( self::$defaultOptions ); + $this->assertTrue( true ); // form instantiation must throw exception on failure + } + + public function testValidateCallsUserDefinedValidationCallback() { + $called = false; + $field = new HTMLCheckMatrix( self::$defaultOptions + array( + 'validation-callback' => function() use ( &$called ) { + $called = true; + return false; + }, + ) ); + $this->assertEquals( false, $this->validate( $field, array() ) ); + $this->assertTrue( $called ); + } + + public function testValidateRequiresArrayInput() { + $field = new HTMLCheckMatrix( self::$defaultOptions ); + $this->assertEquals( false, $this->validate( $field, null ) ); + $this->assertEquals( false, $this->validate( $field, true ) ); + $this->assertEquals( false, $this->validate( $field, 'abc' ) ); + $this->assertEquals( false, $this->validate( $field, new stdClass ) ); + $this->assertEquals( true, $this->validate( $field, array() ) ); + } + + public function testValidateAllowsOnlyKnownTags() { + $field = new HTMLCheckMatrix( self::$defaultOptions ); + $this->assertInternalType( 'string', $this->validate( $field, array( 'foo' ) ) ); + } + + public function testValidateAcceptsPartialTagList() { + $field = new HTMLCheckMatrix( self::$defaultOptions ); + $this->assertTrue( $this->validate( $field, array() ) ); + $this->assertTrue( $this->validate( $field, array( 'c1-r1' ) ) ); + $this->assertTrue( $this->validate( $field, array( 'c1-r1', 'c1-r2', 'c2-r1', 'c2-r2' ) ) ); + } + + /** + * This form object actually has no visibility into what happens later on, but essentially + * if the data submitted by the user passes validate the following is run: + * foreach ( $field->filterDataForSubmit( $data ) as $k => $v ) { + * $user->setOption( $k, $v ); + * } + */ + public function testValuesForcedOnRemainOn() { + $field = new HTMLCheckMatrix( self::$defaultOptions + array( + 'force-options-on' => array( 'c2-r1' ), + ) ); + $expected = array( + 'c1-r1' => false, + 'c1-r2' => false, + 'c2-r1' => true, + 'c2-r2' => false, + ); + $this->assertEquals( $expected, $field->filterDataForSubmit( array() ) ); + } + + public function testValuesForcedOffRemainOff() { + $field = new HTMLCheckMatrix( self::$defaultOptions + array( + 'force-options-off' => array( 'c1-r2', 'c2-r2' ), + ) ); + $expected = array( + 'c1-r1' => true, + 'c1-r2' => false, + 'c2-r1' => true, + 'c2-r2' => false, + ); + // array_keys on the result simulates submitting all fields checked + $this->assertEquals( $expected, $field->filterDataForSubmit( array_keys( $expected ) ) ); + } + + protected function validate( HTMLFormField $field, $submitted ) { + return $field->validate( + $submitted, + array( self::$defaultOptions['fieldname'] => $submitted ) + ); + } +} diff --git a/tests/phpunit/includes/HashRingTest.php b/tests/phpunit/includes/HashRingTest.php new file mode 100644 index 00000000..65f13696 --- /dev/null +++ b/tests/phpunit/includes/HashRingTest.php @@ -0,0 +1,53 @@ + 1, 's2' => 1, 's3' => 2, 's4' => 2, 's5' => 2, 's6' => 3 ) ); + + $locations = array(); + for ( $i = 0; $i < 20; $i++ ) { + $locations[ "hello$i"] = $ring->getLocation( "hello$i" ); + } + $expectedLocations = array( + "hello0" => "s5", + "hello1" => "s6", + "hello2" => "s2", + "hello3" => "s5", + "hello4" => "s6", + "hello5" => "s4", + "hello6" => "s5", + "hello7" => "s4", + "hello8" => "s5", + "hello9" => "s5", + "hello10" => "s3", + "hello11" => "s6", + "hello12" => "s1", + "hello13" => "s3", + "hello14" => "s3", + "hello15" => "s5", + "hello16" => "s4", + "hello17" => "s6", + "hello18" => "s6", + "hello19" => "s3" + ); + + $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' ); + + $locations = array(); + for ( $i = 0; $i < 5; $i++ ) { + $locations[ "hello$i"] = $ring->getLocations( "hello$i", 2 ); + } + + $expectedLocations = array( + "hello0" => array( "s5", "s6" ), + "hello1" => array( "s6", "s4" ), + "hello2" => array( "s2", "s1" ), + "hello3" => array( "s5", "s6" ), + "hello4" => array( "s6", "s4" ), + ); + $this->assertEquals( $expectedLocations, $locations, 'Items placed at proper locations' ); + } +} diff --git a/tests/phpunit/includes/HooksTest.php b/tests/phpunit/includes/HooksTest.php index 89e789b1..81dd4870 100644 --- a/tests/phpunit/includes/HooksTest.php +++ b/tests/phpunit/includes/HooksTest.php @@ -2,81 +2,62 @@ class HooksTest extends MediaWikiTestCase { - public function testOldStyleHooks() { - $foo = 'Foo'; - $bar = 'Bar'; - - $i = new NothingClass(); - + function setUp() { global $wgHooks; - - $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStatic' ); - - wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'fOO', $foo, 'Standard method' ); - $foo = 'Foo'; - - $wgHooks['MediaWikiHooksTest001'][] = $i; - - wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'foo', $foo, 'onEventName style' ); - $foo = 'Foo'; - - $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someNonStaticWithData', 'baz' ); - - wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'baz', $foo, 'Data included' ); - $foo = 'Foo'; - - $wgHooks['MediaWikiHooksTest001'][] = array( $i, 'someStatic' ); - - wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'bah', $foo, 'Standard static method' ); - //$foo = 'Foo'; - + parent::setUp(); + Hooks::clear( 'MediaWikiHooksTest001' ); unset( $wgHooks['MediaWikiHooksTest001'] ); - } - public function testNewStyleHooks() { - $foo = 'Foo'; - $bar = 'Bar'; - + public static function provideHooks() { $i = new NothingClass(); - Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStatic' ) ); - - Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'fOO', $foo, 'Standard method' ); - $foo = 'Foo'; - - Hooks::register( 'MediaWikiHooksTest001', $i ); - - Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - - $this->assertEquals( 'foo', $foo, 'onEventName style' ); - $foo = 'Foo'; + return array( + array( 'Object and method', array( $i, 'someNonStatic' ), 'changed-nonstatic', 'changed-nonstatic' ), + array( 'Object and no method', array( $i ), 'changed-onevent', 'original' ), + array( 'Object and method with data', array( $i, 'someNonStaticWithData', 'data' ), 'data', 'original' ), + array( 'Object and static method', array( $i, 'someStatic' ), 'changed-static', 'original' ), + array( 'Class::method static call', array( 'NothingClass::someStatic' ), 'changed-static', 'original' ), + array( 'Global function', array( 'NothingFunction' ), 'changed-func', 'original' ), + array( 'Global function with data', array( 'NothingFunctionData', 'data' ), 'data', 'original' ), + array( 'Closure', array( function ( &$foo, $bar ) { + $foo = 'changed-closure'; + + return true; + } ), 'changed-closure', 'original' ), + array( 'Closure with data', array( function ( $data, &$foo, $bar ) { + $foo = $data; + + return true; + }, 'data' ), 'data', 'original' ) + ); + } - Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someNonStaticWithData', 'baz' ) ); + /** + * @dataProvider provideHooks + */ + public function testOldStyleHooks( $msg, array $hook, $expectedFoo, $expectedBar ) { + global $wgHooks; + $foo = $bar = 'original'; - Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); + $wgHooks['MediaWikiHooksTest001'][] = $hook; + wfRunHooks( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - $this->assertEquals( 'baz', $foo, 'Data included' ); - $foo = 'Foo'; + $this->assertSame( $expectedFoo, $foo, $msg ); + $this->assertSame( $expectedBar, $bar, $msg ); + } - Hooks::register( 'MediaWikiHooksTest001', array( $i, 'someStatic' ) ); + /** + * @dataProvider provideHooks + */ + public function testNewStyleHooks( $msg, $hook, $expectedFoo, $expectedBar ) { + $foo = $bar = 'original'; + Hooks::register( 'MediaWikiHooksTest001', $hook ); Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); - $this->assertEquals( 'bah', $foo, 'Standard static method' ); - $foo = 'Foo'; - - Hooks::clear( 'MediaWikiHooksTest001' ); + $this->assertSame( $expectedFoo, $foo, $msg ); + $this->assertSame( $expectedBar, $bar, $msg ); } public function testNewStyleHookInteraction() { @@ -85,10 +66,6 @@ class HooksTest extends MediaWikiTestCase { $a = new NothingClass(); $b = new NothingClass(); - // make sure to start with a clean slate - Hooks::clear( 'MediaWikiHooksTest001' ); - unset( $wgHooks['MediaWikiHooksTest001'] ); - $wgHooks['MediaWikiHooksTest001'][] = $a; $this->assertTrue( Hooks::isRegistered( 'MediaWikiHooksTest001' ), 'Hook registered via $wgHooks should be noticed by Hooks::isRegistered' ); @@ -101,37 +78,81 @@ class HooksTest extends MediaWikiTestCase { Hooks::run( 'MediaWikiHooksTest001', array( &$foo, &$bar ) ); $this->assertEquals( 1, $a->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register' ); $this->assertEquals( 1, $b->calls, 'Hooks::run() should run hooks registered via wgHooks as well as Hooks::register' ); + } - // clean up - Hooks::clear( 'MediaWikiHooksTest001' ); - unset( $wgHooks['MediaWikiHooksTest001'] ); + /** + * @expectedException MWException + */ + public function testUncallableFunction() { + Hooks::register( 'MediaWikiHooksTest001', 'ThisFunctionDoesntExist' ); + Hooks::run( 'MediaWikiHooksTest001', array() ); } + + public function testFalseReturn() { + Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) { + return false; + } ); + Hooks::register( 'MediaWikiHooksTest001', function ( &$foo ) { + $foo = 'test'; + + return true; + } ); + $foo = 'original'; + Hooks::run( 'MediaWikiHooksTest001', array( &$foo ) ); + $this->assertSame( 'original', $foo, 'Hooks continued processing after a false return.' ); + } + + /** + * @expectedException FatalError + */ + public function testFatalError() { + Hooks::register( 'MediaWikiHooksTest001', function () { + return 'test'; + } ); + Hooks::run( 'MediaWikiHooksTest001', array() ); + } +} + +function NothingFunction( &$foo, &$bar ) { + $foo = 'changed-func'; + + return true; +} + +function NothingFunctionData( $data, &$foo, &$bar ) { + $foo = $data; + + return true; } class NothingClass { public $calls = 0; public static function someStatic( &$foo, &$bar ) { - $foo = 'bah'; + $foo = 'changed-static'; + return true; } public function someNonStatic( &$foo, &$bar ) { $this->calls++; - $foo = 'fOO'; - $bar = 'bAR'; + $foo = 'changed-nonstatic'; + $bar = 'changed-nonstatic'; + return true; } public function onMediaWikiHooksTest001( &$foo, &$bar ) { $this->calls++; - $foo = 'foo'; + $foo = 'changed-onevent'; + return true; } - public function someNonStaticWithData( $foo, &$bar ) { + public function someNonStaticWithData( $data, &$foo, &$bar ) { $this->calls++; - $bar = $foo; + $foo = $data; + return true; } } diff --git a/tests/phpunit/includes/HtmlFormatterTest.php b/tests/phpunit/includes/HtmlFormatterTest.php new file mode 100644 index 00000000..a37df74f --- /dev/null +++ b/tests/phpunit/includes/HtmlFormatterTest.php @@ -0,0 +1,81 @@ +filterContent(); + $html = $formatter->getText(); + $this->assertEquals( self::normalize( $expected ), self::normalize( $html ) ); + } + + private static function normalize( $s ) { + return str_replace( "\n", '', + str_replace( "\r", '', $s ) // "yay" to Windows! + ); + } + + public function getHtmlData() { + $removeImages = function( HtmlFormatter $f ) { + $f->setRemoveMedia(); + }; + $removeTags = function( HtmlFormatter $f ) { + $f->remove( array( 'table', '.foo', '#bar', 'div.baz' ) ); + }; + $flattenSomeStuff = function( HtmlFormatter $f ) { + $f->flatten( array( 's', 'div' ) ); + }; + $flattenEverything = function( HtmlFormatter $f ) { + $f->flattenAllTags(); + }; + return array( + // remove images if asked + array( + '', + '', + $removeImages, + ), + // basic tag removal + array( + '
foo foofoobar +foobartest+baz', + + 'test+baz', + $removeTags, + ), + // don't flatten tags that start like chosen ones + array( + '', + 'foo bar', + $flattenSomeStuff, + ), + // total flattening + array( + 'foobarbar2', + 'bar2', + $flattenEverything, + ), + // UTF-8 preservation and security + array( + '<Тест!> &<&&&&', + '<Тест!> &<&&&&', + ), + // https://bugzilla.wikimedia.org/show_bug.cgi?id=53086 + array( + 'Foo[1] Bar', + 'Foo[1] Bar', + ), + ); + } +} diff --git a/tests/phpunit/includes/HtmlTest.php b/tests/phpunit/includes/HtmlTest.php index 590664e8..1c62d032 100644 --- a/tests/phpunit/includes/HtmlTest.php +++ b/tests/phpunit/includes/HtmlTest.php @@ -37,14 +37,11 @@ class HtmlTest extends MediaWikiTestCase { 'wgLanguageCode' => $langCode, 'wgContLang' => $langObj, 'wgLang' => $langObj, - 'wgHtml5' => true, 'wgWellFormedXml' => false, ) ); } public function testElementBasics() { - global $wgWellFormedXml; - $this->assertEquals( '', Html::element( 'img', null, '' ), @@ -63,7 +60,7 @@ class HtmlTest extends MediaWikiTestCase { 'Close tag for empty element (array, string)' ); - $wgWellFormedXml = true; + $this->setMwGlobals( 'wgWellFormedXml', true ); $this->assertEquals( '', @@ -72,6 +69,31 @@ class HtmlTest extends MediaWikiTestCase { ); } + public function dataXmlMimeType() { + return array( + // ( $mimetype, $isXmlMimeType ) + # HTML is not an XML MimeType + array( 'text/html', false ), + # XML is an XML MimeType + array( 'text/xml', true ), + array( 'application/xml', true ), + # XHTML is an XML MimeType + array( 'application/xhtml+xml', true ), + # Make sure other +xml MimeTypes are supported + # SVG is another random MimeType even though we don't use it + array( 'image/svg+xml', true ), + # Complete random other MimeTypes are not XML + array( 'text/plain', false ), + ); + } + + /** + * @dataProvider dataXmlMimeType + */ + public function testXmlMimeType( $mimetype, $isXmlMimeType ) { + $this->assertEquals( $isXmlMimeType, Html::isXmlMimeType( $mimetype ) ); + } + public function testExpandAttributesSkipsNullAndFalse() { ### EMPTY ######## @@ -90,8 +112,6 @@ class HtmlTest extends MediaWikiTestCase { } public function testExpandAttributesForBooleans() { - global $wgHtml5, $wgWellFormedXml; - $this->assertEquals( '', Html::expandAttributes( array( 'selected' => false ) ), @@ -114,21 +134,13 @@ class HtmlTest extends MediaWikiTestCase { 'Boolean attributes have no value when value is true (passed as numerical array)' ); - $wgWellFormedXml = true; + $this->setMwGlobals( 'wgWellFormedXml', true ); $this->assertEquals( ' selected=""', Html::expandAttributes( array( 'selected' => true ) ), 'Boolean attributes have empty string value when value is true (wgWellFormedXml)' ); - - $wgHtml5 = false; - - $this->assertEquals( - ' selected="selected"', - Html::expandAttributes( array( 'selected' => true ) ), - 'Boolean attributes have their key as value when value is true (wgWellFormedXml, wgHTML5 = false)' - ); } /** @@ -136,8 +148,6 @@ class HtmlTest extends MediaWikiTestCase { * Please note it output a string prefixed with a space! */ public function testExpandAttributesVariousExpansions() { - global $wgWellFormedXml; - ### NOT EMPTY #### $this->assertEquals( ' empty_string=""', @@ -160,7 +170,7 @@ class HtmlTest extends MediaWikiTestCase { 'Number 0 value needs no quotes' ); - $wgWellFormedXml = true; + $this->setMwGlobals( 'wgWellFormedXml', true ); $this->assertEquals( ' empty_string=""', @@ -240,7 +250,7 @@ class HtmlTest extends MediaWikiTestCase { * Test feature added by r96188, let pass attributes values as * a PHP array. Restricted to class,rel, accesskey. */ - function testExpandAttributesSpaceSeparatedAttributesWithBoolean() { + public function testExpandAttributesSpaceSeparatedAttributesWithBoolean() { $this->assertEquals( ' class="booltrue one"', Html::expandAttributes( array( 'class' => array( @@ -264,7 +274,7 @@ class HtmlTest extends MediaWikiTestCase { * * Feature added by r96188 */ - function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() { + public function testValueIsAuthoritativeInSpaceSeparatedAttributesArrays() { $this->assertEquals( ' class=""', Html::expandAttributes( array( 'class' => array( @@ -275,7 +285,7 @@ class HtmlTest extends MediaWikiTestCase { ); } - function testNamespaceSelector() { + public function testNamespaceSelector() { $this->assertEquals( '