Commit graph

182 commits

Author SHA1 Message Date
jenkins-bot ce14db4048 Merge "Add parser tests for the responsive="…" feature" 2019-12-18 07:10:22 +00:00
Thiemo Kreuz 1f76199ed8 Add parser tests for the responsive="…" feature
Change-Id: Id9d733dabf82f2c26f51c6fbd1e03fe0574e88a8
2019-12-17 15:51:41 +01:00
Thiemo Kreuz e5cda65fbe Remove single use classes from the use section
The name of the base class in tests is guaranteed to only occur a
single time in a file. There is not much value in making it relative,
and requiring it to appear in the use section. Especially because it
is in the root namespace.

This reflects what I once encoded in the sniff
https://github.com/wmde/WikibaseCodeSniffer/blob/master/Wikibase/Sniffs/Namespaces/FullQualifiedClassNameSniff.php
I wish we could pick this rule and use it in our codebases. But it
seems it is to specific and can't be applied on all codebases, hence
it can't become part of the upstream MediaWiki rule set. At least not
at the moment.

Change-Id: I77c2490c565b7a468c5c944301fc684d20206ec4
2019-12-17 14:57:55 +01:00
Thiemo Kreuz 51ff3cc819 Several code cleanups after getting rid of cloning
* Use the Html class to safely create HTML code.
* $this->referenceStack can not be null any more.
* $this->inReferencesGroup is not needed during output, only when
  parsing tags.
* Replace ReferencesStack::getGroupRefs() as well as deleteGroup()
  with a combined popGroup() that does both things.
* Extract the code responsible for the "responsive" behavior to a
  separate function.
* Some TestingAccessWrapper are not needed.

Change-Id: Ie1cf2533d7417ae2f6647664ff1145e37b814a39
2019-12-16 15:47:23 +01:00
Adam Wight 870b9ec181 Rename test to match class
Change-Id: I1814f31ead3882d4c484e0da2808fc7fbc9d2f37
2019-12-12 11:15:13 +01:00
Adam Wight ab07a3253c Remove Parser state from CiteErrorReporter
Finishes breaking the circular reference between Cite and Parser.

This patch also demonstrates how evil it is to allow the error reporter
to be called from anywhere, and have side-effects.  At least it's explicit
now.

Also fixes a bug where the inner error message would not be in the
interface language.

Bug: T240431
Change-Id: Ic3325cafb503e78295d72231ac6da5c121402def
2019-12-12 11:15:07 +01:00
Adam Wight 22b2f78db6 Remove Parser state from ReferencesFormatter
Bug: T240431
Change-Id: I3477a64b9a9dba0cfe890c4b598a51c2f971c76c
2019-12-12 11:12:17 +01:00
Adam Wight 2a5976f007 Remove Parser state from FootnoteMarkFormatter
Bug: T240431
Change-Id: Ie53444114c032e083293d3b5325252debb0640a7
2019-12-12 11:12:17 +01:00
Adam Wight 852a503262 Don't keep parser reference in Cite
This begins our journey of breaking the circular reference between
Cite and Parser.  In later patches the child objects will also take
Parser as a parameter.

Bug: T240431
Change-Id: Ic672bb4bae19ac5f1e1f5817de171d76b3bd8786
2019-12-12 11:12:17 +01:00
Adam Wight a227395e3a Lazy instantiation of Cite
Only create a Cite object if we need one.  Never clearState, just
destroy and recreate later.

This makes it less likely that we leak state between parsers, and
saves memory and processing on pages without references.

It's also preparation to decouple Cite logic from state.

Change-Id: I3db517591f4131c23151c76c223af7419cc00ae9
2019-12-12 11:12:17 +01:00
Thiemo Kreuz 3f2aeb7e31 Rename two Cite… classes and clean up test setups
* All classes are in a Cite\ namespace now. No need to repeat the word
"Cite" all over the place.

* The "key formatter" is more an ID or anchor formatter. The strings it
returns are all used in id="…" attributes, as well as in href="#…" links
to jump to these IDs.

* This patch also removes quite a bunch of callbacks from tests that
don't need to be callbacks.

* I'm also replacing all json_encode().

* To make the test code more readable, I shorten a bunch of variable
names to e.g. $msg. The fact they are mocks is still relevant, and still
visible because these variable names are only used in very short scopes.

Change-Id: I2bd7c731efd815bcdc5d33bccb0c8e280d55bd06
2019-12-12 08:48:02 +01:00
jenkins-bot 9cc9e9cdc1 Merge "Add parser tests for reused extended <ref> before defined" 2019-12-11 16:04:53 +00:00
jenkins-bot 5b7f6d2d35 Merge "Add parser test for duplicate extended references" 2019-12-11 15:35:33 +00:00
jenkins-bot 0dafe64305 Merge "Rename CiteParserTagHooks::initialize to register" 2019-12-11 15:35:32 +00:00
jenkins-bot 5d5fd30a3c Merge "Minor improvements to the test coverage" 2019-12-11 15:35:32 +00:00
Thiemo Kreuz f86b5073fd Add parser tests for reused extended <ref> before defined
Bug: T240424
Change-Id: I945c2e12cfa3ff851380a1ff4491c8af076f523a
2019-12-11 16:30:17 +01:00
Thiemo Kreuz 193b840010 Add parser test for duplicate extended references
Bug: T240459
Change-Id: Ifc7a695e89a49ccc6c66d49efe41b2321b0915f0
2019-12-11 15:58:34 +01:00
jenkins-bot e39b1d6cbd Merge "Use messagelocalizer in CiteErrorReporter" 2019-12-11 11:42:28 +00:00
Thiemo Kreuz d0cb639e03 Minor improvements to the test coverage
We are *so* close to 90%.

