Commit badb271f82906638acc066c5070e3dba8f5d4351
- Diff rendering mode:
- inline
- side by side
t/creole.php
(599 / 0)
|   | |||
| 1 | <?php | ||
| 2 | |||
| 3 | require_once('./test-more.php'); | ||
| 4 | require_once('../creole.php'); | ||
| 5 | |||
| 6 | $tests = array( | ||
| 7 | array( | ||
| 8 | 'name' => "Basic paragraph markup", | ||
| 9 | 'input' => "Basic paragraph test with <, >, & and \"", | ||
| 10 | 'output' => "<p>Basic paragraph test with <, >, & and "</p>" | ||
| 11 | ), | ||
| 12 | array( | ||
| 13 | 'name' => "Simple unordered list", | ||
| 14 | 'input' => "* list item\n*list item 2", | ||
| 15 | 'output' => "<ul><li> list item</li>\n<li>list item 2</li></ul>" | ||
| 16 | ), | ||
| 17 | array( | ||
| 18 | 'name' => "Simple ordered list", | ||
| 19 | 'input' => "# list item\n#list item 2", | ||
| 20 | 'output' => "<ol><li> list item</li>\n<li>list item 2</li></ol>" | ||
| 21 | ), | ||
| 22 | array( // Test an ul item with a sublist | ||
| 23 | 'name' => "Unordered item with unordered sublist", | ||
| 24 | 'input' => "* Item\n** Subitem", | ||
| 25 | 'output' => "<ul><li> Item<ul>\n<li> Subitem</li></ul></li></ul>" | ||
| 26 | ), | ||
| 27 | array( // Test an ol item with a sublist | ||
| 28 | 'name' => "Ordered item with ordered sublist", | ||
| 29 | 'input' => "# Item\n## Subitem", | ||
| 30 | 'output' => "<ol><li> Item<ol>\n<li> Subitem</li></ol></li></ol>" | ||
| 31 | ), | ||
| 32 | array( // Test a sublist without an initial tag (should not make a list) | ||
| 33 | 'name' => "Ordered sublist without initial tag", | ||
| 34 | 'input' => "## Sublist item", | ||
| 35 | 'output' => "<p>## Sublist item</p>" | ||
| 36 | ), | ||
| 37 | array( // Test an unordered list with an ordered sublist | ||
| 38 | 'name' => "Unordered item with ordered sublist", | ||
| 39 | 'input' => "* Item\n*# Subitem", | ||
| 40 | 'output' => "<ul><li> Item<ol>\n<li> Subitem</li></ol></li></ul>" | ||
| 41 | ), | ||
| 42 | array( | ||
| 43 | 'name' => "Multiline unordered item", | ||
| 44 | 'input' => "* Item\nstill continues", | ||
| 45 | 'output' => "<ul><li> Item\nstill continues</li></ul>" | ||
| 46 | ), | ||
| 47 | array( | ||
| 48 | 'name' => "Multiline ordered item", | ||
| 49 | 'input' => "# Item\nstill continues", | ||
| 50 | 'output' => "<ol><li> Item\nstill continues</li></ol>" | ||
| 51 | ), | ||
| 52 | array( | ||
| 53 | 'name' => "Unordered list and paragraph", | ||
| 54 | 'input' => "* Item\n\nParagraph", | ||
| 55 | 'output' => "<ul><li> Item</li>\n</ul><p>\nParagraph</p>" | ||
| 56 | ), | ||
| 57 | array( | ||
| 58 | 'name' => "Ordered list and paragraph", | ||
| 59 | 'input' => "# Item\n\nParagraph", | ||
| 60 | 'output' => "<ol><li> Item</li>\n</ol><p>\nParagraph</p>" | ||
| 61 | ), | ||
| 62 | array( | ||
| 63 | 'name' => "Unordered list with leading whitespace", | ||
| 64 | 'input' => " \t* Item", | ||
| 65 | 'output' => "<ul><li> Item</li></ul>" | ||
| 66 | ), | ||
| 67 | array( | ||
| 68 | 'name' => "Ordered list with leading whitespace", | ||
| 69 | 'input' => " \t# Item", | ||
| 70 | 'output' => "<ol><li> Item</li></ol>" | ||
| 71 | ), | ||
| 72 | array( | ||
| 73 | 'name' => "Unordered list with bold item", | ||
| 74 | 'input' => "* Item\n* **Bold item**", | ||
| 75 | 'output' => "<ul><li> Item</li>\n<li> <strong>Bold item</strong></li></ul>" | ||
| 76 | ), | ||
| 77 | array( | ||
| 78 | 'name' => "Ordered list with bold item", | ||
| 79 | 'input' => "# Item\n# **Bold item**", | ||
| 80 | 'output' => "<ol><li> Item</li>\n<li> <strong>Bold item</strong></li></ol>" | ||
| 81 | ), | ||
| 82 | array( // Test hr | ||
| 83 | 'name' => "Horizontal rule", | ||
| 84 | 'input' => "Some text\n----\nSome more text", | ||
| 85 | 'output' => "<p>Some text</p><hr/><p>Some more text</p>" | ||
| 86 | ), | ||
| 87 | array( // Test pre block | ||
| 88 | 'name' => "Preformatted block", | ||
| 89 | 'input' => "{{{\nPreformatted block\n}}}", | ||
| 90 | 'output' => "<pre>Preformatted block\n</pre>" | ||
| 91 | ), | ||
| 92 | array( // Test two pre blocks | ||
| 93 | 'name' => "Two preformatted blocks", | ||
| 94 | 'input' => "{{{\nPreformatted block\n}}}\n{{{Block 2}}}", | ||
| 95 | 'output' => "<pre>Preformatted block\n</pre><p><tt>Block 2</tt></p>" | ||
| 96 | ), | ||
| 97 | array( | ||
| 98 | 'name' => "Space escapes nowiki", | ||
| 99 | 'input' => "{{{\nPreformatted block\n }}}\n}}}", | ||
| 100 | 'output' => "<pre>Preformatted block\n}}}\n</pre>" | ||
| 101 | ), | ||
| 102 | array( | ||
| 103 | 'name' => "Inline nowiki with trailing braces", | ||
| 104 | 'input' => "{{{foo}}}}}}", | ||
| 105 | 'output' => "<p><tt>foo}}}</tt></p>" | ||
| 106 | ), | ||
| 107 | array( // Test h1 | ||
| 108 | 'name' => "h1", | ||
| 109 | 'input' => "= Header =", | ||
| 110 | 'output' => "<h1>Header</h1>" | ||
| 111 | ), | ||
| 112 | array( // Test h2 | ||
| 113 | 'name' => "h2", | ||
| 114 | 'input' => "== Header =", | ||
| 115 | 'output' => "<h2>Header</h2>" | ||
| 116 | ), | ||
| 117 | array( // Test h3 | ||
| 118 | 'name' => "h3", | ||
| 119 | 'input' => "=== Header =", | ||
| 120 | 'output' => "<h3>Header</h3>" | ||
| 121 | ), | ||
| 122 | array( // Test h4 | ||
| 123 | 'name' => "h4", | ||
| 124 | 'input' => "==== Header =", | ||
| 125 | 'output' => "<h4>Header</h4>" | ||
| 126 | ), | ||
| 127 | array( // Test h5 | ||
| 128 | 'name' => "h5", | ||
| 129 | 'input' => "===== Header", | ||
| 130 | 'output' => "<h5>Header</h5>" | ||
| 131 | ), | ||
| 132 | array( // Test h6 | ||
| 133 | 'name' => "h6", | ||
| 134 | 'input' => "====== Header =", | ||
| 135 | 'output' => "<h6>Header</h6>" | ||
| 136 | ), | ||
| 137 | array( // Test above h6 (should be ignored) | ||
| 138 | 'name' => ">h6", | ||
| 139 | 'input' => "======= Header =", | ||
| 140 | 'output' => "<p>======= Header =</p>" | ||
| 141 | ), | ||
| 142 | array( // Test h1 ending with tilde | ||
| 143 | 'name' => "h1 ending with tilde", | ||
| 144 | 'input' => "= Header ~", | ||
| 145 | 'output' => "<h1>Header ~</h1>" | ||
| 146 | ), | ||
| 147 | array( // Test h2 ending with tilde | ||
| 148 | 'name' => "h2 ending with tilde", | ||
| 149 | 'input' => "== Header ~", | ||
| 150 | 'output' => "<h2>Header ~</h2>" | ||
| 151 | ), | ||
| 152 | array( // Test h3 ending with tilde | ||
| 153 | 'name' => "h3 ending with tilde", | ||
| 154 | 'input' => "=== Header ~", | ||
| 155 | 'output' => "<h3>Header ~</h3>" | ||
| 156 | ), | ||
| 157 | array( // Test h4 ending with tilde | ||
| 158 | 'name' => "h4 ending with tilde", | ||
| 159 | 'input' => "==== Header ~", | ||
| 160 | 'output' => "<h4>Header ~</h4>" | ||
| 161 | ), | ||
| 162 | array( // Test h5 ending with tilde | ||
| 163 | 'name' => "h5 ending with tilde", | ||
| 164 | 'input' => "===== Header ~", | ||
| 165 | 'output' => "<h5>Header ~</h5>" | ||
| 166 | ), | ||
| 167 | array( // Test h6 ending with tilde | ||
| 168 | 'name' => "h6 ending with tilde", | ||
| 169 | 'input' => "====== Header ~", | ||
| 170 | 'output' => "<h6>Header ~</h6>" | ||
| 171 | ), | ||
| 172 | array( | ||
| 173 | 'name' => "Tables", | ||
| 174 | 'input' => "| A | B |\n| C | D |", | ||
| 175 | 'output' => "<table><tr><td> A </td><td> B </td></tr>" + | ||
| 176 | "<tr><td> C </td><td> D </td></tr></table>" | ||
| 177 | ), | ||
| 178 | array( | ||
| 179 | 'name' => "Tables without trailing pipe", | ||
| 180 | 'input' => "| A | B\n| C | D", | ||
| 181 | 'output' => "<table><tr><td> A </td><td> B</td></tr>" + | ||
| 182 | "<tr><td> C </td><td> D</td></tr></table>" | ||
| 183 | ), | ||
| 184 | array( | ||
| 185 | 'name' => "Table headers", | ||
| 186 | 'input' => "|= A | B |\n| C |= D |", | ||
| 187 | 'output' => "<table><tr><th> A </th><td> B </td></tr>" + | ||
| 188 | "<tr><td> C </td><th> D </th></tr></table>" | ||
| 189 | ), | ||
| 190 | array( | ||
| 191 | 'name' => "Table inline markup", | ||
| 192 | 'input' => "| A | B |\n| //C// | **D** \\\\ E |", | ||
| 193 | 'output' => "<table><tr><td> A </td><td> B </td></tr>" + | ||
| 194 | "<tr><td> <em>C</em> </td>" + | ||
| 195 | "<td> <strong>D</strong> <br /> E </td></tr></table>" | ||
| 196 | ), | ||
| 197 | array( | ||
| 198 | 'name' => "Escaped table inline markup", | ||
| 199 | 'input' => "| A | B |\n| {{{//C//}}} | {{{**D** \\\\ E}}} |", | ||
| 200 | 'output' => "<table><tr><td> A </td><td> B </td></tr>" + | ||
| 201 | "<tr><td> <tt>//C//</tt> </td>" + | ||
| 202 | "<td> <tt>**D** \\\\ E</tt> </td></tr></table>" | ||
| 203 | ), | ||
| 204 | array( // Test raw URL | ||
| 205 | 'name' => "Raw URL", | ||
| 206 | 'input' => "http://example.com/examplepage", | ||
| 207 | 'output' => "<p><a href=\"http://example.com/examplepage\">" + | ||
| 208 | "http://example.com/examplepage</a></p>" | ||
| 209 | ), | ||
| 210 | array( | ||
| 211 | 'name' => "Raw URL with tilde", | ||
| 212 | 'input' => "http://example.com/~user", | ||
| 213 | 'output' => "<p><a href=\"http://example.com/~user\">" + | ||
| 214 | "http://example.com/~user</a></p>" | ||
| 215 | ), | ||
| 216 | array( // Test unnamed URL | ||
| 217 | 'name' => "Unnamed URL", | ||
| 218 | 'input' => "[[http://example.com/examplepage]]", | ||
| 219 | 'output' => "<p><a href=\"http://example.com/examplepage\">" + | ||
| 220 | "http://example.com/examplepage</a></p>" | ||
| 221 | ), | ||
| 222 | array( | ||
| 223 | 'name' => "Unnamed URL with tilde", | ||
| 224 | 'input' => "[[http://example.com/~user]]", | ||
| 225 | 'output' => "<p><a href=\"http://example.com/~user\">" + | ||
| 226 | "http://example.com/~user</a></p>" | ||
| 227 | ), | ||
| 228 | array( // Test named URL | ||
| 229 | 'name' => "Named URL", | ||
| 230 | 'input' => "[[http://example.com/examplepage|Example Page]]", | ||
| 231 | 'output' => "<p>" + | ||
| 232 | "<a href=\"http://example.com/examplepage\">Example Page</a></p>" | ||
| 233 | ), | ||
| 234 | array( // Test unnamed link | ||
| 235 | 'name' => "Unnamed link", | ||
| 236 | 'input' => "[[MyPage]]", | ||
| 237 | 'output' => "<p><a href=\"/wiki/MyPage\">MyPage</a></p>" | ||
| 238 | ), | ||
| 239 | array( // Test named link | ||
| 240 | 'name' => "Named link", | ||
| 241 | 'input' => "[[MyPage|My page]]", | ||
| 242 | 'output' => "<p><a href=\"/wiki/MyPage\">My page</a></p>" | ||
| 243 | ), | ||
| 244 | array( | ||
| 245 | 'name' => "Unnamed interwiki link", | ||
| 246 | 'input' => "[[WikiCreole:Creole1.0]]", | ||
| 247 | 'output' => "<p><a href=\"http://www.wikicreole.org/wiki/Creole1.0\">WikiCreole:Creole1.0</a></p>" | ||
| 248 | ), | ||
| 249 | array( | ||
| 250 | 'name' => "Named interwiki link", | ||
| 251 | 'input' => "[[WikiCreole:Creole1.0|Creole 1.0]]", | ||
| 252 | 'output' => "<p><a href=\"http://www.wikicreole.org/wiki/Creole1.0\">Creole 1.0</a></p>" | ||
| 253 | ), | ||
| 254 | array( // Test images | ||
| 255 | 'name' => "Image", | ||
| 256 | 'input' => "{{image.gif|my image}}", | ||
| 257 | 'output' => "<p><img src=\"image.gif\" alt=\"my image\"/></p>" | ||
| 258 | ), | ||
| 259 | array( // Test inline tt | ||
| 260 | 'name' => "Inline tt", | ||
| 261 | 'input' => "Inline {{{tt}}} example {{{here}}}!", | ||
| 262 | 'output' => "<p>Inline <tt>tt</tt> example <tt>here</tt>!</p>" | ||
| 263 | ), | ||
| 264 | array( // Test **strong** | ||
| 265 | 'name' => "Strong", | ||
| 266 | 'input' => "**Strong**", | ||
| 267 | 'output' => "<p><strong>Strong</strong></p>" | ||
| 268 | ), | ||
| 269 | array( // Test runaway **strong | ||
| 270 | 'name' => "Runaway strong #1", | ||
| 271 | 'input' => "**Strong", | ||
| 272 | 'output' => "<p><strong>Strong</strong></p>" | ||
| 273 | ), | ||
| 274 | array( | ||
| 275 | 'name' => "Runaway strong #2", | ||
| 276 | 'input' => "** Strong *", | ||
| 277 | 'output' => "<p><strong> Strong *</strong></p>" | ||
| 278 | ), | ||
| 279 | array( // Test //emphasis// | ||
| 280 | 'name' => "Emphasis", | ||
| 281 | 'input' => "//Emphasis//", | ||
| 282 | 'output' => "<p><em>Emphasis</em></p>" | ||
| 283 | ), | ||
| 284 | array( // Test runaway //emphasis | ||
| 285 | 'name' => "Runaway emphasis #1", | ||
| 286 | 'input' => "//Emphasis", | ||
| 287 | 'output' => "<p><em>Emphasis</em></p>" | ||
| 288 | ), | ||
| 289 | array( | ||
| 290 | 'name' => "Runaway emphasis #2", | ||
| 291 | 'input' => "// Emphasis /", | ||
| 292 | 'output' => "<p><em> Emphasis /</em></p>" | ||
| 293 | ), | ||
| 294 | |||
| 295 | //// WikiCreole tests | ||
| 296 | array( // Tests multi-line emphasis behaviour | ||
| 297 | 'name' => "Multi-line emphasis", | ||
| 298 | 'input' => "Bold and italics should //be\nable// to cross lines.\n\n" + | ||
| 299 | "But, should //not be...\n\n...able// to cross paragraphs.", | ||
| 300 | 'output' => "<p>Bold and italics should <em>be\nable</em> to cross lines." + | ||
| 301 | "\n</p>" + "<p>\nBut, should <em>not be...\n</em></p>" + | ||
| 302 | "<p>\n...able<em> to cross paragraphs.</em></p>" | ||
| 303 | ), | ||
| 304 | array( // Tests URL/emphasis ambiguity handling | ||
| 305 | 'name' => "URL/emphasis ambiguity", | ||
| 306 | 'input' => "This is an //italic// text. This is a url: " + | ||
| 307 | "http://www.wikicreole.org. This is what can go wrong://this " + | ||
| 308 | "should be an italic text//.", | ||
| 309 | 'output' => "<p>This is an <em>italic</em> text. This is a url: " + | ||
| 310 | "<a href=\"http://www.wikicreole.org\">" + | ||
| 311 | "http://www.wikicreole.org</a>. This is what can go wrong:" + | ||
| 312 | "<em>this should be an italic text</em>." | ||
| 313 | ), | ||
| 314 | |||
| 315 | //// Awkward emphasis edge cases | ||
| 316 | array( | ||
| 317 | 'name' => "Difficult emphasis #1", | ||
| 318 | 'input' => "// http://www.link.org //", | ||
| 319 | 'output' => "<p><em> <a href=\"http://www.link.org\">" + | ||
| 320 | "http://www.link.org</a> </em></p>" | ||
| 321 | ), | ||
| 322 | array( | ||
| 323 | 'name' => "Difficult emphasis #2", | ||
| 324 | 'input' => "// http //", | ||
| 325 | 'output' => "<p><em> http </em></p>" | ||
| 326 | ), | ||
| 327 | array( | ||
| 328 | 'name' => "Difficult emphasis #3", | ||
| 329 | 'input' => "// httphpthtpht //", | ||
| 330 | 'output' => "<p><em> httphpthtpht </em></p>" | ||
| 331 | ), | ||
| 332 | array( | ||
| 333 | 'name' => "Difficult emphasis #4", | ||
| 334 | 'input' => "// http: //", | ||
| 335 | 'output' => "<p><em> http: </em></p>" | ||
| 336 | ), | ||
| 337 | array( | ||
| 338 | 'name' => "Difficult emphasis #5 (runaway)", | ||
| 339 | 'input' => "// http://example.org", | ||
| 340 | 'output' => "<p><em> <a href=\"http://example.org\">http://example.org</a></em></p>" | ||
| 341 | ), | ||
| 342 | array( | ||
| 343 | 'name' => "Difficult emphasis #6 (runaway)", | ||
| 344 | 'input' => "// http://example.org//", | ||
| 345 | 'output' => "<p><em> <a href=\"http://example.org//\">http://example.org//</a></em></p>" | ||
| 346 | ), | ||
| 347 | array( | ||
| 348 | 'name' => "Difficult emphasis #7", | ||
| 349 | 'input' => "//httphpthtphtt//", | ||
| 350 | 'output' => "<p><em>httphpthtphtt</em></p>" | ||
| 351 | ), | ||
| 352 | array( | ||
| 353 | 'name' => "Difficult emphasis #8", | ||
| 354 | 'input' => "// ftp://www.link.org //", | ||
| 355 | 'output' => "<p><em> <a href=\"ftp://www.link.org\">" + | ||
| 356 | "ftp://www.link.org</a> </em></p>" | ||
| 357 | ), | ||
| 358 | array( | ||
| 359 | 'name' => "Difficult emphasis #9", | ||
| 360 | 'input' => "// ftp //", | ||
| 361 | 'output' => "<p><em> ftp </em></p>" | ||
| 362 | ), | ||
| 363 | array( | ||
| 364 | 'name' => "Difficult emphasis #10", | ||
| 365 | 'input' => "// fttpfptftpft //", | ||
| 366 | 'output' => "<p><em> fttpfptftpft </em></p>" | ||
| 367 | ), | ||
| 368 | array( | ||
| 369 | 'name' => "Difficult emphasis #11", | ||
| 370 | 'input' => "// ftp: //", | ||
| 371 | 'output' => "<p><em> ftp: </em></p>" | ||
| 372 | ), | ||
| 373 | array( | ||
| 374 | 'name' => "Difficult emphasis #12 (runaway)", | ||
| 375 | 'input' => "// ftp://example.org", | ||
| 376 | 'output' => "<p><em> <a href=\"ftp://example.org\">ftp://example.org</a></em></p>" | ||
| 377 | ), | ||
| 378 | array( | ||
| 379 | 'name' => "Difficult emphasis #13 (runaway)", | ||
| 380 | 'input' => "//ftp://username:password@example.org/path//", | ||
| 381 | 'output' => "<p><em><a href=\"ftp://username:password@example.org/path//\">" + | ||
| 382 | "ftp://username:password@example.org/path//</a></em></p>" | ||
| 383 | ), | ||
| 384 | array( | ||
| 385 | 'name' => "Difficult emphasis #14", | ||
| 386 | 'input' => "//fttpfptftpftt//", | ||
| 387 | 'output' => "<p><em>fttpfptftpftt</em></p>" | ||
| 388 | ), | ||
| 389 | array( | ||
| 390 | 'name' => "Difficult emphasis #15", | ||
| 391 | 'input' => "//ftp://username:password@link.org/path/", | ||
| 392 | 'output' => "<p><em><a href=\"ftp://username:password@link.org/path/\">" + | ||
| 393 | "ftp://username:password@link.org/path/</a></em></p>" | ||
| 394 | ), | ||
| 395 | array( | ||
| 396 | 'name' => "Escaped emphasis", | ||
| 397 | 'input' => "~//Not emphasized~//", | ||
| 398 | 'output' => "<p><span class=\"escaped\">/</span>/Not emphasized<span class=\"escaped\">/</span>/</p>" | ||
| 399 | ), | ||
| 400 | array( | ||
| 401 | 'name' => "Tilde escapes self", | ||
| 402 | 'input' => "Tilde: ~~", | ||
| 403 | 'output' => "<p>Tilde: <span class=\"escaped\">~</span></p>" | ||
| 404 | ), | ||
| 405 | array( | ||
| 406 | 'name' => "Escaped URL", | ||
| 407 | 'input' => "~http://link.org", | ||
| 408 | 'output' => "<p><span class=\"escaped\">http://link.org</span></p>" | ||
| 409 | ), | ||
| 410 | array( | ||
| 411 | 'name' => "Escaped strong ending", | ||
| 412 | 'input' => "Plain ** bold ~** bold too", | ||
| 413 | 'output' => "<p>Plain <strong> bold <span class=\"escaped\">*</span>* bold too</strong></p>" | ||
| 414 | ), | ||
| 415 | array( | ||
| 416 | 'name' => "Escaped emphasis ending", | ||
| 417 | 'input' => "Plain // emphasized ~// emphasized too", | ||
| 418 | 'output' => "<p>Plain <em> emphasized <span class=\"escaped\">/</span>/ emphasized too</em></p>" | ||
| 419 | ), | ||
| 420 | array( | ||
| 421 | 'name' => "Escaped h1 ending", | ||
| 422 | 'input' => "= Header ~=", | ||
| 423 | 'output' => "<h1>Header <span class=\"escaped\">=</span></h1>" | ||
| 424 | ), | ||
| 425 | array( | ||
| 426 | 'name' => "Escaped h2 ending", | ||
| 427 | 'input' => "== Header ~==", | ||
| 428 | 'output' => "<h2>Header <span class=\"escaped\">=</span></h2>" | ||
| 429 | ), | ||
| 430 | array( | ||
| 431 | 'name' => "Escaped h3 ending", | ||
| 432 | 'input' => "=== Header ~===", | ||
| 433 | 'output' => "<h3>Header <span class=\"escaped\">=</span></h3>" | ||
| 434 | ), | ||
| 435 | array( | ||
| 436 | 'name' => "Escaped h4 ending", | ||
| 437 | 'input' => "==== Header ~====", | ||
| 438 | 'output' => "<h4>Header <span class=\"escaped\">=</span></h4>" | ||
| 439 | ), | ||
| 440 | array( | ||
| 441 | 'name' => "Escaped h5 ending", | ||
| 442 | 'input' => "===== Header ~=====", | ||
| 443 | 'output' => "<h5>Header <span class=\"escaped\">=</span></h5>" | ||
| 444 | ), | ||
| 445 | array( | ||
| 446 | 'name' => "Escaped h6 ending", | ||
| 447 | 'input' => "====== Header ~======", | ||
| 448 | 'output' => "<h6>Header <span class=\"escaped\">=</span></h6>" | ||
| 449 | ), | ||
| 450 | array( | ||
| 451 | 'name' => "Escaped link ending #1", | ||
| 452 | 'input' => "[[Link~]]]", | ||
| 453 | 'output' => "<p><a href=\"/wiki/Link]\">Link<span class=\"escaped\">]</span></a></p>" | ||
| 454 | ), | ||
| 455 | array( | ||
| 456 | 'name' => "Escaped link ending #2", | ||
| 457 | 'input' => "[[Link]~]]]", | ||
| 458 | 'output' => "<p><a href=\"/wiki/Link]]\">Link]<span class=\"escaped\">]</span></a></p>" | ||
| 459 | ), | ||
| 460 | array( | ||
| 461 | 'name' => "Escaped link ending #3", | ||
| 462 | 'input' => "[[Link~]]", | ||
| 463 | 'output' => "<p>[[Link<span class=\"escaped\">]</span>]</p>" | ||
| 464 | ), | ||
| 465 | array( | ||
| 466 | 'name' => "Escaped link ending #4", | ||
| 467 | 'input' => "[[Link|some text~]]]", | ||
| 468 | 'output' => "<p><a href=\"/wiki/Link\">some text<span class=\"escaped\">]</span></a></p>" | ||
| 469 | ), | ||
| 470 | array( | ||
| 471 | 'name' => "Escaped link text separator #1", | ||
| 472 | 'input' => "[[Link~|some text]]", | ||
| 473 | 'output' => "<p><a href=\"/wiki/Link|some text\">Link<span class=\"escaped\">|</span>some text</a></p>" | ||
| 474 | ), | ||
| 475 | array( | ||
| 476 | 'name' => "Escaped link text separator #2", | ||
| 477 | 'input' => "[[Link~||some text]]", | ||
| 478 | 'output' => "<p><a href=\"/wiki/Link|\">some text</a></p>" | ||
| 479 | ), | ||
| 480 | array( | ||
| 481 | 'name' => "Escaped link text separator #3", | ||
| 482 | 'input' => "[[Link|~|some text]]", | ||
| 483 | 'output' => "<p><a href=\"/wiki/Link\"><span class=\"escaped\">|</span>some text</a></p>" | ||
| 484 | ), | ||
| 485 | array( | ||
| 486 | 'name' => "Escaped img ending #1", | ||
| 487 | 'input' => "{{image.png|Alternative text~}}}", | ||
| 488 | 'output' => "<p><img src=\"image.png\" alt=\"Alternative text}\"/></p>" | ||
| 489 | ), | ||
| 490 | array( | ||
| 491 | 'name' => "Escaped img ending #2", | ||
| 492 | 'input' => "{{image.png|Alternative text}~}}}", | ||
| 493 | 'output' => "<p><img src=\"image.png\" alt=\"Alternative text}}\"/></p>" | ||
| 494 | ), | ||
| 495 | array( | ||
| 496 | 'name' => "Escaped img ending #3", | ||
| 497 | 'input' => "{{image.png|Alternative text~}}", | ||
| 498 | 'output' => "<p>{{image.png|Alternative text<span class=\"escaped\">}</span>}</p>" | ||
| 499 | ), | ||
| 500 | array( | ||
| 501 | 'name' => "Escaped img ending #4", | ||
| 502 | 'input' => "{{image.png|Alternative~}} text}}", | ||
| 503 | 'output' => "<p><img src=\"image.png\" alt=\"Alternative}} text\"/></p>" | ||
| 504 | ), | ||
| 505 | array( | ||
| 506 | 'name' => "Image URI with tilde #1", | ||
| 507 | 'input' => "{{image.png~|Alternative text}}", | ||
| 508 | 'output' => "<p><img src=\"image.png~\" alt=\"Alternative text\"/></p>" | ||
| 509 | ), | ||
| 510 | array( | ||
| 511 | 'name' => "Image URI with tilde #2", | ||
| 512 | 'input' => "{{image.png~||Alternative text}}", | ||
| 513 | 'output' => "<p><img src=\"image.png~\" alt=\"|Alternative text\"/></p>" | ||
| 514 | ), | ||
| 515 | array( | ||
| 516 | 'name' => "Tables with escaped separator", | ||
| 517 | 'input' => "| A | B |\n| C | D ~| E |", | ||
| 518 | 'output' => "<table><tr><td> A </td><td> B </td></tr>" + | ||
| 519 | "<tr><td> C </td><td> D <span class=\"escaped\">|</span> E </td></tr></table>" | ||
| 520 | ), | ||
| 521 | array( | ||
| 522 | 'name' => "Image in link", | ||
| 523 | 'input' => "[[Link|Before {{image.png|Alternate}} After]]", | ||
| 524 | 'output' => "<p><a href=\"/wiki/Link\">Before <img src=\"image.png\" alt=\"Alternate\"/> After</a></p>" | ||
| 525 | ), | ||
| 526 | array( | ||
| 527 | 'name' => "Formatting interwiki links with function", | ||
| 528 | 'input' => "[[Palindrome:Creole]]", | ||
| 529 | 'output' => "<p><a href=\"http://www.example.com/wiki/eloerC\">Palindrome:Creole</a></p>" | ||
| 530 | ), | ||
| 531 | array( | ||
| 532 | 'name' => "Named link in table", | ||
| 533 | 'input' => "| [[MyLink|My link]] |", | ||
| 534 | 'output' => '<table><tr><td> <a href="/wiki/MyLink">My link</a> </td></tr></table>' | ||
| 535 | ), | ||
| 536 | array( | ||
| 537 | 'name' => "Image in table", | ||
| 538 | 'input' => "| {{image.png|Alternative text}} |", | ||
| 539 | 'output' => '<table><tr><td> <img src="image.png" alt="Alternative text"/> </td></tr></table>' | ||
| 540 | ), | ||
| 541 | array( | ||
| 542 | 'name' => "Image in table (strict)", | ||
| 543 | 'input' => "| {{image.png|Alternative text}} |", | ||
| 544 | 'output' => '<table><tr><td> {{image.png</td><td>Alternative text}} </td></tr></table>', | ||
| 545 | 'options' => array( 'strict' => true ) | ||
| 546 | ), | ||
| 547 | array( | ||
| 548 | 'name' => "Image in named link in table", | ||
| 549 | 'input' => "| [[Link|{{image.png|Alternative text}}]] |", | ||
| 550 | 'output' => '<table><tr><td> <a href="/wiki/Link"><img src="image.png" alt="Alternative text"/></a> </td></tr></table>' | ||
| 551 | ), | ||
| 552 | array( | ||
| 553 | 'name' => "Image without alternative text", | ||
| 554 | 'input' => "{{image.png}}", | ||
| 555 | 'output' => '<p><img src="image.png" alt=""/></p>' | ||
| 556 | ), | ||
| 557 | array( | ||
| 558 | 'name' => "Image without alternative text (strict)", | ||
| 559 | 'input' => "{{image.png}}", | ||
| 560 | 'output' => '<p>{{image.png}}</p>', | ||
| 561 | 'options' => array( 'strict' => true ) | ||
| 562 | ), | ||
| 563 | array( | ||
| 564 | 'name' => "Image with empty alternative text", | ||
| 565 | 'input' => "{{image.png|}}", | ||
| 566 | 'output' => '<p><img src="image.png" alt=""/></p>', | ||
| 567 | 'options' => array( 'strict' => true ) | ||
| 568 | ), | ||
| 569 | array( | ||
| 570 | 'name' => "Image with custom default alternative text", | ||
| 571 | 'input' => "{{image.png}}", | ||
| 572 | 'output' => '<p><img src="image.png" alt="Image"/></p>', | ||
| 573 | 'options' => array( 'default_image_text' => 'Image' ) | ||
| 574 | ) | ||
| 575 | ); | ||
| 576 | |||
| 577 | plan(count($array)); | ||
| 578 | |||
| 579 | function palindrome ($link) { | ||
| 580 | return 'http://www.example.com/wiki/' . strrev($link); | ||
| 581 | } | ||
| 582 | |||
| 583 | foreach ($tests as $test) { | ||
| 584 | $options = array( | ||
| 585 | 'link_format' => '/wiki/%s', | ||
| 586 | 'interwiki' => array( | ||
| 587 | 'MeatBall' => 'http://www.usemod.com/cgi-bin/mb.pl?%s', | ||
| 588 | 'WikiCreole' => 'http://www.wikicreole.org/wiki/%s', | ||
| 589 | 'Palindrome' => 'palindrome' | ||
| 590 | ) | ||
| 591 | ); | ||
| 592 | if (isset($test['options'])) { | ||
| 593 | $options = array_merge($options, $test['options']); | ||
| 594 | } | ||
| 595 | $creole = new creole($options); | ||
| 596 | is($creole->parse($test['input']), $test['output'], $test['name']); | ||
| 597 | } | ||
| 598 | |||
| 599 | ?> |
t/test-more.php
(363 / 0)
|   | |||
| 1 | <?php | ||
| 2 | |||
| 3 | /*******************************************************************\ | ||
| 4 | * PROJECT INFORMATION * | ||
| 5 | * * | ||
| 6 | * Project: Apache-Test * | ||
| 7 | * URL: http://perl.apache.org/Apache-Test/ * | ||
| 8 | * Notice: Copyright (c) 2006 The Apache Software Foundation * | ||
| 9 | * * | ||
| 10 | ********************************************************************* | ||
| 11 | * LICENSE INFORMATION * | ||
| 12 | * * | ||
| 13 | * Licensed under the Apache License, Version 2.0 (the "License"); * | ||
| 14 | * you may not use this file except in compliance with the * | ||
| 15 | * License. You may obtain a copy of the License at: * | ||
| 16 | * * | ||
| 17 | * http://www.apache.org/licenses/LICENSE-2.0 * | ||
| 18 | * * | ||
| 19 | * Unless required by applicable law or agreed to in writing, * | ||
| 20 | * software distributed under the License is distributed on an "AS * | ||
| 21 | * IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * | ||
| 22 | * express or implied. See the License for the specific language * | ||
| 23 | * governing permissions and limitations under the License. * | ||
| 24 | * * | ||
| 25 | ********************************************************************* | ||
| 26 | * MODULE INFORMATION * | ||
| 27 | * * | ||
| 28 | * This is a PHP implementation of Test::More: * | ||
| 29 | * * | ||
| 30 | * http://search.cpan.org/dist/Test-Simple/lib/Test/More.pm * | ||
| 31 | * * | ||
| 32 | ********************************************************************* | ||
| 33 | * CREDITS * | ||
| 34 | * * | ||
| 35 | * Originally inspired by work from Andy Lester. Written and * | ||
| 36 | * maintained by Chris Shiflett. For contact information, see: * | ||
| 37 | * * | ||
| 38 | * http://shiflett.org/ * | ||
| 39 | * * | ||
| 40 | \*******************************************************************/ | ||
| 41 | |||
| 42 | header('Content-Type: text/plain'); | ||
| 43 | register_shutdown_function('_test_end'); | ||
| 44 | |||
| 45 | $_no_plan = FALSE; | ||
| 46 | $_num_failures = 0; | ||
| 47 | $_num_skips = 0; | ||
| 48 | $_test_num = 0; | ||
| 49 | |||
| 50 | function plan($plan) | ||
| 51 | { | ||
| 52 | /* | ||
| 53 | plan('no_plan'); | ||
| 54 | plan('skip_all'); | ||
| 55 | plan(array('skip_all' => 'My reason is...')); | ||
| 56 | plan(23); | ||
| 57 | */ | ||
| 58 | |||
| 59 | global $_no_plan; | ||
| 60 | global $_skip_all; | ||
| 61 | global $_skip_reason; | ||
| 62 | |||
| 63 | switch ($plan) | ||
| 64 | { | ||
| 65 | case 'no_plan': | ||
| 66 | $_no_plan = TRUE; | ||
| 67 | break; | ||
| 68 | |||
| 69 | case 'skip_all': | ||
| 70 | echo "1..0\n"; | ||
| 71 | break; | ||
| 72 | |||
| 73 | default: | ||
| 74 | if (is_array($plan)) | ||
| 75 | { | ||
| 76 | echo "1..0 # Skip {$plan['skip_all']}\n"; | ||
| 77 | exit; | ||
| 78 | } | ||
| 79 | |||
| 80 | echo "1..$plan\n"; | ||
| 81 | break; | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | function ok($pass, $test_name = '') | ||
| 86 | { | ||
| 87 | global $_test_num; | ||
| 88 | global $_num_failures; | ||
| 89 | global $_num_skips; | ||
| 90 | |||
| 91 | $_test_num++; | ||
| 92 | |||
| 93 | if ($_num_skips) | ||
| 94 | { | ||
| 95 | $_num_skips--; | ||
| 96 | return TRUE; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (!empty($test_name) && $test_name[0] != '#') | ||
| 100 | { | ||
| 101 | $test_name = "- $test_name"; | ||
| 102 | } | ||
| 103 | |||
| 104 | if ($pass) | ||
| 105 | { | ||
| 106 | echo "ok $_test_num $test_name\n"; | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | echo "not ok $_test_num $test_name\n"; | ||
| 111 | |||
| 112 | $_num_failures++; | ||
| 113 | $caller = debug_backtrace(); | ||
| 114 | |||
| 115 | if (strstr($caller['0']['file'], $_SERVER['PHP_SELF'])) | ||
| 116 | { | ||
| 117 | $file = $caller['0']['file']; | ||
| 118 | $line = $caller['0']['line']; | ||
| 119 | } | ||
| 120 | else | ||
| 121 | { | ||
| 122 | $file = $caller['1']['file']; | ||
| 123 | $line = $caller['1']['line']; | ||
| 124 | } | ||
| 125 | |||
| 126 | $file = str_replace($_SERVER['SERVER_ROOT'], 't', $file); | ||
| 127 | |||
| 128 | diag(" Failed test ($file at line $line)"); | ||
| 129 | } | ||
| 130 | |||
| 131 | return $pass; | ||
| 132 | } | ||
| 133 | |||
| 134 | function is($this, $that, $test_name = '') | ||
| 135 | { | ||
| 136 | $pass = ($this == $that); | ||
| 137 | |||
| 138 | ok($pass, $test_name); | ||
| 139 | |||
| 140 | if (!$pass) | ||
| 141 | { | ||
| 142 | diag(" got: '$this'"); | ||
| 143 | diag(" expected: '$that'"); | ||
| 144 | } | ||
| 145 | |||
| 146 | return $pass; | ||
| 147 | } | ||
| 148 | |||
| 149 | function isnt($this, $that, $test_name = '') | ||
| 150 | { | ||
| 151 | $pass = ($this != $that); | ||
| 152 | |||
| 153 | ok($pass, $test_name); | ||
| 154 | |||
| 155 | if (!$pass) | ||
| 156 | { | ||
| 157 | diag(" '$this'"); | ||
| 158 | diag(' !='); | ||
| 159 | diag(" '$that'"); | ||
| 160 | } | ||
| 161 | |||
| 162 | return $pass; | ||
| 163 | } | ||
| 164 | |||
| 165 | function like($string, $pattern, $test_name = '') | ||
| 166 | { | ||
| 167 | $pass = preg_match($pattern, $string); | ||
| 168 | |||
| 169 | ok($pass, $test_name); | ||
| 170 | |||
| 171 | if (!$pass) | ||
| 172 | { | ||
| 173 | diag(" '$string'"); | ||
| 174 | diag(" doesn't match '$pattern'"); | ||
| 175 | } | ||
| 176 | |||
| 177 | return $pass; | ||
| 178 | } | ||
| 179 | |||
| 180 | function unlike($string, $pattern, $test_name = '') | ||
| 181 | { | ||
| 182 | $pass = !preg_match($pattern, $string); | ||
| 183 | |||
| 184 | ok($pass, $test_name); | ||
| 185 | |||
| 186 | if (!$pass) | ||
| 187 | { | ||
| 188 | diag(" '$string'"); | ||
| 189 | diag(" matches '$pattern'"); | ||
| 190 | } | ||
| 191 | |||
| 192 | return $pass; | ||
| 193 | } | ||
| 194 | |||
| 195 | function cmp_ok($this, $operator, $that, $test_name = '') | ||
| 196 | { | ||
| 197 | eval("\$pass = (\$this $operator \$that);"); | ||
| 198 | |||
| 199 | ok($pass, $test_name); | ||
| 200 | |||
| 201 | if (!$pass) | ||
| 202 | { | ||
| 203 | diag(" got: '$this'"); | ||
| 204 | diag(" expected: '$that'"); | ||
| 205 | } | ||
| 206 | |||
| 207 | return $pass; | ||
| 208 | } | ||
| 209 | |||
| 210 | function can_ok($object, $methods) | ||
| 211 | { | ||
| 212 | $pass = TRUE; | ||
| 213 | $errors = array(); | ||
| 214 | |||
| 215 | foreach ($methods as $method) | ||
| 216 | { | ||
| 217 | if (!method_exists($object, $method)) | ||
| 218 | { | ||
| 219 | $pass = FALSE; | ||
| 220 | $errors[] = " method_exists(\$object, $method) failed"; | ||
| 221 | } | ||
| 222 | } | ||
| 223 | |||
| 224 | if ($pass) | ||
| 225 | { | ||
| 226 | ok(TRUE, "method_exists(\$object, ...)"); | ||
| 227 | } | ||
| 228 | else | ||
| 229 | { | ||
| 230 | ok(FALSE, "method_exists(\$object, ...)"); | ||
| 231 | diag($errors); | ||
| 232 | } | ||
| 233 | |||
| 234 | return $pass; | ||
| 235 | } | ||
| 236 | |||
| 237 | function isa_ok($object, $expected_class, $object_name = 'The object') | ||
| 238 | { | ||
| 239 | $got_class = get_class($object); | ||
| 240 | |||
| 241 | if (version_compare(php_version(), '5', '>=')) | ||
| 242 | { | ||
| 243 | $pass = ($got_class == $expected_class); | ||
| 244 | } | ||
| 245 | else | ||
| 246 | { | ||
| 247 | $pass = ($got_class == strtolower($expected_class)); | ||
| 248 | } | ||
| 249 | |||
| 250 | if ($pass) | ||
| 251 | { | ||
| 252 | ok(TRUE, "$object_name isa $expected_class"); | ||
| 253 | } | ||
| 254 | else | ||
| 255 | { | ||
| 256 | ok(FALSE, "$object_name isn't a '$expected_class' it's a '$got_class'"); | ||
| 257 | } | ||
| 258 | |||
| 259 | return $pass; | ||
| 260 | } | ||
| 261 | |||
| 262 | function pass($test_name = '') | ||
| 263 | { | ||
| 264 | return ok(TRUE, $test_name); | ||
| 265 | } | ||
| 266 | |||
| 267 | function fail($test_name = '') | ||
| 268 | { | ||
| 269 | return ok(FALSE, $test_name); | ||
| 270 | } | ||
| 271 | |||
| 272 | function diag($message) | ||
| 273 | { | ||
| 274 | if (is_array($message)) | ||
| 275 | { | ||
| 276 | foreach($message as $current) | ||
| 277 | { | ||
| 278 | echo "# $current\n"; | ||
| 279 | } | ||
| 280 | } | ||
| 281 | else | ||
| 282 | { | ||
| 283 | echo "# $message\n"; | ||
| 284 | } | ||
| 285 | } | ||
| 286 | |||
| 287 | function include_ok($module) | ||
| 288 | { | ||
| 289 | $pass = ((include $module) == 'OK'); | ||
| 290 | return ok($pass); | ||
| 291 | } | ||
| 292 | |||
| 293 | function require_ok($module) | ||
| 294 | { | ||
| 295 | $pass = ((require $module) == 'OK'); | ||
| 296 | return ok($pass); | ||
| 297 | } | ||
| 298 | |||
| 299 | function skip($message, $num) | ||
| 300 | { | ||
| 301 | global $_num_skips; | ||
| 302 | |||
| 303 | if ($num < 0) | ||
| 304 | { | ||
| 305 | $num = 0; | ||
| 306 | } | ||
| 307 | |||
| 308 | for ($i = 0; $i < $num; $i++) | ||
| 309 | { | ||
| 310 | pass("# SKIP $message"); | ||
| 311 | } | ||
| 312 | |||
| 313 | $_num_skips = $num; | ||
| 314 | } | ||
| 315 | |||
| 316 | /* | ||
| 317 | |||
| 318 | TODO: | ||
| 319 | |||
| 320 | function todo() | ||
| 321 | { | ||
| 322 | } | ||
| 323 | |||
| 324 | function todo_skip() | ||
| 325 | { | ||
| 326 | } | ||
| 327 | |||
| 328 | function is_deeply() | ||
| 329 | { | ||
| 330 | } | ||
| 331 | |||
| 332 | function eq_array() | ||
| 333 | { | ||
| 334 | } | ||
| 335 | |||
| 336 | function eq_hash() | ||
| 337 | { | ||
| 338 | } | ||
| 339 | |||
| 340 | function eq_set() | ||
| 341 | { | ||
| 342 | } | ||
| 343 | |||
| 344 | */ | ||
| 345 | |||
| 346 | function _test_end() | ||
| 347 | { | ||
| 348 | global $_no_plan; | ||
| 349 | global $_num_failures; | ||
| 350 | global $_test_num; | ||
| 351 | |||
| 352 | if ($_no_plan) | ||
| 353 | { | ||
| 354 | echo "1..$_test_num\n"; | ||
| 355 | } | ||
| 356 | |||
| 357 | if ($_num_failures) | ||
| 358 | { | ||
| 359 | diag("Looks like you failed $_num_failures tests of $_test_num."); | ||
| 360 | } | ||
| 361 | } | ||
| 362 | |||
| 363 | ?> |

