From: addshore Date: Tue, 10 Oct 2017 16:38:31 +0000 (+0100) Subject: RevisionTest: refactor test dataProviders X-Git-Tag: 1.31.0-rc.0~1805^2~4 X-Git-Url: http://git.cyclocoop.org/%22.%20generer_url_ecrire%28%22sites_tous%22%2C%22%22%29.%20%22?a=commitdiff_plain;h=5fabead899905f78358e75104c568ccc8aed695a;p=lhc%2Fweb%2Fwiklou.git RevisionTest: refactor test dataProviders Change-Id: I238d0294de7112a78ef18ffba195c0c175d6d735 --- diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index ba19f3b2ae..80a690fbe3 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -57,86 +57,128 @@ class RevisionTest extends MediaWikiTestCase { parent::tearDown(); } - /** - * @covers Revision::getRevisionText - */ - public function testGetRevisionText() { - $row = new stdClass; - $row->old_flags = ''; - $row->old_text = 'This is a bunch of revision text.'; - $this->assertEquals( - 'This is a bunch of revision text.', - Revision::getRevisionText( $row ) ); + public function provideConstruct() { + yield 'with text' => [ + [ + 'text' => 'hello world.', + 'content_model' => CONTENT_MODEL_JAVASCRIPT + ], + ]; + yield 'with content' => [ + [ + 'content' => ContentHandler::makeContent( + 'hello world.', + Title::newFromText( 'RevisionTest_testConstructWithContent' ), + CONTENT_MODEL_JAVASCRIPT + ), + ], + ]; } /** - * @covers Revision::getRevisionText + * @dataProvider provideConstruct */ - public function testGetRevisionTextGzip() { - $this->checkPHPExtension( 'zlib' ); + public function testConstruct( $rowArray ) { + $rev = new Revision( $rowArray ); + $this->assertNotNull( $rev->getContent(), 'no content object available' ); + $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() ); + $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() ); + } - $row = new stdClass; - $row->old_flags = 'gzip'; - $row->old_text = gzdeflate( 'This is a bunch of revision text.' ); - $this->assertEquals( - 'This is a bunch of revision text.', - Revision::getRevisionText( $row ) ); + public function provideGetRevisionText() { + yield 'Generic test' => [ + 'This is a goat of revision text.', + [ + 'old_flags' => '', + 'old_text' => 'This is a goat of revision text.', + ], + ]; } /** * @covers Revision::getRevisionText + * @dataProvider provideGetRevisionText */ - public function testGetRevisionTextUtf8Native() { - $row = new stdClass; - $row->old_flags = 'utf-8'; - $row->old_text = "Wiki est l'\xc3\xa9cole superieur !"; - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; + public function testGetRevisionText( $expected, $rowData, $prefix = 'old_', $wiki = false ) { $this->assertEquals( - "Wiki est l'\xc3\xa9cole superieur !", - Revision::getRevisionText( $row ) ); + $expected, + Revision::getRevisionText( (object)$rowData, $prefix, $wiki ) ); + } + + public function provideGetRevisionTextWithZlibExtension() { + yield 'Generic gzip test' => [ + 'This is a small goat of revision text.', + [ + 'old_flags' => 'gzip', + 'old_text' => gzdeflate( 'This is a small goat of revision text.' ), + ], + ]; } /** * @covers Revision::getRevisionText + * @dataProvider provideGetRevisionTextWithZlibExtension */ - public function testGetRevisionTextUtf8Legacy() { - $row = new stdClass; - $row->old_flags = ''; - $row->old_text = "Wiki est l'\xe9cole superieur !"; - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; - $this->assertEquals( + public function testGetRevisionWithZlibExtension( $expected, $rowData ) { + $this->checkPHPExtension( 'zlib' ); + $this->testGetRevisionText( $expected, $rowData ); + } + + public function provideGetRevisionTextWithLegacyEncoding() { + yield 'Utf8Native' => [ + "Wiki est l'\xc3\xa9cole superieur !", + 'iso-8859-1', + [ + 'old_flags' => 'utf-8', + 'old_text' => "Wiki est l'\xc3\xa9cole superieur !", + ] + ]; + yield 'Utf8Legacy' => [ "Wiki est l'\xc3\xa9cole superieur !", - Revision::getRevisionText( $row ) ); + 'iso-8859-1', + [ + 'old_flags' => '', + 'old_text' => "Wiki est l'\xe9cole superieur !", + ] + ]; } /** * @covers Revision::getRevisionText + * @dataProvider provideGetRevisionTextWithLegacyEncoding */ - public function testGetRevisionTextUtf8NativeGzip() { - $this->checkPHPExtension( 'zlib' ); + public function testGetRevisionWithLegacyEncoding( $expected, $encoding, $rowData ) { + $GLOBALS['wgLegacyEncoding'] = $encoding; + $this->testGetRevisionText( $expected, $rowData ); + } - $row = new stdClass; - $row->old_flags = 'gzip,utf-8'; - $row->old_text = gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ); - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; - $this->assertEquals( + public function provideGetRevisionTextWithGzipAndLegacyEncoding() { + yield 'Utf8NativeGzip' => [ "Wiki est l'\xc3\xa9cole superieur !", - Revision::getRevisionText( $row ) ); + 'iso-8859-1', + [ + 'old_flags' => 'gzip,utf-8', + 'old_text' => gzdeflate( "Wiki est l'\xc3\xa9cole superieur !" ), + ] + ]; + yield 'Utf8LegacyGzip' => [ + "Wiki est l'\xc3\xa9cole superieur !", + 'iso-8859-1', + [ + 'old_flags' => 'gzip', + 'old_text' => gzdeflate( "Wiki est l'\xe9cole superieur !" ), + ] + ]; } /** * @covers Revision::getRevisionText + * @dataProvider provideGetRevisionTextWithGzipAndLegacyEncoding */ - public function testGetRevisionTextUtf8LegacyGzip() { + public function testGetRevisionWithGzipAndLegacyEncoding( $expected, $encoding, $rowData ) { $this->checkPHPExtension( 'zlib' ); - - $row = new stdClass; - $row->old_flags = 'gzip'; - $row->old_text = gzdeflate( "Wiki est l'\xe9cole superieur !" ); - $GLOBALS['wgLegacyEncoding'] = 'iso-8859-1'; - $this->assertEquals( - "Wiki est l'\xc3\xa9cole superieur !", - Revision::getRevisionText( $row ) ); + $GLOBALS['wgLegacyEncoding'] = $encoding; + $this->testGetRevisionText( $expected, $rowData ); } /** @@ -176,8 +218,6 @@ class RevisionTest extends MediaWikiTestCase { Revision::getRevisionText( $row ), "getRevisionText" ); } - # ========================================================================= - /** * @param string $text * @param string $title @@ -213,7 +253,7 @@ class RevisionTest extends MediaWikiTestCase { return $rev; } - public function dataGetContentModel() { + public function provideGetContentModel() { // NOTE: we expect the help namespace to always contain wikitext return [ [ 'hello world', 'Help:Hello', null, null, CONTENT_MODEL_WIKITEXT ], @@ -224,7 +264,7 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database - * @dataProvider dataGetContentModel + * @dataProvider provideGetContentModel * @covers Revision::getContentModel */ public function testGetContentModel( $text, $title, $model, $format, $expectedModel ) { @@ -233,7 +273,7 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( $expectedModel, $rev->getContentModel() ); } - public function dataGetContentFormat() { + public function provideGetContentFormat() { // NOTE: we expect the help namespace to always contain wikitext return [ [ 'hello world', 'Help:Hello', null, null, CONTENT_FORMAT_WIKITEXT ], @@ -245,7 +285,7 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database - * @dataProvider dataGetContentFormat + * @dataProvider provideGetContentFormat * @covers Revision::getContentFormat */ public function testGetContentFormat( $text, $title, $model, $format, $expectedFormat ) { @@ -254,7 +294,7 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( $expectedFormat, $rev->getContentFormat() ); } - public function dataGetContentHandler() { + public function provideGetContentHandler() { // NOTE: we expect the help namespace to always contain wikitext return [ [ 'hello world', 'Help:Hello', null, null, 'WikitextContentHandler' ], @@ -265,7 +305,7 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database - * @dataProvider dataGetContentHandler + * @dataProvider provideGetContentHandler * @covers Revision::getContentHandler */ public function testGetContentHandler( $text, $title, $model, $format, $expectedClass ) { @@ -274,7 +314,7 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( $expectedClass, get_class( $rev->getContentHandler() ) ); } - public function dataGetContent() { + public function provideGetContent() { // NOTE: we expect the help namespace to always contain wikitext return [ [ 'hello world', 'Help:Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ], @@ -299,7 +339,7 @@ class RevisionTest extends MediaWikiTestCase { /** * @group Database - * @dataProvider dataGetContent + * @dataProvider provideGetContent * @covers Revision::getContent */ public function testGetContent( $text, $title, $model, $format, @@ -314,7 +354,7 @@ class RevisionTest extends MediaWikiTestCase { ); } - public function dataGetSize() { + public function provideGetSize() { return [ [ "hello world.", CONTENT_MODEL_WIKITEXT, 12 ], [ serialize( "hello world." ), "testing", 12 ], @@ -324,14 +364,14 @@ class RevisionTest extends MediaWikiTestCase { /** * @covers Revision::getSize * @group Database - * @dataProvider dataGetSize + * @dataProvider provideGetSize */ public function testGetSize( $text, $model, $expected_size ) { $rev = $this->newTestRevision( $text, 'RevisionTest_testGetSize', $model ); $this->assertEquals( $expected_size, $rev->getSize() ); } - public function dataGetSha1() { + public function provideGetSha1() { return [ [ "hello world.", CONTENT_MODEL_WIKITEXT, Revision::base36Sha1( "hello world." ) ], [ @@ -345,42 +385,13 @@ class RevisionTest extends MediaWikiTestCase { /** * @covers Revision::getSha1 * @group Database - * @dataProvider dataGetSha1 + * @dataProvider provideGetSha1 */ public function testGetSha1( $text, $model, $expected_hash ) { $rev = $this->newTestRevision( $text, 'RevisionTest_testGetSha1', $model ); $this->assertEquals( $expected_hash, $rev->getSha1() ); } - /** - * @covers Revision::__construct - */ - public function testConstructWithText() { - $rev = new Revision( [ - 'text' => 'hello world.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT - ] ); - - $this->assertNotNull( $rev->getContent(), 'no content object available' ); - $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() ); - $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() ); - } - - /** - * @covers Revision::__construct - */ - public function testConstructWithContent() { - $title = Title::newFromText( 'RevisionTest_testConstructWithContent' ); - - $rev = new Revision( [ - 'content' => ContentHandler::makeContent( 'hello world.', $title, CONTENT_MODEL_JAVASCRIPT ), - ] ); - - $this->assertNotNull( $rev->getContent(), 'no content object available' ); - $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContent()->getModel() ); - $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() ); - } - /** * Tests whether $rev->getContent() returns a clone when needed. *