Commit graph

75 commits

Author SHA1 Message Date
Volker E
2c1729e4e9 HTML: Remove self-closing XHTML syntax from core
Syntactical leftover with no significance in modern web.

Bug: T309150
Depends-On: I3a029ca950db42b938962b2452ad136ae8ddea6f
Depends-On: Id0557ac19583de36d7226b14a4c06933da47fe97
Depends-On: I17580a72e4a9384d7d774866e610197e950900cb
Change-Id: I4bbfa47fbf6e30fb90d920d6d02cdf6e0b1cdb46
2023-05-03 10:44:41 +02:00
Tim Starling
5e30a927bc tests: Make some PHPUnit data providers static
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
2023-03-24 02:53:57 +00:00
C. Scott Ananian
35cb2e524b tests: don't assume wgLanguageCode is 'en'
Change-Id: Ic748489309a1c8ff0f916b3f55aacc93ca128ea3
2022-07-21 19:32:41 -04:00
Umherirrender
246bc931f6 tests: Set wgLang with MediaWikiIntegrationTestCase::setUserLang
Change-Id: Ic1247a6719032b3a0ea1f76514edc5ffd5a7854a
2022-07-13 00:59:46 +02:00
Derick Alangi
a3a2ed268a tests: Use overrideConfig(Value|Values) where needed
This patch covers: tests/phpunit/includes/actions/ and
tests/phpunit/includes/api/.

Change-Id: I60d8fb7b8a63b423606db935fa0d24cf859b2512
2022-07-12 22:24:50 +00:00
Alexander Vorwerk
decbaf4f38 phpunit: use ->getServiceContainer() in integration tests
Change-Id: I38299cb65eeaadfdc0eb05db4e8c0b0119cfb37d
2022-01-27 22:04:16 +01:00
libraryupgrader
5357695270 build: Updating dependencies
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
2021-07-22 03:36:05 +00:00
DannyS712
7c47a17b42 Move Xml::expandAttributes tests to unit tests
No integration logic needed

Change-Id: If903ea138dba3703f06c4f4dc27cac1b192b9bbe
2021-03-07 19:27:11 +00:00
Thiemo Kreuz
47171f7b94 Don't accept empty option group names for dropdown elements
When this code parses a string that looks like this:

*
** A
** B

It creates an option group with 2 options, but the name
of the group is an empty string. This makes the OOUI
DropdownInputWidget fail later.

Since the empty group name is useless anyway, drop it. This
makes the code behave as if the parsed string looked like
this:

* A
* B

Live example for the issue:
https://el.wikipedia.org/wiki/MediaWiki:Protect-dropdown

Bug: T275125
Change-Id: I780c1be27740b0ed3b35aa569b5a528112d7238f
2021-02-19 17:04:35 +01:00
DannyS712
52359768c5 Convert or split some tests to MediaWikiUnitTestCase
Don't require any integration

Change-Id: I293a84ce8fe87fc6932f8a6400d6ca443ccc6235
2021-01-07 17:51:27 +00:00
DannyS712
1326cb3be5 Cleanup some tests to reduce code duplications
Also fix incorrect order of some other assertions

Change-Id: Idf50f98de7a17311ea8db6f2cae3b101f4c1da89
2020-12-21 10:08:29 +00:00
Umherirrender
e878341bfc Drop down lists: Do not use the value for 'other' as option group
Instead use them as groupless reason list

Bug: T251351
Change-Id: Id691d97e3e6f205615f639e051619f3d0f67c7ba
2020-09-16 19:30:43 +00:00
addshore
959bc315f2 MediaWikiTestCase to MediaWikiIntegrationTestCase
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
2020-06-30 17:02:22 +01:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Max Semenik
e14fa40ecd More backwards compatible changes for PHPUnit
The change in XmlTest is because PHPUnit 8 messes with serialization
settings.

