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 );
56 * @covers LinksUpdate::addLink
58 public function testUpdate_pagelinks() {
59 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
61 $po->addLink( Title
::newFromText( "Foo" ) );
62 $po->addLink( Title
::newFromText( "Special:Foo" ) ); // special namespace should be ignored
63 $po->addLink( Title
::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
64 $po->addLink( Title
::newFromText( "#Foo" ) ); // hash link should be ignored
66 $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
67 array( NS_MAIN
, 'Foo' ),
69 $this->assertArrayEquals( array(
70 Title
::makeTitle( NS_MAIN
, 'Foo' ), // newFromText doesn't yield the same internal state....
71 ), $update->getAddedLinks() );
73 $po = new ParserOutput();
74 $po->setTitleText( $t->getPrefixedText() );
76 $po->addLink( Title
::newFromText( "Bar" ) );
77 $po->addLink( Title
::newFromText( "Talk:Bar" ) );
79 $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
80 array( NS_MAIN
, 'Bar' ),
81 array( NS_TALK
, 'Bar' ),
83 $this->assertArrayEquals( array(
84 Title
::makeTitle( NS_MAIN
, 'Bar' ),
85 Title
::makeTitle( NS_TALK
, 'Bar' ),
86 ), $update->getAddedLinks() );
87 $this->assertArrayEquals( array(
88 Title
::makeTitle( NS_MAIN
, 'Foo' ),
89 ), $update->getRemovedLinks() );
93 * @covers LinksUpdate::addExternalLink
95 public function testUpdate_externallinks() {
96 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
98 $po->addExternalLink( "http://testing.com/wiki/Foo" );
100 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
101 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
106 * @covers LinksUpdate::addCategory
108 public function testUpdate_categorylinks() {
109 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
111 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
113 $po->addCategory( "Foo", "FOO" );
115 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
116 array( 'Foo', "FOO\nTESTING" ),
121 * @covers LinksUpdate::addInterwikiLink
123 public function testUpdate_iwlinks() {
124 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
126 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
127 $po->addInterwikiLink( $target );
129 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
130 array( 'linksupdatetest', 'Foo' ),
135 * @covers LinksUpdate::addTemplate
137 public function testUpdate_templatelinks() {
138 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
140 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
142 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
143 array( NS_TEMPLATE
, 'Foo' ),
148 * @covers LinksUpdate::addImage
150 public function testUpdate_imagelinks() {
151 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
153 $po->addImage( "Foo.png" );
155 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
161 * @covers LinksUpdate::addLanguageLink
163 public function testUpdate_langlinks() {
164 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
166 $po->addLanguageLink( Title
::newFromText( "en:Foo" )->getFullText() );
168 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
169 array( 'En', 'Foo' ),
174 * @covers LinksUpdate::setProperty
176 public function testUpdate_page_props() {
177 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
179 $po->setProperty( "foo", "bar" );
181 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
182 array( 'foo', 'bar' ),
186 // @todo test recursive, too!
188 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput, $table, $fields, $condition, array $expectedRows ) {
189 $update = new LinksUpdate( $title, $parserOutput );
191 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
192 $update->beginTransaction();
194 $update->commitTransaction();
196 $this->assertSelect( $table, $fields, $condition, $expectedRows );