This patch should raise the coverage for the CiteDataModule to 100%.
I'm also adding a pure unit test for the clone() behavior. Note the
later is already covered by the CiteDbTest.

Question: Do we want the CiteDbTest to @cover anything?

Change-Id: I40763d01e18991f509bc30b6655aa57b23412fd9
2019-12-11 12:22:59 +01:00
Adam Wight f93f1b4fe0 Use messagelocalizer in CiteErrorReporter
Fixes a bug introduced in Icf61c9a27fd, which would cause a parser
cache split any time the Cite extension was initialized.  The
`setLanguage` interface is regrettable, but I'm hoping it will only
be around temporarily.

Converts an integration test into a unit test and completes coverage.

Bug: T239988
Change-Id: I4b1f8909700845c9fa0cbc1a3de50ee7d42f69a5
2019-12-11 09:53:47 +01:00
jenkins-bot 6556f75c38 Merge "Integration parser test for ParserFunctions" 2019-12-11 08:45:34 +00:00
jenkins-bot 76b4706938 Merge "Rename formatNumNoSeparators() to localizeDigits()" 2019-12-11 08:29:09 +00:00
Adam Wight 084ca6b3d4 Integration parser test for ParserFunctions
Depends-On: I09844079f163e583d3b1e941c701f8cda5029a0a
Bug: T240345
Change-Id: I86c55ff88d9f4b800e8868728dfec6b4ceda82c2
2019-12-11 08:58:58 +01:00
Adam Wight cad4d18458 Integration test to hit cloned Cite bug
Tickle very particular edge case in which a recursive parse corrupts
the $parser->extCite object.

Bug: T240248
Change-Id: I70d100e88fa72825194ed9c477b030bbf0b6b486
2019-12-10 17:07:44 +01:00
Thiemo Kreuz 75016551e7 Rename formatNumNoSeparators() to localizeDigits()
Because that is what it does. Note our method is different from the one
in the Language class. We only accept strings.

Change-Id: I39107e837cc29f2d7c8867c1e602aa643f9e1a57
2019-12-10 16:21:12 +01:00
Thiemo Kreuz 01bcfa773d Rename CiteParserTagHooks::initialize to register
It's called "register" in MediaWiki core as well.

Change-Id: Iad3dc3badbb7ad10a14276c3a144376acf70e5e5
2019-12-10 14:19:33 +00:00
Thiemo Kreuz 71c6dc7fe4 Better naming for ReferenceFormatter class and methods
This class renders a <references> tag and everything inside. The
previous name sounds like it is responsible for rendering the contents
of a <ref>…</ref> tag. I mean, the class contains a method that does
exactly this. But this method is private.

Change-Id: I1cd06c9a11e0a74104f2874a34efa3e0843a0f70
2019-12-10 08:40:09 +01:00
Thiemo Kreuz f92792f64a Fix bad localization of extended references numbers when reused
This adds a test for numbers like "1.2.0" that appear when an extended
reference (e.g. "1.2.") is reused multiple times.

The first separator is from the extended reference. We decided to never
localize it. However, the second seperator is from reusing a reference.
This was always localized. We believe this is a bug, but haven't fixed
it yet.

The test is documenting the status quo "1.2,0" with a comma. This kind
of makes sense, one could argue, because the "1.2" appears like this up
in the text, but the ",0" is a different indicator for a reuse, which
*never* occurs in the text.

Change-Id: Ie3d26bcadd8929b906bfbcac4806af2150d61f2a
2019-12-09 17:25:14 +01:00
jenkins-bot 4a0026d9bc Merge "Split validation function depending on inReferencesGroup" 2019-12-09 12:21:17 +00:00
Adam Wight 8097c4c148 Split validation function depending on inReferencesGroup
Some validation is exclusively used in a specific context, some is shared.

Change-Id: I390db1c9d4854871e25a2e74411476e4e1c0b66f
2019-12-09 12:27:52 +01:00
Adam Wight f51060eaf4 Fix footnote mark after extends numbering glitch
The visible numbering needed to be rolled back after an extends.

