X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fmaintenance%2FfetchTextTest.php;h=5a28bfb5ff76044b741523c92cc3a773c6894c16;hb=f8b3f04ae6d78a13b5793a0c4e3bc7080b2c72af;hp=4e38418a18428acbe64d5ffa2633c6c292078e82;hpb=16a9dd96bd5d7bec87c83d47fb954f2e7934dffe;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/maintenance/fetchTextTest.php b/tests/phpunit/maintenance/fetchTextTest.php index 4e38418a18..5a28bfb5ff 100644 --- a/tests/phpunit/maintenance/fetchTextTest.php +++ b/tests/phpunit/maintenance/fetchTextTest.php @@ -23,7 +23,7 @@ class SemiMockedFetchText extends FetchText { /** * @var array Invocation counters for the mocked aspects */ - private $mockInvocations = array( 'getStdin' => 0 ); + private $mockInvocations = [ 'getStdin' => 0 ]; /** * Data for the fake stdin @@ -75,11 +75,11 @@ class FetchTextTest extends MediaWikiTestCase { // We add 5 Revisions for this test. Their corresponding text id's // are stored in the following 5 variables. - private $textId1; - private $textId2; - private $textId3; - private $textId4; - private $textId5; + protected static $textId1; + protected static $textId2; + protected static $textId3; + protected static $textId4; + protected static $textId5; /** * @var Exception|null As the current MediaWikiTestCase::run is not @@ -88,7 +88,7 @@ class FetchTextTest extends MediaWikiTestCase { * we catch the exception and store it until we are in setUp and may * finally rethrow the exception without crashing the test suite. */ - private $exceptionFromAddDBData; + protected static $exceptionFromAddDBDataOnce; /** * @var FetchText The (mocked) FetchText that is to test @@ -123,17 +123,13 @@ class FetchTextTest extends MediaWikiTestCase { throw new MWException( "Could not determine text id" ); } - function addDBData() { - $this->tablesUsed[] = 'page'; - $this->tablesUsed[] = 'revision'; - $this->tablesUsed[] = 'text'; - + function addDBDataOnce() { $wikitextNamespace = $this->getDefaultWikitextNS(); try { $title = Title::newFromText( 'FetchTextTestPage1', $wikitextNamespace ); $page = WikiPage::factory( $title ); - $this->textId1 = $this->addRevision( + self::$textId1 = $this->addRevision( $page, "FetchTextTestPage1Text1", "FetchTextTestPage1Summary1" @@ -141,30 +137,30 @@ class FetchTextTest extends MediaWikiTestCase { $title = Title::newFromText( 'FetchTextTestPage2', $wikitextNamespace ); $page = WikiPage::factory( $title ); - $this->textId2 = $this->addRevision( + self::$textId2 = $this->addRevision( $page, "FetchTextTestPage2Text1", "FetchTextTestPage2Summary1" ); - $this->textId3 = $this->addRevision( + self::$textId3 = $this->addRevision( $page, "FetchTextTestPage2Text2", "FetchTextTestPage2Summary2" ); - $this->textId4 = $this->addRevision( + self::$textId4 = $this->addRevision( $page, "FetchTextTestPage2Text3", "FetchTextTestPage2Summary3" ); - $this->textId5 = $this->addRevision( + self::$textId5 = $this->addRevision( $page, "FetchTextTestPage2Text4 some additional Text ", "FetchTextTestPage2Summary4 extra " ); } catch ( Exception $e ) { // We'd love to pass $e directly. However, ... see - // documentation of exceptionFromAddDBData - $this->exceptionFromAddDBData = $e; + // documentation of exceptionFromAddDBDataOnce + self::$exceptionFromAddDBDataOnce = $e; } } @@ -172,8 +168,8 @@ class FetchTextTest extends MediaWikiTestCase { parent::setUp(); // Check if any Exception is stored for rethrowing from addDBData - if ( $this->exceptionFromAddDBData !== null ) { - throw $this->exceptionFromAddDBData; + if ( self::$exceptionFromAddDBDataOnce !== null ) { + throw self::$exceptionFromAddDBDataOnce; } $this->fetchText = new SemiMockedFetchText(); @@ -198,25 +194,30 @@ class FetchTextTest extends MediaWikiTestCase { // provider would not know the required ids. function testExistingSimple() { - $this->assertFilter( $this->textId2, - $this->textId2 . "\n23\nFetchTextTestPage2Text1" ); + $this->assertFilter( self::$textId2, + self::$textId2 . "\n23\nFetchTextTestPage2Text1" ); } function testExistingSimpleWithNewline() { - $this->assertFilter( $this->textId2 . "\n", - $this->textId2 . "\n23\nFetchTextTestPage2Text1" ); + $this->assertFilter( self::$textId2 . "\n", + self::$textId2 . "\n23\nFetchTextTestPage2Text1" ); } function testExistingSeveral() { - $this->assertFilter( "$this->textId1\n$this->textId5\n" - . "$this->textId3\n$this->textId3", - implode( "", array( - $this->textId1 . "\n23\nFetchTextTestPage1Text1", - $this->textId5 . "\n44\nFetchTextTestPage2Text4 " + $this->assertFilter( + join( "\n", [ + self::$textId1, + self::$textId5, + self::$textId3, + self::$textId3, + ] ), + implode( '', [ + self::$textId1 . "\n23\nFetchTextTestPage1Text1", + self::$textId5 . "\n44\nFetchTextTestPage2Text4 " . "some additional Text", - $this->textId3 . "\n23\nFetchTextTestPage2Text2", - $this->textId3 . "\n23\nFetchTextTestPage2Text2" - ) ) ); + self::$textId3 . "\n23\nFetchTextTestPage2Text2", + self::$textId3 . "\n23\nFetchTextTestPage2Text2" + ] ) ); } function testEmpty() { @@ -224,7 +225,7 @@ class FetchTextTest extends MediaWikiTestCase { } function testNonExisting() { - $this->assertFilter( $this->textId5 + 10, ( $this->textId5 + 10 ) . "\n-1\n" ); + $this->assertFilter( self::$textId5 + 10, ( self::$textId5 + 10 ) . "\n-1\n" ); } function testNegativeInteger() { @@ -233,13 +234,13 @@ class FetchTextTest extends MediaWikiTestCase { function testFloatingPointNumberExisting() { // float -> int -> revision - $this->assertFilter( $this->textId3 + 0.14159, - $this->textId3 . "\n23\nFetchTextTestPage2Text2" ); + $this->assertFilter( self::$textId3 + 0.14159, + self::$textId3 . "\n23\nFetchTextTestPage2Text2" ); } function testFloatingPointNumberNonExisting() { - $this->assertFilter( $this->textId5 + 3.14159, - ( $this->textId5 + 3 ) . "\n-1\n" ); + $this->assertFilter( self::$textId5 + 3.14159, + ( self::$textId5 + 3 ) . "\n-1\n" ); } function testCharacters() { @@ -247,15 +248,15 @@ class FetchTextTest extends MediaWikiTestCase { } function testMix() { - $this->assertFilter( "ab\n" . $this->textId4 . ".5cd\n\nefg\n" . $this->textId2 - . "\n" . $this->textId3, - implode( "", array( + $this->assertFilter( "ab\n" . self::$textId4 . ".5cd\n\nefg\n" . self::$textId2 + . "\n" . self::$textId3, + implode( "", [ "0\n-1\n", - $this->textId4 . "\n23\nFetchTextTestPage2Text3", + self::$textId4 . "\n23\nFetchTextTestPage2Text3", "0\n-1\n", "0\n-1\n", - $this->textId2 . "\n23\nFetchTextTestPage2Text1", - $this->textId3 . "\n23\nFetchTextTestPage2Text2" - ) ) ); + self::$textId2 . "\n23\nFetchTextTestPage2Text1", + self::$textId3 . "\n23\nFetchTextTestPage2Text2" + ] ) ); } }