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(
73 array( array( NS_MAIN
, 'Foo' ) )
75 $this->assertArrayEquals( array(
76 Title
::makeTitle( NS_MAIN
, 'Foo' ), // newFromText doesn't yield the same internal state....
77 ), $update->getAddedLinks() );
79 $po = new ParserOutput();
80 $po->setTitleText( $t->getPrefixedText() );
82 $po->addLink( Title
::newFromText( "Bar" ) );
83 $po->addLink( Title
::newFromText( "Talk:Bar" ) );
85 $update = $this->assertLinksUpdate(
93 array( NS_MAIN
, 'Bar' ),
94 array( NS_TALK
, 'Bar' ),
97 $this->assertArrayEquals( array(
98 Title
::makeTitle( NS_MAIN
, 'Bar' ),
99 Title
::makeTitle( NS_TALK
, 'Bar' ),
100 ), $update->getAddedLinks() );
101 $this->assertArrayEquals( array(
102 Title
::makeTitle( NS_MAIN
, 'Foo' ),
103 ), $update->getRemovedLinks() );
107 * @covers ParserOutput::addExternalLink
109 public function testUpdate_externallinks() {
110 /** @var ParserOutput $po */
111 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
113 $po->addExternalLink( "http://testing.com/wiki/Foo" );
115 $this->assertLinksUpdate( $t, $po, 'externallinks', 'el_to, el_index', 'el_from = 111', array(
116 array( 'http://testing.com/wiki/Foo', 'http://com.testing./wiki/Foo' ),
121 * @covers ParserOutput::addCategory
123 public function testUpdate_categorylinks() {
124 /** @var ParserOutput $po */
125 $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' );
127 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
129 $po->addCategory( "Foo", "FOO" );
131 $this->assertLinksUpdate( $t, $po, 'categorylinks', 'cl_to, cl_sortkey', 'cl_from = 111', array(
132 array( 'Foo', "FOO\nTESTING" ),
137 * @covers ParserOutput::addInterwikiLink
139 public function testUpdate_iwlinks() {
140 /** @var ParserOutput $po */
141 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
143 $target = Title
::makeTitleSafe( NS_MAIN
, "Foo", '', 'linksupdatetest' );
144 $po->addInterwikiLink( $target );
146 $this->assertLinksUpdate( $t, $po, 'iwlinks', 'iwl_prefix, iwl_title', 'iwl_from = 111', array(
147 array( 'linksupdatetest', 'Foo' ),
152 * @covers ParserOutput::addTemplate
154 public function testUpdate_templatelinks() {
155 /** @var ParserOutput $po */
156 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
158 $po->addTemplate( Title
::newFromText( "Template:Foo" ), 23, 42 );
160 $this->assertLinksUpdate(
167 array( array( NS_TEMPLATE
, 'Foo' ) )
172 * @covers ParserOutput::addImage
174 public function testUpdate_imagelinks() {
175 /** @var ParserOutput $po */
176 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
178 $po->addImage( "Foo.png" );
180 $this->assertLinksUpdate( $t, $po, 'imagelinks', 'il_to', 'il_from = 111', array(
186 * @covers ParserOutput::addLanguageLink
188 public function testUpdate_langlinks() {
189 $this->setMwGlobals( array(
190 'wgCapitalLinks' => true,
193 /** @var ParserOutput $po */
194 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
196 $po->addLanguageLink( Title
::newFromText( "en:Foo" )->getFullText() );
198 $this->assertLinksUpdate( $t, $po, 'langlinks', 'll_lang, ll_title', 'll_from = 111', array(
199 array( 'En', 'Foo' ),
204 * @covers ParserOutput::setProperty
206 public function testUpdate_page_props() {
207 global $wgPagePropsHaveSortkey;
209 /** @var ParserOutput $po */
210 list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 );
212 $fields = array( 'pp_propname', 'pp_value' );
215 $po->setProperty( "bool", true );
216 $expected[] = array( "bool", true );
218 $po->setProperty( "float", 4.0 +
1.0 / 4.0 );
219 $expected[] = array( "float", 4.0 +
1.0 / 4.0 );
221 $po->setProperty( "int", -7 );
222 $expected[] = array( "int", -7 );
224 $po->setProperty( "string", "33 bar" );
225 $expected[] = array( "string", "33 bar" );
227 // compute expected sortkey values
228 if ( $wgPagePropsHaveSortkey ) {
229 $fields[] = 'pp_sortkey';
231 foreach ( $expected as &$row ) {
234 if ( is_int( $value ) ||
is_float( $value ) ||
is_bool( $value ) ) {
235 $row[] = floatval( $value );
242 $this->assertLinksUpdate( $t, $po, 'page_props', $fields, 'pp_page = 111', $expected );
245 public function testUpdate_page_props_without_sortkey() {
246 $this->setMwGlobals( 'wgPagePropsHaveSortkey', false );
248 $this->testUpdate_page_props();
251 // @todo test recursive, too!
253 protected function assertLinksUpdate( Title
$title, ParserOutput
$parserOutput,
254 $table, $fields, $condition, array $expectedRows
256 $update = new LinksUpdate( $title, $parserOutput );
258 //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.
259 $update->beginTransaction();
261 $update->commitTransaction();
263 $this->assertSelect( $table, $fields, $condition, $expectedRows );