aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/HtmlTest.php
Commit message (Collapse)AuthorAgeFilesLines
* tests: Move test cases from /includes/ into sub folderUmherirrender2023-09-131-942/+0
| | | | | | | Follow move of the tested class Most moves are part of T321882 Change-Id: I74ab45d6a5331dcb2ff0b65dc2cc7c6315146646
* tests: Change some setMwGlobals to overrideConfigValueUmherirrender2023-07-171-1/+1
| | | | Change-Id: I21b9bf907e313947360b1607f11ae9917488f109
* Html: Move encodeJsVar() + encodeJsCall() from XmlLucas Werkmeister2023-07-141-0/+44
| | | | | | | | | These methods really belong in the Html class, not Xml. Leave behind soft-deprecated Xml methods that forward to the Html ones, as well as a class alias for HtmlJsCode (renamed from XmlJsCode). Bug: T341779 Change-Id: I99a5f9de1411d4eb5ee30226b4e8ace3ea8b2c3b
* Html: Support more attr types in getTextInputAttributes()Lucas Werkmeister2023-07-111-16/+57
| | | | | | | | | | Properly support class values that are strings, lists, or associative arrays, while ensuring that strings stay string for the usage in the Xml class (because Xml::expandAttributes(), unlike Html::expandAttributes(), doesn’t support array values). Bug: T341566 Change-Id: I3ee2be956d4b239901fa16440890bbcfb2fcf930
* Always return the class as string from Html::getTextInputAttributesMatěj Suchánek2023-07-111-4/+5
| | | | | | | | | Iba9101e5f is not compatible with existing callers. E.g., I4ded6b4e fails with FlaggedRevs in stacktrace. Better stick to returning string in all cases. Bug: T341566 Change-Id: Id3bae3ded872d99320b5f7a60a8328c1d18c77f8
* Html: Fixes Error: [] operator not supported for stringsJon Robson2023-07-101-1/+17
| | | | | Bug: T341534 Change-Id: Iba9101e5fcf83f547b864c5782866962a3772a3f
* Use Codex markup on message box componentJon Robson2023-06-161-6/+24
| | | | | | | | | | | | | | | | This will allow interfaces using Codex to style message boxes consistently on the server side. Skins can now remove the ResourceLoaderSkin message box module and instead load the codex-styles module. Since certain JavaScript may be looking for the existing classes, these are retained for now (this prevents Selenium tests failing) Depends-On: I3959c8f8d4c7bbe019f5e3b356649b5b7dc88907 Depends-On: I45c60e9f5cbb57eae61c9487f120b9165bf5a190 Bug: T326587 Change-Id: I16d8f53b9a83a468acdb3803044f6c4e9d5dfeeb
* OutputPage,Html,Xml: Widen `@covers` annotations in unit testsTimo Tijhof2023-06-021-54/+3
| | | | | | | | | | | | | | | | | | | | | | Follows-up I6d845bdfbb80, I69b5385868, I4c7d826c7e, I1287f3979ab, which widened the `@covers` annotations of other test suites: > We lose useful coverage and spend valuable time keeping these tags > accurate through refactors (or worse, forget to do so). > > I've audited each test to confirm it is a general test of the > subject class, where tagging missing methods would be an accepted > change, thus widening it is merely a no-op that clarifies intent > and reduces maintenance. I am not disabling the "only track coverage > of specified subject" mechanism, nor am I claiming coverage in > in classes outside the subject under test. > > Tracking this narrow detail wastes time to keep methods in sync during > refactors, time to realize (and fix) when other people inevitably > dodn't keep them in sync, time lost in finding uncovered code to > write tests for only to realize it is already covered but not tagged. Change-Id: I9d63105fd64b0a863d5bfaa67ae069c14531a4cf
* phpunit: Update `@covers` annotations for namespaced classesFunc2023-05-271-28/+28
| | | | | | | | | | | | We renamed many classes to be namespaced, but the `@covers` and `@coversDefaultClass` annotations weren't updated properly. PHPUnit didn't support short cover annotations with `use` statements, these didn't trigger any errors yet, because they are class alias. This patch is populated by a modified version of PhpunitAnnotationsSniff. Change-Id: I6c602290a30099239b17d2dc0d67b1488b4eaeeb
* HTML: Remove self-closing XHTML syntax from coreVolker E2023-05-031-21/+21
| | | | | | | | | | Syntactical leftover with no significance in modern web. Bug: T309150 Depends-On: I3a029ca950db42b938962b2452ad136ae8ddea6f Depends-On: Id0557ac19583de36d7226b14a4c06933da47fe97 Depends-On: I17580a72e4a9384d7d774866e610197e950900cb Change-Id: I4bbfa47fbf6e30fb90d920d6d02cdf6e0b1cdb46
* tests: Make some PHPUnit data providers staticTim Starling2023-03-241-3/+3
| | | | | | | | | | | | | Just methods where adding "static" to the declaration was enough, I didn't do anything with providers that used $this. Initially by search and replace. There were many mistakes which I found mostly by running the PHPStorm inspection which searches for $this usage in a static method. Later I used the PHPStorm "make static" action which avoids the more obvious mistakes. Bug: T332865 Change-Id: I47ed6692945607dfa5c139d42edbd934fa4f3a36
* Reorg: Move HTML-related classes out of includes/ to Html/Amir Sarabadani2023-02-161-0/+1
| | | | | Bug: T321882 Change-Id: I5dc1f7e9c303cd3f5b9dd7010d6bb470d8400a18
* tests: Replace assertEmpty with assertSameUmherirrender2022-11-251-1/+1
| | | | | | | assertSame avoids use of loose comparisons and allows to check the expected type Change-Id: If821d1be2bc1ff9f8b70968a339f33c7a8e8880a
* Enable pig-latin variant for testingdaniel2022-11-081-0/+1
| | | | | | | | | | Having pig-latin enabled per default in dev environments is convenient for manual testing. More importantly, it will allow us to write end-to-end tests for variant conversion. Depends-On: I9dc2f743ac487b0f7cfb667150c0f6950d5e7fce Depends-On: I85b66c85be3959d48a048733af17197bc4cf70af Change-Id: Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38
* tests: Use `overrideConfigValue(s)` where necessaryDerick Alangi2022-07-161-3/+3
| | | | | | | The files in `tests/phpunit/includes/` directory are now all covered. Will do sub-directories of `/includes/` next. Change-Id: I8d5655ce267b6d32cf3c7ee40dc5d2992631b5a6
* Drop messagebox, warningbox, errorbox classesJon Robson2022-04-111-6/+6
| | | | | | | | This can be done when relevant communities have been notified and the classes have rolled out of cached HTML. Bug: T270796 Change-Id: If35ebe88702bf97f2306c77b26d8b3cab4c0420d
* tests: Change use of AtEase to at operatorTimo Tijhof2022-02-241-17/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Follows-up I361fde0de7f4406bce6ed075ed397effa5be3359. Per T253461, not mass-changing source code, but the use of the native error silencing operator (@) is especially useful in tests because: 1. It requires any/all statements to be explicitly marked. The suppressWarnings/restoreWarnings sections encourage developers to be "lazy" and thus encapsulate more than needed if there are multiple ones near each other, which would ignore potentially important warnings in a test case, which is generally exactly the time when it is really useful to get warnings etc. 2. It avoids leaking state, for example in LBFactoryTest the assertFalse call would throw a PHPUnit assertion error (not meant to be caught by the local catch), and thus won't reach AtEase::restoreWarnings. This then causes later code to end up in a mismatching state and creates a confusing error_reporting state. See .phpcs.xml, where the at operator is allowed for all test code. Change-Id: I68d1725d685e0a7586468bc9de6dc29ceea31b8a
* tests: Replace some usages of Wikimedia\(suppress|restore)Warnings()Reedy2022-02-241-2/+4
| | | | Change-Id: I361fde0de7f4406bce6ed075ed397effa5be3359
* Clean up tests that misused the parameters of assertSame/EqualsFunc2022-02-081-2/+2
| | | | | | | | | | | | Expected value is the first parameter to assertSame() or assertEquals(). And turn to use assertCount() for some assertions aginst count of array. Based on code search `assert(?:Same|Equals)\(.+,.+expected` and I look through files roughly, so some assertions that don't contains 'expected' are also fixed. In the meantime, some assertions that I am not clear about are not touched. Change-Id: I75798b60d29fd19b33f4fdf34ed3c788db420d01
* phpunit: use ->getServiceContainer() in integration testsAlexander Vorwerk2022-01-271-3/+1
| | | | Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
* Untie Wikimedia message boxes from on-wiki messageboxesJdlrobson2022-01-271-6/+6
| | | | | | | | | | | | | | Many communities for historic reasons use "messagebox" to style certain templates. Going forward we aim to make sure all internally produced CSS classes are prefixed with "mw-". A user notice has been run notifying editors that this is potentially a breaking change with directions on how to update their CSS in preparation for this change. Bug: T270796 Depends-On: Id258e328d1691f7bd31d2b3c57d64d5434706561 Change-Id: I2df24431ec72641b63fbe2fc929025a53459c06c
* build: Updating dependencieslibraryupgrader2021-07-221-2/+2
| | | | | | | | | | | | | | composer: * mediawiki/mediawiki-codesniffer: 36.0.0 → 37.0.0 The following sniffs now pass and were enabled: * Generic.ControlStructures.InlineControlStructure * MediaWiki.PHPUnit.AssertCount.NotUsed npm: * svgo: 2.3.0 → 2.3.1 * https://npmjs.com/advisories/1754 (CVE-2021-33587) Change-Id: I2a9bbee2fecbf7259876d335f565ece4b3622426
* Revert "message boxes: Use CSS classes adhering to class naming scheme"VolkerE2021-01-251-6/+6
| | | | | | | | | This reverts commit 066e77735e962900950d1230d79fcfddc578a67b. Reason for revert: Objections brought up on ticket by Esanders are in alignmenet with own objections, that arose after initially providing this patch. We need clarification that is better addressed in new patch, reverting this. Bug: T270796 Change-Id: Id873b3e3b7efb3003daa4986225b1fb3e7e218c8
* message boxes: Use CSS classes adhering to class naming schemeVolker E2021-01-141-6/+6
| | | | | | | | Change to reflect class naming scheme. Depends-On: I14ee75bd173fb2de1e33067f95ce09deba5bf27a Bug: T270796 Change-Id: I7bf7f293712a8516862247d10e98289ff2e3e2cd
* Use expectWarning/Deprecation/Notice/Error() in phpunit testsUmherirrender2021-01-041-3/+2
| | | | | | | It is deprecated in newer phpunit versions Bug: T271049 Change-Id: I3b2105cbd582ecc57ab8bc1bb1617300f15682ad
* Cleanup some tests to reduce code duplicationsDannyS7122020-12-211-162/+114
| | | | | | Also fix incorrect order of some other assertions Change-Id: Idf50f98de7a17311ea8db6f2cae3b101f4c1da89
* MediaWikiTestCase to MediaWikiIntegrationTestCaseaddshore2020-06-301-1/+1
| | | | | | | | | | | | | The name change happened some time ago, and I think its about time to start using the name name! (Done with a find and replace) My personal motivation for doing this is that I have started trying out vscode as an IDE for mediawiki development, and right now it doesn't appear to handle php aliases very well or at all. Change-Id: I412235d91ae26e4c1c6a62e0dbb7e7cf3c5ed4a6
* Simplify overly complex data providers in HtmlTestThiemo Kreuz2020-05-291-15/+3
| | | | Change-Id: I399a5671ef2bbc63db2c82b0695d72df80f052dc
* tests: Add explicit return type void to setUp() and tearDown()Max Semenik2019-10-301-2/+2
| | | | | | Bug: T192167 Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43 Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
* Remove Language::factory and getParentLanguage useAryeh Gregor2019-10-271-4/+4
| | | | Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
* phpcs: Enable ↵James D. Forrester2019-10-141-1/+1
| | | | | | MediaWiki.Commenting.PhpunitAnnotations.ForbiddenExpectedException* and make pass Change-Id: I63f97497714a32236268be6965c5e181dade6c58
* Add public as visibility in tests folderUmherirrender2019-10-101-1/+1
| | | | | | | Add public, protected or private to function missing a visibility Enable the tests folder for the phpcs sniff Change-Id: Ibefce76ea9984c47e08c94889ea2eafca7565e2c
* Update tests to use PHPUnit 6 class namesMax Semenik2019-10-061-2/+4
| | | | | Bug: T192167 Change-Id: I42b0c8908b4968b95b08f861a40af18dc79fa0a1
* Replace infobox usages and extend successbox, warningbox and errorboxVolker E2019-09-241-3/+3
| | | | | | | | | | Adding optional $className parameter to provide additional styling options. Optional parameter $heading was introduced for MobileFrontend. Therefore leaving inconsistent parameter order is necessary for the time being. Bug: T232903 Change-Id: I5857b2c58a47a83156c32f086a73fe2bd48ab0c8
* tests: Prefer PHPUnit's assertSame() when comparing empty stringsThiemo Kreuz2019-09-201-2/+2
| | | | | | | | assertSame() is guaranteed to never do any magic type conversion. This can be critical when accidentially comparing empty strings (a value PHP considers to be "falsy") to false, 0, 0.0, null, and such. Change-Id: I2e2685c5992cae252f629a68ffe1a049f2e5ed1b
* Don't process "all" option in Html::namespaceSelectorOptionsMatěj Suchánek2019-07-041-0/+20
| | | | | | | | | The value of "all" can be completely arbitrary and in practice it's usually an empty string. Avoid attempting to filter it out and format anyhow. Bug: T227202 Change-Id: I371466407bd038914faa4dc3b0cae9547cf427eb
* Use [...] instead of array(...) in PHP comments and documentationFomafix2019-06-171-1/+1
| | | | Change-Id: I0c83783051bf35fe785bc01644eeb2946902b6b2
* Remove comments literally documenting unit tests being unit testsThiemo Kreuz2019-02-191-1/+0
| | | | | | | | The name of the test class and method as well as the @covers tags already explain well enough which code a test is testing. Repeating this does not provide additional information. Change-Id: Ieec4ec131e5925d11704a11e1df46bc00c9fad9b
* Add warning if you give Html::openElement a name with a spaceBrian Wolff2018-12-201-0/+9
| | | | | Bug: T201747 Change-Id: I7772f1e8c0c12bdf1fd60d62e015f2ec82d8ac90
* Merge "Render namespace lists in the user's language"jenkins-bot2018-11-071-0/+27
|\
| * Render namespace lists in the user's languageErik Bernhardson2018-10-121-0/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Asking users to select from a list that is in a namespace other than their user language can be quite difficult. Transition a number of use cases. This was applied via a flag to avoid unexpectedly changing extensions also utilizing the namespace selector. Pages updated: * Special:Search * Special:Watchlist * Special:RecentChanges * Special:Contributions * Special:Import * Special:WhatLinksHere Bug: T174057 Change-Id: I3fdac72179a124849ef7ad1e0e54eb66396c3c6e
* | Merge "HtmlTest: Perform multilingual tests"jenkins-bot2018-10-121-9/+34
|\|
| * HtmlTest: Perform multilingual testsErik Bernhardson2018-10-121-9/+34
| | | | | | | | | | | | | | | | | | The tests here were only testing when user and content language are the same, but the way things are rendered when they differ is perhaps more interesting as it allows ensuring the two are used in the correct places. Change-Id: I357f50b082882fee485a95323d3a0a7cadb9a63c
* | Fix TitlePermissionTest failures due to test leakageAaron Schulz2018-10-101-0/+3
|/ | | | | Bug: T201776 Change-Id: I46d44c031ec45ac0be4c372891d2992c1e4f35ab
* Html: Reject </script> from inlineScript() and leave rest unescapedTimo Tijhof2018-08-301-10/+33
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are three problems with the CDATA approach: 1. It doesn't work. HTML5 already interprets the contents of <script> tags as CDATA, which means escaping of characters like & is not needed. In fact, in HTML5 mode, a plain script tag with <script>0&amp;1;</script> would be a syntax error. Indicating it is not interpreted as text, but as CDATA. Effectively, the only thing an HTML parser looks for is </script>. And that's exactly the problem. Producing an inline script containing the characters "</string>" for legitimate reasons, is currently broken. No alternate wrapping or setting can make it work, either. See also: https://people.wikimedia.org/~krinkle/200506-html-inlinescript.html which contains: <script>/*<![CDATA[*/ if (true && true) { console.log('This is a <script></script> tag (original)'); } /*]]>*/</script> In a browser, the script is terminated by the first "</script>", leaving the code unfinished, throwing a SyntaxError, and outputting the rest of the script as plain text on the page. 2. CDATA is only for XML mode, whereas MediaWiki does not support the XML/XHTML output mode (since MediaWiki 1.22). Instead, we only output HTML (5). Code that does need to produce XML, should use the class from Xml.php instead. 3. It gives a false sense of security. We could just remove the CDATA code as-is and that in itself would be an improvement per point 2 and 3, and would break nothing per point 1. However, this commit attempts to address the underlying bug by rejecting the characters "</script>" from input. If this is needed in a literal, it is the responsibility of the caller to escape it in a way that is appropiate for how it is used (string, comment, regex, etc.). There are two ways this can be used currently in core: * User input as exported through JSON (e.g. mw.config, or mw.messages). This is already fine as both FormatJson::encode and json_encode handle escape either < or / in the string by default already. * Previews of edits to user scripts. This is currently already broken and causes the script to end early and produce arbitrary HTML on the page. This commit limits the impact by refusing to output such script in a broken way. I will further address that use case in a follow-up. Bug: T200506 Change-Id: I67ceb34eabf2f62fd3f3841b8f1459289fad28fb
* Support a heading of '0' in Html::messageBox()Kunal Mehta2018-08-191-0/+4
| | | | Change-Id: I181cb6f92ab1b10d87b1213a043a5f291149d094
* Html: Add test coverage for inlineScript()Timo Tijhof2018-08-091-0/+39
| | | | | | | | This asserts current behaviour in preparation for changing it in a later commit (see T200506). Bug: T200506 Change-Id: I76fd15c32c763754d0825d02a49de3d9973c4f8f
* Use \u{00A0} instead of &#160; or &nbsp;Fomafix2018-06-241-2/+2
| | | | | | | | | | | | | Directly use the UTF-8 encoding of the 'NO-BREAK SPACE' (U+00A0) instead of the HTML/XML entities &#160; or &#xa0; or &nbsp;. With the UTF-8 character the generated HTML is shorter and better to read. Also change the special value for the label in HTMLForm from &#160; to U+00A0 but also support &#160; for backward compability. Bug: T154300 Change-Id: I882599ac1120789bb4e524c4394870680caca4f4
* Use PHP 7 '??' operator instead of '?:' with 'isset()' where convenientBartosz Dziewoński2018-05-301-1/+1
| | | | | | | | | | | | | | Find: /isset\(\s*([^()]+?)\s*\)\s*\?\s*\1\s*:\s*/ Replace with: '\1 ?? ' (Everywhere except includes/PHPVersionCheck.php) (Then, manually fix some line length and indentation issues) Then manually reviewed the replacements for cases where confusing operator precedence would result in incorrect results (fixing those in I478db046a1cc162c6767003ce45c9b56270f3372). Change-Id: I33b421c8cb11cdd4ce896488c9ff5313f03a38cf
* Remove very, very old disabled test cases and todosThiemo Mättig2017-12-281-1/+0
| | | | | | Some of this is from 2011. Change-Id: I3cf78e6b451af92063746af87c25c1d352ce94da