Bug: T192167
Change-Id: I5c9358d7cfc451845e01fca67c8d15add4039dae
2019-11-12 17:07:23 -08:00
Max Semenik
48a323f702 tests: Add explicit return type void to setUp() and tearDown()
Bug: T192167
Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43
Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
2019-10-30 14:31:22 -07:00
Aryeh Gregor
0de9c47b50 Remove Language::factory and getParentLanguage use
Change-Id: I11f8801ef47ec1a1f63d840116e69667e6f3ae3c
2019-10-27 12:34:28 +02:00
Daimona Eaytoy
98fcdd8f7d Replace setExpectedException with single arg
Find: (\$this->)setExpected(Exception\( \\?[a-z\\]+::class \);)
Replace: $1expect$2

Bug: T192167
Change-Id: I33a24d42b6dc1e126f32d5dbf41daa0bccb1414f
2019-10-05 17:39:46 +02:00
Thiemo Kreuz
e06ce9f467 tests: Prefer PHPUnit's assertSame() when comparing empty strings
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
2019-09-20 15:27:58 +00:00
Roan Kattouw
fbbd65d2df ResourceLoader: Add support for packageFiles
Package files are files that are part of a module, but are not
immediately executed when the module executes. Instead, they are
lazy-excecuted when require() is called on them. Package files can be
scripts (JS) or data (JSON), and can be real files on the file system,
or virtual files generated by a callback.

Using virtual data files, server-side data and config variables can be
bundled with a module. Support for file-based require() allows us to
import npm modules into ResourceLoader more easily.

The require function passed to each script execution context, which was
previously a reference to the global mw.loader.require() function, is
changed to one that is scoped to the module and the file being executed.
This is needed to support relative paths: require( '../foo.js' ) can
mean a different file depending on the path of the calling file.

The results of require()ing each file (i.e. the value of module.exports
after executing it) are stored, and calling require() on the same file a
second time won't execute it again, but will return the stored value.

Miscellaneous changes:
- Add XmlJsCode::encodeObject(), which combines an associative array of
  XmlJsCode objects into one larger XmlJsCode object. This is needed for
  encoding the packageFiles parameter in mw.loader.implement() calls.

Bug: T133462
Change-Id: I78cc86e626de0720397718cd2bed8ed279579112
2019-02-05 22:05:02 +00:00
Fomafix
37789ebf45 Xml.php: Do not escape double quotes in $contents of Xml::element()
There is no need to escape double quotes in content of XML.
Html::element() also does not escape double quotes in content.

ENT_NOQUOTES escapes '<', '>' and '&' but not "'" and '"'.
https://secure.php.net/manual/en/function.htmlspecialchars.php

Change-Id: I3b585c43e532cca1a8951d6c9e8b4825fc3b012d
2018-05-23 20:03:54 +00:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
818e93ed2b Fix @covers in XmlTest
Follows up 389fa13ff8.

Change-Id: I32ddf37b24a6b5162b383260233d616cb49f7ddb
2017-12-24 19:16:26 -08:00
Amir Sarabadani
389fa13ff8 Add tests for several methods of Xml
Added tests for methods: monthSelector, span, buildTable, buildTableRow

Change-Id: I5ca6bb231b5ed95f57f649a92d659245a4852c85
2017-12-25 03:45:32 +01:00
jenkins-bot
6d3641b7a7 Merge "Improve namespace handling in tests" 2017-09-29 05:33:26 +00:00
Brad Jorsch
2d9f29a846 Improve namespace handling in tests
MWNamespace has three internal caches, only one of which can be cleared
(and that somewhat oddly by passing a boolean to
MWNamespace::getCanonicalNamespaces()).

This change introduces a MWNamespace::clearCaches() method to clear all
three caches. It also adds some resetting in tests that seemed to be
missing it.

Change-Id: I1dcfcd8713888b3ff8fc75e95329ba72bd95d0c9
2017-09-29 05:21:47 +00:00
Bartosz Dziewoński
15dc2f8eaa Revert "Xml: Fix Xml::fieldset() when $content is not given"
Apparently that is intentional and documented. Huh. Whoops.

This reverts commit 0f1cc3bb6e.

Also add test cases for this bizarre function.

Change-Id: I0311f7c85cd575f2a66d50589ec364072be486fb
2017-09-17 19:25:01 +02:00
Bartosz Dziewoński
a5c3d029c5 Reduce code duplication for parsing messages into dropdown menus
The same behavior was implemented by Xml::listDropDown(),
Article::confirmDelete() and HTMLFormField::getOptions().
A new function Xml::listDropDownOptions() is added and
all three are changed to use it.

Additionally:
* Xml::listDropDown() now uses XmlSelect internally to generate the
  dropdown HTML.
* Xml::listDropDownOptionsOoui() is introduced to handle converting
  the existing format to the OOUI format, which was previously
  duplicated in Article::confirmDelete() and HTMLFormField::getOptionsOOUI().
* This change allows HTMLForm 'select' fields (HTMLSelectField) to
  support nested options (optgroups) in OOUI mode. This is a
  prerequisite for T117781.

Bug: T117781
Change-Id: I0a088f61eb32ec59677113583c7ecdcbc3fd2af0
2017-09-12 20:49:20 +02:00
Timo Tijhof
4a1c7381d2 Xml: Add test for listDropDown and remove unused getArrayFromWikiTextList
Follows-up 4b49705613 and 8c7095be85 (T34950).

Change-Id: I95b7f7ce03b2cbe68215a7ff17afc1997a54f9b1
2017-03-20 22:47:19 +00:00
James D. Forrester
1e9c361960 tests: Replace implicit Bugzilla bug numbers with Phab ones
It's unreasonable to expect newbies to know that "bug 12345" means "Task T14345"
except where it doesn't, so let's just standardise on the real numbers.

Change-Id: I46261416f7603558dceb76ebe695a5cac274e417
2017-02-21 02:14:34 +00:00
Reedy
7ae2669643 Removed Xml::escapeJsString()
Change-Id: Iead8385a72a79632a90594a8828080a6d572e039
2016-12-02 00:31:59 -08:00
Brian Wolff
ee4d5c6eed Remove support for $wgWellFormedXml=false
tl;dr: Having unnessary complexity in security critical code is bad.

* Extra options add extra complexity and maintenance burden
** Thus we should only have one html output mode. well formed = false
     was already vetoed in T52040, so lets go with WellFormed=true.
* Options which are used by very few people tend to get tested less
* Escaping is an area of code where we should be very conservative
* Having escaping rules depend on making assumptions about which
    characters various browsers consider "whitespace" is scary
* $wgWellFormedXml=false has had a negative security impact in the
    past (Usually not directly its fault, but has made other bugs
    more exploitable)
* Saving a couple bytes (even less bytes after gzip taken into
    account) is really not worth it in this context (imho).

Change-Id: I5c922e0980d3f9eb39adb5bb5833e158afda42ed
2016-05-12 17:40:01 -04:00
addshore
afa65fe50c wgUseMediaWikiUIEverywhere false in Html/XmlTest
It seems both of these tests assertions all expect
this to be false.

Ic675e92d8dd8f11fa67914d2ce1dc00a379106ca
ended up discovering these issues somehow
with these tests suddenly starting to fail.

Change-Id: I9d2d3c18d1c9640e2ff04d6fd4296abb86e26877
2016-03-24 15:02:34 +00:00
Timo Tijhof
dd2d7d0ffc OutputPage: Minor clean up of <head> and HTML
* Remove trailing space in self-closing tag.
  Brings parserTest output of Parser and Parsoid closer together.

* Remove various line breaks at begin and end of script contents.

* Remove FILTER_NOMIN from makeConfigSetScript() output.
  This isn't part of any user- or page-dependent module and not minified.
  And Xml::encodeJsCall already ensures compact output for prod mode.

