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
,
29 $dbw = wfGetDB( DB_MASTER
);
34 'iw_prefix' => 'linksupdatetest',
35 'iw_url' => 'http://testing.com/wiki/$1',
36 'iw_api' => 'http://testing.com/w/api.php',
39 'iw_wikiid' => 'linksupdatetest',
44 protected function makeTitleAndParserOutput( $name, $id ) {
45 $t = Title
::newFromText( $name );
46 $t->mArticleID
= $id; # XXX: this is fugly
48 $po = new ParserOutput();
49 $po->setTitleText( $t->getPrefixedText() );
51 return array( $t, $po );
54 public function testUpdate_pagelinks() {
55 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
57 $po->addLink( Title
::newFromText( "Foo" ) );
58 $po->addLink( Title
::newFromText( "Special:Foo" ) ); // special namespace should be ignored
59 $po->addLink( Title
::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored
60 $po->addLink( Title
::newFromText( "#Foo" ) ); // hash link should be ignored
62 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
63 array( NS_MAIN
, 'Foo' ),
66 $po = new ParserOutput();
67 $po->setTitleText( $t->getPrefixedText() );
69 $po->addLink( Title
::newFromText( "Bar" ) );
71 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array(
72 array( NS_MAIN
, 'Bar' ),
76 public function testUpdate_externallinks() {
77 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
79 $po->addExternalLink( "http://testing.com/wiki/Foo" );
81 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
82 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
86 public function testUpdate_categorylinks() {
87 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
89 $po->addCategory( "Foo", "FOO" );
91 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
92 array( 'Foo', "FOO\nTESTING" ),
96 public function testUpdate_iwlinks() {
97 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
99 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
100 $po->addInterwikiLink( $target );
102 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
103 array( 'linksupdatetest', 'Foo' ),
107 public function testUpdate_templatelinks() {
108 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
110 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
112 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
113 array( NS_TEMPLATE
, 'Foo' ),
117 public function testUpdate_imagelinks() {
118 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
120 $po->addImage( "Foo.png" );
123 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
128 public function testUpdate_langlinks() {
129 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
131 $po->addLanguageLink( Title
::newFromText( "en:Foo" ) );
134 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
135 array( 'En', 'Foo' ),
139 public function testUpdate_page_props() {
140 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
142 $po->setProperty( "foo", "bar" );
144 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
145 array( 'foo', 'bar' ),
149 #@todo: test recursive, too!
151 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput, $table, $fields, $condition, Array $expectedRows ) {
152 $update = new LinksUpdate( $title, $parserOutput );
156 $this->assertSelect( $table, $fields, $condition, $expectedRows );