aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/unit/includes/parser
Commit message (Collapse)AuthorAgeFilesLines
...
* Hooks::run() call site migrationTim Starling2020-05-301-11/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Migrate all callers of Hooks::run() to use the new HookContainer/HookRunner system. General principles: * Use DI if it is already used. We're not changing the way state is managed in this patch. * HookContainer is always injected, not HookRunner. HookContainer is a service, it's a more generic interface, it is the only thing that provides isRegistered() which is needed in some cases, and a HookRunner can be efficiently constructed from it (confirmed by benchmark). Because HookContainer is needed for object construction, it is also needed by all factories. * "Ask your friendly local base class". Big hierarchies like SpecialPage and ApiBase have getHookContainer() and getHookRunner() methods in the base class, and classes that extend that base class are not expected to know or care where the base class gets its HookContainer from. * ProtectedHookAccessorTrait provides protected getHookContainer() and getHookRunner() methods, getting them from the global service container. The point of this is to ease migration to DI by ensuring that call sites ask their local friendly base class rather than getting a HookRunner from the service container directly. * Private $this->hookRunner. In some smaller classes where accessor methods did not seem warranted, there is a private HookRunner property which is accessed directly. Very rarely (two cases), there is a protected property, for consistency with code that conventionally assumes protected=private, but in cases where the class might actually be overridden, a protected accessor is preferred over a protected property. * The last resort: Hooks::runner(). Mostly for static, file-scope and global code. In a few cases it was used for objects with broken construction schemes, out of horror or laziness. Constructors with new required arguments: * AuthManager * BadFileLookup * BlockManager * ClassicInterwikiLookup * ContentHandlerFactory * ContentSecurityPolicy * DefaultOptionsManager * DerivedPageDataUpdater * FullSearchResultWidget * HtmlCacheUpdater * LanguageFactory * LanguageNameUtils * LinkRenderer * LinkRendererFactory * LocalisationCache * MagicWordFactory * MessageCache * NamespaceInfo * PageEditStash * PageHandlerFactory * PageUpdater * ParserFactory * PermissionManager * RevisionStore * RevisionStoreFactory * SearchEngineConfig * SearchEngineFactory * SearchFormWidget * SearchNearMatcher * SessionBackend * SpecialPageFactory * UserNameUtils * UserOptionsManager * WatchedItemQueryService * WatchedItemStore Constructors with new optional arguments: * DefaultPreferencesFactory * Language * LinkHolderArray * MovePage * Parser * ParserCache * PasswordReset * Router setHookContainer() now required after construction: * AuthenticationProvider * ResourceLoaderModule * SearchEngine Change-Id: Id442b0dbe43aba84bd5cf801d86dedc768b082c7
* Function visibility in ParserFactoryTest.phpReedy2020-05-101-2/+2
| | | | Change-Id: I043f0b92ac0694aa5c36267edd77869b707f4812
* Deprecate a few more tidy-related methodsC. Scott Ananian2020-05-011-3/+0
| | | | | | | | | | | | | Hard-deprecate ParserOptions::getTidy(), since it always returns true and is rarely used. Code search: https://codesearch.wmflabs.org/search/?q=getTidy%5C%28&i=nope&files=&repos= Soft deprecate most methods of MWTidy; folks should use MWTidy::tidy() as the entry point here. Code search: https://codesearch.wmflabs.org/search/?q=MWTidy&i=nope&files=&repos= Bug: T198214 Change-Id: I3584181070da7ed4888beaaf04e083114aca1eab
* Deprecate Parser::firstCallInit()C. Scott Ananian2020-04-171-1/+18
| | | | | | | | | | | | | | | | | | Originally we created a Parser object on every request, and so care was taken to make Parser construction lightweight. In particular, all potentially costly initialization was moved into a separate Parser::firstCallInit() method. Starting with 1.32, parser construction has instead been done lazily, via the ParserFactory registered with MediaWikiServices. The extra complexity associated with the old manual lazy initialization of Parser is therefore no longer needed. Deprecate Parser::firstCallInit() as part of a general plan to refactor the Parser class to allow subclasses and alternate parser implementations. Add some tests to assert that parsers are being created lazily, and are not being created when they are not needed. Bug: T250444 Change-Id: Iffd2b38a2f848dad88010d243250b37506b2c715
* Remove auto-generated and empty lines in commentsThiemo Kreuz2020-03-171-0/+1
| | | | | | … and add the missing newline after the initial <?php. Change-Id: I83bbbb1504e4b2bd97eec63c7626d34c655c3197
* Fix the namespace of SpecialPageFactoryTim Starling2020-02-211-1/+1
| | | | | | | | | | | | | | | Follows-up d4045035b07. This class was added to the MediaWiki\Special namespace, contrary to the plan in T166010 which reserves that namespace for core special pages. Instead, use MediaWiki\SpecialPage, following the directory in which it is located. Also, fix two bugs which prevented the introduction of a namespaced class alias. Bug: T166010 Change-Id: I6e31340aaae32a89beb7e45b79d76a7fea9808d2
* parser: Inject a LanguageConverterFactory through DI containers:Peter Ovchyn2020-02-041-0/+65
| | | | | | | | | | | | | 1. into class Parser 2. into class LinkHoderArray 3. into class DefaultPreferencesFactory Add more tests for DefaultPreferencesFactory: 1. testVariantsSupport verifies that converter with variants is used correctly. 2. Test testUserGroupMemberships verifies that membership is used correctly Bug: T243320, T243321, T243317 Change-Id: I1e5c37e18332d0d32391c74c06e3d84862e48df8
* Hard-deprecate Sanitizer::escapeId()C. Scott Ananian2020-01-261-0/+1
| | | | | | | | | | | | | | | Deprecated in MW 1.30; time to clean up any remaining uses. Code search: https://codesearch.wmflabs.org/deployed/?q=escapeId%5C%28&i=nope&files=&repos= Depends-On: Ic03a5da2e1d6b8f5656555420dd573a1d698b9cc Depends-On: I311f44a5035f73c0fb2289f727eb39b73007429b Depends-On: I76c5b539bae5572c4ac65f28fec9c0c36381348c Depends-On: Id4cbfc3b113b1b04f949d485187e89ffe0b487f5 Depends-On: I7d5ba4930688ed7f011a4babed5986b8e40910a0 Depends-On: I964f83ce88fb9c66a7c59037c6066f4567bcf4c9 Change-Id: I89504cfdf8e02831d54a26900bfdc63a33b4eade
* Prefer assertSame() in SanitizerUnitTestThiemo Kreuz2019-11-231-5/+5
| | | | | | | | | This test compares strings. I find it critical to know this test will start failing if, for example, a method that is expected to return the string "" starts returning null. assertEquals() will not report this and quite a bunch of other edge-cases. Change-Id: I9a3f19f91b95aa384ca612f9a58c7af685306d57
* Address TODO asking for a dataProviderMax Semenik2019-11-231-76/+35
| | | | Change-Id: Iaf0a277c2f246291706d65f7fca0874bc0e8bdda
* tests: Add explicit return type void to setUp() and tearDown()Max Semenik2019-10-301-1/+1
| | | | | | Bug: T192167 Depends-On: I581e54278ac5da3f4e399e33f2c7ad468bae6b43 Change-Id: I3a21fb55db76bac51afdd399cf40ed0760e4f343
* phpunit: Repair GLOBALS reset in MediaWikiUnitTestCaseTimo Tijhof2019-09-021-32/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This code didn't work because the $GLOBALS array is exposed by reference. Once this reference was broken by unset(), the rest just manipulated a local array that happens to be called "GLOBALS". It must not be unset or re-assigned. It can only be changed in-place. Before this, the execution of a MediaWikiUnitTestCase test stored a copy of GLOBALS in unitGlobals, then lost the GLOBALS pointer and created a new variable called "GLOBALS". As such, the tearDown() function didn't do what it meant to do, either – which then results in odd failures like T230023 Rewrite it as follows: * In setup, store the current GLOBALS keys and values, then reduce GLOBALS to only the whitelisted keys and values. * In teardown, restore the original state. * As optimisation, do this from setUpBeforeClass as well, so that there are relatively few globals to reset between tests. (Thanks @Simetrical!) The following tests were previously passing by accident under MediaWikiUnitTestCase but actually did depend on global config. * MainSlotRoleHandlerTest (…, ContentHandler, $wgContentHandlers) * SlotRecordTest (…, ContentHandler, $wgContentHandlers) * WikiReferenceTest (wfParseUrl, $wgUrlProtocols) * DifferenceEngineSlotDiffRendererTest (DifferenceEngine, wfDebug, …) * SlotDiffRendererTest (…, ContentHandler, $wgContentHandlers) * FileBackendDBRepoWrapperTest (wfWikiID, "Backend domain ID not provided") * JpegMetadataExtractorTest (…, wfDebug, …, LoggerFactory, …) * ParserFactoryTest (…, wfDebug, …, LoggerFactory, InvalidArgumentException) * MediaWikiPageNameNormalizerTest (…, wfDebug, …, LoggerFactory, …) * SiteExporterTest (SiteImporter, wfLogWarning, …) * SiteImporterTest (Site::newForType, $wgSiteTypes) * ZipDirectoryReaderTest (…, wfDebug, …, LoggerFactory, …) Bug: T230023 Change-Id: Ic22075bb5e81b7c2c4c1b8647547aa55306a10a7
* Introduce MovePageFactoryAryeh Gregor2019-08-191-0/+32
| | | | | | | | | | | | This will help make MovePage more testable. In the course of abstracting the logic out of ParserFactoryTest to FactoryArgTestTrait so it could be used in MovePageFactoryTest, I made them all unit tests instead of integration. This required some modification to the Parser constructor so that it didn't access MediaWikiServices unnecessarily. Change-Id: Idaa1633f32dfedfa37516bb9180cfcfbe7ca31aa
* Unset all globals unneeded for unit tests, assert correct directoryAmir Sarabadani2019-07-091-24/+0
| | | | | | | | | | | | | * Unset globals to avoid tests that look like unit tests but actually rely on globals * move some tests out of unit directory so that the test suite will pass. * Assert that tests which extend MediaWikiUnitTestCase are in a directory with "/unit/" in its path name Depends-On: I67b37b1bde94eaa3d4298d9bd98ac57995ce93b9 Depends-On: I90921679518ee95fe393f8b1bbd9134daf0ba032 Bug: T87781 Change-Id: I16691fc8ac063705ba0c2bc63b96c4534ca8660b
* Split SanitizerTest to unit and integration testsAmir Sarabadani2019-07-081-0/+352
| | | | | | | Out of 150 tests of SanitizerTest.php, 100 of them are pure unit tests they are moved to the new file in the new structure, the rest stay Change-Id: I366d37607abff4bcd624a56fb8b2299729fbc088
* Move trivially compatible tests to the unit tests suiteMáté Szabó2019-06-301-0/+64
| | | | | | | | | | | | | | | | | | | | | This changeset resumes work on T89432 and related tickets by porting an initial set of tests to the new unit test suite separated out in I69b92db3e70093570e05cc0a64c7780a278b321a. The tests were only ported if they worked immediately without requiring any changes other than changing the test case class to MediaWikiUnitTestCase and moving the test to the new suite. If a test failed for any reason (even trivial misconfiguration), it was NOT ported. With this change, the unit tests suite now consits of a total of 455 tests. As before, you can run these tests via the following command: $ composer phpunit:unit Bug: T84948 Bug: T89432 Bug: T87781 Change-Id: Ibb8175981092d7f41864e641cc3c118af70a5c76
* Revert "Separate MediaWiki unit and integration tests"Legoktm2019-06-133-457/+0
| | | | | | | | This reverts commit 0a2b996278e57a8b8c5377cd3a3eaa54f993d4a9. Reason for revert: Broke postgres tests. Change-Id: I27d8e0c807ad5f0748b9611a4f3df84cc213fbe1
* Separate MediaWiki unit and integration testsMáté Szabó2019-06-133-0/+457
This changeset implements T89432 and related tickets and is based on exploration done at the Prague Hackathon. The goal is to identify tests in MediaWiki core that can be run without having to install & configure MediaWiki and its dependencies, and provide a way to execute these tests via the standard phpunit entry point, allowing for faster development and integration with existing tooling like IDEs. The initial set of tests that met these criteria were identified using the work Amir did in I88822667693d9e00ac3d4639c87bc24e5083e5e8. These tests were then moved into a new subdirectory under phpunit/ and organized into a separate test suite. The environment for this suite is set up via a PHPUnit bootstrap file without a custom entry point. You can execute these tests by running: $ vendor/bin/phpunit -d memory_limit=512M -c tests/phpunit/unit-tests.xml Bug: T89432 Bug: T87781 Bug: T84948 Change-Id: Iad01033a0548afd4d2a6f2c1ef6fcc9debf72c0d