Commit graph

46 commits

Author SHA1 Message Date
jenkins-bot
412d9c8bbc Merge "Make REST tests more robust against content language" 2020-03-30 14:49:27 +00:00
daniel
905f6fc890 REST: page/ endpoints: don't use tokens with OAuth
CSRF tokens should only be required (and only be allowed) if
the current session isn't already inherently safe against
CSRF due to the way the authentication mechanism works.
This allows (and requires) tokens to be omitted for requests
that use an OAuth Authorization header.

Bug: T230843
Bug: T230842
Bug: T237852
Change-Id: Ib2922d556ff2470d4bf8c386c18986ca9f37d1b5
2020-03-27 12:20:22 +01:00
daniel
c8acf2655e Make REST tests more robust against content language
Change-Id: Id24536e96d89be768b96c2acd0edde6d371f438b
2020-03-27 09:23:36 +01:00
Bill Pirkle
c50523f1fc Display different errors for title vs file not found in MediaFileHandler
In Core REST API MediaFileHandler, display a different error for
title not found vs file not found. Files may be unfindable even if
the title exists due to permission errors, or if they are missing
from the file system.

Bug: T238374
Change-Id: If49273b979291e284043f6251ad8d989a10defe1
2020-03-26 11:58:12 -05:00
jenkins-bot
fde16090b6 Merge "REST endpoints: Add etag and last-modified headers" 2020-03-26 03:15:58 +00:00
jenkins-bot
6d791abd80 Merge "Define POST handler for /page/: create page" 2020-03-26 01:33:50 +00:00
daniel
22561b64a7 REST endpoints: Add etag and last-modified headers
Modified endpoints:
* /v1/page/{title}/history
* /v1/revision/{id}/bare
* /coredev/v0/page/{title}/links/language
* /coredev/v0/page/{title}/links/media
* /coredev/v0/file/{title}

Bug: T238374
Change-Id: I3ddf8fafc17eba3aec724a445d38af98bbc74dc1
2020-03-26 00:18:34 +01:00
daniel
65342f8353 Define POST handler for /page/: create page
NOTE: once this is merged, also merge Ie7b47e6868cc on the OAuth repo,
to fix unit tests after a breaking change to Router's constructor
signature.

Bug: T230842
Change-Id: I8f5b92918a58e44a4f2d8c78d234d9f64c2d06bf
2020-03-25 20:49:20 +01:00
daniel
f32abbaf0d LanguageLinksHandler: add phpunit integration test
Bug: T236172
Change-Id: Ib8b2af03bf9377dc8133e019237cef7feff919b3
2020-03-25 18:29:30 +01:00
Timo Tijhof
a5e4174d82 TemplateParser: Refactor the two integration test classes
* There were two separate integration test suites, both testing
  the TemplateParser class. One extended MediaWikiTestCase, which is an
  alias for MediaWikiIntegrationTestCase. The other was extending
  MediaWikiIntegrationTestCase directly.

  I've merged these into the same file.

* Use an injected BagOStuff instance.

  This means we can inject a mock and more cleanly assert the
  subject class' observable behaviour and contract toward BagOStuff,
  without hardcoding any internal details of TemplateParser.

* Add coverage for getTemplate() not using the cache in any way
  when wgSecretKey is false.

Change-Id: Ic01f23b1d59c430ab6adf247e0244514b98e20b8
2020-03-23 21:54:47 +00:00
Krinkle
e539ed73b4 Merge "TemplateParser: Inject BagOStuff and deprecate '$forceRecompile'" 2020-03-23 21:54:39 +00:00
jenkins-bot
a67762cab9 Merge "page/update: return diffs on conflict" 2020-03-23 20:12:31 +00:00
Timo Tijhof
e4b7341fb6 TemplateParser: Inject BagOStuff and deprecate '$forceRecompile'
* Injecting the cache object makes the class easier to test.

* The $forceRecompile parameter was not used anywhere, not tested,
  and only mentioned in one README (fixed in I13fba7314).
  Based on past experience I generally expect that when bypassing a
  cache, it is neither read from nor written to. Such feature might
  be reached out to when testing something, in which case it should
  not be stored.

  If this was intended as a way to purge it in prod via eval.php,
  we generally don't provide dedicated purging commands in code.
  We either call BagOStuff or Memc/Apcu directly, or invalidate the
  underlying data (e.g. touch the template file, or bump the cache
  version).

  To use TemplateParser without caching, one can still pass
  'new EmptyBagOStuff' instead if needed.

* Set the $ttl parameter in the set() call.
  It is generally an anti-pattern to store something without
  any TTL as that means it can needlessly compete for space
  even after further deployments have changed the key or stopped
  using a particular key. For now I used a liberal default
  of 1 week.

Change-Id: Ic84b996b46c72e9dc33eed2645204fc2d6c5240c
2020-03-23 20:09:05 +00:00
jenkins-bot
e764195a4d Merge "page/update endpoint" 2020-03-23 19:57:53 +00:00
daniel
81a47eaad3 page/update: return diffs on conflict
This adds diffs for use in an interactive merge when detecting an edit
conflict.

