Commit graph

80 commits

Author SHA1 Message Date
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
David Causse
c9d3eb8e6d Add test for completionSearch with wgCapitalLinkOverrides
Bug: T208255
Change-Id: Id2299a013b2dc9b5391d400d7c7c4dc37185f714
2018-11-06 15:03:16 +01:00
Aaron Schulz
c4d9d51506 Clear the title cache in MutableRevisionRecordTest
Also do so in various other test classes.

Follows-up 170c49d61c. Fixes Travis CI regression:

> 1) MediaWiki\Tests\Revision\MutableRevisionRecordTest::testSetGetPageId
> Failed asserting that 2 is identical to 0.
> tests/phpunit/includes/Revision/MutableRevisionRecordTest.php:129

Change-Id: I41c8bda8e620ebe7608a393d81f3b0f13af68ba7
2018-10-25 21:16:27 +00:00
Erik Bernhardson
b357416273 Go search to consider fragment only title invalid
When submiting using the 'go' feature of Special:Search (standard
usecase for autocomplete) a nearby title can be selected.
Unfortunately a fragment only title is considered valid, which
sends the user to Main_Page#searchterm.

Instead don't allow a search starting with # to trigger the go
feature.

Bug: T182452
Change-Id: I8ce3ce8633e23db41ae6eafb9996ca7294f8445a
2018-09-11 13:03:53 -07:00
Tim Starling
5322107191 Reset services before every test
Trying to avoid resetting services introduces a lot of complexity and
several bugs. We were doing a reset for 70% of @group Database tests
anyway.

Instead:

* Reset services at the start of MediaWikiTestCase::run().
* Capture the actual original service container instead of making a
  special shared service container.
* The test-isolated local service container can now only be initialised
  non-statically. Revert the recent conversion of overrideMwServices()
  to static.
* Store a reference to the local service container in the test case
  object. In MediaWikiTestCase, always use the original or local service
  container directly, to avoid confusion about which one is active at
  the time.
* Remove a lot of unnecessary teardown
* Always call ServiceContainer::destroy() before forceGlobalInstance()
  since the memory is not otherwise freed.

Change-Id: I4a17c1c7ec92c14e3bc471f0216473ebe19477b9
2018-09-03 16:38:58 +00:00
Aryeh Gregor
d4045035b0 Make SpecialPageFactory a service
Calling SpecialPageFactory methods statically is now soft-deprecated.

SpecialPageFactory::resetList() is a no-op, and I changed tests
in core to use overrideMwServices() instead.

Methods that fell back to $wgUser now require a User object being passed.

Depends-On: Ie1f80315871085b9fd4763a265b588849d94414d
Change-Id: Id8a92d57743f790b7d8c377c033cef38d1bb24de
2018-08-17 11:12:23 -07:00
Aryeh Gregor
05d78a6c71 Move utility methods from ApiTestCase to MediaWikiTestCase
Change-Id: I79c4e37092958c63a693194b27a9eafae70cb2f8
2018-07-29 12:47:45 +03:00
David Causse
3115b3202d Unify SearchEngine normalizeNamespace and parseNamespacePrefixes
These methods are very similar there should be no need to have
two differents way to extract the namespace prefix.

Bug: T198860
Change-Id: I22802278452559d35a3d8f6068549c1fef1a5e86
2018-07-17 21:56:05 +00:00
Erik Bernhardson
83bae78c3a Silently drop unknown titles in completion search
This mimics how full text works by silenty dropping results returned from
search that no longer exist. This could be because the search index is slightly
out of sync with reality, or the search engine could simply be broken.

Only silent from the users perspective. We maintain a count in statsd of
the number of titles dropped. This can be monitored over time to
recognize any increases.

