| 1 |
<?php |
| 2 |
|
| 3 |
use MediaWiki\Deferred\LinksUpdate\LinksDeletionUpdate; |
| 4 |
use MediaWiki\Deferred\LinksUpdate\LinksUpdate; |
| 5 |
use MediaWiki\Parser\ParserOutput; |
| 6 |
use MediaWiki\Title\TitleValue; |
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
class LinksDeletionUpdateTest extends MediaWikiLangTestCase { |
| 29 |
public function testUpdate() { |
| 30 |
$res = $this->insertPage( 'Source' ); |
| 31 |
$id = $res['id']; |
| 32 |
$title = $res['title']; |
| 33 |
$wikiPage = $this->getServiceContainer()->getWikiPageFactory()->newFromTitle( $title ); |
| 34 |
|
| 35 |
$po = new ParserOutput(); |
| 36 |
$po->addCategory( new TitleValue( NS_CATEGORY, 'Cat' ), 'cat' ); |
| 37 |
$po->addExternalLink( 'https://en.wikipedia.org/' ); |
| 38 |
$po->addImage( new TitleValue( NS_FILE, 'Wiki.png' ) ); |
| 39 |
$po->addLink( new TitleValue( 0, 'foo', '', 'iwprefix' ) ); |
| 40 |
$po->addLanguageLink( new TitleValue( 0, 'Francais', '', 'fr' ) ); |
| 41 |
$po->addLink( new TitleValue( 0, 'Target' ) ); |
| 42 |
$po->setNumericPageProperty( 'int', 1 ); |
| 43 |
$po->addTemplate( new TitleValue( NS_TEMPLATE, '!' ), 1, 1 ); |
| 44 |
|
| 45 |
$linksUpdate = new LinksUpdate( $title, $po, false ); |
| 46 |
$linksUpdate->setTransactionTicket( |
| 47 |
$this->getServiceContainer()->getConnectionProvider()->getEmptyTransactionTicket( __METHOD__ ) |
| 48 |
); |
| 49 |
$linksUpdate->doUpdate(); |
| 50 |
|
| 51 |
$tables = [ |
| 52 |
'categorylinks' => 'cl_from', |
| 53 |
'externallinks' => 'el_from', |
| 54 |
'imagelinks' => 'il_from', |
| 55 |
'iwlinks' => 'iwl_from', |
| 56 |
'langlinks' => 'll_from', |
| 57 |
'pagelinks' => 'pl_from', |
| 58 |
'page_props' => 'pp_page', |
| 59 |
'templatelinks' => 'tl_from', |
| 60 |
]; |
| 61 |
foreach ( $tables as $table => $fromField ) { |
| 62 |
$res = $this->getDb()->newSelectQueryBuilder() |
| 63 |
->select( [ 1 ] ) |
| 64 |
->from( $table ) |
| 65 |
->where( [ $fromField => $id ] ) |
| 66 |
->caller( __METHOD__ )->fetchResultSet(); |
| 67 |
$this->assertSame( 1, $res->numRows(), "Number of rows in table $table" ); |
| 68 |
} |
| 69 |
|
| 70 |
$linksDeletionUpdate = new LinksDeletionUpdate( $wikiPage, $id ); |
| 71 |
$linksDeletionUpdate->setTransactionTicket( |
| 72 |
$this->getServiceContainer()->getConnectionProvider()->getEmptyTransactionTicket( __METHOD__ ) |
| 73 |
); |
| 74 |
$linksDeletionUpdate->doUpdate(); |
| 75 |
|
| 76 |
foreach ( $tables as $table => $fromField ) { |
| 77 |
$res = $this->getDb()->newSelectQueryBuilder() |
| 78 |
->select( [ 1 ] ) |
| 79 |
->from( $table ) |
| 80 |
->where( [ $fromField => $id ] ) |
| 81 |
->caller( __METHOD__ )->fetchResultSet(); |
| 82 |
$this->assertSame( 0, $res->numRows(), "Number of rows in table $table" ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |