6 * ^--- make sure temporary tables are used.
8 class LinksUpdateTest
extends MediaWikiTestCase
{
10 function __construct( $name = null, array $data = array(), $dataName = '' ) {
11 parent
::__construct( $name, $data, $dataName );
13 $this->tablesUsed
= array_merge( $this->tablesUsed
,
28 protected function setUp() {
30 $dbw = wfGetDB( DB_MASTER
);
35 'iw_prefix' => 'linksupdatetest',
36 'iw_url' => 'http://testing.com/wiki/$1',
37 'iw_api' => 'http://testing.com/w/api.php',
40 'iw_wikiid' => 'linksupdatetest',
45 protected function makeTitleAndParserOutput( $name, $id ) {
46 $t = Title
::newFromText( $name );
47 $t->mArticleID
= $id; # XXX: this is fugly
49 $po = new ParserOutput();
50 $po->setTitleText( $t->getPrefixedText() );
52 return array( $t, $po );
55 public function testUpdate_pagelinks() {
56 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
58 $po->addLink( Title
::newFromText( "Foo" ) );
59 $po->addLink( Title
::newFromText( "Special:Foo" ) ); // special namespace should be ignored
60 $po->addLink( Title
::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
61 $po->addLink( Title
::newFromText( "#Foo" ) ); // hash link should be ignored
63 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
64 array( NS_MAIN
, 'Foo' ),
67 $po = new ParserOutput();
68 $po->setTitleText( $t->getPrefixedText() );
70 $po->addLink( Title
::newFromText( "Bar" ) );
72 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
73 array( NS_MAIN
, 'Bar' ),
77 public function testUpdate_externallinks() {
78 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
80 $po->addExternalLink( "http://testing.com/wiki/Foo" );
82 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
83 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
87 public function testUpdate_categorylinks() {
88 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
90 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
92 $po->addCategory( "Foo", "FOO" );
94 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
95 array( 'Foo', "FOO\nTESTING" ),
99 public function testUpdate_iwlinks() {
100 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
102 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
103 $po->addInterwikiLink( $target );
105 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
106 array( 'linksupdatetest', 'Foo' ),
110 public function testUpdate_templatelinks() {
111 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
113 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
115 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
116 array( NS_TEMPLATE
, 'Foo' ),
120 public function testUpdate_imagelinks() {
121 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
123 $po->addImage( "Foo.png" );
125 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
130 public function testUpdate_langlinks() {
131 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
133 $po->addLanguageLink( Title
::newFromText( "en:Foo" )->getFullText() );
135 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
136 array( 'En', 'Foo' ),
140 public function testUpdate_page_props() {
141 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
143 $po->setProperty( "foo", "bar" );
145 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
146 array( 'foo', 'bar' ),
150 // @todo test recursive, too!
152 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput, $table, $fields, $condition, array $expectedRows ) {
153 $update = new LinksUpdate( $title, $parserOutput );
155 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
156 $update->beginTransaction();
158 $update->commitTransaction();
160 $this->assertSelect( $table, $fields, $condition, $expectedRows );