Bug: T237241
Change-Id: I95404515110df1fa7e3279ea499577df0ed45ddf
2019-12-09 12:06:59 +01:00
jenkins-bot a8e882e39f Merge "Show "Preview" headline in user instead of content language" 2019-12-09 10:13:17 +00:00
jenkins-bot 3b41cfa472 Merge "Fail early on nested extends="…", if possible" 2019-12-09 10:12:54 +00:00
jenkins-bot 399a9c63bf Merge "Numbering bug: Parser test which should fail" 2019-12-09 10:06:06 +00:00
Thiemo Kreuz c5fe49ff11 Fail early on nested extends="…", if possible
This partly reverts Ied2e3f5. I haven't properly tested this before.
Rendering a bad extends (that extends a <ref> that's already extended)
not indented messes the order up and rips other extended <ref>s out of
context.

For now it might be better to stick to the previous, "magic" behavior:
Such an extends behaves like it is extending the *parent*, and is
ordered and indented as such. This is still not correct, but I feel
this is much better than rendering such a bad extends on the top level.

This patch also makes the code fail much earlier for a nested extends,
if this decision can be made already. In this case the error message is
rendered in the middle of the text (as other errors also are), not in
the <references> section.

Change-Id: I33c6a763cd6c11df09d10dfab73f955ed15e9d36
2019-12-09 10:54:52 +01:00
Thiemo Kreuz 8fdce945bd Show "Preview" headline in user instead of content language
This partly reverts Id7a4036e64920acdeccb4dfcf6bef31d0e5657ab.

The message "cite_section_preview_references" says "Preview of references".
This line is not meant to be part of the content, but an interface message.
It should use the users (interface) language, not the content language.

Change-Id: I1b1b5106266606eb0dfaa31f4abd3cee9ba92e8c
2019-12-09 10:53:07 +01:00
Adam Wight a91cf43154 Remove outdated TODOs
These edge cases are handled correctly already, I just forgot to
remove the TODOs when updating test content.

Note that there's only one TODO left, and it's to forbid a feature which
actually works!

Change-Id: I0d3a1f55f0ce943b0d034dda40e3779fbf241fe4
2019-12-09 10:25:19 +01:00
Adam Wight d8433101a7 Numbering bug: Parser test which should fail
Includes the TODO for what correct output looks like.

Bug: T237241
Change-Id: I0e60724f2c418b19e5affc24dca7f446c2b38bb3
2019-12-09 09:53:53 +01:00
Adam Wight 3d80501829 Narrow message localizer interface
We never access Language directly, so proxy its method instead of
returning the full object.

I believe I've found a bug, but not fixing here: the footnote body
numeric backlinks like "2.1" behave as if they were decimals rather
than two numbers stuck together with a dot.  So they are localized
to "2,1".

Bug: T239725
Change-Id: If386bf96d48cb95c0a287a02bedfe984941efe30
2019-12-06 12:17:09 +01:00
jenkins-bot f745a6b2f2 Merge "Roll up a range in test fixture" 2019-12-05 14:50:29 +00:00
Adam Wight 01c76f46a6 Use message localizer in CiteKeyFormatter
Makes more tests easier.

Change-Id: I222ba61bfcf0be3e29cb04e39f44f0be7a9e0778
2019-12-05 14:57:32 +01:00
Adam Wight 1ce4079ce2 Use message localizer in FootnoteMarkFormatter
Completes test coverage.

Change-Id: Ib2ec24cf4a9de52769744d1888cb13d2bf08ae3b
2019-12-05 14:56:53 +01:00
Adam Wight 430086cb6b Use the message localizer in Cite
Allows us to convert another integration test into a unit test.

Change-Id: Id7a4036e64920acdeccb4dfcf6bef31d0e5657ab
2019-12-05 13:23:31 +01:00
Adam Wight 4dec6afbb8 Tests for checkRefsNoReferences
One of these cannot be a unit test yet, because of a wfMessage call.

Change-Id: Ie2e2e28ee4c369cc7380c528411665fbb51691be
2019-12-05 09:14:30 +01:00
Adam Wight 855a3d6d48 Roll up a range in test fixture
This... might not be helpful.

Change-Id: Iff3342d5fbf81aa27b9aaaf1b3fc4c59fa65a365
2019-12-05 09:05:03 +01:00
Adam Wight 1f92841662 Test coverage for guardedReferences
Change-Id: Id97ba7a965dfd78579fc18e7f3d21a595e6bf432
2019-12-05 08:59:22 +01:00
jenkins-bot 336dd4a27c Merge "Complete validateRef coverage" 2019-12-04 17:18:40 +00:00
jenkins-bot 6386212f1e Merge "Tests for guardedRef" 2019-12-04 17:09:19 +00:00
Adam Wight 5705228d17 Complete validateRef coverage
Change-Id: Id61fba34a8815a0c512ecf4bc57da3be4e15c8bb
2019-12-04 18:00:13 +01:00
Adam Wight 3d049159c2 Tests for guardedRef
This is a mess of a function, and the tests show it.  There are lots
of side-effects and context-sensitivity, which can be addressed in
later work.  The interface with ReferenceStack is too wide.

Change-Id: I00cab2a555b2a9efd32d937979cd722d43ac1005
2019-12-04 16:06:10 +00:00