From 7a246669356e0a2c45fce3018dc4501bef474e8c Mon Sep 17 00:00:00 2001 From: Siebrand Mazeland Date: Thu, 14 Feb 2013 12:36:35 +0100 Subject: [PATCH] Update formatting 2 of n. Change-Id: I5406673e99ed53e4e330ed47f022a17177544daa --- tests/phpunit/includes/RecentChangeTest.php | 37 ++- tests/phpunit/includes/ResourceLoaderTest.php | 2 +- .../phpunit/includes/RevisionStorageTest.php | 106 ++++---- ...evisionStorageTest_ContentHandlerUseDB.php | 18 +- tests/phpunit/includes/RevisionTest.php | 58 ++--- tests/phpunit/includes/SampleTest.php | 18 +- tests/phpunit/includes/SanitizerTest.php | 32 +-- .../includes/SanitizerValidateEmailTest.php | 21 +- .../includes/SeleniumConfigurationTest.php | 99 ++++--- tests/phpunit/includes/StringUtilsTest.php | 14 +- tests/phpunit/includes/TimeAdjustTest.php | 12 +- tests/phpunit/includes/TimestampTest.php | 1 + .../phpunit/includes/TitlePermissionTest.php | 246 +++++++++--------- tests/phpunit/includes/TitleTest.php | 90 +++---- tests/phpunit/includes/UserTest.php | 18 +- tests/phpunit/includes/WebRequestTest.php | 4 +- 16 files changed, 398 insertions(+), 378 deletions(-) diff --git a/tests/phpunit/includes/RecentChangeTest.php b/tests/phpunit/includes/RecentChangeTest.php index 5b99628e4d..a1e623630e 100644 --- a/tests/phpunit/includes/RecentChangeTest.php +++ b/tests/phpunit/includes/RecentChangeTest.php @@ -12,9 +12,9 @@ class RecentChangeTest extends MediaWikiTestCase { function __construct() { parent::__construct(); - $this->title = Title::newFromText( 'SomeTitle' ); + $this->title = Title::newFromText( 'SomeTitle' ); $this->target = Title::newFromText( 'TestTarget' ); - $this->user = User::newFromName( 'UserName' ); + $this->user = User::newFromName( 'UserName' ); $this->user_comment = ''; $this->context = RequestContext::newExtraneousContext( $this->title ); @@ -61,14 +61,14 @@ class RecentChangeTest extends MediaWikiTestCase { # block/block $this->assertIRCComment( - $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'blocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'block', 'block', array(), $this->user_comment ); # block/unblock $this->assertIRCComment( - $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'unblocklogentry', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'block', 'unblock', array(), $this->user_comment @@ -83,7 +83,7 @@ class RecentChangeTest extends MediaWikiTestCase { # delete/delete $this->assertIRCComment( - $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'deletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'delete', 'delete', array(), $this->user_comment @@ -91,7 +91,7 @@ class RecentChangeTest extends MediaWikiTestCase { # delete/restore $this->assertIRCComment( - $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'undeletedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'delete', 'restore', array(), $this->user_comment @@ -129,14 +129,14 @@ class RecentChangeTest extends MediaWikiTestCase { */ function testIrcMsgForLogTypeMove() { $move_params = array( - '4::target' => $this->target->getPrefixedText(), + '4::target' => $this->target->getPrefixedText(), '5::noredir' => 0, ); $sep = $this->context->msg( 'colon-separator' )->text(); # move/move $this->assertIRCComment( - $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment, + $this->context->msg( '1movedto2', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment, 'move', 'move', $move_params, $this->user_comment @@ -144,7 +144,7 @@ class RecentChangeTest extends MediaWikiTestCase { # move/move_redir $this->assertIRCComment( - $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment, + $this->context->msg( '1movedto2_redir', 'SomeTitle', 'TestTarget' )->plain() . $sep . $this->user_comment, 'move', 'move_redir', $move_params, $this->user_comment @@ -160,9 +160,9 @@ class RecentChangeTest extends MediaWikiTestCase { $this->context->msg( 'patrol-log-line', 'revision 777', '[[SomeTitle]]', '' )->plain(), 'patrol', 'patrol', array( - '4::curid' => '777', + '4::curid' => '777', '5::previd' => '666', - '6::auto' => 0, + '6::auto' => 0, ) ); } @@ -178,7 +178,7 @@ class RecentChangeTest extends MediaWikiTestCase { # protect/protect $this->assertIRCComment( - $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment, + $this->context->msg( 'protectedarticle', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment, 'protect', 'protect', $protectParams, $this->user_comment @@ -186,7 +186,7 @@ class RecentChangeTest extends MediaWikiTestCase { # protect/unprotect $this->assertIRCComment( - $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'unprotectedarticle', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'protect', 'unprotect', array(), $this->user_comment @@ -194,7 +194,7 @@ class RecentChangeTest extends MediaWikiTestCase { # protect/modify $this->assertIRCComment( - $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment, + $this->context->msg( 'modifiedarticleprotection', 'SomeTitle ' . $protectParams[0] )->plain() . $sep . $this->user_comment, 'protect', 'modify', $protectParams, $this->user_comment @@ -209,7 +209,7 @@ class RecentChangeTest extends MediaWikiTestCase { # upload/upload $this->assertIRCComment( - $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'uploadedimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'upload', 'upload', array(), $this->user_comment @@ -217,7 +217,7 @@ class RecentChangeTest extends MediaWikiTestCase { # upload/overwrite $this->assertIRCComment( - $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, + $this->context->msg( 'overwroteimage', 'SomeTitle' )->plain() . $sep . $this->user_comment, 'upload', 'overwrite', array(), $this->user_comment @@ -229,7 +229,7 @@ class RecentChangeTest extends MediaWikiTestCase { * raw edit summary from RecentChange object * -- */ -/* + /* function testIrcMsgForBlankingAES() { // $this->context->msg( 'autosumm-blank', .. ); } @@ -245,8 +245,7 @@ class RecentChangeTest extends MediaWikiTestCase { function testIrcMsgForUndoAES() { // $this->context->msg( 'undo-summary', .. ); } - -*/ + */ /** * @param $expected String Expected IRC text without colors codes diff --git a/tests/phpunit/includes/ResourceLoaderTest.php b/tests/phpunit/includes/ResourceLoaderTest.php index 893d2600a7..60618b1010 100644 --- a/tests/phpunit/includes/ResourceLoaderTest.php +++ b/tests/phpunit/includes/ResourceLoaderTest.php @@ -84,7 +84,7 @@ class ResourceLoaderTest extends MediaWikiTestCase { /* Stubs */ -class ResourceLoaderTestModule extends ResourceLoaderModule { } +class ResourceLoaderTestModule extends ResourceLoaderModule {} /* Hooks */ global $wgHooks; diff --git a/tests/phpunit/includes/RevisionStorageTest.php b/tests/phpunit/includes/RevisionStorageTest.php index 1301bf375f..e8d8db0a33 100644 --- a/tests/phpunit/includes/RevisionStorageTest.php +++ b/tests/phpunit/includes/RevisionStorageTest.php @@ -21,21 +21,21 @@ class RevisionStorageTest extends MediaWikiTestCase { parent::__construct( $name, $data, $dataName ); $this->tablesUsed = array_merge( $this->tablesUsed, - array( 'page', - 'revision', - 'text', - - 'recentchanges', - 'logging', - - 'page_props', - 'pagelinks', - 'categorylinks', - 'langlinks', - 'externallinks', - 'imagelinks', - 'templatelinks', - 'iwlinks' ) ); + array( 'page', + 'revision', + 'text', + + 'recentchanges', + 'logging', + + 'page_props', + 'pagelinks', + 'categorylinks', + 'langlinks', + 'externallinks', + 'imagelinks', + 'templatelinks', + 'iwlinks' ) ); } public function setUp() { @@ -43,11 +43,11 @@ class RevisionStorageTest extends MediaWikiTestCase { parent::setUp(); - $wgExtraNamespaces[ 12312 ] = 'Dummy'; - $wgExtraNamespaces[ 12313 ] = 'Dummy_talk'; + $wgExtraNamespaces[12312] = 'Dummy'; + $wgExtraNamespaces[12313] = 'Dummy_talk'; - $wgNamespaceContentModels[ 12312 ] = 'DUMMY'; - $wgContentHandlers[ 'DUMMY' ] = 'DummyContentHandlerForTesting'; + $wgNamespaceContentModels[12312] = 'DUMMY'; + $wgContentHandlers['DUMMY'] = 'DummyContentHandlerForTesting'; MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache @@ -61,22 +61,32 @@ class RevisionStorageTest extends MediaWikiTestCase { parent::tearDown(); - unset( $wgExtraNamespaces[ 12312 ] ); - unset( $wgExtraNamespaces[ 12313 ] ); + unset( $wgExtraNamespaces[12312] ); + unset( $wgExtraNamespaces[12313] ); - unset( $wgNamespaceContentModels[ 12312 ] ); - unset( $wgContentHandlers[ 'DUMMY' ] ); + unset( $wgNamespaceContentModels[12312] ); + unset( $wgContentHandlers['DUMMY'] ); MWNamespace::getCanonicalNamespaces( true ); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache } protected function makeRevision( $props = null ) { - if ( $props === null ) $props = array(); + if ( $props === null ) { + $props = array(); + } - if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) $props['text'] = 'Lorem Ipsum'; - if ( !isset( $props['comment'] ) ) $props['comment'] = 'just a test'; - if ( !isset( $props['page'] ) ) $props['page'] = $this->the_page->getId(); + if ( !isset( $props['content'] ) && !isset( $props['text'] ) ) { + $props['text'] = 'Lorem Ipsum'; + } + + if ( !isset( $props['comment'] ) ) { + $props['comment'] = 'just a test'; + } + + if ( !isset( $props['page'] ) ) { + $props['page'] = $this->the_page->getId(); + } $rev = new Revision( $props ); @@ -89,8 +99,8 @@ class RevisionStorageTest extends MediaWikiTestCase { protected function createPage( $page, $text, $model = null ) { if ( is_string( $page ) ) { if ( !preg_match( '/:/', $page ) && - ( $model === null || $model === CONTENT_MODEL_WIKITEXT ) ) { - + ( $model === null || $model === CONTENT_MODEL_WIKITEXT ) + ) { $ns = $this->getDefaultWikitextNS(); $page = MWNamespace::getCanonicalName( $ns ) . ':' . $page; } @@ -207,11 +217,11 @@ class RevisionStorageTest extends MediaWikiTestCase { #note: order is unspecified $rows = array(); while ( ( $row = $res->fetchObject() ) ) { - $rows[ $row->rev_id ]= $row; + $rows[$row->rev_id] = $row; } $row = $res->fetchObject(); - $this->assertEquals( 1, count($rows), 'expected exactly one revision' ); + $this->assertEquals( 1, count( $rows ), 'expected exactly one revision' ); $this->assertArrayHasKey( $id2, $rows, 'missing revision with id ' . $id2 ); } @@ -223,16 +233,16 @@ class RevisionStorageTest extends MediaWikiTestCase { $fields = Revision::selectFields(); - $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields'); - $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields'); - $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields'); - $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields'); + $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' ); + $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' ); + $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields' ); + $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' ); if ( $wgContentHandlerUseDB ) { $this->assertTrue( in_array( 'rev_content_model', $fields ), - 'missing rev_content_model in list of fields'); + 'missing rev_content_model in list of fields' ); $this->assertTrue( in_array( 'rev_content_format', $fields ), - 'missing rev_content_format in list of fields'); + 'missing rev_content_format in list of fields' ); } } @@ -265,7 +275,7 @@ class RevisionStorageTest extends MediaWikiTestCase { */ public function testGetContent_failure() { $rev = new Revision( array( - 'page' => $this->the_page->getId(), + 'page' => $this->the_page->getId(), 'content_model' => $this->the_page->getContentModel(), 'text_id' => 123456789, // not in the test DB ) ); @@ -322,7 +332,7 @@ class RevisionStorageTest extends MediaWikiTestCase { } $orig = $this->makeRevision( array( 'text' => 'hello hello.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT ) ); + 'content_model' => CONTENT_MODEL_JAVASCRIPT ) ); $rev = Revision::newFromId( $orig->getId() ); $this->assertEquals( CONTENT_MODEL_JAVASCRIPT, $rev->getContentModel() ); @@ -338,9 +348,11 @@ class RevisionStorageTest extends MediaWikiTestCase { $this->markTestSkipped( '$wgContentHandlerUseDB is disabled' ); } - $orig = $this->makeRevision( array( 'text' => 'hello hello.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT, - 'content_format' => CONTENT_FORMAT_JAVASCRIPT ) ); + $orig = $this->makeRevision( array( + 'text' => 'hello hello.', + 'content_model' => CONTENT_MODEL_JAVASCRIPT, + 'content_format' => CONTENT_FORMAT_JAVASCRIPT + ) ); $rev = Revision::newFromId( $orig->getId() ); $this->assertEquals( CONTENT_FORMAT_JAVASCRIPT, $rev->getContentFormat() ); @@ -382,7 +394,7 @@ class RevisionStorageTest extends MediaWikiTestCase { $this->assertNull( $rev1->getPrevious() ); $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ), - 'second rev testGetPrevious' ); + 'second rev testGetPrevious' ); $rev2 = $page->getRevision(); $this->assertNotNull( $rev2->getPrevious() ); @@ -399,7 +411,7 @@ class RevisionStorageTest extends MediaWikiTestCase { $this->assertNull( $rev1->getNext() ); $page->doEditContent( ContentHandler::makeContent( 'Bla bla', $page->getTitle(), CONTENT_MODEL_WIKITEXT ), - 'second rev testGetNext' ); + 'second rev testGetNext' ); $rev2 = $page->getRevision(); $this->assertNotNull( $rev1->getNext() ); @@ -417,9 +429,9 @@ class RevisionStorageTest extends MediaWikiTestCase { $rev = Revision::newNullRevision( $dbw, $page->getId(), 'a null revision', false ); $this->assertNotEquals( $orig->getId(), $rev->getId(), - 'new null revision shold have a different id from the original revision' ); + 'new null revision shold have a different id from the original revision' ); $this->assertEquals( $orig->getTextId(), $rev->getTextId(), - 'new null revision shold have the same text id as the original revision' ); + 'new null revision shold have the same text id as the original revision' ); $this->assertEquals( 'some testing text', $rev->getContent()->getNativeData() ); } @@ -525,7 +537,7 @@ class RevisionStorageTest extends MediaWikiTestCase { $revisions[4]->insertOn( $dbw ); // test it --------------------------------- - $since = $revisions[ $sinceIdx ]->getTimestamp(); + $since = $revisions[$sinceIdx]->getTimestamp(); $wasLast = Revision::userWasLastToEdit( $dbw, $page->getId(), $userA->getId(), $since ); diff --git a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php index d0cdfc6908..3948e34595 100644 --- a/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php +++ b/tests/phpunit/includes/RevisionStorageTest_ContentHandlerUseDB.php @@ -46,13 +46,13 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest { public function testSelectFields() { $fields = Revision::selectFields(); - $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields'); - $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields'); - $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields'); - $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields'); + $this->assertTrue( in_array( 'rev_id', $fields ), 'missing rev_id in list of fields' ); + $this->assertTrue( in_array( 'rev_page', $fields ), 'missing rev_page in list of fields' ); + $this->assertTrue( in_array( 'rev_timestamp', $fields ), 'missing rev_timestamp in list of fields' ); + $this->assertTrue( in_array( 'rev_user', $fields ), 'missing rev_user in list of fields' ); - $this->assertFalse( in_array( 'rev_content_model', $fields ), 'missing rev_content_model in list of fields'); - $this->assertFalse( in_array( 'rev_content_format', $fields ), 'missing rev_content_format in list of fields'); + $this->assertFalse( in_array( 'rev_content_model', $fields ), 'missing rev_content_model in list of fields' ); + $this->assertFalse( in_array( 'rev_content_format', $fields ), 'missing rev_content_format in list of fields' ); } /** @@ -61,7 +61,7 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest { public function testGetContentModel() { try { $this->makeRevision( array( 'text' => 'hello hello.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT ) ); + 'content_model' => CONTENT_MODEL_JAVASCRIPT ) ); $this->fail( "Creating JavaScript content on a wikitext page should fail with " . "\$wgContentHandlerUseDB disabled" ); @@ -82,8 +82,8 @@ class RevisionTest_ContentHandlerUseDB extends RevisionStorageTest { // used for this though. $this->makeRevision( array( 'text' => 'hello hello.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT, - 'content_format' => 'text/javascript' ) ); + 'content_model' => CONTENT_MODEL_JAVASCRIPT, + 'content_format' => 'text/javascript' ) ); $this->fail( "Creating JavaScript content on a wikitext page should fail with " . "\$wgContentHandlerUseDB disabled" ); diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index 197bb061f0..db0245b959 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -168,13 +168,13 @@ class RevisionTest extends MediaWikiTestCase { $rev = new Revision( array( - 'id' => 42, - 'page' => 23, - 'title' => $title, + 'id' => 42, + 'page' => 23, + 'title' => $title, - 'content' => $content, - 'length' => $content->getSize(), - 'comment' => "testing", + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", 'minor_edit' => false, 'content_format' => $format, @@ -189,7 +189,7 @@ class RevisionTest extends MediaWikiTestCase { return array( array( 'hello world', 'Help:Hello', null, null, CONTENT_MODEL_WIKITEXT ), array( 'hello world', 'User:hello/there.css', null, null, CONTENT_MODEL_CSS ), - array( serialize('hello world'), 'Dummy:Hello', null, null, "testing" ), + array( serialize( 'hello world' ), 'Dummy:Hello', null, null, "testing" ), ); } @@ -209,7 +209,7 @@ class RevisionTest extends MediaWikiTestCase { array( 'hello world', 'Help:Hello', null, null, CONTENT_FORMAT_WIKITEXT ), array( 'hello world', 'Help:Hello', CONTENT_MODEL_CSS, null, CONTENT_FORMAT_CSS ), array( 'hello world', 'User:hello/there.css', null, null, CONTENT_FORMAT_CSS ), - array( serialize('hello world'), 'Dummy:Hello', null, null, "testing" ), + array( serialize( 'hello world' ), 'Dummy:Hello', null, null, "testing" ), ); } @@ -228,7 +228,7 @@ class RevisionTest extends MediaWikiTestCase { return array( array( 'hello world', 'Help:Hello', null, null, 'WikitextContentHandler' ), array( 'hello world', 'User:hello/there.css', null, null, 'CssContentHandler' ), - array( serialize('hello world'), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ), + array( serialize( 'hello world' ), 'Dummy:Hello', null, null, 'DummyContentHandlerForTesting' ), ); } @@ -246,8 +246,8 @@ class RevisionTest extends MediaWikiTestCase { //NOTE: we expect the help namespace to always contain wikitext return array( array( 'hello world', 'Help:Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ), - array( serialize('hello world'), 'Hello', "testing", null, Revision::FOR_PUBLIC, serialize('hello world') ), - array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, serialize('hello world') ), + array( serialize( 'hello world' ), 'Hello', "testing", null, Revision::FOR_PUBLIC, serialize( 'hello world' ) ), + array( serialize( 'hello world' ), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, serialize( 'hello world' ) ), ); } @@ -266,8 +266,8 @@ class RevisionTest extends MediaWikiTestCase { //NOTE: we expect the help namespace to always contain wikitext return array( array( 'hello world', 'Help:Hello', null, null, Revision::FOR_PUBLIC, 'hello world' ), - array( serialize('hello world'), 'Hello', "testing", null, Revision::FOR_PUBLIC, null ), - array( serialize('hello world'), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, null ), + array( serialize( 'hello world' ), 'Hello', "testing", null, Revision::FOR_PUBLIC, null ), + array( serialize( 'hello world' ), 'Dummy:Hello', null, null, Revision::FOR_PUBLIC, null ), ); } @@ -296,7 +296,7 @@ class RevisionTest extends MediaWikiTestCase { } - public function dataGetSize( ) { + public function dataGetSize() { return array( array( "hello world.", CONTENT_MODEL_WIKITEXT, 12 ), array( serialize( "hello world." ), "testing", 12 ), @@ -313,7 +313,7 @@ class RevisionTest extends MediaWikiTestCase { $this->assertEquals( $expected_size, $rev->getSize() ); } - public function dataGetSha1( ) { + public function dataGetSha1() { return array( array( "hello world.", CONTENT_MODEL_WIKITEXT, Revision::base36Sha1( "hello world." ) ), array( serialize( "hello world." ), "testing", Revision::base36Sha1( serialize( "hello world." ) ) ), @@ -334,9 +334,9 @@ class RevisionTest extends MediaWikiTestCase { $this->hideDeprecated( "Revision::getText" ); $rev = new Revision( array( - 'text' => 'hello world.', - 'content_model' => CONTENT_MODEL_JAVASCRIPT - )); + 'text' => 'hello world.', + 'content_model' => CONTENT_MODEL_JAVASCRIPT + ) ); $this->assertNotNull( $rev->getText(), 'no content text' ); $this->assertNotNull( $rev->getContent(), 'no content object available' ); @@ -350,8 +350,8 @@ class RevisionTest extends MediaWikiTestCase { $title = Title::newFromText( 'RevisionTest_testConstructWithContent' ); $rev = new Revision( array( - 'content' => ContentHandler::makeContent( 'hello world.', $title, CONTENT_MODEL_JAVASCRIPT ), - )); + 'content' => ContentHandler::makeContent( 'hello world.', $title, CONTENT_MODEL_JAVASCRIPT ), + ) ); $this->assertNotNull( $rev->getText(), 'no content text' ); $this->assertNotNull( $rev->getContent(), 'no content object available' ); @@ -364,18 +364,18 @@ class RevisionTest extends MediaWikiTestCase { * * @group Database */ - function testGetContentClone( ) { + function testGetContentClone() { $content = new RevisionTestModifyableContent( "foo" ); $rev = new Revision( array( - 'id' => 42, - 'page' => 23, - 'title' => Title::newFromText( "testGetContentClone_dummy" ), + 'id' => 42, + 'page' => 23, + 'title' => Title::newFromText( "testGetContentClone_dummy" ), - 'content' => $content, - 'length' => $content->getSize(), - 'comment' => "testing", + 'content' => $content, + 'length' => $content->getSize(), + 'comment' => "testing", 'minor_edit' => false, ) ); @@ -413,7 +413,7 @@ class RevisionTestModifyableContent extends TextContent { parent::__construct( $text, "RevisionTestModifyableContent" ); } - public function copy( ) { + public function copy() { return new RevisionTestModifyableContent( $this->mText ); } @@ -429,7 +429,7 @@ class RevisionTestModifyableContent extends TextContent { class RevisionTestModifyableContentHandler extends TextContentHandler { - public function __construct( ) { + public function __construct() { parent::__construct( "RevisionTestModifyableContent", array( CONTENT_FORMAT_TEXT ) ); } diff --git a/tests/phpunit/includes/SampleTest.php b/tests/phpunit/includes/SampleTest.php index 1439e44580..8a881915ad 100644 --- a/tests/phpunit/includes/SampleTest.php +++ b/tests/phpunit/includes/SampleTest.php @@ -34,12 +34,12 @@ class TestSample extends MediaWikiLangTestCase { * http://www.phpunit.de/manual/3.4/en/other-uses-for-tests.html */ function testTitleObjectStringConversion() { - $title = Title::newFromText("text"); - $this->assertInstanceOf('Title', $title, "Title creation"); - $this->assertEquals("Text", $title, "Automatic string conversion"); + $title = Title::newFromText( "text" ); + $this->assertInstanceOf( 'Title', $title, "Title creation" ); + $this->assertEquals( "Text", $title, "Automatic string conversion" ); - $title = Title::newFromText("text", NS_MEDIA); - $this->assertEquals("Media:Text", $title, "Title creation with namespace"); + $title = Title::newFromText( "text", NS_MEDIA ); + $this->assertEquals( "Media:Text", $title, "Title creation with namespace" ); } /** @@ -62,14 +62,14 @@ class TestSample extends MediaWikiLangTestCase { * @dataProvider provideTitles * See http://www.phpunit.de/manual/3.4/en/appendixes.annotations.html#appendixes.annotations.dataProvider */ - public function testCreateBasicListOfTitles($titleName, $ns, $text) { - $title = Title::newFromText($titleName, $ns); - $this->assertEquals($text, "$title", "see if '$titleName' matches '$text'"); + public function testCreateBasicListOfTitles( $titleName, $ns, $text ) { + $title = Title::newFromText( $titleName, $ns ); + $this->assertEquals( $text, "$title", "see if '$titleName' matches '$text'" ); } public function testSetUpMainPageTitleForNextTest() { $title = Title::newMainPage(); - $this->assertEquals("Main Page", "$title", "Test initial creation of a title"); + $this->assertEquals( "Main Page", "$title", "Test initial creation of a title" ); return $title; } diff --git a/tests/phpunit/includes/SanitizerTest.php b/tests/phpunit/includes/SanitizerTest.php index 2d039d9f41..92abb9e45e 100644 --- a/tests/phpunit/includes/SanitizerTest.php +++ b/tests/phpunit/includes/SanitizerTest.php @@ -74,9 +74,9 @@ class SanitizerTest extends MediaWikiTestCase { # Enable HTML5 mode 'wgHtml5' => true, 'wgUseTidy' => false - )); + ) ); - if( $escaped ) { + if ( $escaped ) { $this->assertEquals( "<$tag>", Sanitizer::removeHTMLtags( "<$tag>" ) ); @@ -91,8 +91,8 @@ class SanitizerTest extends MediaWikiTestCase { * Provide HTML5 tags */ function provideHtml5Tags() { - $ESCAPED = true; # We want tag to be escaped - $VERBATIM = false; # We want to keep the tag + $ESCAPED = true; # We want tag to be escaped + $VERBATIM = false; # We want to keep the tag return array( array( 'data', $VERBATIM ), array( 'mark', $VERBATIM ), @@ -104,7 +104,7 @@ class SanitizerTest extends MediaWikiTestCase { function testSelfClosingTag() { $this->setMwGlobals( array( 'wgUseTidy' => false - )); + ) ); $this->assertEquals( '
Hello world
', @@ -211,18 +211,18 @@ class SanitizerTest extends MediaWikiTestCase { array( ' ', "\\2f\\2a foo \\2a\\2f", 'Backslash-escaped comments must be stripped (bug 28450)' ), array( '', '/* unfinished comment structure', - 'Remove anything after a comment-start token' ), + 'Remove anything after a comment-start token' ), array( '', "\\2f\\2a unifinished comment'", - 'Remove anything after a backslash-escaped comment-start token' ), - array( '/* insecure input */', 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\');'), - array( '/* insecure input */', '-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\')";'), - array( '/* insecure input */', 'width: expression(1+1);'), - array( '/* insecure input */', 'background-image: image(asdf.png);'), - array( '/* insecure input */', 'background-image: -webkit-image(asdf.png);'), - array( '/* insecure input */', 'background-image: -moz-image(asdf.png);'), - array( '/* insecure input */', 'background-image: image-set("asdf.png" 1x, "asdf.png" 2x);'), - array( '/* insecure input */', 'background-image: -webkit-image-set("asdf.png" 1x, "asdf.png" 2x);'), - array( '/* insecure input */', 'background-image: -moz-image-set("asdf.png" 1x, "asdf.png" 2x);'), + 'Remove anything after a backslash-escaped comment-start token' ), + array( '/* insecure input */', 'filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\');' ), + array( '/* insecure input */', '-ms-filter: "progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\'asdf.png\',sizingMethod=\'scale\')";' ), + array( '/* insecure input */', 'width: expression(1+1);' ), + array( '/* insecure input */', 'background-image: image(asdf.png);' ), + array( '/* insecure input */', 'background-image: -webkit-image(asdf.png);' ), + array( '/* insecure input */', 'background-image: -moz-image(asdf.png);' ), + array( '/* insecure input */', 'background-image: image-set("asdf.png" 1x, "asdf.png" 2x);' ), + array( '/* insecure input */', 'background-image: -webkit-image-set("asdf.png" 1x, "asdf.png" 2x);' ), + array( '/* insecure input */', 'background-image: -moz-image-set("asdf.png" 1x, "asdf.png" 2x);' ), ); } } diff --git a/tests/phpunit/includes/SanitizerValidateEmailTest.php b/tests/phpunit/includes/SanitizerValidateEmailTest.php index 14d799cfe0..fe0bc64e2f 100644 --- a/tests/phpunit/includes/SanitizerValidateEmailTest.php +++ b/tests/phpunit/includes/SanitizerValidateEmailTest.php @@ -2,17 +2,22 @@ class SanitizerValidateEmailTest extends MediaWikiTestCase { - private function checkEmail( $addr, $expected = true, $msg = '') { - if( $msg == '' ) { $msg = "Testing $addr"; } + private function checkEmail( $addr, $expected = true, $msg = '' ) { + if ( $msg == '' ) { + $msg = "Testing $addr"; + } + $this->assertEquals( $expected, Sanitizer::validateEmail( $addr ), $msg ); } + private function valid( $addr, $msg = '' ) { $this->checkEmail( $addr, true, $msg ); } + private function invalid( $addr, $msg = '' ) { $this->checkEmail( $addr, false, $msg ); } @@ -21,41 +26,49 @@ class SanitizerValidateEmailTest extends MediaWikiTestCase { $this->valid( 'user@example.com' ); $this->valid( 'user@example.museum' ); } + function testEmailWithUpperCaseCharactersAreValid() { $this->valid( 'USER@example.com' ); $this->valid( 'user@EXAMPLE.COM' ); $this->valid( 'user@Example.com' ); $this->valid( 'USER@eXAMPLE.com' ); } + function testEmailWithAPlusInUserName() { $this->valid( 'user+sub@example.com' ); $this->valid( 'user+@example.com' ); } + function testEmailDoesNotNeedATopLevelDomain() { $this->valid( "user@localhost" ); $this->valid( "FooBar@localdomain" ); $this->valid( "nobody@mycompany" ); } + function testEmailWithWhiteSpacesBeforeOrAfterAreInvalids() { $this->invalid( " user@host.com" ); $this->invalid( "user@host.com " ); $this->invalid( "\tuser@host.com" ); $this->invalid( "user@host.com\t" ); } + function testEmailWithWhiteSpacesAreInvalids() { $this->invalid( "User user@host" ); $this->invalid( "first last@mycompany" ); $this->invalid( "firstlast@my company" ); } + // bug 26948 : comma were matched by an incorrect regexp range function testEmailWithCommasAreInvalids() { $this->invalid( "user,foo@example.org" ); $this->invalid( "userfoo@ex,ample.org" ); } + function testEmailWithHyphens() { $this->valid( "user-foo@example.org" ); $this->valid( "userfoo@ex-ample.org" ); } + function testEmailDomainCanNotBeginWithDot() { $this->invalid( "user@." ); $this->invalid( "user@.localdomain" ); @@ -64,15 +77,19 @@ class SanitizerValidateEmailTest extends MediaWikiTestCase { $this->valid( ".@localdomain" ); $this->invalid( ".@a............" ); } + function testEmailWithFunnyCharacters() { $this->valid( "\$user!ex{this}@123.com" ); } + function testEmailTopLevelDomainCanBeNumerical() { $this->valid( "user@example.1234" ); } + function testEmailWithoutAtSignIsInvalid() { $this->invalid( 'useràexample.com' ); } + function testEmailWithOneCharacterDomainIsValid() { $this->valid( 'user@a' ); } diff --git a/tests/phpunit/includes/SeleniumConfigurationTest.php b/tests/phpunit/includes/SeleniumConfigurationTest.php index 3989fad5e7..3422c90c42 100644 --- a/tests/phpunit/includes/SeleniumConfigurationTest.php +++ b/tests/phpunit/includes/SeleniumConfigurationTest.php @@ -11,8 +11,7 @@ class SeleniumConfigurationTest extends MediaWikiTestCase { /** * String containing the a sample selenium settings */ - private $testConfig0 = -' + private $testConfig0 = ' [SeleniumSettings] browsers[firefox] = "*firefox" browsers[iexplorer] = "*iexploreproxy" @@ -35,20 +34,20 @@ testSuite[TestSuiteName] = "testSuitePath" /** * Array of expected browsers from $testConfig0 */ - private $testBrowsers0 = array( 'firefox' => '*firefox', - 'iexplorer' => '*iexploreproxy', - 'chrome' => '*chrome' + private $testBrowsers0 = array( 'firefox' => '*firefox', + 'iexplorer' => '*iexploreproxy', + 'chrome' => '*chrome' ); /** * Array of expected selenium settings from $testConfig0 */ private $testSettings0 = array( - 'host' => 'localhost', - 'port' => 'foobarr', - 'wikiUrl' => 'http://localhost/deployment', - 'username' => 'xxxxxxx', - 'userPassword' => '', - 'testBrowser' => 'chrome', + 'host' => 'localhost', + 'port' => 'foobarr', + 'wikiUrl' => 'http://localhost/deployment', + 'username' => 'xxxxxxx', + 'userPassword' => '', + 'testBrowser' => 'chrome', 'startserver' => null, 'stopserver' => null, 'seleniumserverexecpath' => null, @@ -59,16 +58,15 @@ testSuite[TestSuiteName] = "testSuitePath" * Array of expected testSuites from $testConfig0 */ private $testSuites0 = array( - 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php', - 'TestSuiteName' => 'testSuitePath' + 'SimpleSeleniumTestSuite' => 'tests/selenium/SimpleSeleniumTestSuite.php', + 'TestSuiteName' => 'testSuitePath' ); - /** * Another sample selenium settings file contents */ private $testConfig1 = -' + ' [SeleniumSettings] host = "localhost" testBrowser = "firefox" @@ -81,12 +79,12 @@ testBrowser = "firefox" * Expected selenium settings from $testConfig1 */ private $testSettings1 = array( - 'host' => 'localhost', - 'port' => null, - 'wikiUrl' => null, - 'username' => null, - 'userPassword' => null, - 'testBrowser' => 'firefox', + 'host' => 'localhost', + 'port' => null, + 'wikiUrl' => null, + 'username' => null, + 'userPassword' => null, + 'testBrowser' => 'firefox', 'startserver' => null, 'stopserver' => null, 'seleniumserverexecpath' => null, @@ -126,11 +124,10 @@ testBrowser = "firefox" $seleniumBrowsers = array(); $seleniumTestSuites = array(); - SeleniumConfig::getSeleniumSettings($seleniumSettings, + SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, $seleniumTestSuites, "Some_fake_settings_file.ini" ); - } /** @@ -143,9 +140,9 @@ testBrowser = "firefox" $seleniumTestSuites = array(); global $wgSeleniumConfigFile; $wgSeleniumConfigFile = ''; - SeleniumConfig::getSeleniumSettings($seleniumSettings, + SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, - $seleniumTestSuites); + $seleniumTestSuites ); } /** @@ -158,17 +155,17 @@ testBrowser = "firefox" global $wgSeleniumConfigFile; $this->writeToTempFile( $this->testConfig0 ); $wgSeleniumConfigFile = $this->tempFileName; - SeleniumConfig::getSeleniumSettings($seleniumSettings, + SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, - $seleniumTestSuites); - $this->assertEquals($seleniumSettings, $this->testSettings0, - 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile' + $seleniumTestSuites ); + $this->assertEquals( $seleniumSettings, $this->testSettings0, + 'The selenium settings should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumBrowsers, $this->testBrowsers0, - 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile' + $this->assertEquals( $seleniumBrowsers, $this->testBrowsers0, + 'The available browsers should have been read from the file defined in $wgSeleniumConfigFile' ); - $this->assertEquals($seleniumTestSuites, $this->testSuites0, - 'The test suites should have been read from the file defined in $wgSeleniumConfigFile' + $this->assertEquals( $seleniumTestSuites, $this->testSuites0, + 'The test suites should have been read from the file defined in $wgSeleniumConfigFile' ); } @@ -176,54 +173,50 @@ testBrowser = "firefox" * @group SeleniumFramework * @dataProvider sampleConfigs */ - public function testgetSeleniumSettings($sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { + public function testgetSeleniumSettings( $sampleConfig, $expectedSettings, $expectedBrowsers, $expectedSuites ) { $this->writeToTempFile( $sampleConfig ); $seleniumSettings = array(); $seleniumBrowsers = array(); $seleniumTestSuites = null; - SeleniumConfig::getSeleniumSettings($seleniumSettings, + SeleniumConfig::getSeleniumSettings( $seleniumSettings, $seleniumBrowsers, $seleniumTestSuites, $this->tempFileName ); - $this->assertEquals($seleniumSettings, $expectedSettings, - "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig + $this->assertEquals( $seleniumSettings, $expectedSettings, + "The selenium settings for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumBrowsers, $expectedBrowsers, - "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig + $this->assertEquals( $seleniumBrowsers, $expectedBrowsers, + "The available browsers for the following test configuration was not retrieved correctly" . $sampleConfig ); - $this->assertEquals($seleniumTestSuites, $expectedSuites, - "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig + $this->assertEquals( $seleniumTestSuites, $expectedSuites, + "The test suites for the following test configuration was not retrieved correctly" . $sampleConfig ); - - } /** * create a temp file and write text to it. * @param $testToWrite the text to write to the temp file */ - private function writeToTempFile($textToWrite) { - $this->tempFileName = tempnam(sys_get_temp_dir(), 'test_settings.'); - $tempFile = fopen( $this->tempFileName, "w" ); - fwrite($tempFile, $textToWrite); - fclose($tempFile); + private function writeToTempFile( $textToWrite ) { + $this->tempFileName = tempnam( sys_get_temp_dir(), 'test_settings.' ); + $tempFile = fopen( $this->tempFileName, "w" ); + fwrite( $tempFile, $textToWrite ); + fclose( $tempFile ); } /** * Returns an array containing: - * The contents of the selenium cingiguration ini file + * The contents of the selenium cingiguration ini file * The expected selenium configuration array that getSeleniumSettings should return * The expected available browsers array that getSeleniumSettings should return * The expected test suites arrya that getSeleniumSettings should return */ public function sampleConfigs() { return array( - array($this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ), - array($this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) + array( $this->testConfig0, $this->testSettings0, $this->testBrowsers0, $this->testSuites0 ), + array( $this->testConfig1, $this->testSettings1, $this->testBrowsers1, $this->testSuites1 ) ); } - - } diff --git a/tests/phpunit/includes/StringUtilsTest.php b/tests/phpunit/includes/StringUtilsTest.php index 401b322db3..ae003aedd5 100644 --- a/tests/phpunit/includes/StringUtilsTest.php +++ b/tests/phpunit/includes/StringUtilsTest.php @@ -9,8 +9,8 @@ class StringUtilsTest extends MediaWikiTestCase { * @cover StringUtils::isUtf8 * @dataProvider provideStringsForIsUtf8Check */ - function testIsUtf8WithMbstring($expected, $string ) { - if( !function_exists( 'mb_check_encoding' ) ) { + function testIsUtf8WithMbstring( $expected, $string ) { + if ( !function_exists( 'mb_check_encoding' ) ) { $this->markTestSkipped( 'Test requires the mbstring PHP extension' ); } $this->assertEquals( $expected, @@ -27,7 +27,7 @@ class StringUtilsTest extends MediaWikiTestCase { * @cover StringUtils::isUtf8 * @dataProvider provideStringsForIsUtf8Check */ - function testIsUtf8WithPhpFallbackImplementation($expected, $string ) { + function testIsUtf8WithPhpFallbackImplementation( $expected, $string ) { $this->assertEquals( $expected, StringUtils::isUtf8( $string, /** disable mbstring: */ true ), 'Testing string "' . $this->escaped( $string ) . '" with pure PHP implementation' @@ -39,11 +39,11 @@ class StringUtilsTest extends MediaWikiTestCase { */ function escaped( $string ) { $escaped = ''; - for($i=0; $i 127 ) { - $escaped .='\x' . dechex($val); + $val = ord( $char ); + if ( $val > 127 ) { + $escaped .= '\x' . dechex( $val ); } else { $escaped .= $char; } diff --git a/tests/phpunit/includes/TimeAdjustTest.php b/tests/phpunit/includes/TimeAdjustTest.php index 07ce84bf02..a58702b257 100644 --- a/tests/phpunit/includes/TimeAdjustTest.php +++ b/tests/phpunit/includes/TimeAdjustTest.php @@ -20,14 +20,14 @@ class TimeAdjustTest extends MediaWikiLangTestCase { #  Collection of parameters for Language_t_Offset. # Format: date to be formatted, localTZoffset value, expected date $userAdjust_tests = array( - array( 20061231235959, 0, 20061231235959 ), - array( 20061231235959, 5, 20070101000459 ), - array( 20061231235959, 15, 20070101001459 ), - array( 20061231235959, 60, 20070101005959 ), - array( 20061231235959, 90, 20070101012959 ), + array( 20061231235959, 0, 20061231235959 ), + array( 20061231235959, 5, 20070101000459 ), + array( 20061231235959, 15, 20070101001459 ), + array( 20061231235959, 60, 20070101005959 ), + array( 20061231235959, 90, 20070101012959 ), array( 20061231235959, 120, 20070101015959 ), array( 20061231235959, 540, 20070101085959 ), - array( 20061231235959, -5, 20061231235459 ), + array( 20061231235959, -5, 20061231235459 ), array( 20061231235959, -30, 20061231232959 ), array( 20061231235959, -60, 20061231225959 ), ); diff --git a/tests/phpunit/includes/TimestampTest.php b/tests/phpunit/includes/TimestampTest.php index de2f855ef5..91c23ec638 100644 --- a/tests/phpunit/includes/TimestampTest.php +++ b/tests/phpunit/includes/TimestampTest.php @@ -14,6 +14,7 @@ class TimestampTest extends MediaWikiTestCase { 'wgLang' => Language::factory( 'en' ), ) ); } + /** * Test parsing of valid timestamps and outputing to MW format. * @dataProvider provideValidTimestamps diff --git a/tests/phpunit/includes/TitlePermissionTest.php b/tests/phpunit/includes/TitlePermissionTest.php index 05f140805b..e2c079a7f5 100644 --- a/tests/phpunit/includes/TitlePermissionTest.php +++ b/tests/phpunit/includes/TitlePermissionTest.php @@ -116,7 +116,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_MAIN ); $this->setUserPerm( "createpage" ); $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setTitle( NS_MAIN ); $this->setUserPerm( "createtalk" ); @@ -127,7 +127,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_TALK ); $this->setUserPerm( "createtalk" ); $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setTitle( NS_TALK ); $this->setUserPerm( "createpage" ); @@ -142,7 +142,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_MAIN ); $this->setUserPerm( "createpage" ); $res = $this->title->getUserPermissionsErrors( 'create', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setTitle( NS_MAIN ); $this->setUserPerm( "createtalk" ); @@ -239,7 +239,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_MAIN ); $this->setUser( 'anon' ); $this->setUserPerm( "move" ); - $this->runGroupPermissions( 'move', array( ) ); + $this->runGroupPermissions( 'move', array() ); $this->setUserPerm( "" ); $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ), @@ -250,12 +250,12 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runGroupPermissions( 'move', array( array( 'movenotallowed' ) ) ); $this->setUserPerm( "move" ); - $this->runGroupPermissions( 'move', array( ) ); + $this->runGroupPermissions( 'move', array() ); $this->setUser( 'anon' ); $this->setUserPerm( 'move' ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setUserPerm( '' ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); @@ -266,7 +266,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setUser( $this->userName ); $this->setUserPerm( array( "move", "move-rootuserpages" ) ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setUserPerm( "move" ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); @@ -275,25 +275,25 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setUser( 'anon' ); $this->setUserPerm( array( "move", "move-rootuserpages" ) ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setTitle( NS_USER, "User/subpage" ); $this->setUserPerm( array( "move", "move-rootuserpages" ) ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setUserPerm( "move" ); $res = $this->title->getUserPermissionsErrors( 'move-target', $this->user ); - $this->assertEquals( array( ), $res ); + $this->assertEquals( array(), $res ); $this->setUser( 'anon' ); $check = array( 'edit' => array( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ) ), - array( array( 'badaccess-group0' ) ), - array( ), true ), - 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ), - array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ), - array( array( 'protect-cantedit' ) ), false ), - '' => array( array( ), array( ), array( ), true ) ); + array( array( 'badaccess-group0' ) ), + array(), true ), + 'protect' => array( array( array( 'badaccess-groups', "[[$prefix:Administrators|Administrators]]", 1 ), array( 'protect-cantedit' ) ), + array( array( 'badaccess-group0' ), array( 'protect-cantedit' ) ), + array( array( 'protect-cantedit' ) ), false ), + '' => array( array(), array(), array(), true ) ); foreach ( array( "edit", "protect", "" ) as $action ) { $this->setUserPerm( null ); @@ -325,7 +325,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase { function runGroupPermissions( $action, $result, $result2 = null ) { global $wgGroupPermissions; - if ( $result2 === null ) $result2 = $result; + if ( $result2 === null ) { + $result2 = $result; + } $wgGroupPermissions['autoconfirmed']['move'] = false; $wgGroupPermissions['user']['move'] = false; @@ -355,48 +357,48 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setTitle( NS_SPECIAL ); $this->assertEquals( array( array( 'badaccess-group0' ), array( 'ns-specialprotected' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->setTitle( NS_MAIN ); $this->setUserPerm( 'bogus' ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->setTitle( NS_MAIN ); $this->setUserPerm( '' ); $this->assertEquals( array( array( 'badaccess-group0' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $wgNamespaceProtection[NS_USER] = array( 'bogus' ); $this->setTitle( NS_USER ); $this->setUserPerm( '' ); $this->assertEquals( array( array( 'badaccess-group0' ), array( 'namespaceprotected', 'User' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->setTitle( NS_MEDIAWIKI ); $this->setUserPerm( 'bogus' ); $this->assertEquals( array( array( 'protectedinterface' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->setTitle( NS_MEDIAWIKI ); $this->setUserPerm( 'bogus' ); $this->assertEquals( array( array( 'protectedinterface' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $wgNamespaceProtection = null; $this->setUserPerm( 'bogus' ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->assertEquals( true, - $this->title->userCan( 'bogus', $this->user ) ); + $this->title->userCan( 'bogus', $this->user ) ); $this->setUserPerm( '' ); $this->assertEquals( array( array( 'badaccess-group0' ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->assertEquals( false, - $this->title->userCan( 'bogus', $this->user ) ); + $this->title->userCan( 'bogus', $this->user ) ); } function testCssAndJavascriptPermissions() { @@ -412,7 +414,7 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->runCSSandJSPermissions( array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ), array( array( 'badaccess-group0' ) ), - array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) ); + array( array( 'badaccess-group0' ), array( 'customcssprotected' ) ) ); $this->setTitle( NS_USER, $this->altUserName . '/tempo' ); $this->runCSSandJSPermissions( @@ -424,28 +426,28 @@ class TitlePermissionTest extends MediaWikiLangTestCase { function runCSSandJSPermissions( $result0, $result1, $result2 ) { $this->setUserPerm( '' ); $this->assertEquals( $result0, - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->setUserPerm( 'editusercss' ); $this->assertEquals( $result1, - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->setUserPerm( 'edituserjs' ); $this->assertEquals( $result2, - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->setUserPerm( 'editusercssjs' ); $this->assertEquals( array( array( 'badaccess-group0' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->setUserPerm( array( 'edituserjs', 'editusercss' ) ); $this->assertEquals( array( array( 'badaccess-group0' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); } function testPageRestrictions() { @@ -458,65 +460,65 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->setUserPerm( "edit" ); $this->title->mRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'edit', - $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'edit', + $this->user ) ); $this->assertEquals( true, - $this->title->quickUserCan( 'edit', $this->user ) ); + $this->title->quickUserCan( 'edit', $this->user ) ); $this->title->mRestrictions = array( "edit" => array( 'bogus', "sysop", "protect", "" ), - "bogus" => array( 'bogus', "sysop", "protect", "" ) ); + "bogus" => array( 'bogus', "sysop", "protect", "" ) ); $this->assertEquals( array( array( 'badaccess-group0' ), - array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + array( 'protectedpagetext', 'bogus' ), + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'edit', - $this->user ) ); + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'edit', + $this->user ) ); $this->setUserPerm( "" ); $this->assertEquals( array( array( 'badaccess-group0' ), - array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + array( 'protectedpagetext', 'bogus' ), + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->assertEquals( array( array( 'badaccess-groups', "*, [[$prefix:Users|Users]]", 2 ), - array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'edit', - $this->user ) ); + array( 'protectedpagetext', 'bogus' ), + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'edit', + $this->user ) ); $this->setUserPerm( array( "edit", "editprotected" ) ); $this->assertEquals( array( array( 'badaccess-group0' ), - array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'edit', - $this->user ) ); + array( 'protectedpagetext', 'bogus' ), + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'edit', + $this->user ) ); $this->title->mCascadeRestriction = true; $this->assertEquals( false, - $this->title->quickUserCan( 'bogus', $this->user ) ); + $this->title->quickUserCan( 'bogus', $this->user ) ); $this->assertEquals( false, - $this->title->quickUserCan( 'edit', $this->user ) ); + $this->title->quickUserCan( 'edit', $this->user ) ); $this->assertEquals( array( array( 'badaccess-group0' ), - array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'bogus', - $this->user ) ); + array( 'protectedpagetext', 'bogus' ), + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'bogus', + $this->user ) ); $this->assertEquals( array( array( 'protectedpagetext', 'bogus' ), - array( 'protectedpagetext', 'protect' ), - array( 'protectedpagetext', 'protect' ) ), - $this->title->getUserPermissionsErrors( 'edit', - $this->user ) ); + array( 'protectedpagetext', 'protect' ), + array( 'protectedpagetext', 'protect' ) ), + $this->title->getUserPermissionsErrors( 'edit', + $this->user ) ); } function testCascadingSourcesRestrictions() { @@ -527,15 +529,15 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->mCascadingRestrictions = array( "bogus" => array( 'bogus', "sysop", "protect", "" ) ); $this->assertEquals( false, - $this->title->userCan( 'bogus', $this->user ) ); + $this->title->userCan( 'bogus', $this->user ) ); $this->assertEquals( array( array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ), - array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ), - $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); + array( "cascadeprotected", 2, "* [[:Bogus]]\n* [[:UnBogus]]\n" ) ), + $this->title->getUserPermissionsErrors( 'bogus', $this->user ) ); $this->assertEquals( true, - $this->title->userCan( 'edit', $this->user ) ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); + $this->title->userCan( 'edit', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'edit', $this->user ) ); } @@ -549,60 +551,60 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->title->mCascadeRestriction = false; $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ), - $this->title->getUserPermissionsErrors( 'create', $this->user ) ); + $this->title->getUserPermissionsErrors( 'create', $this->user ) ); $this->assertEquals( false, - $this->title->userCan( 'create', $this->user ) ); + $this->title->userCan( 'create', $this->user ) ); $this->title->mTitleProtection['pt_create_perm'] = 'sysop'; $this->setUserPerm( array( 'createpage', 'protect' ) ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'create', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'create', $this->user ) ); $this->assertEquals( true, - $this->title->userCan( 'create', $this->user ) ); + $this->title->userCan( 'create', $this->user ) ); $this->setUserPerm( array( 'createpage' ) ); $this->assertEquals( array( array( 'titleprotected', 'Useruser', 'test' ) ), - $this->title->getUserPermissionsErrors( 'create', $this->user ) ); + $this->title->getUserPermissionsErrors( 'create', $this->user ) ); $this->assertEquals( false, - $this->title->userCan( 'create', $this->user ) ); + $this->title->userCan( 'create', $this->user ) ); $this->setTitle( NS_MEDIA, "test page" ); $this->setUserPerm( array( "move" ) ); $this->assertEquals( false, - $this->title->userCan( 'move', $this->user ) ); + $this->title->userCan( 'move', $this->user ) ); $this->assertEquals( array( array( 'immobile-source-namespace', 'Media' ) ), - $this->title->getUserPermissionsErrors( 'move', $this->user ) ); + $this->title->getUserPermissionsErrors( 'move', $this->user ) ); $this->setTitle( NS_HELP, "test page" ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'move', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'move', $this->user ) ); $this->assertEquals( true, - $this->title->userCan( 'move', $this->user ) ); + $this->title->userCan( 'move', $this->user ) ); $this->title->mInterwiki = "no"; $this->assertEquals( array( array( 'immobile-source-page' ) ), - $this->title->getUserPermissionsErrors( 'move', $this->user ) ); + $this->title->getUserPermissionsErrors( 'move', $this->user ) ); $this->assertEquals( false, - $this->title->userCan( 'move', $this->user ) ); + $this->title->userCan( 'move', $this->user ) ); $this->setTitle( NS_MEDIA, "test page" ); $this->assertEquals( false, - $this->title->userCan( 'move-target', $this->user ) ); + $this->title->userCan( 'move-target', $this->user ) ); $this->assertEquals( array( array( 'immobile-target-namespace', 'Media' ) ), - $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); + $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); $this->setTitle( NS_HELP, "test page" ); - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); $this->assertEquals( true, - $this->title->userCan( 'move-target', $this->user ) ); + $this->title->userCan( 'move-target', $this->user ) ); $this->title->mInterwiki = "no"; $this->assertEquals( array( array( 'immobile-target-page' ) ), - $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); + $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); $this->assertEquals( false, - $this->title->userCan( 'move-target', $this->user ) ); + $this->title->userCan( 'move-target', $this->user ) ); } @@ -616,28 +618,28 @@ class TitlePermissionTest extends MediaWikiLangTestCase { # $short $this->assertEquals( array( array( 'confirmedittext' ) ), - $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); + $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); $wgEmailConfirmToEdit = false; $this->assertEquals( true, $this->title->userCan( 'move-target', $this->user ) ); # $wgEmailConfirmToEdit && !$user->isEmailConfirmed() && $action != 'createaccount' - $this->assertEquals( array( ), - $this->title->getUserPermissionsErrors( 'move-target', - $this->user ) ); + $this->assertEquals( array(), + $this->title->getUserPermissionsErrors( 'move-target', + $this->user ) ); global $wgLang; $prev = time(); $now = time() + 120; $this->user->mBlockedby = $this->user->getId(); $this->user->mBlock = new Block( '127.0.8.1', 0, $this->user->getId(), - 'no reason given', $prev + 3600, 1, 0 ); + 'no reason given', $prev + 3600, 1, 0 ); $this->user->mBlock->mTimestamp = 0; $this->assertEquals( array( array( 'autoblockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, 'infinite', '127.0.8.1', - $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ), + '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', + 'Useruser', null, 'infinite', '127.0.8.1', + $wgLang->timeanddate( wfTimestamp( TS_MW, $prev ), true ) ) ), $this->title->getUserPermissionsErrors( 'move-target', - $this->user ) ); + $this->user ) ); $this->assertEquals( false, $this->title->userCan( 'move-target', $this->user ) ); // quickUserCan should ignore user blocks @@ -648,9 +650,9 @@ class TitlePermissionTest extends MediaWikiLangTestCase { $this->user->mBlockedby = $this->user->getName(); $this->user->mBlock = new Block( '127.0.8.1', 0, 1, 'no reason given', $now, 0, 10 ); $this->assertEquals( array( array( 'blockedtext', - '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', - 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', - $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ), + '[[User:Useruser|Useruser]]', 'no reason given', '127.0.0.1', + 'Useruser', null, '23:00, 31 December 1969', '127.0.8.1', + $wgLang->timeanddate( wfTimestamp( TS_MW, $now ), true ) ) ), $this->title->getUserPermissionsErrors( 'move-target', $this->user ) ); # $action != 'read' && $action != 'createaccount' && $user->isBlockedFrom( $this ) diff --git a/tests/phpunit/includes/TitleTest.php b/tests/phpunit/includes/TitleTest.php index 6399d48378..3dc5e82215 100644 --- a/tests/phpunit/includes/TitleTest.php +++ b/tests/phpunit/includes/TitleTest.php @@ -6,7 +6,6 @@ * ^--- needed for language cache stuff */ class TitleTest extends MediaWikiTestCase { - protected function setUp() { parent::setUp(); @@ -55,10 +54,10 @@ class TitleTest extends MediaWikiTestCase { array( 'Special:Version/param', 'param' ), ); } - + /** * Auth-less test of Title::isValidMoveOperation - * + * * @group Database * @param string $source * @param string $target @@ -78,7 +77,7 @@ class TitleTest extends MediaWikiTestCase { } } } - + /** * Provides test parameter values for testIsValidMoveOperation() */ @@ -100,13 +99,12 @@ class TitleTest extends MediaWikiTestCase { * @covers Title::checkReadPermission * @dataProvider dataWgWhitelistReadRegexp */ - function testWgWhitelistReadRegexp($whitelistRegexp, $source, $action, $expected) { - + function testWgWhitelistReadRegexp( $whitelistRegexp, $source, $action, $expected ) { // $wgWhitelistReadRegexp must be an array. Since the provided test cases // usually have only one regex, it is more concise to write the lonely regex // as a string. Thus we cast to an array() to honor $wgWhitelistReadRegexp // type requisite. - if( is_string( $whitelistRegexp ) ) { + if ( is_string( $whitelistRegexp ) ) { $whitelistRegexp = array( $whitelistRegexp ); } @@ -126,8 +124,8 @@ class TitleTest extends MediaWikiTestCase { $wgWhitelistRead = array( 'some random non sense title' ); global $wgWhitelistReadRegexp; - $oldWhitelistRegexp = $wgWhitelistReadRegexp; - $wgWhitelistReadRegexp = $whitelistRegexp ; + $oldWhitelistRegexp = $wgWhitelistReadRegexp; + $wgWhitelistReadRegexp = $whitelistRegexp; // Just use $wgUser which in test is a user object for '127.0.0.1' global $wgUser; @@ -141,12 +139,11 @@ class TitleTest extends MediaWikiTestCase { $wgWhitelistRead = $oldWhitelist; $wgWhitelistReadRegexp = $oldWhitelistRegexp; - if( is_bool( $expected ) ) { + if ( is_bool( $expected ) ) { # Forge the assertion message depending on the assertion expectation $allowableness = $expected ? " should be allowed" - : " should NOT be allowed" - ; + : " should NOT be allowed"; $this->assertEquals( $expected, $errors, "User action '$action' on [[$source]] $allowableness." ); } else { $errors = $this->flattenErrorsArray( $errors ); @@ -160,7 +157,7 @@ class TitleTest extends MediaWikiTestCase { * Provides test parameter values for testWgWhitelistReadRegexp() */ function dataWgWhitelistReadRegexp() { - $ALLOWED = true; + $ALLOWED = true; $DISALLOWED = false; return array( @@ -202,9 +199,9 @@ class TitleTest extends MediaWikiTestCase { } return $result; } - + public static function provideTestIsValidMoveOperation() { - return array( + return array( array( 'Test', 'Test', 'selfmove' ), array( 'File:Test.jpg', 'Page', 'imagenocrossnamespace' ) ); @@ -246,28 +243,28 @@ class TitleTest extends MediaWikiTestCase { array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', false ), array( 'zh', 'Help:I_need_somebody', 'zh', 'zh-tw', false ), - array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ), - array( 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ), - array( 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ), - array( 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ), - array( 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ), - array( 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ), - array( 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ), - array( 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ), - - array( 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ), - array( 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ), - array( 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ), - array( 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ), - array( 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ), - array( 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ), - array( 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ), - array( 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ), - array( 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ), - array( 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ), - - array( 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ), - array( 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ), + array( 'es', 'Help:I_need_somebody', 'es', 'zh-tw', 'zh-cn' ), + array( 'es', 'MediaWiki:About', 'es', 'zh-tw', 'zh-cn' ), + array( 'es', 'MediaWiki:About/', 'es', 'zh-tw', 'zh-cn' ), + array( 'de', 'MediaWiki:About/de', 'es', 'zh-tw', 'zh-cn' ), + array( 'en', 'MediaWiki:Common.js', 'es', 'zh-tw', 'zh-cn' ), + array( 'en', 'MediaWiki:Common.css', 'es', 'zh-tw', 'zh-cn' ), + array( 'en', 'User:JohnDoe/Common.js', 'es', 'zh-tw', 'zh-cn' ), + array( 'en', 'User:JohnDoe/Monobook.css', 'es', 'zh-tw', 'zh-cn' ), + + array( 'zh-cn', 'Help:I_need_somebody', 'zh', 'zh-tw', 'zh-cn' ), + array( 'zh', 'MediaWiki:About', 'zh', 'zh-tw', 'zh-cn' ), + array( 'zh', 'MediaWiki:About/', 'zh', 'zh-tw', 'zh-cn' ), + array( 'de', 'MediaWiki:About/de', 'zh', 'zh-tw', 'zh-cn' ), + array( 'zh-cn', 'MediaWiki:About/zh-cn', 'zh', 'zh-tw', 'zh-cn' ), + array( 'zh-tw', 'MediaWiki:About/zh-tw', 'zh', 'zh-tw', 'zh-cn' ), + array( 'en', 'MediaWiki:Common.js', 'zh', 'zh-tw', 'zh-cn' ), + array( 'en', 'MediaWiki:Common.css', 'zh', 'zh-tw', 'zh-cn' ), + array( 'en', 'User:JohnDoe/Common.js', 'zh', 'zh-tw', 'zh-cn' ), + array( 'en', 'User:JohnDoe/Monobook.css', 'zh', 'zh-tw', 'zh-cn' ), + + array( 'zh-tw', 'Special:NewPages', 'es', 'zh-tw', 'zh-cn' ), + array( 'zh-tw', 'Special:NewPages', 'zh', 'zh-tw', 'zh-cn' ), ); } @@ -275,7 +272,7 @@ class TitleTest extends MediaWikiTestCase { /** * @dataProvider provideBaseTitleCases */ - function testExtractingBaseTextFromTitle( $title, $expected, $msg='' ) { + function testExtractingBaseTextFromTitle( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getBaseText(), @@ -286,15 +283,15 @@ class TitleTest extends MediaWikiTestCase { function provideBaseTitleCases() { return array( # Title, expected base, optional message - array('User:John_Doe/subOne/subTwo', 'John Doe/subOne' ), - array('User:Foo/Bar/Baz', 'Foo/Bar' ), + array( 'User:John_Doe/subOne/subTwo', 'John Doe/subOne' ), + array( 'User:Foo/Bar/Baz', 'Foo/Bar' ), ); } /** * @dataProvider provideRootTitleCases */ - function testExtractingRootTextFromTitle( $title, $expected, $msg='' ) { + function testExtractingRootTextFromTitle( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getRootText(), @@ -305,8 +302,8 @@ class TitleTest extends MediaWikiTestCase { public static function provideRootTitleCases() { return array( # Title, expected base, optional message - array('User:John_Doe/subOne/subTwo', 'John Doe' ), - array('User:Foo/Bar/Baz', 'Foo' ), + array( 'User:John_Doe/subOne/subTwo', 'John Doe' ), + array( 'User:Foo/Bar/Baz', 'Foo' ), ); } @@ -314,7 +311,7 @@ class TitleTest extends MediaWikiTestCase { * @todo Handle $wgNamespacesWithSubpages cases * @dataProvider provideSubpageTitleCases */ - function testExtractingSubpageTextFromTitle( $title, $expected, $msg='' ) { + function testExtractingSubpageTextFromTitle( $title, $expected, $msg = '' ) { $title = Title::newFromText( $title ); $this->assertEquals( $expected, $title->getSubpageText(), @@ -325,9 +322,8 @@ class TitleTest extends MediaWikiTestCase { function provideSubpageTitleCases() { return array( # Title, expected base, optional message - array('User:John_Doe/subOne/subTwo', 'subTwo' ), - array('User:John_Doe/subOne', 'subOne' ), + array( 'User:John_Doe/subOne/subTwo', 'subTwo' ), + array( 'User:John_Doe/subOne', 'subOne' ), ); } - } diff --git a/tests/phpunit/includes/UserTest.php b/tests/phpunit/includes/UserTest.php index a9dfca1d6d..e777179a24 100644 --- a/tests/phpunit/includes/UserTest.php +++ b/tests/phpunit/includes/UserTest.php @@ -7,7 +7,6 @@ define( 'NS_UNITTEST_TALK', 5601 ); * @group Database */ class UserTest extends MediaWikiTestCase { - /** * @var User */ @@ -62,6 +61,7 @@ class UserTest extends MediaWikiTestCase { $this->assertContains( 'modifytest', $rights ); $this->assertNotContains( 'nukeworld', $rights ); } + public function testRevokePermissions() { $rights = User::getGroupPermissions( array( 'unittesters', 'formertesters' ) ); $this->assertNotContains( 'runtest', $rights ); @@ -122,15 +122,15 @@ class UserTest extends MediaWikiTestCase { array( '', false, 'Empty string' ), array( ' ', false, 'Blank space' ), array( 'abcd', false, 'Starts with small letter' ), - array( 'Ab/cd', false, 'Contains slash' ), - array( 'Ab cd' , true, 'Whitespace' ), - array( '192.168.1.1', false, 'IP' ), + array( 'Ab/cd', false, 'Contains slash' ), + array( 'Ab cd', true, 'Whitespace' ), + array( '192.168.1.1', false, 'IP' ), array( 'User:Abcd', false, 'Reserved Namespace' ), - array( '12abcd232' , true , 'Starts with Numbers' ), - array( '?abcd' , true, 'Start with ? mark' ), + array( '12abcd232', true, 'Starts with Numbers' ), + array( '?abcd', true, 'Start with ? mark' ), array( '#abcd', false, 'Start with #' ), - array( 'Abcdകഖഗഘ', true, ' Mixed scripts' ), - array( 'ജോസ്‌തോമസ്', false, 'ZWNJ- Format control character' ), + array( 'Abcdകഖഗഘ', true, ' Mixed scripts' ), + array( 'ജോസ്‌തോമസ്', false, 'ZWNJ- Format control character' ), array( 'Ab cd', false, ' Ideographic space' ), ); } @@ -174,7 +174,7 @@ class UserTest extends MediaWikiTestCase { // let the user have a few (3) edits $page = WikiPage::factory( Title::newFromText( 'Help:UserTest_EditCount' ) ); - for( $i = 0; $i < 3; $i++ ) { + for ( $i = 0; $i < 3; $i++ ) { $page->doEdit( (string)$i, 'test', 0, false, $user ); } diff --git a/tests/phpunit/includes/WebRequestTest.php b/tests/phpunit/includes/WebRequestTest.php index 153ff78700..46f802553e 100644 --- a/tests/phpunit/includes/WebRequestTest.php +++ b/tests/phpunit/includes/WebRequestTest.php @@ -212,9 +212,9 @@ class WebRequestTest extends MediaWikiTestCase { /** * @dataProvider provideLanguageData */ - function testAcceptLang($acceptLanguageHeader, $expectedLanguages, $description) { + function testAcceptLang( $acceptLanguageHeader, $expectedLanguages, $description ) { $_SERVER = array( 'HTTP_ACCEPT_LANGUAGE' => $acceptLanguageHeader ); $request = new WebRequest(); - $this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description); + $this->assertSame( $request->getAcceptLang(), $expectedLanguages, $description ); } } -- 2.20.1