X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fmaintenance%2FfetchTextTest.php;h=8eadb0ead143afda9160109f2e70b8c34140da2f;hb=5a451fd01be397db3209c1881a335423706da5c2;hp=7cbda3c95712810a888b6a9c8de22dc69571a54c;hpb=d98de9926d033b9eaa30306379dc1815ee27b42f;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/maintenance/fetchTextTest.php b/tests/phpunit/maintenance/fetchTextTest.php index 7cbda3c957..8eadb0ead1 100644 --- a/tests/phpunit/maintenance/fetchTextTest.php +++ b/tests/phpunit/maintenance/fetchTextTest.php @@ -4,6 +4,7 @@ namespace MediaWiki\Tests\Maintenance; use ContentHandler; use FetchText; +use MediaWiki\Storage\RevisionRecord; use MediaWikiTestCase; use MWException; use Title; @@ -104,12 +105,12 @@ class FetchTextTest extends MediaWikiTestCase { private $fetchText; /** - * Adds a revision to a page, while returning the resuting text's id + * Adds a revision to a page and returns the main slot's blob address * * @param WikiPage $page The page to add the revision to * @param string $text The revisions text * @param string $summary The revisions summare - * @return int + * @return string * @throws MWException */ private function addRevision( $page, $text, $summary ) { @@ -120,15 +121,14 @@ class FetchTextTest extends MediaWikiTestCase { if ( $status->isGood() ) { $value = $status->getValue(); - $revision = $value['revision']; - $id = $revision->getTextId(); - if ( $id > 0 ) { - return $id; - } + /** @var RevisionRecord $revision */ + $revision = $value['revision-record']; + $address = $revision->getSlot( 'main' )->getAddress(); + return $address; } - throw new MWException( "Could not determine text id" ); + throw new MWException( "Could not create revision" ); } function addDBDataOnce() { @@ -211,6 +211,11 @@ class FetchTextTest extends MediaWikiTestCase { self::$textId2 . "\n23\nFetchTextTestPage2Text1" ); } + function testExistingInteger() { + $this->assertFilter( (int)preg_replace( '/^tt:/', '', self::$textId2 ), + self::$textId2 . "\n23\nFetchTextTestPage2Text1" ); + } + function testExistingSeveral() { $this->assertFilter( implode( "\n", [ @@ -233,36 +238,52 @@ class FetchTextTest extends MediaWikiTestCase { } function testNonExisting() { - $this->assertFilter( self::$textId5 + 10, ( self::$textId5 + 10 ) . "\n-1\n" ); + \Wikimedia\suppressWarnings(); + $this->assertFilter( 'tt:77889911', 'tt:77889911' . "\n-1\n" ); + \Wikimedia\suppressWarnings( true ); + } + + function testNonExistingInteger() { + \Wikimedia\suppressWarnings(); + $this->assertFilter( '77889911', 'tt:77889911' . "\n-1\n" ); + \Wikimedia\suppressWarnings( true ); + } + + function testBadBlobAddressWithColon() { + $this->assertFilter( 'foo:bar', 'foo:bar' . "\n-1\n" ); } function testNegativeInteger() { - $this->assertFilter( "-42", "-42\n-1\n" ); + $this->assertFilter( "-42", "tt:-42\n-1\n" ); } function testFloatingPointNumberExisting() { - // float -> int -> revision - $this->assertFilter( self::$textId3 + 0.14159, + // float -> int -> address -> revision + $id = intval( preg_replace( '/^tt:/', '', self::$textId3 ) ) + 0.14159; + $this->assertFilter( 'tt:' . intval( $id ), self::$textId3 . "\n23\nFetchTextTestPage2Text2" ); } function testFloatingPointNumberNonExisting() { - $this->assertFilter( self::$textId5 + 3.14159, - ( self::$textId5 + 3 ) . "\n-1\n" ); + \Wikimedia\suppressWarnings(); + $id = intval( preg_replace( '/^tt:/', '', self::$textId5 ) ) + 3.14159; + $this->assertFilter( $id, 'tt:' . intval( $id ) . "\n-1\n" ); + \Wikimedia\suppressWarnings( true ); } function testCharacters() { - $this->assertFilter( "abc", "0\n-1\n" ); + $this->assertFilter( "abc", "abc\n-1\n" ); } function testMix() { - $this->assertFilter( "ab\n" . self::$textId4 . ".5cd\n\nefg\n" . self::$textId2 + $this->assertFilter( "ab\n" . self::$textId4 . ".5cd\n\nefg\nfoo:bar\n" . self::$textId2 . "\n" . self::$textId3, implode( "", [ - "0\n-1\n", - self::$textId4 . "\n23\nFetchTextTestPage2Text3", - "0\n-1\n", - "0\n-1\n", + "ab\n-1\n", + self::$textId4 . ".5cd\n-1\n", + "\n-1\n", + "efg\n-1\n", + "foo:bar\n-1\n", self::$textId2 . "\n23\nFetchTextTestPage2Text1", self::$textId3 . "\n23\nFetchTextTestPage2Text2" ] ) );