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