5 * ^--- make sure temporary tables are used.
7 class LinksUpdateTest
extends MediaWikiTestCase
{
9 function __construct( $name = null, array $data = array(), $dataName = '' ) {
10 parent
::__construct( $name, $data, $dataName );
12 $this->tablesUsed
= array_merge( $this->tablesUsed
,
27 protected function setUp() {
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 );
55 * @covers ParserOutput::addLink
57 public function testUpdate_pagelinks() {
58 /** @var ParserOutput $po */
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 ParserOutput::addExternalLink
95 public function testUpdate_externallinks() {
96 /** @var ParserOutput $po */
97 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
99 $po->addExternalLink( "http://testing.com/wiki/Foo" );
101 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
102 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
107 * @covers ParserOutput::addCategory
109 public function testUpdate_categorylinks() {
110 /** @var ParserOutput $po */
111 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
113 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
115 $po->addCategory( "Foo", "FOO" );
117 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
118 array( 'Foo', "FOO\nTESTING" ),
123 * @covers ParserOutput::addInterwikiLink
125 public function testUpdate_iwlinks() {
126 /** @var ParserOutput $po */
127 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
129 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
130 $po->addInterwikiLink( $target );
132 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
133 array( 'linksupdatetest', 'Foo' ),
138 * @covers ParserOutput::addTemplate
140 public function testUpdate_templatelinks() {
141 /** @var ParserOutput $po */
142 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
144 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
146 $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array(
147 array( NS_TEMPLATE
, 'Foo' ),
152 * @covers ParserOutput::addImage
154 public function testUpdate_imagelinks() {
155 /** @var ParserOutput $po */
156 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
158 $po->addImage( "Foo.png" );
160 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
166 * @covers ParserOutput::addLanguageLink
168 public function testUpdate_langlinks() {
169 /** @var ParserOutput $po */
170 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
172 $po->addLanguageLink( Title
::newFromText( "en:Foo" )->getFullText() );
174 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
175 array( 'En', 'Foo' ),
180 * @covers ParserOutput::setProperty
182 public function testUpdate_page_props() {
183 /** @var ParserOutput $po */
184 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
186 $po->setProperty( "foo", "bar" );
188 $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array(
189 array( 'foo', 'bar' ),
193 // @todo test recursive, too!
195 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput, $table, $fields, $condition, array $expectedRows ) {
196 $update = new LinksUpdate( $title, $parserOutput );
198 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
199 $update->beginTransaction();
201 $update->commitTransaction();
203 $this->assertSelect( $table, $fields, $condition, $expectedRows );