aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/integration/includes/Rest/Handler/PageHTMLHandlerTest.php
Commit message (Collapse)AuthorAgeFilesLines
* Remove 2-line PHPDocs that just repeat the types from the codethiemowmde2025-01-171-4/+0
| | | | | | | | | | | | | | | | Same as Ia294bf4 did for 1-line comments. This patch removes slightly more complex 2-line PHPDoc comments that don't add any new information to the code, but literally repeat what the code already says. They say "don't document the code, code the documentation", and we are doing this more and more. We just tend to forget to remove the obsolete comments. Note I'm also removing a line of text in a few cases when it's very short and literally says the same as the method name. Again, such comments add zero new information. Change-Id: I01535404bab458c6c47e48e5456403b7a64198ed
* REST: Allow page endpoint "redirect" parameter to have value "false".bpirkle2024-11-071-0/+37
| | | | | Bug: T374683 Change-Id: Id5072010fae7debe309e59f0479f44fbeb036934
* [HtmlOutputRendererHelper] Remove use of ParsoidOutputAccess::parseUncacheableC. Scott Ananian2024-07-191-1/+1
| | | | | | | | | This removes the last use of ParsoidOutputAccess in core, allowing it to be deprecated and eventually removed. Bug: T367074 Bug: T317018 Change-Id: Ica2c880e2e7c2b126aaea66a3e4be460b3f2234f
* Merge "Use MainConfigNames constants in tests where possible"jenkins-bot2024-07-111-1/+1
|\
| * Use MainConfigNames constants in tests where possiblethiemowmde2024-07-101-1/+1
| | | | | | | | | | | | | | I believe this makes the code less brittle, and also makes it a bit more obvious what these strings are meant to represent. Change-Id: Ia39b5c80af4b495931d0a68fd091b783645dd709
* | Add namespace to the root classes of ObjectCacheEbrahim Byagowi2024-07-101-1/+1
|/ | | | | | | | | And deprecated aliases for the the no namespaced classes. ReplicatedBagOStuff that already is deprecated isn't moved. Bug: T353458 Change-Id: Ie01962517e5b53e59b9721e9996d4f1ea95abb51
* Use real type hints for services etc. in includes/Rest/Bartosz Dziewoński2024-06-111-2/+1
| | | | | | | | | | | | | | | | | Mostly used find-and-replace: Find: /\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?)[\s\*]+/\s*(private|protected|public) (\$[a-z]\w+;\n)((?=\s*/\*[\*\s]+@var (I?[A-Z](\w+)(?:Interface)?))\n|) Replace with: \3 \1 \4 More could be done, but to keep this patch reasonably sized, I only changed the most obvious and unambiguously correct cases. In some cases, I also removed redundant doc comments on the constructor, and re-ordered the properties to match the constructor. Change-Id: Ifa710fdf4d8d44a2d7244798b787a1b2a58c35a7
* objectcache: Introduce `ObjectCacheFactory` MW serviceDerick Alangi2024-03-191-0/+10
| | | | | | | | | | | | | | | | | | | | | ObjectCache is already doing a lot of factory pattern logic like creating instances of the various BagOStuff, this should really be the responsibility of the factory servicet. This patch introduces a proper factory (ObjectCacheFactory) to handle the responsibility of creating various instances of BagOStuff. Since `newFromParams()` is a static function that gets passed in configuration of $wgObjectCaches, that can stay that way (to keep supporting how we do this in prod today). Technical Breaking Change: `ObjectCache::makeLocalServerCache()` now has a parameter and requires it but there are no callers of this method outside MW core hence it is safe to change (and this patch update all callers) to work correctly. Cache prefix is gotten from global state because sometimes at this stage, the services container is not available. Bug: T358346 Change-Id: I3179a387486377c6a575d173f39f82870c49c321
* REST: Add tests for handling file description pagesdaniel2024-01-021-0/+49
| | | | | | | | | This adds high level test that ensure that the page HTML endpoint behaves correctly for file description pages on wikis that make use of a remote file repo. Bug: T353688 Change-Id: Ied774b885be08a7db9e78aacb6bb56382fd8c2c0
* Namespace remaining files under includes/deferredJames D. Forrester2023-11-221-1/+1
| | | | | Bug: T166010 Change-Id: Ibd40734b96fd2900e3ce12239d09becfb4150059
* Follow-up 71ff05267: Stop writing to tablesUsed in tests, now unnecessaryJames D. Forrester2023-11-211-9/+0
| | | | | Bug: T342301 Change-Id: I5ea01f7ee103570165261bde0965c5b65e04c369
* Rest: Remove some unused variables from testsDerick Alangi2023-11-151-1/+1
| | | | Change-Id: I10b7c03f16c06ac271ed3241b82dd0f87c28f6d7
* REST: Inject Authority instead of full User objectDerick Alangi2023-11-131-4/+4
| | | | | | | | | | | | | | | | | | | | | Per T310476, it looks like the Authority interface now supports rate limiting, so we can just use that instead of a heavy full user object. Possible followups ================== More can be done to make all consumers of the HTML helper's `init()` method to inject Authority instead. This patch is needed for the work happening in I08ebea5e8a601f161f. NOTE: This is technically not a breaking change as the Authority interface is implemented by both UserAuthority and User classes, so passing either is fine so consumers passing a full user object should still work even though we changed the signature of a public method in HtmlOutputRendererHelper. Change-Id: I025cd83cc81f73ded861fcab943ba3b942d7c390
* Make ParsoidOutputAccess a wrapper over ParserOutputAccessSubramanya Sastry2023-10-131-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Updated ParserOutput to set Parsoid render ids that REST API functionality expects in ParserOutput objects. * CacheThresholdTime functionality no longer exists since it was implemented in ParsoidOutputAccess and ParserOutputAccess doesn't support it. This is tracked in T346765. * Enforce the constraint that uncacheable parses are only for fake or mutable revisions. Updated tests that violated this constraint to use 'getParseOutput' instead of calling the parse method directly. * Had to make some changes in ParsoidParser around use of preferredVariant passed to Parsoid. I also left some TODO comments for future fixes. T267067 is also relevant here. PARSOID-SPECIFIC OPTIONS: * logLinterData: linter data is always logged by default -- removed support to disable it. Linter extension handles stale lints properly and it is better to let it handle it rather than add special cases to the API. * offsetType: Moved this support to ParsoidHandler as a post-processing of byte-offset output. This eliminates the need to support this Parsoid-specific options in the ContentHandler hierarchies. * body_only / wrapSections: Handled this in HtmlOutputRendererHelper as a post-processing of regular output by removing sections and returning the body content only. This does result in some useless section-wrapping work with Parsoid, but the simplification is probably worth it. If in the future, we support Parsoid-specific options in the ContentHandler hierarchy, we could re-introduce this. But, in any case, this "fragment" flavor options is likely to get moved out of core into the VisualEditor extension code. DEPLOYMENT: * This patch changes the cache key by setting the useParsoid option in ParserOptions. The parent patch handles this to ensure we don't encounter a cold cache on deploy. TESTS: * Updated tests and mocks to reflect new reality. * Do we need any new tests? Bug: T332931 Change-Id: Ic9b7cc0fcf365e772b7d080d76a065e3fd585f80
* Make use of assertStatusGood/Error and such in teststhiemowmde2023-10-041-6/+3
| | | | Change-Id: I11eace3d9823ca28a1d9a64f959f5f8ca2945821
* Reorg: Move MWTimestamp to MediaWiki\UtilsAmir Sarabadani2023-08-191-1/+1
| | | | | Bug: T321882 Change-Id: I48c10343295c4eb3d9ef8037343b0070e928f040
* REST tests: don't require the Parsoid extension.daniel2023-06-181-10/+0
| | | | | | | | Several tests were marked skipped when the Parsoid extension isn't loaded. But the extension is no longer needed to use parsoid. So these tests should not be skipped. Change-Id: I9febdbd143237bf247c82bfa386bc2560ef411aa
* tests: Make some PHPUnit data providers staticTim Starling2023-03-241-2/+2
| | | | | | | | | | | | | 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
* Fix tests that fail when $wgUsePigLatinVariant = falseTim Starling2023-03-171-0/+1
| | | | | | | | | | * ParserTestRunner: LocalisationCache needs to be reset since it has a reference to LanguageNameUtils which has a copy of $wgUsePigLatinVariant. Also factor out some MediaWikiServices::getInstance() calls. * In some other tests, set the variable. Change-Id: I6c1e9bfad9790cf805809c28a3f8d45952cbb981
* Reorg: Namespace the Title classJames D. Forrester2023-03-021-1/+1
| | | | | | | | | | | | | | | | | | | This is moderately messy. Process was principally: * xargs rg --files-with-matches '^use Title;' | grep 'php$' | \ xargs -P 1 -n 1 sed -i -z 's/use Title;/use MediaWiki\\Title\\Title;/1' * rg --files-without-match 'MediaWiki\\Title\\Title;' . | grep 'php$' | \ xargs rg --files-with-matches 'Title\b' | \ xargs -P 1 -n 1 sed -i -z 's/\nuse /\nuse MediaWiki\\Title\\Title;\nuse /1' * composer fix Then manual fix-ups for a few files that don't have any use statements. Bug: T166010 Follows-Up: Ia5d8cb759dc3bc9e9bbe217d0fb109e2f8c4101a Change-Id: If8fc9d0d95fc1a114021e282a706fc3e7da3524b
* Parsoid: implicitly enable linting in API endpointsdaniel2022-12-131-0/+29
| | | | | | | | | | Logging linter data should be enabled automatically by HtmlOutputRendererHelper. This change enables linting data for requests coming in via the v1/page/{title}/html endpoint. Change-Id: Idafd29784ec712547e36fea88a8c159784b97f2b
* tests: Remove unnecessary override to use pig-latinAbijeet2022-12-081-1/+0
| | | | | | | Pig latin is enabled by default since Ia80ad33cbf5e311fa8b84bd765a8df8d156f4c38 Change-Id: I0cd922bb0ee1fd7bce2ced2eacbdb6ed25ada7d8
* Follow redirects for page/{title} formats source/baremsantos2022-12-021-130/+2
| | | | | | | | | | | | | | | | | | * Share logic previously implemented for html/with formats through a trait class * source/bare formats doesn't execute a temporary redirect. the JSON body will contain a key "redirect_target" instead if a wiki redirect is found * Introduce PageRedirectHandlerTest to test redirect logic shared between multiple handlers * Move Handler instatiation to HandlerTestTrait * Update api-testing tests in Update.js Change-Id: Id66e33e19adabdb3c9621eaea4a5d441f23edafd
* HtmlOutputRendererHelper: add more convenient settersdaniel2022-11-281-1/+3
| | | | | | | | | REST helper objects should be geared towards accepting input directly from an HTTP request. As such, they should offer setters that take string values. And native representation of things like page titles, languages, or content objects should be done implicitly by the helper. Change-Id: I9b81cad4d5cc575e7c5283035e385ac0457e8059
* Rest: Allow fetching content of pages with system messagesDerick Alangi2022-11-231-1/+61
| | | | | | | NOTE: some phan suppressions removed, no longer needed now. Bug: T317017 Change-Id: Iccbffb502eeace841f86ddb1987e77be50003973
* Introduce PageRestHelperFactorydaniel2022-11-211-9/+26
| | | | | | | | This allows extensions like VisualEditor to safely instantiate REST helper objects. It also reduces the number of services that need to be injected into REST handlers from route definitions. Change-Id: I10af85b2da96568cfffd03867d1cb299645fb371
* Follow redirects for page/{title} formats html/with_htmlmsantos2022-11-161-1/+47
| | | | | | | | | | | | | | | | * Apply Legacy Temporary redirects (302) if page is a redirect in order to have feature parity with RESTBase * Check for normalization redirects and execute permanent redirects (301) * Add/Update mocha tests for the redirects functionality * Add query parameter 'redirect=no' check to bypass redirect logic * Unit tests to check status code and location headers Bug: T301372 Change-Id: I841c21d54a58e118617aaf5e2c604ea22914adaa
* Rename HTMLTransform to HtmlToContentTransformdaniel2022-11-031-1/+1
| | | | | | | | | | * We will have several kinds of HTML transformations. Rename HTMLTransform to indicate that its for converting HTML to Content objects. * Using Naming Convention 'Html' instead of 'HTML' Change-Id: I506f3303ae8f9e4db17299211366bef1558f142c
* page/html endpoint: Support variant conversionAbijeet2022-11-011-1/+64
| | | | | | | | | Variant conversion is based on the Accept-Language header. Updated the HtmlOutputRendererHelper to set the HTTP headers related to variant conversion. Bug: T317019 Change-Id: I5e11452f1c531a757e8d860f9c727b5810406bce
* Merge "Use markTestSkippedIfExtensionNotLoaded() shortcut in tests"jenkins-bot2022-10-141-14/+4
|\
| * Use markTestSkippedIfExtensionNotLoaded() shortcut in teststhiemowmde2022-10-041-14/+4
| | | | | | | | Change-Id: Ie7cc7b8c3aad0225f2f2d2d2241046756c03c0d5
* | Fix passing the wikiId into ParsoidOutputAccess.daniel2022-10-071-1/+1
| | | | | | | | | | | | | | It's not clear if Parsoid still need this, but let's err on the side of caution. Change-Id: I7cef2827da23af3c3466cb855de5f42e05375515
* | ParsoidOutputAccess: Add support for `fragment` flavorDerick Alangi2022-10-061-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This is needed by VE when performing Wikitext -> HTML transformation during editing. Also, this patch introduces the new flavor: fragment, that is passed in via $envOptions to activate VisualEditor's body only mode functionality. NOTE: This patch also fixes a PHPUnit test that broke by correctly injecting the appropriate parsoid instance for checking error handling. Bug: T308743 Change-Id: I838a3b05d7d8523a469236cf112158349063283c
* | HtmlInputTransformHelper: Fall back to ParserCachedaniel2022-09-301-0/+1
|/ | | | | | | | | | | | | If a render ID is given via the use-cache parameter, but the key is not found in the parsoid stash, look at the most recent known rendering of the revision, and use it if it matches the render ID. This patch moves the responsibility for looking up RevisionRecords and PageRecords into ParsoidOutputAccess. This way, callers only need to have a PageIdentity, and optionally a revision ID. Bug: T318395 Change-Id: I1aa5b0fd9fb1acaa2544d5a58125fa3810a0eb39
* Make RateLimiter use WRStatsTim Starling2022-07-161-1/+0
| | | | | Bug: T261744 Change-Id: Ib947340cbac19fb26176257e1707e51426c7f76e
* tests: Use `overrideConfig(Value|Values)` where neededDerick Alangi2022-07-121-2/+3
| | | | | | | | This continues the work in the child patch to replace callers of setMwGlobals() with the appropriate method. Directory this patch covers is `tests/phpunit/integration/`. Change-Id: I0a9abf0d2a43587f2ffa029b68024a1ba5165fc7
* PHPUnit: introduce setMainCachedaniel2022-07-071-2/+3
| | | | | | | | | | | | The main object cache is disabled during testing. Some integration tests need it though. This provides a clean way to enable it, to replace the hacks that were used so far. Note that we may want to enable the main cache during testing soon. When that happens, this method is still useful to disable the cache in certain tests, and to set a specific cache instance. Change-Id: I04ae1bf1b6b2c8f6310acd2edf89459d01a9c870
* Protect against passing unsupported content models to Parsoid.daniel2022-06-301-0/+1
| | | | | | | | | | | | Parsoid currently only supports wikitext (and JSON), so don't give it anything else. NOTE: ParsoidOutputAccess will fail on content that is unsupported by parsoid. This will however not affect the /transform and /page endpoints in the parsoid extension, since they use the ParsoidHandler base class, which doesn't rely on ParsoidOutputAccess. Bug: T301371 Change-Id: I6bc9b978947b31455a4bce6385b7bdf64ed4043c
* Storage: Warm parsoid parser cache with parsoid outputsDerick Alangi2022-06-281-49/+29
| | | | | | | | | | | | This patch introduces a ParsoidOutputAccess service for getting parsoid outputs and warms the cache with pregenerated outputs. It also introduces a config variable in ParsoidCacheConfig that is turned off by default for controlling the cache warming. Bug: T301371 Change-Id: I6152c42ea765d94093d8d62598b1b4278314adec
* Configure caching parsoid output per wiki based on thresholdDerick Alangi2022-06-161-4/+9
| | | | | | | | | Cache the parsoid outputs only if a certain time is exceeded on parse and consider the parse operation within this time limit as not expensive per that wiki and not cache the parsoid output at all. Bug: T308588 Change-Id: I7793b77feab13400ccd04343e7878ad701f5e6a7
* Add rate limiting to ParsoidHTMLHelperdaniel2022-06-151-0/+21
| | | | | Bug: T267991 Change-Id: I52a83e7d3bdb0bcde59160e2d193f06908fda3d4
* ParserCache: always use JSONdaniel2022-06-071-1/+0
| | | | | | | | | | | | | When JSON support was introduced into ParserCache in 1.36, it was controlled by a feature flag, $wgParserCacheUseJson. The feature flag was "born deprecated" in 1.36. It can now be removed. This means that ParserCache will always store entries as JSON. Support for reading old non-JSON entries remains intact. This is needed when updating wikis from a version older than 1.36 to the current version. Change-Id: Id04e42bfb458d98414bac50e0d6c505e8878e5c0
* Rest: Collect stats on Cache & Stash usageDerick Alangi2022-05-301-1/+2
| | | | | | | | | | As a means of understanding the usage of the stash FEAT for /page/html & /revision/html endpoints used by VE extension, this patch introduces the collection of stats using the StatsDataFactory. Bug: T309017 Change-Id: I4e17d50e79da263637bdd55ab62e993df441fe38
* Rest: Return different eTags for different output modesDerick Alangi2022-05-251-3/+15
| | | | | | | | | | | | This patch enables the response from PageHTMLHandler and RevisionHTMLHandler to have different eTags for different output modes and varying flavors. Before, the only difference we got was when the stashing option is set or not, but we need more flavors. Bug: T308744 Change-Id: I2e9679e46a31955a2106a52af4eb612b32799c8c
* Rest: Migrate parsoid stashing logic from RESTbaseDerick Alangi2022-05-231-17/+62
| | | | | | | | | | | | | | | | | Add stash option to /page/html & /revision/html endpoints. When this option is set, the PageBundle returned by Parsoid is stashed and an etag is returned that can later be used to make use of the stashed PageBundle. The stash is for now backed by the BagOStuff returned by ObjectCache::getLocalClusterInstance(). This patch adds additional data to the ParserOutput stored in ParserCache. Old entries lacking that data will be ignored. Bug: T267990 Co-Authored-by: Nikki <nnikkhoui@wikimedia.org> Change-Id: Id35f1423a69e3ff63e4f9883b3f7e3f9521d81d5
* Remove or replace usages of "sanity"Reedy2021-11-211-3/+3
| | | | | | | Still some more to go... Bug: T254646 Change-Id: Ia117f01e443c35b4765f3275cab4f2707e1be96f
* Eliminate use of Title object in REST infrastructurePetr Pchelko2021-05-051-4/+2
| | | | Change-Id: I585f0f23cac5f6dc2a4879f69f7b83828fda3dd3
* Convert ParserCache to PageRecordPetr Pchelko2021-04-021-1/+3
| | | | | | | | | | | | | | | ParserOptions not updated cause they depend on Title::getLanguage implementation. Tests converted to not require a DB anymore. Can't be proper unit tests yet due to globals in ParserOptions and fake time hacks, but exec time does go down from 70 seconds to 9 seconds. Page content model is still emitted in the metrics since it was considered useful. Should be removed when we get something like a page type concept. Change-Id: Ib16fd0b5b87ffc3cb4d21f4aa43d1203cb7206d2
* Rest: use Authority in all core handlersPetr Pchelko2021-01-211-1/+0
| | | | | Bug: T239753 Change-Id: Idf2229255f49514dd8b68bf63573c5b619b4f2f1
* tests: Remove @param docs from test code that just repeat the signatureThiemo Kreuz2021-01-211-2/+0
| | | | | | | | | | | | | | These are not only 100% identical to the actual code, but also: * It's error-prone. Some are already wrong. * These test…() functions are not meant to be called from anywhere. What is the target audience for this documentation? * There is a @dataProvider. What such @param tags actually do is document the provider, but in an odd place. Just looking at the provider should give the same information. * The MediaWiki CodeSniffer allows to skip @param when there is a @dataProvider, for the reasone listed. Change-Id: I0f6f42f9a15776df944a0da48a50f9d5a2fb6349