MediaWiki
REL1_21
|
00001 <?php 00002 00008 class LinksUpdateTest extends MediaWikiTestCase { 00009 00010 function __construct( $name = null, array $data = array(), $dataName = '' ) { 00011 parent::__construct( $name, $data, $dataName ); 00012 00013 $this->tablesUsed = array_merge( $this->tablesUsed, 00014 array( 00015 'interwiki', 00016 'page_props', 00017 'pagelinks', 00018 'categorylinks', 00019 'langlinks', 00020 'externallinks', 00021 'imagelinks', 00022 'templatelinks', 00023 'iwlinks' 00024 ) 00025 ); 00026 } 00027 00028 protected function setUp() { 00029 parent::setUp(); 00030 $dbw = wfGetDB( DB_MASTER ); 00031 $dbw->replace( 00032 'interwiki', 00033 array( 'iw_prefix' ), 00034 array( 00035 'iw_prefix' => 'linksupdatetest', 00036 'iw_url' => 'http://testing.com/wiki/$1', 00037 'iw_api' => 'http://testing.com/w/api.php', 00038 'iw_local' => 0, 00039 'iw_trans' => 0, 00040 'iw_wikiid' => 'linksupdatetest', 00041 ) 00042 ); 00043 } 00044 00045 protected function makeTitleAndParserOutput( $name, $id ) { 00046 $t = Title::newFromText( $name ); 00047 $t->mArticleID = $id; # XXX: this is fugly 00048 00049 $po = new ParserOutput(); 00050 $po->setTitleText( $t->getPrefixedText() ); 00051 00052 return array( $t, $po ); 00053 } 00054 00055 public function testUpdate_pagelinks() { 00056 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00057 00058 $po->addLink( Title::newFromText( "Foo" ) ); 00059 $po->addLink( Title::newFromText( "Special:Foo" ) ); // special namespace should be ignored 00060 $po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored 00061 $po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored 00062 00063 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array( 00064 array( NS_MAIN, 'Foo' ), 00065 ) ); 00066 00067 $po = new ParserOutput(); 00068 $po->setTitleText( $t->getPrefixedText() ); 00069 00070 $po->addLink( Title::newFromText( "Bar" ) ); 00071 00072 $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array( 00073 array( NS_MAIN, 'Bar' ), 00074 ) ); 00075 } 00076 00077 public function testUpdate_externallinks() { 00078 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00079 00080 $po->addExternalLink( "http://testing.com/wiki/Foo" ); 00081 00082 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array( 00083 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ), 00084 ) ); 00085 } 00086 00087 public function testUpdate_categorylinks() { 00088 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' ); 00089 00090 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00091 00092 $po->addCategory( "Foo", "FOO" ); 00093 00094 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array( 00095 array( 'Foo', "FOO\nTESTING" ), 00096 ) ); 00097 } 00098 00099 public function testUpdate_iwlinks() { 00100 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00101 00102 $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' ); 00103 $po->addInterwikiLink( $target ); 00104 00105 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array( 00106 array( 'linksupdatetest', 'Foo' ), 00107 ) ); 00108 } 00109 00110 public function testUpdate_templatelinks() { 00111 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00112 00113 $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 ); 00114 00115 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array( 00116 array( NS_TEMPLATE, 'Foo' ), 00117 ) ); 00118 } 00119 00120 public function testUpdate_imagelinks() { 00121 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00122 00123 $po->addImage( "Foo.png" ); 00124 00125 00126 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array( 00127 array( 'Foo.png' ), 00128 ) ); 00129 } 00130 00131 public function testUpdate_langlinks() { 00132 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00133 00134 $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() ); 00135 00136 00137 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array( 00138 array( 'En', 'Foo' ), 00139 ) ); 00140 } 00141 00142 public function testUpdate_page_props() { 00143 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); 00144 00145 $po->setProperty( "foo", "bar" ); 00146 00147 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array( 00148 array( 'foo', 'bar' ), 00149 ) ); 00150 } 00151 00152 #@todo: test recursive, too! 00153 00154 protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput, $table, $fields, $condition, array $expectedRows ) { 00155 $update = new LinksUpdate( $title, $parserOutput ); 00156 00157 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction. 00158 $update->beginTransaction(); 00159 $update->doUpdate(); 00160 $update->commitTransaction(); 00161 00162 $this->assertSelect( $table, $fields, $condition, $expectedRows ); 00163 } 00164 }