2012-05-10 20:56:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @group Database
|
|
|
|
|
* ^--- make sure temporary tables are used.
|
|
|
|
|
*/
|
|
|
|
|
class LinksUpdateTest extends MediaWikiTestCase {
|
|
|
|
|
|
2013-03-18 19:44:43 +00:00
|
|
|
function __construct( $name = null, array $data = array(), $dataName = '' ) {
|
2012-05-10 20:56:34 +00:00
|
|
|
parent::__construct( $name, $data, $dataName );
|
|
|
|
|
|
2012-10-02 08:39:30 +00:00
|
|
|
$this->tablesUsed = array_merge( $this->tablesUsed,
|
|
|
|
|
array(
|
|
|
|
|
'interwiki',
|
|
|
|
|
'page_props',
|
|
|
|
|
'pagelinks',
|
|
|
|
|
'categorylinks',
|
|
|
|
|
'langlinks',
|
|
|
|
|
'externallinks',
|
|
|
|
|
'imagelinks',
|
|
|
|
|
'templatelinks',
|
|
|
|
|
'iwlinks'
|
|
|
|
|
)
|
|
|
|
|
);
|
2012-05-10 20:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 10:56:20 +00:00
|
|
|
protected function setUp() {
|
2012-10-23 17:02:36 +00:00
|
|
|
parent::setUp();
|
2012-05-10 20:56:34 +00:00
|
|
|
$dbw = wfGetDB( DB_MASTER );
|
2012-10-02 08:39:30 +00:00
|
|
|
$dbw->replace(
|
|
|
|
|
'interwiki',
|
|
|
|
|
array( 'iw_prefix' ),
|
|
|
|
|
array(
|
|
|
|
|
'iw_prefix' => 'linksupdatetest',
|
|
|
|
|
'iw_url' => 'http://testing.com/wiki/$1',
|
|
|
|
|
'iw_api' => 'http://testing.com/w/api.php',
|
|
|
|
|
'iw_local' => 0,
|
|
|
|
|
'iw_trans' => 0,
|
|
|
|
|
'iw_wikiid' => 'linksupdatetest',
|
|
|
|
|
)
|
|
|
|
|
);
|
2012-05-10 20:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function makeTitleAndParserOutput( $name, $id ) {
|
|
|
|
|
$t = Title::newFromText( $name );
|
|
|
|
|
$t->mArticleID = $id; # XXX: this is fugly
|
|
|
|
|
|
|
|
|
|
$po = new ParserOutput();
|
|
|
|
|
$po->setTitleText( $t->getPrefixedText() );
|
|
|
|
|
|
|
|
|
|
return array( $t, $po );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addLink
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_pagelinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->addLink( Title::newFromText( "Foo" ) );
|
|
|
|
|
$po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored
|
|
|
|
|
$po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
|
|
|
|
|
$po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored
|
|
|
|
|
|
2013-10-09 18:48:37 +00:00
|
|
|
$update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
|
2012-05-10 20:56:34 +00:00
|
|
|
array( NS_MAIN, 'Foo' ),
|
|
|
|
|
) );
|
2013-10-09 18:48:37 +00:00
|
|
|
$this->assertArrayEquals( array(
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Foo' ), // newFromText doesn't yield the same internal state....
|
|
|
|
|
), $update->getAddedLinks() );
|
2012-05-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
$po = new ParserOutput();
|
|
|
|
|
$po->setTitleText( $t->getPrefixedText() );
|
|
|
|
|
|
|
|
|
|
$po->addLink( Title::newFromText( "Bar" ) );
|
2013-10-09 18:48:37 +00:00
|
|
|
$po->addLink( Title::newFromText( "Talk:Bar" ) );
|
2012-05-10 20:56:34 +00:00
|
|
|
|
2013-10-09 18:48:37 +00:00
|
|
|
$update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
|
2012-05-10 20:56:34 +00:00
|
|
|
array( NS_MAIN, 'Bar' ),
|
2013-10-09 18:48:37 +00:00
|
|
|
array( NS_TALK, 'Bar' ),
|
2012-05-10 20:56:34 +00:00
|
|
|
) );
|
2013-10-09 18:48:37 +00:00
|
|
|
$this->assertArrayEquals( array(
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Bar' ),
|
|
|
|
|
Title::makeTitle( NS_TALK, 'Bar' ),
|
|
|
|
|
), $update->getAddedLinks() );
|
|
|
|
|
$this->assertArrayEquals( array(
|
|
|
|
|
Title::makeTitle( NS_MAIN, 'Foo' ),
|
|
|
|
|
), $update->getRemovedLinks() );
|
2012-05-10 20:56:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addExternalLink
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_externallinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->addExternalLink( "http://testing.com/wiki/Foo" );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
|
|
|
|
|
array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addCategory
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_categorylinks() {
|
2013-03-01 20:02:42 +00:00
|
|
|
$this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
|
|
|
|
|
|
2012-05-10 20:56:34 +00:00
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->addCategory( "Foo", "FOO" );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
|
|
|
|
|
array( 'Foo', "FOO\nTESTING" ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addInterwikiLink
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_iwlinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' );
|
|
|
|
|
$po->addInterwikiLink( $target );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
|
|
|
|
|
array( 'linksupdatetest', 'Foo' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addTemplate
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_templatelinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
|
|
|
|
|
array( NS_TEMPLATE, 'Foo' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addImage
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_imagelinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->addImage( "Foo.png" );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
|
|
|
|
|
array( 'Foo.png' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::addLanguageLink
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_langlinks() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
2012-12-07 11:33:47 +00:00
|
|
|
$po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
|
2012-05-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
|
|
|
|
|
array( 'En', 'Foo' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-24 16:45:52 +00:00
|
|
|
/**
|
|
|
|
|
* @covers LinksUpdate::setProperty
|
|
|
|
|
*/
|
2012-05-10 20:56:34 +00:00
|
|
|
public function testUpdate_page_props() {
|
|
|
|
|
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
|
|
|
|
|
|
|
|
|
|
$po->setProperty( "foo", "bar" );
|
|
|
|
|
|
|
|
|
|
$this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
|
|
|
|
|
array( 'foo', 'bar' ),
|
|
|
|
|
) );
|
|
|
|
|
}
|
|
|
|
|
|
2013-05-15 01:12:35 +00:00
|
|
|
// @todo test recursive, too!
|
2012-05-10 20:56:34 +00:00
|
|
|
|
2012-10-05 14:11:18 +00:00
|
|
|
protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput, $table, $fields, $condition, array $expectedRows ) {
|
2012-05-10 20:56:34 +00:00
|
|
|
$update = new LinksUpdate( $title, $parserOutput );
|
|
|
|
|
|
2012-10-08 15:26:11 +00:00
|
|
|
//NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
|
2012-06-13 15:43:07 +00:00
|
|
|
$update->beginTransaction();
|
2012-05-10 20:56:34 +00:00
|
|
|
$update->doUpdate();
|
2012-06-13 15:43:07 +00:00
|
|
|
$update->commitTransaction();
|
2012-05-10 20:56:34 +00:00
|
|
|
|
|
|
|
|
$this->assertSelect( $table, $fields, $condition, $expectedRows );
|
2013-10-09 18:48:37 +00:00
|
|
|
return $update;
|
2012-05-10 20:56:34 +00:00
|
|
|
}
|
|
|
|
|
}
|