Bug: T127328
Change-Id: I85a5a59fd0955c1a112e8b24b933f0d9e983a156
2016-03-24 03:24:31 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
Geoffrey Mon
78401facfe Use XmlSelect to simplify Xml::monthSelector
* Modify Xml::monthSelector
 * Tweak XmlTest.php to swap the order of some props (XmlSelect
    output swaps the position of id and name props of <select>s)

Bug: T93234
Change-Id: If7e41251a6b2314e36dac8b7522c8e7b765f1814
2015-06-06 20:26:57 -04:00
Bartosz Dziewoński
896fdb3d97 Html: Make addition of 'mw-ui-input' conditional on $wgUseMediaWikiUIEverywhere
We were always adding it previously, which seemed harmless since
'mediawiki.ui.input' RL module, providing the styling, was only loaded
if $wgUseMediaWikiUIEverywhere was true… unless someone loaded it
manually to have specific input fields styled. Whoops.

There are a lot more unconditional additions like this in tons of
places in the code, and someone should check whether each one is
intentional or not, but probably no one will. Oh well.

Bug: T92496
Change-Id: I5e91a3852a76ebbbfe64485bccb4c30ddee28b66
2015-03-13 19:02:34 +00:00
jdlrobson
aa15d5287d Add blanket support for mediawiki ui via globals
This provides better mobile experiences on various pages
and a more consistent UI across both mobile and desktop.

It does this in two ways.

1) Forces HTMLForms to not use table based layouts so as
not to interfere with responsive nature of mediawiki ui elements

2) Applies MediaWiki.UI classes to most pages
If a page is created via Xml or Html classes it will use mediawiki ui
Where possible I've added classes unconditionally, but for cases of buttons
this is behind the $wgUseMediaWikiUIEverywhere global since button styling is
enabled on pages by default and for checkboxes since it is changes HTML markup.

3) Adds all MediaWiki.UI styles to pages which can use it
When enabled:
* Apply these styles to all pages which use HTMLForms
* Apply to EditPage
* Apply to anything that uses certain elements outputted by the
Xml or HTML helper classes
* Apply to History page
* Apply to protection page
* Apply to move page
* Apply to deletion page

Currently kept behind a global to allow us time to finetune
existing elements. After further testing we will look to kill the
globals and make mediawiki.ui the default

See: I430c0fbb79d2a33bb828b2427bda0ee01115d73f
Change-Id: I47db5eab4569514d039261d11b6dedb0eeae17b5
2014-08-15 14:48:00 -07:00
Siebrand Mazeland
e1d58d9071 Pass phpcs-strict on some test files (8/11)
Change-Id: I138c1f9bf2c3c7e9218d5fa29365e78b309fb459
2014-04-24 13:49:48 -07:00
Siebrand Mazeland
80a8a8e85c Pass phpcs-strict on some test files (5/x)
Change-Id: I690645cd8a9b1165dcc8271b201c695ea9391226
2014-04-24 18:51:45 +02:00
addshore
f86db05d8d Remove unused stuff from tests
Change-Id: Iddabfbc80378b02fa4a2c58f80d50241be8105d3
2014-03-07 21:16:32 +00:00
addshore
de7af7ac2c Fix scope on all /phpunit test methods
Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
2013-10-24 10:31:32 +02:00
addshore
fb16eb2abe Add more @covers tags and test cleanup
Other cleanup includes
 - Adding method scopes
 - Fixing php comments
 - Adding todos

