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 $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
64 array( NS_MAIN
, 'Foo' ),
66 $this->assertArrayEquals( array(
67 Title
::makeTitle( NS_MAIN
, 'Foo' ), // newFromText doesn't yield the same internal state....
68 ), $update->getAddedLinks() );
70 $po = new ParserOutput();
71 $po->setTitleText( $t->getPrefixedText() );
73 $po->addLink( Title
::newFromText( "Bar" ) );
74 $po->addLink( Title
::newFromText( "Talk:Bar" ) );
76 $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
77 array( NS_MAIN
, 'Bar' ),
78 array( NS_TALK
, 'Bar' ),
80 $this->assertArrayEquals( array(
81 Title
::makeTitle( NS_MAIN
, 'Bar' ),
82 Title
::makeTitle( NS_TALK
, 'Bar' ),
83 ), $update->getAddedLinks() );
84 $this->assertArrayEquals( array(
85 Title
::makeTitle( NS_MAIN
, 'Foo' ),
86 ), $update->getRemovedLinks() );
89 public function testUpdate_externallinks() {
90 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
92 $po->addExternalLink( "http://testing.com/wiki/Foo" );
94 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
95 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
99 public function testUpdate_categorylinks() {
100 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
102 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
104 $po->addCategory( "Foo", "FOO" );
106 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
107 array( 'Foo', "FOO\nTESTING" ),
111 public function testUpdate_iwlinks() {
112 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
114 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
115 $po->addInterwikiLink( $target );
117 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
118 array( 'linksupdatetest', 'Foo' ),
122 public function testUpdate_templatelinks() {
123 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
125 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
127 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
128 array( NS_TEMPLATE
, 'Foo' ),
132 public function testUpdate_imagelinks() {
133 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
135 $po->addImage( "Foo.png" );
137 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
142 public function testUpdate_langlinks() {
143 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
145 $po->addLanguageLink( Title
::newFromText( "en:Foo" )->getFullText() );
147 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
148 array( 'En', 'Foo' ),
152 public function testUpdate_page_props() {
153 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
155 $po->setProperty( "foo", "bar" );
157 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
158 array( 'foo', 'bar' ),
162 // @todo test recursive, too!
164 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput, $table, $fields, $condition, array $expectedRows ) {
165 $update = new LinksUpdate( $title, $parserOutput );
167 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
168 $update->beginTransaction();
170 $update->commitTransaction();
172 $this->assertSelect( $table, $fields, $condition, $expectedRows );