X-Git-Url: http://git.cyclocoop.org/%7B%24admin_url%7Dcompta/comptes/journal.php?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FLinksUpdateTest.php;h=9ff547c1d54ec219467c126749fa2333f7b62700;hb=bd2a78a159ce6d9f7b27fd75d05570228b44c3cb;hp=b37ff2e3b76692ef49a5134da5944b788cedea5c;hpb=bcb8fee4a9524cb0e47e8334c1963ac9e721d963;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/LinksUpdateTest.php b/tests/phpunit/includes/LinksUpdateTest.php index b37ff2e3b7..9ff547c1d5 100644 --- a/tests/phpunit/includes/LinksUpdateTest.php +++ b/tests/phpunit/includes/LinksUpdateTest.php @@ -1,7 +1,6 @@ makeTitleAndParserOutput( "Testing", 111 ); $po->addLink( Title::newFromText( "Foo" ) ); @@ -63,9 +63,15 @@ class LinksUpdateTest extends MediaWikiTestCase { $po->addLink( Title::newFromText( "linksupdatetest:Foo" ) ); // interwiki link should be ignored $po->addLink( Title::newFromText( "#Foo" ) ); // hash link should be ignored - $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array( - array( NS_MAIN, 'Foo' ), - ) ); + $update = $this->assertLinksUpdate( + $t, + $po, + 'pagelinks', + 'pl_namespace, + pl_title', + 'pl_from = 111', + array( array( NS_MAIN, 'Foo' ) ) + ); $this->assertArrayEquals( array( Title::makeTitle( NS_MAIN, 'Foo' ), // newFromText doesn't yield the same internal state.... ), $update->getAddedLinks() ); @@ -76,10 +82,18 @@ class LinksUpdateTest extends MediaWikiTestCase { $po->addLink( Title::newFromText( "Bar" ) ); $po->addLink( Title::newFromText( "Talk:Bar" ) ); - $update = $this->assertLinksUpdate( $t, $po, 'pagelinks', 'pl_namespace, pl_title', 'pl_from = 111', array( - array( NS_MAIN, 'Bar' ), - array( NS_TALK, 'Bar' ), - ) ); + $update = $this->assertLinksUpdate( + $t, + $po, + 'pagelinks', + 'pl_namespace, + pl_title', + 'pl_from = 111', + array( + array( NS_MAIN, 'Bar' ), + array( NS_TALK, 'Bar' ), + ) + ); $this->assertArrayEquals( array( Title::makeTitle( NS_MAIN, 'Bar' ), Title::makeTitle( NS_TALK, 'Bar' ), @@ -90,9 +104,10 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::addExternalLink + * @covers ParserOutput::addExternalLink */ public function testUpdate_externallinks() { + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); $po->addExternalLink( "http://testing.com/wiki/Foo" ); @@ -103,9 +118,10 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::addCategory + * @covers ParserOutput::addCategory */ public function testUpdate_categorylinks() { + /** @var ParserOutput $po */ $this->setMwGlobals( 'wgCategoryCollation', 'uppercase' ); list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); @@ -118,9 +134,10 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::addInterwikiLink + * @covers ParserOutput::addInterwikiLink */ public function testUpdate_iwlinks() { + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); $target = Title::makeTitleSafe( NS_MAIN, "Foo", '', 'linksupdatetest' ); @@ -132,22 +149,30 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::addTemplate + * @covers ParserOutput::addTemplate */ public function testUpdate_templatelinks() { + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); $po->addTemplate( Title::newFromText( "Template:Foo" ), 23, 42 ); - $this->assertLinksUpdate( $t, $po, 'templatelinks', 'tl_namespace, tl_title', 'tl_from = 111', array( - array( NS_TEMPLATE, 'Foo' ), - ) ); + $this->assertLinksUpdate( + $t, + $po, + 'templatelinks', + 'tl_namespace, + tl_title', + 'tl_from = 111', + array( array( NS_TEMPLATE, 'Foo' ) ) + ); } /** - * @covers LinksUpdate::addImage + * @covers ParserOutput::addImage */ public function testUpdate_imagelinks() { + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); $po->addImage( "Foo.png" ); @@ -158,9 +183,10 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::addLanguageLink + * @covers ParserOutput::addLanguageLink */ public function testUpdate_langlinks() { + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); $po->addLanguageLink( Title::newFromText( "en:Foo" )->getFullText() ); @@ -171,21 +197,58 @@ class LinksUpdateTest extends MediaWikiTestCase { } /** - * @covers LinksUpdate::setProperty + * @covers ParserOutput::setProperty */ public function testUpdate_page_props() { + global $wgPagePropsHaveSortkey; + + /** @var ParserOutput $po */ list( $t, $po ) = $this->makeTitleAndParserOutput( "Testing", 111 ); - $po->setProperty( "foo", "bar" ); + $fields = array( 'pp_propname', 'pp_value' ); + $expected = array(); - $this->assertLinksUpdate( $t, $po, 'page_props', 'pp_propname, pp_value', 'pp_page = 111', array( - array( 'foo', 'bar' ), - ) ); + $po->setProperty( "bool", true ); + $expected[] = array( "bool", true ); + + $po->setProperty( "float", 4.0 + 1.0/4.0 ); + $expected[] = array( "float", 4.0 + 1.0/4.0 ); + + $po->setProperty( "int", -7 ); + $expected[] = array( "int", -7 ); + + $po->setProperty( "string", "33 bar" ); + $expected[] = array( "string", "33 bar" ); + + // compute expected sortkey values + if ( $wgPagePropsHaveSortkey ) { + $fields[] = 'pp_sortkey'; + + foreach ( $expected as &$row ) { + $value = $row[1]; + + if ( is_int( $value ) || is_float( $value ) || is_bool( $value ) ) { + $row[] = floatval( $value ); + } else { + $row[] = null; + } + } + } + + $this->assertLinksUpdate( $t, $po, 'page_props', $fields, 'pp_page = 111', $expected ); + } + + public function testUpdate_page_props_without_sortkey() { + $this->setMwGlobals( 'wgPagePropsHaveSortkey', false ); + + $this->testUpdate_page_props(); } // @todo test recursive, too! - protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput, $table, $fields, $condition, array $expectedRows ) { + protected function assertLinksUpdate( Title $title, ParserOutput $parserOutput, + $table, $fields, $condition, array $expectedRows + ) { $update = new LinksUpdate( $title, $parserOutput ); //NOTE: make sure LinksUpdate does not generate warnings when called inside a transaction.