Bug: T230843
Change-Id: I6345361fce98524027ad778749d4fbf54169ccb6
2020-03-23 15:59:47 +00:00
daniel
58e5332991 page/update endpoint
Bug: T230843
Change-Id: I95289eddfc9ab2e0cef11b9363a5e239cdb2258e
2020-03-23 16:59:21 +01:00
Aaron Schulz
86533ae590 Drop DEFAULT from *_actor columns for SQLite tables that still have it
These were left out by mistake (made easier by a bug where some phpunit
tests never run). Fixing the test bug is blocked on fixing the SQLite
schema so that DatabaseSqliteTest.php passes when it actually runs.

Bug: T246077
Change-Id: I75d7a7fb56a07c2984e987b6136e1fd00615c421
2020-03-19 21:17:56 -07:00
jenkins-bot
eece76a030 Merge "Fix obsolete version-based tests in DatabaseSqliteTest" 2020-03-20 01:37:47 +00:00
Sam Smith
d4be8b9c08 TemplateParser: Include template dir in cache key
Template names aren't expected to be globally unique. Template paths are
by construction.

Include the template directory in the cache key in order to avoid the
cache keys of ambiguosly-named templates - e.g. index.mustache -
overriding one another.

Bug: T113095
Bug: T248010
Change-Id: I3196967ec2a7a5cec409a0c7ce4471a7d8773978
2020-03-18 21:57:34 +00:00
Aaron Schulz
f13b3c8521 Fix obsolete version-based tests in DatabaseSqliteTest
These failed and servered no use after 6cf729838f

Change-Id: I29f5e761b977c1c831afd75da901b5e58a4bbde1
2020-03-18 14:32:26 -07:00
Aaron Schulz
13b11a946e rdbms: reduce duplication in Database via helper methods
Add several new internal methods to help with wrangling
the various formats that rows, conditions, options, and
unique key lists can come in. Remove now unused method
isMultiRowArray().

Add various sanity checks and logging for parameters to
upsert(), replace(), insert(), and insertSelect().

Move DatabasePostgresTest to the integration/ directory.

Change-Id: If5988a6f0816e8da2cbf2fd612e1a3e3a2e9c52f
2020-03-10 22:26:04 +00:00
Reedy
abf2463056 Rename TemplateParserTest.php -> TemplateParserIntegrationTest.php
Follows-up 419bbcd8f9.

We already have a TemplateParserTest.php and class.

Bug: T113095
Change-Id: Id4c18a3d1706865df60f9d1bff73d8c454196224
2020-03-08 18:41:33 +00:00
jenkins-bot
5f1362ccb5 Merge "TemplateParser: Test server-local cache interaction" 2020-03-05 19:54:10 +00:00
jenkins-bot
44354f45eb Merge "rdbms: inject replLogger into Database and consolidate duplicated logging" 2020-03-04 21:29:23 +00:00
Sam Smith
419bbcd8f9 TemplateParser: Test server-local cache interaction
Add integration tests covering how TemplateParser::getTemplate interacts
with the server-local cache.

Bug: T113095
Change-Id: Ie0da8a157796bfe8ab4d758f38a4c6a2d5dc90ce
2020-03-04 17:34:23 +00:00
Aaron Schulz
a14a1f39a1 rdbms: support native batched replace() in DatabaseSqlite
Change-Id: Icc6d6ff7412d6a686b200e7d8432840b46377d10
2020-03-02 15:10:15 +00:00
Peter Ovchyn
9b34f6786a sqlite: Fix broken integration tests for SQLite db driver
Bug: T245995
Change-Id: I280487bf27e4864eba8c0f02f408306061b948b2
2020-02-26 21:57:09 +02:00
Timo Tijhof
f575721a06 Update all use of $wgVersion to MW_VERSION
Follows-up I04628de4152dd5.

Bug: T212738
Change-Id: I718474ec0d9fd29ac2c05477f0f2493615d8aff5
2020-02-25 02:16:12 +00:00
Aaron Schulz
6c5d937adb rdbms: inject replLogger into Database and consolidate duplicated logging
Bug: T235244
Change-Id: I9397f6f74f703a395ef1be4713702247060d8bd4
2020-02-23 00:33:33 +00:00
jenkins-bot
9b1067846d Merge "Coding style: Auto-fix MediaWiki.Usage.PHPUnit*" 2020-01-10 16:59:11 +00:00
James D. Forrester
5e9fca47b9 Coding style: Auto-fix MediaWiki.Usage.PHPUnit*
Change-Id: I86fc55a4fc8ceafe368692173211bbcd6d8581d7
2020-01-10 10:17:12 +00:00
Aaron Schulz
3c1c9b5098 rdbms: support native batched insert() in DatabaseSqlite
This was added in 4bd1b4b455 but reverted due to a bug in other
changes within that patch, namely, the replace() method changes.

Change-Id: Id73c3fed9e1862daeeecbf47bcfa53d1719c59bb
2020-01-06 18:17:46 +00:00
Daimona Eaytoy
f5529400cc Stop using assertContains with string haystack
This was done automatically by replacing every assertContains with
string *needle*. Then verifying the results.