Bug: T115756
Change-Id: I2f29d73e258cd448a14d35a2b4902a4fb6f61c68
2018-06-11 13:56:19 -07:00
Erik Bernhardson
2a43939ffb Push pagination decision for search into SearchEngine
Various code using the search engine shouldn't need to implement it's
own methods, such as over-fetching, to determine if there are more
results available. This should be knowledge internal to search that is
exposed by a boolean.

Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
2018-06-11 13:35:44 -07:00
Erik Bernhardson
c2a308075f Convert SearchResultSet to typical iteration
The funky iteration here was at best annoying. Switch
it over to an iterator based approach with appropriate
BC code to simulate the old iteration style.

Depends-On: I19a8d6621a130811871dec9335038797627d9448
Change-Id: I9fccda15dd58a0dc35771d3b5cd7a6e8b02514a0
2018-06-11 13:35:41 -07:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01: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
Umherirrender
5544cef16b Add missing type to @param documentation
Change-Id: I6b2c9c7af9a281fe457099cc3a336a60a25e74aa
2017-08-11 20:37:35 +02:00
David Causse
187ada1cf4 Fix phrase search
Partially revert I61dc536 that broke phrase search support.

Fix phrase search by making explicit that there are two
kind of legalSearchChars() usecases :

- the chars allowed to be part of the search query (including special
  syntax chars such as " and *). Used by SearchDatabase::filter() to
  cleanup the whole query string (the default).

- the chars allowed to be part of a search term (excluding special
  syntax chars) Used by search engine implementaions when parsing with
  a regex.

For future reference:
Originally this distinction was made "explicit" by calling directly
SearchEngine::legalSearchChars() during the parsing stage. This was
broken by Iaabc10c by enabling inheritance.
This patch adds a new optional param to legalSearchChars to make this
more explicit.

Also remove the function I introduced in I61dc536 (I wrongly assumed
that the disctinction made between legalSearchChars usecases was due
to a difference in behavior between indexing and searching).

Added more tests to prevent this from happening in the future.

Bug: T167798
Change-Id: Ibdc796bb2881a2ed8194099d8c9f491980010f0f
2017-07-03 11:44:48 +02:00
jenkins-bot
d56b46598d Merge "Fix SearchEngineTest test descriptions" 2017-06-27 23:44:30 +00:00
jenkins-bot
01c3bf3431 Merge "Fix highlighting for phrase queries" 2017-06-27 23:44:27 +00:00
David Causse
158ee86e38 Fix SearchEngineTest test descriptions
These should describe the test not the failure.

Change-Id: I82601795d925d3dd7548909f18c325eeaebd83ff
2017-06-27 15:58:16 +02:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
David Causse
f230f5dcc7 Fix highlighting for phrase queries
I think the bug was introduced during a cleanup in Iaabc10c.
I don't think that " should be part of the legalSearchChars at query
time, it seems to break the regex.
The strategy here is to distinguish legalSearchChars used query time vs
the ones used at index time by introducing:
SearchEngine::legalSearchCharsForUpdate()

Bug: T167798
Change-Id: I61dc53665e26d3c6c48caed78dd3bbde9a33def7
2017-06-26 09:53:13 +02:00
Aaron Schulz
daaeb407af Avoid SearchEnginePrefixTest postgres failures
Slash was ranked a bit differently in how postgres sorts
(seems to be based on the utf8 units as raw bytes).

Bug: T75174
Change-Id: I0a7f3859945218319b3f418f607c0299d8569c61
2017-05-22 17:28:42 -07:00
Paladox
54c56da85a Fix php code style
Preparation change for updating mediawiki code sniffer to 0.8.0

Change-Id: Ib0b3fe4afea9096ffa3a1347b4f7e07d3398b0b2
2017-05-05 12:03:54 +00:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Timo Tijhof
447ce7e39a phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat
The default will remain PHPUnit 4.x due to PHP 5.5 support.

But, we should allow developers to run tests with newer PHPUnit
versions which are noticably faster (especially for code coverage
reports).

* <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0>
  PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock().
  It instead introduces the shortcut createMock() which has better defaults
  than getMockBuilder(). For example, it sets 'disableArgumentCloning' and
  other things by default.

  Going forward, code should either use getMockBuilder directly and configure
  it using the setter methods (instead of the confusing variadic arguments
  of getMock) or simply use the new minimalistic createMock method. This patch
  backports the createMock method to MediaWikiTestCase so that we can start
  using it.

Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
2017-04-06 00:44:32 +00:00
Erik Bernhardson
e4fb4f978b Don't use $this as a function argument
PHP 7.1 adds the limitation that $this cannot be used as a function
parameter. Ensure forward compatability by renaming the parameters.

Bug: T160144
Change-Id: I33d2ab1ffeeeb32e3a467cc146ee8feef0255258
2017-03-13 11:12:50 -07:00
Stanislav Malyshev
cae86036aa Allow fields to define their own merge strategy via callback.
Change-Id: Ic1cc1581f07381224d3f4fcba4feb1eac7085057
2017-03-07 10:36:53 -08:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01: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
Stanislav Malyshev
e421158b1a Rank aliases in search in order they appear in the messages file.
This will ensure the local page name (which is the first alias) is prioritized.

Bug: T151660
Change-Id: I3cc266024f5e052d20ff55c4b2c6cbd2945e3dd3
2016-11-29 15:15:42 -08:00
Aaron Schulz
d2202b8414 Add SearchEngineFactory::getSearchEngineClass() instead of using the DB
Change-Id: I46207cafec737cb830adc2bdf1b501a0d138b40d
2016-09-15 21:31:35 -07:00
Stanislav Malyshev
7e18cfc3b5 Infrastructure for augmenting search results
Bug: T117493
Change-Id: Ia5413a7846cc961026a2dc3542b619493bc76a23
2016-09-15 15:44:03 -07:00
aude
64ee3d3269 Extract ParserOutput search index data fields from WikiTextContentHandler
Bug: T142491
Change-Id: I69b010b893135e53fac7f16f4b927b8fbcba06d2
2016-08-19 09:26:17 -04:00
aude
c67536716d Call parent::getFieldsForSearchIndex in ContentHandlers
ContentHandler implementations were not including fields
defined by their parent ContentHandler classes.

merge method is added to the SearchIndexFieldDefinition
mock in SearchEngineTest, to allow merges of fields
in the way that SearchIndexFieldDefition implementation does.

Change-Id: Id04a51528f566da2666bad0394a2f61c949c69b4
2016-08-15 19:33:09 -04:00
Stanislav Malyshev
add1ebe2ab Make content handlers assemble content for search
Bug: T89733
Change-Id: Ie45de496ecc826211d98eea3a410c7639b4be0a4
2016-07-26 13:08:45 -07:00
Stanislav Malyshev
86b55ad03c Create API to allow content handlers to handle structured data definitions
Change-Id: Ia1738803c42f6114575587c1c838fec62b6f54aa
Bug: T89733
2016-07-06 13:41:20 -07:00
Stanislav Malyshev
68cdf61e57 Fix unit tests running on non-DB environment
Bug: T138551
Change-Id: Ie1d3c8b24e5271d4e12f4190400531cbe606bfd4
2016-06-24 05:38:52 +00:00
Matthew Flaschen
b257385ff2 PrefixSearchTest, SearchEnginePrefixTest: ignore ext. special pages
It was attempting to do this before, but it didn't handle special pages
registered by hook, and was not clearing the list properly (so it was
too late when wgSpecialPages was cleared).

This would cause the test to fail if certain extensions were
installed (e.g. AbuseFilter).

Change-Id: I9affac5ad00e97326ebf9961bbf709ac22aef498
2016-04-29 15:53:37 -04:00
Stanislav Malyshev
34b02d87ac Convert SearchEngine to service containers
Change-Id: Icef1ecbed3d831557e0256fdfa53743b194007cc
2016-04-25 16:25:17 -07:00
daniel
a8995619c1 Avoid rebuilding database fixtures for every test run
This reduces the runtime of database-bound tests by about 40%
(on my system, from 4:55 to 2:47; results from Jenkins are
inconclusive).

The basic idea is to call addCoreDBData() only once, and have
a addDBDataOnce() that is called once per test class, not for
every test method lie addDBData() is. Most tests could be
trivially be changed to implement addDBDataOnce() instead of
addDBData(). The ones for which this did not work immediately
were left out for now. A closer look at the tests that still
implement addDBData() may reveal additional potential for
improvement.

TODO: Once this is merged, try to change addDBData() to
addDBDataOnce() where possible in extensions.

Change-Id: Iec4ed4c8419fb4ad87e6710de808863ede9998b7
2016-03-10 23:44:34 +00:00
Kunal Mehta
b9668d6d80 build: Update mediawiki-codesniffer to 0.6.0, add "composer fix"
* Fix errors spotted by new release
* Introduce "composer fix", which uses phpcbf to automatically fix some
errors spotted by phpcs.
* Drop $PHPCS_ARGS variable that didn't work on Windows, and add -s flag
* Remove rules from phpcs.xml that are now in MW-CS ruleset.

Change-Id: I13e2155695918c918b67497ac65b85a03897095e
2016-02-17 02:54:42 -08: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
Stanislav Malyshev
027972a20f Include completion search into SearchEngine
By default it still uses PrefixSearch and supports PrefixSearchBackend
but it can be deprecated and phased out and SearchEngine extensions used
instead.

New APIs:
- SearchEngine
	public function defaultPrefixSearch( $search );
	public function completionSearch( $search );
	public function completionSearchWithVariants( $search );

Search engines should override:
protected function completionSearchBackend( $search );

Bug: T121430
Change-Id: Ie78649591dff94d21b72fad8e4e5eab010a461df
2016-02-03 23:41:49 +00:00
umherirrender
1d8b52fbfd Move Test files under same folder structure where class is (/includes/)
Change-Id: I95f1aa6f0ed2cc3306aa6e588a11f359854315c1
2014-12-16 21:56:44 +01:00
Timo Tijhof
bfa6b4cab4 MediaWikiTestCase: Centralise insertPage() logic from SearchEngineTest
Make it re-usable for other tests and update SearchEngineTest to
use the addDBData (which is called automatically) instead of
manually keeping track of the state.

Change-Id: I75a6951545d9824e71e00f0f96936c53b400dce6
2014-09-22 14:56:32 -07:00
Siebrand Mazeland
69ec133bc5 Pass phpcs-strict on some test files (10/11)
Change-Id: I5624292143fcabe890779f5095eae735d7afb176
2014-04-24 13:50:56 -07:00
umherirrender
092cd8ee31 Fixed some @params documentation (tests)
Swapped some "$var type" to "type $var" or added missing types
before the $var. Changed some other types to match the more common
spelling. Makes beginning of some text in captial.
Also added some missing @param.

Change-Id: Ic8aaf0a93796b97d0fa4617c1f86ff59f4b36131
2014-04-17 20:43:42 +02:00
addshore
9e85aabe52 Cleanup a bunch of tests and add todos
Change-Id: Iae44427edee3ed2a62abdb5a8f5d9f1ed2e7d660
2014-03-09 15:12:45 +01:00
aude
73bc21bb1c Fix SearchEngineTest when $wgSearchType is set to non-default
$wgSearchType needs to be controlled for at time the pages get created.
This patch sets the $wgSearchType global.

Also, the 'singleton' is removed from SearchEngine::getSearchTypes, which
appears to provide little or no benefit while binding all tests to the
global variable.

SearchEngine::getSearchTypes() gets called in SearchUpdate which is
run on page edits. This means the first page edit in the entire
test suite causes the global variable to be set and subsequent tests
cannot override it.

These changes allow SearchEngineTest to pass, even if one has CirrusSearch
or other such extensions enabled.

Change-Id: I39050da8659dc69db31125f469f494a5fb4b8fca
2014-01-03 11:28:41 +01:00
Mwalker
b06e844804 Merge "@covers tags for more test classes" 2013-10-25 01:09:58 +00:00
addshore
caec5f920a @covers tags for the rest of test files..
Change-Id: I0fafe80531325a412472ab7c9fc6d81c861b3751
2013-10-24 21:38:08 +01:00