Change-Id: I0a231008e6a59110ffcab6af1bd8c4d3ee13f21d
2013-10-22 08:59:42 +00:00
addshore
4e941cf4ca Add @covers tags for more tests
Change-Id: Iff3af78e9b41c445b7f066b6c0d0f4a87d2d6c4e
2013-10-21 11:28:39 +02:00
Daniel Friesen
97caae596d Drop support for XHTML 1.0
* $wgHtml5 = false; is now ignored completely.
* $wgDocType and $wgDTD have been removed.
* $wgXhtmlDefaultNamespace is now ignored.
* XHTML5 will be output if $wgMimeType is set to an XML mime type (according to HTML5's rules).
* For backwards compatibility with extensions $wgHtml5 and $wgXhtmlDefaultNamespace are set
  in Setup.php but depending on them is deprecated.

Change-Id: Iad9634e2ee420b5a3bbffe550421fde4fa1819b0
2013-05-15 23:09:25 -07:00
Siebrand Mazeland
419b02b6df Update formatting
3 of n.

Change-Id: I62ad009018c54da6cf081c334e44eb98a3c72695
2013-02-14 12:56:23 +01:00
umherirrender
ee643dd587 Set wgHtml5/wgWellFormedXml for XmlTests
Change-Id: I3cab843bad9461098cf3c6b574fb767c3267ab14
2012-12-09 11:47:03 +01:00
Timo Tijhof
181c7cdc8e Clean and repair many phpunit tests (+ fix implied configuration)
This commit depends on the introduction of
MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4.

Various tests already set their globals, but forgot to restore
them afterwards, or forgot to call the parent setUp, tearDown...

Either way they won't have to anymore with setMwGlobals.

Consistent use of function characteristics:
* protected function setUp
* protected function tearDown
* public static function (provide..)

(Matching the function signature with PHPUnit/Framework/TestCase.php)

Replaces:
 * public function (setUp|tearDown)\(
 * protected function $1(

 * \tfunction (setUp|tearDown)\(
 * \tprotected function $1(

 * \tfunction (data|provide)\(
 * \tpublic static function $1\(

Also renamed a few "data#", "provider#" and "provides#" functions
to "provide#" for consistency. This also removes confusion where
the /media tests had a few private methods called dataFile(),
which were sometimes expected to be data providers.

Fixes:

TimestampTest often failed due to a previous test setting a
different language (it tests "1 hour ago" so need to make sure
it is set to English).

MWNamespaceTest became a lot cleaner now that it executes with
a known context. Though the now-redundant code that was removed
didn't work anyway because wgContentNamespaces isn't keyed by
namespace id, it had them was values...

FileBackendTest:
* Fixed: "PHP Fatal: Using $this when not in object context"

HttpTest
* Added comment about:
  "PHP Fatal: Call to protected MWHttpRequest::__construct()"
  (too much unrelated code to fix in this commit)

ExternalStoreTest
* Add an assertTrue as well, without it the test is useless
  because regardless of whether wgExternalStores is true or false
  it only uses it if it is an array.

Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
2012-10-09 03:01:51 +02:00
Timo Tijhof
d1c8bf85f8 Fix HtmlTest, XmlTest; Add setMwGlobals method to base TestCase.
The HTML and XML test now set the globals they depend on
(instead of relying on the default settings).

Tests for the "other" scenarios still exist, globals are
overridden inline. They are automatically restored after each
test## function by PHPUnit from MediaWikiTestCase::tearDown.

Also fixed 2 other problems with the test suite:

* HtmlTest::testDropDefaults forgot to pass
  $message to the assertion from the provider ($case[3]).

* The data provider for HtmlTest::testDropDefaults was calling
  Html::element directly (instead of calling it within the test)
  which is problematic because data providers are expected to be
  static. PHPUnit calls them outside the setUp/tearDown flow.
  (also fixed the function to be public static, as PHPUnit
  expects).

That last one was crucial to make the test still pass correctly.

Updated the expected strings to what they are with these
fixed non-leakage settings.

Took wgHtml5 without xmlform as default. And added tests
for variations where it made sense.

Change-Id: Iccf6ea81f4bc2639273ab2ad101c58788ee49d45
2012-10-09 00:26:52 +02:00
Alexandre Emsenhuber
3beaa0a027 Follow-up Ifd700826 (60d119c), address a fixme in a re-enabled test.
Make the "Date menu next month is 11 months ago" also work when the
current month is december.

Change-Id: Ie7b998bf962abbb3e2f789a3d8a9af8c52e7feaa
2012-09-23 10:15:20 +02:00