wiki.techinc.nl/tests/phpunit/includes/LinksUpdateTest.php

163 lines
4.6 KiB
PHP
Raw Normal View History

<?php
/**
*
* @group Database
* ^--- make sure temporary tables are used.
*/
class LinksUpdateTest extends MediaWikiTestCase {
function __construct( $name = null, array $data = array(), $dataName = '' ) {
parent::__construct( $name, $data, $dataName );
$this->tablesUsed = array_merge( $this->tablesUsed,
array(
'interwiki',
'page_props',
'pagelinks',
'categorylinks',
'langlinks',
'externallinks',
'imagelinks',
'templatelinks',
'iwlinks'
)
);
}
Clean and repair many phpunit tests (+ fix implied configuration) 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
2012-10-08 10:56:20 +00:00
protected function setUp() {
parent::setUp();
$dbw = wfGetDB( DB_MASTER );
$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',
)
);
}
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 );
}
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
$this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
array( NS_MAIN, 'Foo' ),
) );
$po = new ParserOutput();
$po->setTitleText( $t->getPrefixedText() );
$po->addLink( Title::newFromText( "Bar" ) );
$this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
array( NS_MAIN, 'Bar' ),
) );
}
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' ),
) );
}
public function testUpdate_categorylinks() {
$this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
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" ),
) );
}
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' ),
) );
}
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' ),
) );
}
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' ),
) );
}
public function testUpdate_langlinks() {
list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
$po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() );
$this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
array( 'En', 'Foo' ),
) );
}
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' ),
) );
}
// @todo test recursive, too!
protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput, $table, $fields, $condition, array $expectedRows ) {
$update = new LinksUpdate( $title, $parserOutput );
//NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
$update->beginTransaction();
$update->doUpdate();
$update->commitTransaction();
$this->assertSelect( $table, $fields, $condition, $expectedRows );
}
}