wiki.techinc.nl/tests/phpunit/includes/deferred/LinksDeletionUpdateTest.php
Timo Tijhof 4ef0891994 rdbms: Consolidate logger channels into one
Notable changes:

* In SqlBagOStuff::getConnectionFromServerInfo, only two loggers were
  injected. The rest implicitly got a NullLogger due to being absent.
  These are now effectively unsilenced.

* Database::__construct() required almost all parameters, even the
  loggers. I've wanted to move some of DatabaseFactory into the ctor
  here for a while. In order to make this change not a breaking
  change, the new 'logger' parameter is optional with NullLogger as
  default. This allowed some of the test cases, which were simply
  passing NullLogger, to be fixed by passing nothing instead of
  passing the new option name.

  The Database class is behind a dozen layers of indirection for
  real use, so this will still be injected just fine (DBF, LB, LBF,
  MWLBF, etc.).

* In LegacyLogger, the handling for $wgDBerrorLog was previously
  limited to DBConnection and DBQuery. This now includes errors
  from other (generally, newer) parts of Rdbms as well, which were
  previously missing.

  This only affects sites (typically CI and dev setup) where
  $wgDBerrorLog is used, as opposed to the more common
  $wgDebugLogGroups by-channel configuration.

* TransactionProfiler gets its logger injected in a rather odd way,
  via entrypoints (MediaWiki.php, ApiMain.php, and MaintenanceRunner)
  as opposed to service wiring. This is kept as-is for now.

* In LBFactoryTest, in particular testInvalidSelectDBIndependent2,
  there are cases that intentionally produce failures of which
  the result is then observed. In CI we assert that dberror.log is
  empty so instead of adding the missing logger fields to that
  LBFactory instance, the only one set (replLogger) is removed.
  The alternative is to set 'logger' now, which would naturally
  cause CI failures due to unexpected entries coming through to
  non-mocked error log.

Bug: T320873
Change-Id: I7ca996618e41b93f488cb5c4de82000bb36e0dd3
2023-01-03 22:46:38 +00:00

90 lines
3.1 KiB
PHP

<?php
use MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate;
use MediaWiki\Deferred\LinksUpdate\LinksUpdate;
/**
* @covers \MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate
* @covers \MediaWiki\Deferred\LinksUpdate\LinksUpdate
* @covers \MediaWiki\Deferred\LinksUpdate\CategoryLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\ExternalLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\GenericPageLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\ImageLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\InterwikiLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\LangLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\LinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\LinksTableGroup
* @covers \MediaWiki\Deferred\LinksUpdate\PageLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\PagePropsTable
* @covers \MediaWiki\Deferred\LinksUpdate\TemplateLinksTable
* @covers \MediaWiki\Deferred\LinksUpdate\TitleLinksTable
*
* @group LinksUpdate
* @group Database
* ^--- make sure temporary tables are used.
*/
class LinksDeletionUpdateTest extends MediaWikiLangTestCase {
public function testUpdate() {
$this->tablesUsed = array_merge( $this->tablesUsed,
[
'interwiki',
'page_props',
'pagelinks',
'categorylinks',
'langlinks',
'externallinks',
'imagelinks',
'templatelinks',
'iwlinks',
'recentchanges',
]
);
$res = $this->insertPage( 'Source' );
$id = $res['id'];
$title = $res['title'];
$wikiPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title );
$po = new ParserOutput();
$po->addCategory( 'Cat', 'cat' );
$po->addExternalLink( 'https://en.wikipedia.org/' );
$po->addImage( 'Wiki.png' );
$po->addLink( new TitleValue( 0, 'foo', '', 'iwprefix' ) );
$po->addLanguageLink( 'fr:Francais' );
$po->addLink( new TitleValue( 0, 'Target' ) );
$po->setPageProperty( 'int', 1 );
$po->addTemplate( new TitleValue( NS_TEMPLATE, '!' ), 1, 1 );
$linksUpdate = new LinksUpdate( $title, $po, false );
$linksUpdate->setTransactionTicket(
$this->getServiceContainer()->getDBLoadBalancerFactory()->getEmptyTransactionTicket( __METHOD__ )
);
$linksUpdate->doUpdate();
$tables = [
'categorylinks' => 'cl_from',
'externallinks' => 'el_from',
'imagelinks' => 'il_from',
'iwlinks' => 'iwl_from',
'langlinks' => 'll_from',
'pagelinks' => 'pl_from',
'page_props' => 'pp_page',
'templatelinks' => 'tl_from',
];
foreach ( $tables as $table => $fromField ) {
$res = $this->db->select( $table, [ 1 ], [ $fromField => $id ], __METHOD__ );
$this->assertSame( 1, $res->numRows(), "Number of rows in table $table" );
}
$linksDeletionUpdate = new LinksDeletionUpdate( $wikiPage, $id );
$linksDeletionUpdate->setTransactionTicket(
$this->getServiceContainer()->getDBLoadBalancerFactory()->getEmptyTransactionTicket( __METHOD__ )
);
$linksDeletionUpdate->doUpdate();
foreach ( $tables as $table => $fromField ) {
$res = $this->db->select( $table, [ 1 ], [ $fromField => $id ], __METHOD__ );
$this->assertSame( 0, $res->numRows(), "Number of rows in table $table" );
}
}
}