Bug: T192167
Change-Id: Id8cbbf3b01e948f80046714183cc299f86be21fd
2019-12-15 00:22:44 +00:00
Daimona Eaytoy
6365eaab8d Autofix 94 PHPUnit 8 compat issues
Done automatically using the master version of MW codesniffer and
running composer fix.

Bug: T192167
Change-Id: If6b40f515fde32ab5eff074a90e821c30c791827
2019-12-13 15:29:10 +01:00
Timo Tijhof
0da1ecfd89 profiler: Remove ProfilerOutputDb and profileinfo.php entry point
Bug: T231366
Change-Id: I211c8192200d9af00914f9847608a6daf2898f91
2019-11-06 15:28:00 -05:00
Brad Jorsch
f3058c81b9 Add $wgDiffEngine
The immediate use case is for testing, where some tests need to use the
PHP implementation even when wikidiff2 is installed.

Bug: T237049
Change-Id: I41dc4c0933429065d7638f518ec31f0a056afc41
2019-11-05 10:38:52 -05: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
jenkins-bot
662c41a0fb Merge "Revert "rdbms: optimize insert(), replace(), and upsert() for sqlite when possible"" 2019-10-08 17:06:53 +00:00
Anomie
be8ef0f2c3 Revert "rdbms: optimize insert(), replace(), and upsert() for sqlite when possible"
This reverts commit 4bd1b4b455.

Reason for revert: Incorrect syntax for SQLite "ON CONFLICT (...) DO UPDATE".

Bug: T234795
Change-Id: I987e6e7052368d5d9d0b6de9dd189edc4feaebe5
2019-10-08 16:51:37 +00:00
jenkins-bot
31b87650c7 Merge "Drop strings for wgExternalDiffEngine, deprecated in 1.27 and 1.32" 2019-10-05 22:14:16 +00:00
Umherirrender
fb3914739e Type hint against IResultWrapper
IDatabase::select returns the interface IResultWrapper,
not the implementation ResultWrapper

Change-Id: I8904eff2db48ff00a4a9486be842266c638bc249
2019-10-04 19:58:19 +02:00
James D. Forrester
5b3bbd5ade Drop strings for wgExternalDiffEngine, deprecated in 1.27 and 1.32
Also move the 'unit' test into integration, given it tests code
using globals.

Change-Id: Ie039cae9b5d2870c18a6deefec9a73de522dd847
2019-10-03 22:09:38 +00:00
Aaron Schulz
4bd1b4b455 rdbms: optimize insert(), replace(), and upsert() for sqlite when possible
Change-Id: Ic884a4ce42a99333f5176f7b681f8a8bba15d2a1
2019-10-03 01:45:24 +00:00
Thiemo Kreuz
32a429e8c4 tests: Prefer assertSame() when comparing the integer 0
assertSame() is guaranteed to not do any type conversion. This can be
critical when acciden tially comparing, for example, 0 to 0.0.

Change-Id: Iffcc9bda69573623ba14af655dcd697d0fcce525
2019-09-19 15:35:23 +00:00
Kosta Harlan
c860482d29 Tests: Set dbname for DatabaseSqliteTest
Bug: T230780
Change-Id: I93d3771233c74443f76b0a402a4820e1e1e30ee7
2019-08-20 11:28:29 +02:00
Kosta Harlan
214750d8d2 Define unit and integration test suites
Following discussion in Ibb8175981092d7f41864e641cc3c118af70a5c76, this patch
proposes to further reduce the scope of what unit tests may access, by removing
the loading of DefaultSettings and GlobalFunctions.php. This also has the
implied effect of disabling the storage backend, as well as the global service
locator.

MediaWikiTestCase is renamed to MediaWikiIntegrationTestCase so it's scope and
purpose is more clear. Whether we still need to keep `@group Database`
annotation around is debatable, as it's unclear to me what the performance costs
are of implying database access for all tests which extend IntegrationTestCase.
As far as I can tell, `@group Database` is primarily used in CI to run faster
tests before slower ones, and with the new UnitTestCase the annotation seems
redundant.

To run all testsuites, use `composer phpunit`. Other composer scripts:

- `composer phpunit:unit` to run unit tests
- `composer phpunit:integration` to run integration tests
- `composer phpunit:coverage` to generate code coverage reports from unit
   tests (requires XDebug).

Note that you can pass arguments to composer scripts with `--`, e.g. `composer
phpunit:integration --exclude-group Dump`.

Other changes:

- Rename bootstrap.php to bootstrap.maintenance.php so it's clear it's part of
  the legacy PHPUnit-as-maintenance-class setup
- Create new bootstrap.php which loads the minimal configuration necessary for
  the tests, and do additional setup in the run() method of the unit/integration
	test case classes
- Move the unit-tests.xml file to phpunit.xml.dist in preparation for this being
  the default test configuration

For a follow-up patch:

- Find unit/integration tests for extensions/skins
- Migrate other test suites from suite.xml
- Support running all tests via vendor/bin/phpunit

Bug: T84948
Bug: T89432
Bug: T87781
Change-Id: Ie717b0ecf4fcfd089d46248f14853c80b7ef4a76
2019-06-28 12:18:18 -04:00