aboutsummaryrefslogtreecommitdiffstats
path: root/tests/phpunit/includes/db/DatabaseSQLTest.php
Commit message (Collapse)AuthorAgeFilesLines
* rdbms: Refactor DatabaseTestTimo Tijhof2017-07-201-1075/+0
| | | | | | | | | | | | | | | | | | | | | * Move DatabaseTest and DatabaseSQLTest to libs, and remove MediaWikiTestCase dependency. * Refactor DatabaseTest to be a test of the Database abstract class, not of whatever current DB backend is configured by LocalSettings. - Remove most switches/conditionals and other tests for specific database backends. Move those to individual test classes for those backends instead. - Some tests appear to have been integration tests for the PHP driver and/or the db backend itself. Moved to a new DatabaseIntegrationTest. - Now that only the abstract Database is invoked, the test runs a bit faster (no real connections/queries). * Add missing @covers tags, and remove or fix broken ones (follows-up 26e52f0c491a4). Change-Id: I9dc4a558e701d00e95789e7eb8e02926783b65ad
* Add Database::unionConditionPermutations()Brad Jorsch2017-06-161-0/+169
| | | | | | | | Constructs a query for the union of permutations of a set of fields, for use in situations where the database otherwise makes poor plans due to inability to use indexes effectively (e.g. T149077 and T168010). Change-Id: I20980dcada664486c09198b8c45896620bd83e81
* DB: Add join conditions to selectField, selectFieldValues, and insertSelectBrad Jorsch2017-06-141-6/+30
| | | | | | | | | | | | | | | selectField() and selectFieldValues() are trivial, they just need to pass it through to select(). In fact, selectFieldValues() was already doing it, just no one ever updated IDatabase. insertSelect() is a little more work. nativeInsertSelect() was originally written as largely a copy-paste of select() and has since gotten well out of sync. Now that we have selectSQLText(), we should be able to just use that. DatabasePostgres's implementation can wrap the parent implementation instead of being another copy-paste, but DatabaseOracle seems to still need to be special. Change-Id: I0e6a9e6daa510639d3212641606047a5db96c500
* New maintenance script to clean up rows with invalid DB keysThis, that and the other2017-03-111-4/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | The TitleValue constructor, used by the link cache among other things, throws an exception for DB keys which do not satisfy a simple sanity test (starting or ending with _, or containing a space, tab, CR or LF character). This has broken certain special pages on a number of WMF sites; see T99736, T146778 and T155091. The new cleanupInvalidDbKeys.php script allows these bogus entries to be removed from the DB, making sure these exceptions won't be thrown in the future. It cleans the title columns of the page, archive, redirect, logging, category, protected_titles, recentchanges, watchlist, pagelinks, templatelinks, and categorylinks tables. The script doesn't support batching; most wikis should have fewer than 500 broken entries in each table. If need be, the script can be run several times. To make the LIKE queries work properly I had to fix the broken escaping behaviour of Database::buildLike() -- previously it had a habit of double- escaping things. Now an ESCAPE clause is added to change the escape character from the problematic default backslash, and tests are added to cover the changes. Bug: T155091 Change-Id: I908e795e884e35be91852c0eaf056d6acfda31d8
* Move LikeMatch to Rdbms namespaceAaron Schulz2017-02-061-0/+2
| | | | Change-Id: I0cba263cd02fc5c4bfe8f063f38d1b4be28246b0
* Replace DatabaseBase:: with Database:: and update type hintsAaron Schulz2016-09-271-18/+18
| | | | Change-Id: I3919b04eb2de4fa0bf8a02239fb5bbf17d347511
* Check Database::mSessionTempTables in Database::tableExists()Aaron Schulz2016-09-211-0/+38
| | | | | | | | Also make the temp table tracking catch plain "DROP TABLE" in addition to the stricter "DROP TEMPORARY TABLE" clause. Bug: T146300 Change-Id: Ia8306ec25e63adcdcf0dcc8f6a700dd01afdc948
* Move all of the reasonable DatabaseBase methods to Database classAaron Schulz2016-09-171-1/+1
| | | | | | | | | | | | | | | The Database class was previously just a short-hand for "Database::", and such calls should still work. The class now resides in /libs/rdbms. The subclasses now extend DatabaseBase to avoid breaking type hints that use that (hints use either IDatabase or DatabaseBase). Also, use CASCADE with DROP TABLE for MySQL as with other DBs. Keep SQLite excempt due to lack of support. Added getDomainID() methods to avoid mentioning the word "wiki". Change-Id: Ibd05d786cb26c21dcc9cb9601f6b2b52056af9ae
* Make insertSelect() do two separate queries in non-CLI modeAaron Schulz2016-08-311-10/+35
| | | | | | | | | | | This avoids slave lag and makes query time account easier. It also avoids table-level autoinc locking and slave drift with statement-based replication in some setups. Also refactored the use of $wgCommandLine mode in DatabaseBase slightly, so that it can be injected. Change-Id: I2dba6024ecf32c9ee24a3080cce3b02568c1458b
* Convert all array() syntax to []Kunal Mehta2016-02-171-297/+297
| | | | | | | | | | 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
* Database::makeList() : Handle NULL when building 'IN' clauseSumit Asthana2015-01-031-0/+15
| | | | | | | | | | | | | Amends to Database::makeList() to check if 'NULL' is present in array while building IN clause. Presently a NULL in array intended to build IN clause, is treated as a usual value. This creates problem:https://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in Therefore null is appended at the end of the IN clause as " $field IS NULL" rather than within the IN clause. DatabaseSQLTest.php: Some test cases added for the modified behaviour. Bug: T50853 Change-Id: Ic255c37e9702fd44d8173027ab8036ddc48f9d2e
* Add SQL tests for Database::makeListumherirrender2014-12-291-0/+65
| | | | Change-Id: I5a5be6769c7d0e5f2a97d3fbefd62df3c59f0716
* Pass phpcs-strict on some test files (6/11)Siebrand Mazeland2014-04-241-1/+5
| | | | Change-Id: I5f4bc0df8183cf338ff45cacfc7279c2cd38ee04
* Fix scope on all /phpunit test methodsaddshore2013-10-241-17/+17
| | | | Change-Id: I3ce92463d485a0fb23e464e9a8059330f32d79af
* Add @covers for main Database test typesaddshore2013-10-181-0/+28
| | | | Change-Id: I010ff5ce7afd85c7f9d528a98f2448547874b8b3
* Added tests for new DatabaseBase::upsertumherirrender2013-06-041-0/+35
| | | | | | | | Follow up Id7fc6652 Pass function name to begin/rollback/commit Use __METHOD__ as default param (see I86cbdeab) Change-Id: I9eb326c035d4a604db5b3492f090d8dd9d21c920
* Update code formattingSiebrand Mazeland2013-04-261-24/+24
| | | | Change-Id: I16a9b42651f1cfb1a70dffbb67b7b83dfeb90d03
* Add non DBMS depending SQL tests for DatabaseBaseumherirrender2013-04-161-29/+539
| | | | | | | Created a DatabaseTestHelper class, which extends DatabaseBase and implements STUBs for the interface methods and abstract methods Change-Id: I9965b3604e78b2722077a35a7b4ce62a5bcb370e
* Update formattingSiebrand Mazeland2013-02-141-21/+21
| | | | | | 4 of n. Change-Id: I23e2409ce9eff14c3434154d236de83c93a92440
* pass codesniffer on tests/Antoine Musso2013-01-281-1/+1
| | | | | | | | | | | | | | | Fix almost all occurences of the following sniffs: Generic.CodeAnalysis.UselessOverridingMethod.Found Generic.Formatting.NoSpaceAfterCast.SpaceFound Generic.Functions.FunctionCallArgumentSpacing.SpaceBeforeComma Generic.Functions.OpeningFunctionBraceKernighanRitchie.BraceOnNewLine Generic.PHP.LowerCaseConstant.Found PSR2.Classes.PropertyDeclaration.ScopeMissing PSR2.Files.EndFileNewline.TooMany PSR2.Methods.MethodDeclaration.StaticBeforeVisibility Change-Id: I96aacef5bafe5a2bca659744fba1380999cfc37d
* Add parent::setUp() to DatabaseSQLTestumherirrender2012-12-061-0/+1
| | | | | | | | 1) DatabaseSQLTest::testMediaWikiTestCaseParentSetupCalled DatabaseSQLTest::setUp() must call parent::setUp() Failed asserting that an array has the key 'setUp'. Change-Id: I6aa5cb09999e0cee9b36fedd9193cb5aa08914ad
* Clean and repair many phpunit tests (+ fix implied configuration)Timo Tijhof2012-10-091-6/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit depends on the introduction of MediaWikiTestCase::setMwGlobals in change Iccf6ea81f4. Various tests already set their globals, but forgot to restore them afterwards, or forgot to call the parent setUp, tearDown... Either way they won't have to anymore with setMwGlobals. Consistent use of function characteristics: * protected function setUp * protected function tearDown * public static function (provide..) (Matching the function signature with PHPUnit/Framework/TestCase.php) Replaces: * public function (setUp|tearDown)\( * protected function $1( * \tfunction (setUp|tearDown)\( * \tprotected function $1( * \tfunction (data|provide)\( * \tpublic static function $1\( Also renamed a few "data#", "provider#" and "provides#" functions to "provide#" for consistency. This also removes confusion where the /media tests had a few private methods called dataFile(), which were sometimes expected to be data providers. Fixes: TimestampTest often failed due to a previous test setting a different language (it tests "1 hour ago" so need to make sure it is set to English). MWNamespaceTest became a lot cleaner now that it executes with a known context. Though the now-redundant code that was removed didn't work anyway because wgContentNamespaces isn't keyed by namespace id, it had them was values... FileBackendTest: * Fixed: "PHP Fatal: Using $this when not in object context" HttpTest * Added comment about: "PHP Fatal: Call to protected MWHttpRequest::__construct()" (too much unrelated code to fix in this commit) ExternalStoreTest * Add an assertTrue as well, without it the test is useless because regardless of whether wgExternalStores is true or false it only uses it if it is an array. Change-Id: I9d2b148e57bada64afeb7d5a99bec0e58f8e1561
* Allow array condition for HAVING in database interfaceumherirrender2012-08-311-0/+40
| | | | | | Current no use in core. Change-Id: I8ed86c8238146285dd1caed4d8586c877cbecf44
* Allow array condition for Database::conditionalumherirrender2012-08-251-3/+35
| | | | | | | Change the one use of that method to use the new syntax. Add some tests. Change-Id: I9ad4e5b5e97d1d13cfd858105167ca5d20ffaf83
* Allow aliased field names with separated syntaxumherirrender2012-08-151-0/+75
This introduce the syntax from aliased table names for aliased field names into the abstract database layer: array( 'alias' => 'field' ) gives 'field AS alias' This patch also includes changes to query pages, api and some more places to show, how the new syntax looks in "production". This allow us to remove the "AS" for Non-PostgreSQL databases, if we want that. Change-Id: I5f0de1c2f29092c173aec3de93ffdef436799e8d